emr-bridge 1.1.1 → 1.2.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
@@ -38,18 +38,21 @@ provideFromMain(contextIsolation)
38
38
 
39
39
  ### Static methods and properties
40
40
 
41
- Use **publicStaticMethod**/**publicStaticProperty** decorators
41
+ **Experimental decorators**
42
+
43
+ Use **publicStaticMethodExp**/**publicStaticPropertyExp**.
42
44
 
43
45
  ```ts
44
46
  // Main process
45
- import { publicStaticMethod, publicStaticProperty, Access } from 'emr-bridge'
47
+
48
+ import { publicStaticMethodExp, publicStaticPropertyExp, Access } from 'emr-bridge'
46
49
 
47
50
  class User {
48
51
  private static name = 'Name'
49
52
  private static age = 20
50
53
  private static money = 1000
51
54
 
52
- @publicStaticProperty('userBalance')
55
+ @publicStaticPropertyExp('userBalance')
53
56
  static get balance(): string {
54
57
  return `${this.money}$`
55
58
  }
@@ -58,7 +61,7 @@ class User {
58
61
  this.money = Number(newBalance.split('$')[0])
59
62
  }
60
63
 
61
- @publicStaticProperty({
64
+ @publicStaticPropertyExp({
62
65
  name: 'userInfo',
63
66
  access: Access.get
64
67
  })
@@ -66,12 +69,59 @@ class User {
66
69
  return `Name: '${this.name}'; Age: '${this.age}'; Money: '${this.money}';`
67
70
  }
68
71
 
69
- @publicStaticMethod()
72
+ @publicStaticMethodExp()
73
+ static setName(newName: string): void {
74
+ this.name = newName
75
+ }
76
+
77
+ @publicStaticMethodExp('getUserAge')
78
+ static getAge(): number {
79
+ return this.age
80
+ }
81
+ }
82
+ ```
83
+
84
+ **New decorators**
85
+
86
+ Use **publicMethod**/**publicProperty**/**publicGetter**/**publicSetter**.
87
+
88
+ ```ts
89
+ // Main process
90
+
91
+ import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge'
92
+
93
+ class User {
94
+ private static name = 'Name'
95
+ private static age = 20
96
+ private static money = 1000
97
+
98
+ @publicGetter('userBalance')
99
+ static get balance(): string {
100
+ return `${this.money}$`
101
+ }
102
+
103
+ @publicSetter('userBalance')
104
+ static set balance(newBalance: string) {
105
+ this.money = Number(newBalance.split('$')[0])
106
+ }
107
+
108
+ @publicGetter({
109
+ name: 'userInfo',
110
+ access: Access.get
111
+ })
112
+ static get info(): string {
113
+ return `Name: '${this.name}'; Age: '${this.age}'; Money: '${this.money}';`
114
+ }
115
+
116
+ @publicProperty()
117
+ static id = 'ID_AJWD3KLW23DK231K'
118
+
119
+ @publicMethod()
70
120
  static setName(newName: string): void {
71
121
  this.name = newName
72
122
  }
73
123
 
74
- @publicStaticMethod('getUserAge')
124
+ @publicMethod('getUserAge')
75
125
  static getAge(): number {
76
126
  return this.age
77
127
  }
@@ -80,29 +130,79 @@ class User {
80
130
 
81
131
  ### Methods and properties
82
132
 
83
- Use **providePublic** and **publicMethod**/**publicProperty** decorators.
133
+ **Experimental decorators**
134
+
135
+ Use **providePublic** and **publicMethodExp**/**publicPropertyExp**.
84
136
 
85
137
  Without calling **providePublic**, public methods will not be accessible from renderer.
86
138
 
87
139
  ```ts
88
140
  // Main process
89
- import { providePublic, publicMethod, publicProperty, Access } from 'emr-bridge'
141
+ import { providePublic, publicMethodExp, publicPropertyExp, Access } from 'emr-bridge'
90
142
 
91
143
  class User {
92
144
  private name = 'Name'
93
145
  private age = 20
94
146
  private money = 1000
95
147
 
148
+ @publicPropertyExp()
149
+ get balance(): string {
150
+ return `${this.money}$`
151
+ }
152
+
153
+ set balance(newBalance: string) {
154
+ this.money = Number(newBalance.split('$')[0])
155
+ }
156
+
157
+ @publicPropertyExp({
158
+ name: 'userInfo',
159
+ access: Access.get
160
+ })
161
+ get info(): string {
162
+ return `Name: '${this.name}'; Age: '${this.age}'; Money: '${this.money}';`
163
+ }
164
+
165
+ @publicMethodExp()
166
+ setName(newName: string): void {
167
+ this.name = newName
168
+ }
169
+
170
+ @publicMethodExp('getUserAge')
171
+ getAge(): number {
172
+ return this.age
173
+ }
174
+ }
175
+
176
+ const user = providePublic(new User())
177
+ ```
178
+
179
+ **New decorators**
180
+
181
+ Use **publicMethod**/**publicProperty**/**publicGetter**/**publicSetter**.
182
+
183
+ ```ts
184
+ // Main process
185
+ import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge'
186
+
187
+ class User {
188
+ private name = 'Name'
189
+ private age = 20
190
+ private money = 1000
191
+
96
192
  @publicProperty()
193
+ id = 'ID_AJWD3KLW23DK231K'
194
+
195
+ @publicGetter()
97
196
  get balance(): string {
98
197
  return `${this.money}$`
99
198
  }
100
199
 
200
+ @publicSetter()
101
201
  set balance(newBalance: string) {
102
202
  this.money = Number(newBalance.split('$')[0])
103
203
  }
104
204
 
105
- @publicProperty({
205
+ @publicGetter({
106
206
  name: 'userInfo',
107
207
  access: Access.get
108
208
  })
@@ -121,7 +221,7 @@ class User {
121
221
  }
122
222
  }
123
223
 
124
- const user = providePublic(new User())
224
+ const user = new User()
125
225
  ```
126
226
 
127
227
  ### Functions and variables
@@ -169,13 +269,13 @@ Accessing an entity outside the specified scope will result in an error being th
169
269
  // Main process
170
270
 
171
271
  // static and non-static
172
- import { Scope, Access, providePublic, publicStaticMethod, publicMethod, publicProperty } from 'emr-bridge'
272
+ import { Scope, Access, providePublic, publicStaticMethodExp, publicMethodExp, publicPropertyExp } from 'emr-bridge'
173
273
 
174
274
  class User {
175
275
  private static age = 20
176
276
  private name = 'Name'
177
277
 
178
- @publicProperty({
278
+ @publicPropertyExp({
179
279
  scope: Scope.preload,
180
280
  access: Access.get
181
281
  })
@@ -183,12 +283,12 @@ class User {
183
283
  return 30
184
284
  }
185
285
 
186
- @publicStaticMethod({ scope: Scope.preload })
286
+ @publicStaticMethodExp({ scope: Scope.preload })
187
287
  static getAge(): number {
188
288
  return this.age
189
289
  }
190
290
 
191
- @publicMethod({
291
+ @publicMethodExp({
192
292
  name: 'getUserName',
193
293
  scope: Scope.renderer
194
294
  })
@@ -228,18 +328,18 @@ Using an entity outside the specified scope _will cause an error_.
228
328
  // Main process
229
329
 
230
330
  // static and non-static
231
- import { publicStaticProperty, publicProperty, providePublic, Access } from 'emr-bridge'
331
+ import { publicStaticPropertyExp, publicPropertyExp, providePublic, Access } from 'emr-bridge'
232
332
 
233
333
  class User {
234
334
  private static name = 'Name'
235
335
  private static surname = 'Surname'
236
336
 
237
- @publicStaticProperty({ access: Access.get })
337
+ @publicStaticPropertyExp({ access: Access.get })
238
338
  static get fullName(): string {
239
339
  return `${this.name} ${this.surname}`
240
340
  }
241
341
 
242
- @publicProperty({
342
+ @publicPropertyExp({
243
343
  name: 'userAge',
244
344
  access: Access.get
245
345
  })
package/lib/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export { Access, Scope } from './enums';
2
- export { providePublic, publicFunction, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty, publicVariable } from './scripts/publish';
2
+ export { publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
3
+ export { providePublic, publicMethod as publicMethodExp, publicProperty as publicPropertyExp, publicStaticMethod as publicStaticMethodExp, publicStaticProperty as publicStaticPropertyExp } from './scripts/oldDecorators';
4
+ export { publicFunction, publicVariable } from './scripts/publish';
3
5
  export type { IPublishMethodArgs, IPublishPropertyArgs, PublicFunction, PublicProperty } from './types';
package/lib/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  export { Access, Scope } from './enums';
2
- export { providePublic, publicFunction, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty, publicVariable } from './scripts/publish';
2
+ export { publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
3
+ export { providePublic, publicMethod as publicMethodExp, publicProperty as publicPropertyExp, publicStaticMethod as publicStaticMethodExp, publicStaticProperty as publicStaticPropertyExp } from './scripts/oldDecorators';
4
+ export { publicFunction, publicVariable } from './scripts/publish';
package/lib/preload.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { Main } from './scripts/Main';
2
- export { provideFromMain } from './scripts/preloadProvider';
1
+ export { default as Main } from './scripts/Main';
2
+ export { default as provideFromMain } from './scripts/preloadProvider';
package/lib/preload.js CHANGED
@@ -1,2 +1,2 @@
1
- export { Main } from './scripts/Main';
2
- export { provideFromMain } from './scripts/preloadProvider';
1
+ export { default as Main } from './scripts/Main';
2
+ export { default as provideFromMain } from './scripts/preloadProvider';
package/lib/renderer.d.ts CHANGED
@@ -1 +1 @@
1
- export { Bridge } from './scripts/Bridge';
1
+ export { default as Bridge } from './scripts/Bridge';
package/lib/renderer.js CHANGED
@@ -1 +1 @@
1
- export { Bridge } from './scripts/Bridge';
1
+ export { default as Bridge } from './scripts/Bridge';
@@ -3,4 +3,5 @@
3
3
  *
4
4
  * _only for renderer process_
5
5
  */
6
- export declare const Bridge: import("../types").ITarget;
6
+ declare const Bridge: import("../types").ITarget;
7
+ export default Bridge;
@@ -1,5 +1,5 @@
1
1
  import { Scope } from '../enums';
2
- import { createProvider } from './provider';
2
+ import createProvider from './provider';
3
3
  if (!window.__provider__)
4
4
  throw new Error('Required methods not provided. Did you forget to call "provide" in preload?');
5
5
  const provider = window.__provider__;
@@ -9,7 +9,7 @@ const info = provider.getInfo();
9
9
  *
10
10
  * _only for renderer process_
11
11
  */
12
- export const Bridge = createProvider({
12
+ const Bridge = createProvider({
13
13
  info,
14
14
  scope: Scope.renderer,
15
15
  callFunction(name, ...args) {
@@ -28,3 +28,4 @@ export const Bridge = createProvider({
28
28
  });
29
29
  }
30
30
  });
31
+ export default Bridge;
@@ -3,4 +3,5 @@
3
3
  *
4
4
  * _only for preload process_
5
5
  */
6
- export declare const Main: import("../types").ITarget;
6
+ declare const Main: import("../types").ITarget;
7
+ export default Main;
@@ -1,6 +1,6 @@
1
1
  import { ipcRenderer } from 'electron';
2
2
  import { IPCChannel, Scope } from '../enums';
3
- import { createProvider } from './provider';
3
+ import createProvider from './provider';
4
4
  const info = ipcRenderer.sendSync(IPCChannel.getPublicInfo);
5
5
  if (!info)
6
6
  throw new Error('Public methods from main is not provided');
@@ -9,7 +9,7 @@ if (!info)
9
9
  *
10
10
  * _only for preload process_
11
11
  */
12
- export const Main = createProvider({
12
+ const Main = createProvider({
13
13
  info,
14
14
  scope: Scope.preload,
15
15
  callFunction(name, ...args) {
@@ -32,3 +32,4 @@ export const Main = createProvider({
32
32
  });
33
33
  }
34
34
  });
35
+ export default Main;
@@ -0,0 +1,81 @@
1
+ import type { ClassGetterDecorator, ClassMethodDecorator, ClassPropertyDecorator, ClassSetterDecorator, IPublishMethodArgs, IPublishPropertyArgs, PublishGetterArgs, PublishSetterArgs } from '../types';
2
+ /**
3
+ * Makes the method available for **renderer** and **preload** processes.
4
+ *
5
+ * _only new decorators_
6
+ */
7
+ export declare function publicMethod(): ClassMethodDecorator;
8
+ /**
9
+ * Makes the method available for **renderer** and **preload** processes.
10
+ *
11
+ * _only new decorators_
12
+ * @param name - name by which the method will be accessed
13
+ */
14
+ export declare function publicMethod(name: string): ClassMethodDecorator;
15
+ /**
16
+ * Makes the method available for **renderer** and **preload** processes.
17
+ *
18
+ * _only new decorators_
19
+ * @param args - publish args
20
+ */
21
+ export declare function publicMethod(args: IPublishMethodArgs): ClassMethodDecorator;
22
+ /**
23
+ * Makes the property available for **renderer** and **preload** processes.
24
+ *
25
+ * _only new decorators_
26
+ */
27
+ export declare function publicProperty(): ClassPropertyDecorator;
28
+ /**
29
+ * Makes the property available for **renderer** and **preload** processes.
30
+ *
31
+ * _only new decorators_
32
+ * @param name - name by which the property will be accessed
33
+ */
34
+ export declare function publicProperty(name: string): ClassPropertyDecorator;
35
+ /**
36
+ * Makes the property available for **renderer** and **preload** processes.
37
+ *
38
+ * _only new decorators_
39
+ * @param args - publish args
40
+ */
41
+ export declare function publicProperty(args: IPublishPropertyArgs): ClassPropertyDecorator;
42
+ /**
43
+ * Makes the property getter available for **renderer** and **preload** processes.
44
+ *
45
+ * _only new decorators_
46
+ */
47
+ export declare function publicGetter(): ClassGetterDecorator;
48
+ /**
49
+ * Makes the property getter available for **renderer** and **preload** processes.
50
+ *
51
+ * _only new decorators_
52
+ * @param name - name by which the property will be accessed
53
+ */
54
+ export declare function publicGetter(name: string): ClassGetterDecorator;
55
+ /**
56
+ * Makes the property getter available for **renderer** and **preload** processes.
57
+ *
58
+ * _only new decorators_
59
+ * @param args - publish args
60
+ */
61
+ export declare function publicGetter(args: PublishGetterArgs): ClassGetterDecorator;
62
+ /**
63
+ * Makes the property setter available for **renderer** and **preload** processes.
64
+ *
65
+ * _only new decorators_
66
+ */
67
+ export declare function publicSetter(): ClassSetterDecorator;
68
+ /**
69
+ * Makes the property setter available for **renderer** and **preload** processes.
70
+ *
71
+ * _only new decorators_
72
+ * @param name - name by which the property will be accessed
73
+ */
74
+ export declare function publicSetter(name: string): ClassSetterDecorator;
75
+ /**
76
+ * Makes the property setter available for **renderer** and **preload** processes.
77
+ *
78
+ * _only new decorators_
79
+ * @param args - publish args
80
+ */
81
+ export declare function publicSetter(args: PublishSetterArgs): ClassSetterDecorator;
@@ -0,0 +1,89 @@
1
+ import { addAccess, addScope, publicFunction, publicVariable } from './publish';
2
+ export function publicMethod(arg) {
3
+ return (method, context) => {
4
+ let name = String(context.name);
5
+ if (arg) {
6
+ if (typeof arg === 'string') {
7
+ name = arg;
8
+ }
9
+ else {
10
+ name = arg.name ?? name;
11
+ if (arg.scope)
12
+ addScope(name, arg.scope);
13
+ }
14
+ }
15
+ context.addInitializer(function () {
16
+ publicFunction(name, method.bind(this));
17
+ });
18
+ };
19
+ }
20
+ export function publicProperty(arg) {
21
+ return (_, context) => {
22
+ const propName = String(context.name);
23
+ let name = propName;
24
+ if (arg) {
25
+ if (typeof arg === 'string') {
26
+ name = arg;
27
+ }
28
+ else {
29
+ name = arg.name ?? name;
30
+ if (arg.scope)
31
+ addScope(name, arg.scope);
32
+ if (arg.access)
33
+ addAccess(name, arg.access);
34
+ }
35
+ }
36
+ context.addInitializer(function () {
37
+ publicVariable(name, {
38
+ get: () => {
39
+ // @ts-ignore
40
+ return this[propName];
41
+ },
42
+ set: (value) => {
43
+ // @ts-ignore
44
+ this[propName] = value;
45
+ }
46
+ });
47
+ });
48
+ };
49
+ }
50
+ export function publicGetter(arg) {
51
+ return (getter, context) => {
52
+ let name = String(context.name);
53
+ if (arg) {
54
+ if (typeof arg === 'string') {
55
+ name = arg;
56
+ }
57
+ else {
58
+ name = arg.name ?? name;
59
+ if (arg.scope)
60
+ addScope(name, arg.scope);
61
+ }
62
+ }
63
+ context.addInitializer(function () {
64
+ publicVariable(name, {
65
+ get: getter.bind(this)
66
+ });
67
+ });
68
+ };
69
+ }
70
+ export function publicSetter(arg) {
71
+ return (setter, context) => {
72
+ let name = String(context.name);
73
+ if (arg) {
74
+ if (typeof arg === 'string') {
75
+ name = arg;
76
+ }
77
+ else {
78
+ name = arg.name ?? name;
79
+ if (arg.scope)
80
+ addScope(name, arg.scope);
81
+ }
82
+ }
83
+ context.addInitializer(function () {
84
+ publicVariable(name, {
85
+ set: setter.bind(this)
86
+ });
87
+ });
88
+ };
89
+ }
@@ -0,0 +1,123 @@
1
+ import type { IPublishMethodArgs, IPublishPropertyArgs } from '../types';
2
+ /**
3
+ * Makes the method available for **renderer** and **preload** processes.
4
+ *
5
+ * _only for static_
6
+ *
7
+ * _experimental decorators_
8
+ */
9
+ export declare function publicStaticMethod(): MethodDecorator;
10
+ /**
11
+ * Makes the method available for **renderer** and **preload** processes.
12
+ *
13
+ * _only for static_
14
+ *
15
+ * _experimental decorators_
16
+ * @param name - name by which the method will be accessed
17
+ */
18
+ export declare function publicStaticMethod(name: string): MethodDecorator;
19
+ /**
20
+ * Makes the method available for **renderer** and **preload** processes.
21
+ *
22
+ * _only for static_
23
+ *
24
+ * _experimental decorators_
25
+ * @param args - publish args
26
+ */
27
+ export declare function publicStaticMethod(args: IPublishMethodArgs): MethodDecorator;
28
+ /**
29
+ * Makes the method available for **renderer** and **preload** processes.
30
+ *
31
+ * _only for non-static_
32
+ *
33
+ * _experimental decorators_
34
+ *
35
+ * _required `providePublic(classInstance)`_
36
+ */
37
+ export declare function publicMethod(): MethodDecorator;
38
+ /**
39
+ * Makes the method available for **renderer** and **preload** processes.
40
+ *
41
+ * _only for non-static_
42
+ *
43
+ * _experimental decorators_
44
+ *
45
+ * _required `providePublic(classInstance)`_
46
+ * @param name - name by which the method will be accessed
47
+ */
48
+ export declare function publicMethod(name: string): MethodDecorator;
49
+ /**
50
+ * Makes the method available for **renderer** and **preload** processes.
51
+ *
52
+ * _only for non-static_
53
+ *
54
+ * _experimental decorators_
55
+ *
56
+ * _required `providePublic(classInstance)`_
57
+ * @param args - publish args
58
+ */
59
+ export declare function publicMethod(args: IPublishMethodArgs): MethodDecorator;
60
+ /**
61
+ * Makes the property available for **renderer** and **preload** processes.
62
+ *
63
+ * _only for static_
64
+ *
65
+ * _experimental decorators_
66
+ */
67
+ export declare function publicStaticProperty(): PropertyDecorator;
68
+ /**
69
+ * Makes the property available for **renderer** and **preload** processes.
70
+ *
71
+ * _only for static_
72
+ *
73
+ * _experimental decorators_
74
+ * @param name - name by which the property will be accessed
75
+ */
76
+ export declare function publicStaticProperty(name: string): PropertyDecorator;
77
+ /**
78
+ * Makes the property 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 publicStaticProperty(args: IPublishPropertyArgs): PropertyDecorator;
86
+ /**
87
+ * Makes the property available for **renderer** and **preload** processes.
88
+ *
89
+ * _only for non-static_
90
+ *
91
+ * _experimental decorators_
92
+ *
93
+ * _required `providePublic(classInstance)`_
94
+ */
95
+ export declare function publicProperty(): PropertyDecorator;
96
+ /**
97
+ * Makes the property available for **renderer** and **preload** processes.
98
+ *
99
+ * _only for non-static_
100
+ *
101
+ * _experimental decorators_
102
+ *
103
+ * _required `providePublic(classInstance)`_
104
+ * @param name - name by which the property will be accessed
105
+ */
106
+ export declare function publicProperty(name: string): PropertyDecorator;
107
+ /**
108
+ * Makes the property available for **renderer** and **preload** processes.
109
+ *
110
+ * _only for non-static_
111
+ *
112
+ * _experimental decorators_
113
+ *
114
+ * _required `providePublic(classInstance)`_
115
+ * @param args - publish args
116
+ */
117
+ export declare function publicProperty(args: IPublishPropertyArgs): PropertyDecorator;
118
+ /**
119
+ * Binds all public entities of a class to a specific instance.
120
+ *
121
+ * _only for class instance_
122
+ */
123
+ export declare function providePublic<InstanceType>(instance: InstanceType): InstanceType;
@@ -0,0 +1,75 @@
1
+ import { addAccess, addScope, publicFunction, publicVariable } from './publish';
2
+ export function publicStaticMethod(arg) {
3
+ return (target, key) => {
4
+ let name = String(key);
5
+ if (arg) {
6
+ if (typeof arg === 'string') {
7
+ name = arg;
8
+ }
9
+ else {
10
+ name = arg.name ?? String(key);
11
+ if (arg.scope)
12
+ addScope(name, arg.scope);
13
+ }
14
+ }
15
+ publicFunction(name, (...args) => target[key](...args));
16
+ };
17
+ }
18
+ export function publicMethod(arg) {
19
+ return (tgt, key, _) => {
20
+ const target = tgt;
21
+ const prevRegister = target.__register__ ?? (() => { });
22
+ target.__register__ = instance => {
23
+ prevRegister(instance);
24
+ publicStaticMethod(arg)(instance, key, _);
25
+ };
26
+ };
27
+ }
28
+ export function publicStaticProperty(arg) {
29
+ return (target, key) => {
30
+ let name = String(key);
31
+ if (arg) {
32
+ if (typeof arg === 'string') {
33
+ name = arg;
34
+ }
35
+ else {
36
+ name = arg.name ?? String(key);
37
+ if (arg.scope)
38
+ addScope(name, arg.scope);
39
+ if (arg.access)
40
+ addAccess(name, arg.access);
41
+ }
42
+ }
43
+ publicVariable(name, {
44
+ get() {
45
+ return target[key];
46
+ },
47
+ set(value) {
48
+ target[key] = value;
49
+ }
50
+ });
51
+ };
52
+ }
53
+ export function publicProperty(arg) {
54
+ return (tgt, key) => {
55
+ const target = tgt;
56
+ const prevRegister = target.__register__ ?? (() => { });
57
+ target.__register__ = instance => {
58
+ prevRegister(instance);
59
+ publicStaticProperty(arg)(instance, key);
60
+ };
61
+ };
62
+ }
63
+ /**
64
+ * Binds all public entities of a class to a specific instance.
65
+ *
66
+ * _only for class instance_
67
+ */
68
+ export function providePublic(instance) {
69
+ const target = instance;
70
+ if (!target.__register__)
71
+ throw new Error('Public methods not defined');
72
+ target.__register__(instance);
73
+ target.__register__ = undefined;
74
+ return instance;
75
+ }
@@ -3,4 +3,5 @@
3
3
  *
4
4
  * @param contextIsolation - _default_: `true`
5
5
  */
6
- export declare function provideFromMain(contextIsolation?: boolean): void;
6
+ declare function provideFromMain(contextIsolation?: boolean): void;
7
+ export default provideFromMain;
@@ -6,7 +6,7 @@ const info = ipcRenderer.sendSync(IPCChannel.getPublicInfo);
6
6
  *
7
7
  * @param contextIsolation - _default_: `true`
8
8
  */
9
- export function provideFromMain(contextIsolation = true) {
9
+ function provideFromMain(contextIsolation = true) {
10
10
  const provider = {
11
11
  getInfo() {
12
12
  return info;
@@ -48,3 +48,4 @@ export function provideFromMain(contextIsolation = true) {
48
48
  else
49
49
  window.__provider__ = provider;
50
50
  }
51
+ export default provideFromMain;
@@ -1,2 +1,3 @@
1
1
  import type { ICreateProviderArgs, ITarget } from '../types';
2
- export declare function createProvider(args: ICreateProviderArgs): ITarget;
2
+ declare function createProvider(args: ICreateProviderArgs): ITarget;
3
+ export default createProvider;
@@ -2,7 +2,7 @@ import { Access, Scope } from '../enums';
2
2
  function errorHandler(error, channel) {
3
3
  console.error(`Error on ${channel}.\n${error}`.replace('Error: ', ''));
4
4
  }
5
- export function createProvider(args) {
5
+ function createProvider(args) {
6
6
  const { info, scope, getVariable, setVariable, callFunction, waitPromise } = args;
7
7
  const target = {
8
8
  as: () => proxy
@@ -97,3 +97,4 @@ export function createProvider(args) {
97
97
  });
98
98
  return proxy;
99
99
  }
100
+ export default createProvider;
@@ -1,103 +1,5 @@
1
- import { Scope } from '../enums';
2
- import type { IPublishMethodArgs, IPublishPropertyArgs, PublicFunction, PublicProperty } from '../types';
3
- /**
4
- * Makes the method available for **renderer** and **preload** processes.
5
- *
6
- * _only for static_
7
- */
8
- export declare function publicStaticMethod(): MethodDecorator;
9
- /**
10
- * Makes the method available for **renderer** and **preload** processes.
11
- *
12
- * _only for static_
13
- * @param name - name by which the method will be accessed
14
- */
15
- export declare function publicStaticMethod(name: string): MethodDecorator;
16
- /**
17
- * Makes the method available for **renderer** and **preload** processes.
18
- *
19
- * _only for static_
20
- * @param args - publish args
21
- */
22
- export declare function publicStaticMethod(args: IPublishMethodArgs): MethodDecorator;
23
- /**
24
- * Makes the method available for **renderer** and **preload** processes.
25
- *
26
- * _only for non-static_
27
- *
28
- * _required `providePublic(classInstance)`_
29
- */
30
- export declare function publicMethod(): MethodDecorator;
31
- /**
32
- * Makes the method available for **renderer** and **preload** processes.
33
- *
34
- * _only for non-static_
35
- *
36
- * _required `providePublic(classInstance)`_
37
- * @param name - name by which the method will be accessed
38
- */
39
- export declare function publicMethod(name: string): MethodDecorator;
40
- /**
41
- * Makes the method available for **renderer** and **preload** processes.
42
- *
43
- * _only for non-static_
44
- *
45
- * _required `providePublic(classInstance)`_
46
- * @param args - publish args
47
- */
48
- export declare function publicMethod(args: IPublishMethodArgs): MethodDecorator;
49
- /**
50
- * Makes the property available for **renderer** and **preload** processes.
51
- *
52
- * _only for static_
53
- */
54
- export declare function publicStaticProperty(): PropertyDecorator;
55
- /**
56
- * Makes the property available for **renderer** and **preload** processes.
57
- *
58
- * _only for static_
59
- * @param name - name by which the property will be accessed
60
- */
61
- export declare function publicStaticProperty(name: string): PropertyDecorator;
62
- /**
63
- * Makes the property available for **renderer** and **preload** processes.
64
- *
65
- * _only for static_
66
- * @param args - publish args
67
- */
68
- export declare function publicStaticProperty(args: IPublishPropertyArgs): PropertyDecorator;
69
- /**
70
- * Makes the property available for **renderer** and **preload** processes.
71
- *
72
- * _only for non-static_
73
- *
74
- * _required `providePublic(classInstance)`_
75
- */
76
- export declare function publicProperty(): PropertyDecorator;
77
- /**
78
- * Makes the property available for **renderer** and **preload** processes.
79
- *
80
- * _only for non-static_
81
- *
82
- * _required `providePublic(classInstance)`_
83
- * @param name - name by which the property will be accessed
84
- */
85
- export declare function publicProperty(name: string): PropertyDecorator;
86
- /**
87
- * Makes the property available for **renderer** and **preload** processes.
88
- *
89
- * _only for non-static_
90
- *
91
- * _required `providePublic(classInstance)`_
92
- * @param args - publish args
93
- */
94
- export declare function publicProperty(args: IPublishPropertyArgs): PropertyDecorator;
95
- /**
96
- * Binds all public entities of a class to a specific instance.
97
- *
98
- * _only for class instance_
99
- */
100
- export declare function providePublic<InstanceType>(instance: InstanceType): InstanceType;
1
+ import { Access, Scope } from '../enums';
2
+ import type { PublicFunction, PublicProperty } from '../types';
101
3
  /**
102
4
  * Makes the function available for **renderer** and **preload** processes.
103
5
  *
@@ -116,3 +18,5 @@ export declare function publicFunction(name: string, func: PublicFunction, scope
116
18
  * @param scopes - variable scopes
117
19
  */
118
20
  export declare function publicVariable(name: string, value: PublicProperty, scopes?: Scope[]): void;
21
+ export declare function addScope(key: string, scope: Scope): void;
22
+ export declare function addAccess(key: string, access: Access): void;
@@ -7,80 +7,6 @@ const publicInfo = {
7
7
  scopes: {}
8
8
  };
9
9
  ipcMain.on(IPCChannel.getPublicInfo, e => e.returnValue = publicInfo);
10
- export function publicStaticMethod(arg) {
11
- return (target, key) => {
12
- let name = String(key);
13
- if (arg) {
14
- if (typeof arg === 'string') {
15
- name = arg;
16
- }
17
- else {
18
- name = arg.name ?? String(key);
19
- if (arg.scope)
20
- scope(name, arg.scope);
21
- }
22
- }
23
- publicFunction(name, (...args) => target[key](...args));
24
- };
25
- }
26
- export function publicMethod(arg) {
27
- return (tgt, key, _) => {
28
- const target = tgt;
29
- const prevRegister = target.__register__ ?? (() => { });
30
- target.__register__ = instance => {
31
- prevRegister(instance);
32
- publicStaticMethod(arg)(instance, key, _);
33
- };
34
- };
35
- }
36
- export function publicStaticProperty(arg) {
37
- return (target, key) => {
38
- let name = String(key);
39
- if (arg) {
40
- if (typeof arg === 'string') {
41
- name = arg;
42
- }
43
- else {
44
- name = arg.name ?? String(key);
45
- if (arg.scope)
46
- scope(name, arg.scope);
47
- if (arg.access)
48
- access(name, arg.access);
49
- }
50
- }
51
- publicVariable(name, {
52
- get() {
53
- return target[key];
54
- },
55
- set(value) {
56
- target[key] = value;
57
- }
58
- });
59
- };
60
- }
61
- export function publicProperty(arg) {
62
- return (tgt, key) => {
63
- const target = tgt;
64
- const prevRegister = target.__register__ ?? (() => { });
65
- target.__register__ = instance => {
66
- prevRegister(instance);
67
- publicStaticProperty(arg)(instance, key);
68
- };
69
- };
70
- }
71
- /**
72
- * Binds all public entities of a class to a specific instance.
73
- *
74
- * _only for class instance_
75
- */
76
- export function providePublic(instance) {
77
- const target = instance;
78
- if (!target.__register__)
79
- throw new Error('Public methods not defined');
80
- target.__register__(instance);
81
- target.__register__ = undefined;
82
- return instance;
83
- }
84
10
  /**
85
11
  * Makes the function available for **renderer** and **preload** processes.
86
12
  *
@@ -137,6 +63,11 @@ export function publicVariable(name, value, scopes = [Scope.renderer, Scope.prel
137
63
  setter && accesses.push(Access.set);
138
64
  publicInfo.accesses[name] = new Set(accesses);
139
65
  }
66
+ else {
67
+ const accesses = publicInfo.accesses[name];
68
+ getter && accesses.add(Access.get);
69
+ setter && accesses.add(Access.set);
70
+ }
140
71
  if (getter) {
141
72
  ipcMain.removeAllListeners(getChannel);
142
73
  ipcMain.on(getChannel, event => {
@@ -162,9 +93,9 @@ export function publicVariable(name, value, scopes = [Scope.renderer, Scope.prel
162
93
  });
163
94
  }
164
95
  }
165
- function scope(key, scope) {
96
+ export function addScope(key, scope) {
166
97
  publicInfo.scopes[key] = new Set([scope]);
167
98
  }
168
- function access(key, access) {
99
+ export function addAccess(key, access) {
169
100
  publicInfo.accesses[key] = new Set([access]);
170
101
  }
package/lib/types.d.ts CHANGED
@@ -3,6 +3,12 @@ import { Access } from './enums';
3
3
  export interface ITarget {
4
4
  as<T>(): T;
5
5
  }
6
+ export type ClassMethodDecorator = <This, Args extends any[], Return>(method: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => void;
7
+ export type ClassPropertyDecorator = <This, Type>(target: undefined, context: ClassFieldDecoratorContext<This, Type>) => void;
8
+ export type ClassGetterDecorator = <This, Type>(getter: () => Type, context: ClassGetterDecoratorContext<This, Type>) => void;
9
+ export type ClassSetterDecorator = <This, Type>(setter: (value: Type) => void, context: ClassSetterDecoratorContext<This, Type>) => void;
10
+ export type PublishSetterArgs = Omit<IPublishPropertyArgs, 'access'>;
11
+ export type PublishGetterArgs = Omit<IPublishPropertyArgs, 'access'>;
6
12
  export interface IIPCResult {
7
13
  value?: any;
8
14
  error?: string;
package/package.json CHANGED
@@ -1,52 +1,52 @@
1
- {
2
- "name": "emr-bridge",
3
- "version": "1.1.1",
4
- "description": "Allows you to easily give access to main methods from the renderer process",
5
- "main": "lib/index.js",
6
- "scripts": {
7
- "compile": "tsc --project ./tsconfig.json"
8
- },
9
- "types": "lib/index.d.ts",
10
- "files": [
11
- "lib"
12
- ],
13
- "typesVersions": {
14
- "*": {
15
- ".": [
16
- "./lib/index.d.ts"
17
- ],
18
- "renderer": [
19
- "./lib/renderer.d.ts"
20
- ],
21
- "preload": [
22
- "./lib/preload.d.ts"
23
- ],
24
- "main": [
25
- "./lib/index.d.ts"
26
- ]
27
- }
28
- },
29
- "exports": {
30
- ".": "./lib/index.js",
31
- "./renderer": "./lib/renderer.js",
32
- "./preload": "./lib/preload.js",
33
- "./main": "./lib/index.js",
34
- "./package.json": "./package.json"
35
- },
36
- "repository": {
37
- "type": "git",
38
- "url": "https://github.com/VerZsuT/emr-bridge.git"
39
- },
40
- "keywords": [
41
- "electron",
42
- "ipc"
43
- ],
44
- "author": "VerZsuT",
45
- "license": "MIT",
46
- "dependencies": {
47
- "electron": "^21.3.0"
48
- },
49
- "devDependencies": {
50
- "typescript": "^4.9.3"
51
- }
52
- }
1
+ {
2
+ "name": "emr-bridge",
3
+ "version": "1.2.0",
4
+ "description": "Allows you to easily give access to main methods from the renderer process",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "compile": "tsc --project ./tsconfig.json"
8
+ },
9
+ "types": "lib/index.d.ts",
10
+ "files": [
11
+ "lib"
12
+ ],
13
+ "typesVersions": {
14
+ "*": {
15
+ ".": [
16
+ "./lib/index.d.ts"
17
+ ],
18
+ "renderer": [
19
+ "./lib/renderer.d.ts"
20
+ ],
21
+ "preload": [
22
+ "./lib/preload.d.ts"
23
+ ],
24
+ "main": [
25
+ "./lib/index.d.ts"
26
+ ]
27
+ }
28
+ },
29
+ "exports": {
30
+ ".": "./lib/index.js",
31
+ "./renderer": "./lib/renderer.js",
32
+ "./preload": "./lib/preload.js",
33
+ "./main": "./lib/index.js",
34
+ "./package.json": "./package.json"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/VerZsuT/emr-bridge.git"
39
+ },
40
+ "keywords": [
41
+ "electron",
42
+ "ipc"
43
+ ],
44
+ "author": "VerZsuT",
45
+ "license": "MIT",
46
+ "peerDependencies": {
47
+ "electron": ">=20.0.0"
48
+ },
49
+ "devDependencies": {
50
+ "typescript": "^5.0.2"
51
+ }
52
+ }