java-bridge 2.2.3-beta.3 → 2.2.3
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/dist/index.prod.min.js +1 -1
- package/dist/index.prod.min.js.map +1 -1
- package/dist/java-ts-gen.js +1 -1
- package/dist/java-ts-gen.js.map +1 -1
- package/dist/ts-src/TypescriptDefinitionGenerator.d.ts +7 -0
- package/dist/ts-src/java.d.ts +36 -3
- package/java-src/build/libs/JavaBridge-2.1.1.jar +0 -0
- package/package.json +11 -8
|
@@ -2,6 +2,7 @@ export interface MethodDeclaration {
|
|
|
2
2
|
returnType: string;
|
|
3
3
|
parameters: string[];
|
|
4
4
|
isStatic: boolean;
|
|
5
|
+
isDefault: boolean;
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
8
|
* A java class declaration converted to typescript
|
|
@@ -41,8 +42,11 @@ export default class TypescriptDefinitionGenerator {
|
|
|
41
42
|
private readonly progressCallback;
|
|
42
43
|
private readonly resolvedImports;
|
|
43
44
|
private usesBasicOrJavaType;
|
|
45
|
+
private usesNewProxy;
|
|
46
|
+
private usesInterfaceProxy;
|
|
44
47
|
private readonly additionalImports;
|
|
45
48
|
private readonly importsToResolve;
|
|
49
|
+
private readonly interfaceImports;
|
|
46
50
|
/**
|
|
47
51
|
* Create a new `TypescriptDefinitionGenerator` instance
|
|
48
52
|
*
|
|
@@ -64,6 +68,9 @@ export default class TypescriptDefinitionGenerator {
|
|
|
64
68
|
private convertParameter;
|
|
65
69
|
private convertParameters;
|
|
66
70
|
private static createMethodComment;
|
|
71
|
+
private createMethodSignature;
|
|
72
|
+
private createInterfaceMethodSignatures;
|
|
73
|
+
private createNewProxyMethod;
|
|
67
74
|
private createMethod;
|
|
68
75
|
private convertMethod;
|
|
69
76
|
private getAdditionalImports;
|
package/dist/ts-src/java.d.ts
CHANGED
|
@@ -434,7 +434,12 @@ export declare namespace stdout {
|
|
|
434
434
|
* ## See also
|
|
435
435
|
* * {@link newProxy}
|
|
436
436
|
*/
|
|
437
|
-
export interface JavaInterfaceProxy {
|
|
437
|
+
export interface JavaInterfaceProxy<T extends ProxyRecord<T> = AnyProxyRecord> {
|
|
438
|
+
/**
|
|
439
|
+
* A dummy property to make sure the type is correct.
|
|
440
|
+
* This property will never be set.
|
|
441
|
+
*/
|
|
442
|
+
_dummy?: T;
|
|
438
443
|
/**
|
|
439
444
|
* Destroy the proxy class.
|
|
440
445
|
* After this call any call to any method defined by the
|
|
@@ -458,6 +463,8 @@ export interface JavaInterfaceProxy {
|
|
|
458
463
|
* @return the value to pass back to the java process
|
|
459
464
|
*/
|
|
460
465
|
export type ProxyMethod = (...args: any[]) => any;
|
|
466
|
+
export type ProxyRecord<T> = Partial<Record<keyof T, ProxyMethod>>;
|
|
467
|
+
export type AnyProxyRecord = Record<string, ProxyMethod>;
|
|
461
468
|
/**
|
|
462
469
|
* Create a new java interface proxy.
|
|
463
470
|
* This allows you to implement java interfaces in javascript.
|
|
@@ -569,7 +576,27 @@ export type ProxyMethod = (...args: any[]) => any;
|
|
|
569
576
|
* ### Keeping the proxy alive
|
|
570
577
|
* If you want to keep the proxy alive, you must keep this instance in scope.
|
|
571
578
|
* If that is not an option for you, you can manually keep the proxy alive
|
|
572
|
-
* by setting the {@link InterfaceProxyOptions.keepAsDaemon
|
|
579
|
+
* by setting the {@link InterfaceProxyOptions}.keepAsDaemon option to true.
|
|
580
|
+
*
|
|
581
|
+
* ```ts
|
|
582
|
+
* const proxy = newProxy('java.lang.Runnable', {
|
|
583
|
+
* run: (): void => {
|
|
584
|
+
* console.log('Hello World!');
|
|
585
|
+
* }
|
|
586
|
+
* }, {
|
|
587
|
+
* keepAsDaemon: true
|
|
588
|
+
* });
|
|
589
|
+
*
|
|
590
|
+
* const TimeUnit = java.importClass('java.util.concurrent.TimeUnit');
|
|
591
|
+
* const ScheduledThreadPoolExecutor = java.importClass(
|
|
592
|
+
* 'java.util.concurrent.ScheduledThreadPoolExecutor'
|
|
593
|
+
* );
|
|
594
|
+
* const executor = new ScheduledThreadPoolExecutor(1);
|
|
595
|
+
*
|
|
596
|
+
* // 'proxy' will eventually be garbage collected,
|
|
597
|
+
* // but it will be kept alive due to this option.
|
|
598
|
+
* executor.scheduleAtFixedRateSync(proxy, 0, 1, TimeUnit.SECONDS);
|
|
599
|
+
* ```
|
|
573
600
|
*
|
|
574
601
|
* This will keep the proxy alive internally, thus the instance can be moved
|
|
575
602
|
* out of scope. However, this will also keep the JVM alive, so you should
|
|
@@ -589,7 +616,7 @@ export type ProxyMethod = (...args: any[]) => any;
|
|
|
589
616
|
* @param opts the options to use
|
|
590
617
|
* @returns a proxy class to pass back to the java process
|
|
591
618
|
*/
|
|
592
|
-
export declare function newProxy(interfaceName: string, methods:
|
|
619
|
+
export declare function newProxy<T extends ProxyRecord<T> = AnyProxyRecord>(interfaceName: string, methods: T, opts?: InterfaceProxyOptions): JavaInterfaceProxy<T>;
|
|
593
620
|
/**
|
|
594
621
|
* Get the static java instance.
|
|
595
622
|
* This has no real use, all important methods are exported explicitly.
|
|
@@ -600,6 +627,8 @@ export declare function getJavaInstance(): Java | null;
|
|
|
600
627
|
*/
|
|
601
628
|
export declare class config {
|
|
602
629
|
/**
|
|
630
|
+
* **Experimental Feature**
|
|
631
|
+
*
|
|
603
632
|
* Set whether to run the event loop when an interface proxy is active.
|
|
604
633
|
* This is disabled by default. Enabling this will cause the bridge
|
|
605
634
|
* to run the event loop when an interface proxy either as direct
|
|
@@ -610,11 +639,15 @@ export declare class config {
|
|
|
610
639
|
*
|
|
611
640
|
* **Note:** Enabling this may cause the application to crash. Use with caution.
|
|
612
641
|
*
|
|
642
|
+
* @experimental
|
|
613
643
|
* @param value whether to run the event loop when an interface proxy is active
|
|
614
644
|
*/
|
|
615
645
|
static set runEventLoopWhenInterfaceProxyIsActive(value: boolean);
|
|
616
646
|
/**
|
|
647
|
+
* **Experimental Feature**
|
|
648
|
+
*
|
|
617
649
|
* Get whether to run the event loop when an interface proxy is active.
|
|
650
|
+
* @experimental
|
|
618
651
|
*/
|
|
619
652
|
static get runEventLoopWhenInterfaceProxyIsActive(): boolean;
|
|
620
653
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "java-bridge",
|
|
3
|
-
"version": "2.2.3
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"main": "dist/index.prod.min.js",
|
|
5
5
|
"types": "dist/ts-src/index.d.ts",
|
|
6
6
|
"description": "A bridge between Node.js and Java APIs",
|
|
@@ -56,8 +56,9 @@
|
|
|
56
56
|
"build:java:win32": "cd java-src && .\\gradlew.bat shadowJar",
|
|
57
57
|
"prepublishOnly": "napi prepublish -t npm",
|
|
58
58
|
"test": "npm run testOnly",
|
|
59
|
-
"testOnly": "
|
|
59
|
+
"testOnly": "npm run mocha",
|
|
60
60
|
"pretestOnly": "npm run generateTestTypes",
|
|
61
|
+
"mocha": "mocha -r ts-node/register test/*.test.ts --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
|
|
61
62
|
"pretest": "npm run build",
|
|
62
63
|
"version": "napi version",
|
|
63
64
|
"prettier": "prettier --write .",
|
|
@@ -78,6 +79,7 @@
|
|
|
78
79
|
"devDependencies": {
|
|
79
80
|
"@napi-rs/cli": "^2.14.8",
|
|
80
81
|
"@types/chai": "^4.3.4",
|
|
82
|
+
"@types/folder-hash": "^4.0.2",
|
|
81
83
|
"@types/glob": "^8.1.0",
|
|
82
84
|
"@types/is-ci": "^3.0.0",
|
|
83
85
|
"@types/mocha": "^10.0.1",
|
|
@@ -89,6 +91,7 @@
|
|
|
89
91
|
"chai": "^4.3.7",
|
|
90
92
|
"cpy-cli": "^4.2.0",
|
|
91
93
|
"expose-gc": "^1.0.0",
|
|
94
|
+
"folder-hash": "^4.0.4",
|
|
92
95
|
"is-ci": "^3.0.1",
|
|
93
96
|
"mocha": "^10.2.0",
|
|
94
97
|
"mocha-junit-reporter": "^2.2.0",
|
|
@@ -110,11 +113,11 @@
|
|
|
110
113
|
"which": "^3.0.0"
|
|
111
114
|
},
|
|
112
115
|
"optionalDependencies": {
|
|
113
|
-
"java-bridge-win32-x64-msvc": "2.2.3
|
|
114
|
-
"java-bridge-darwin-x64": "2.2.3
|
|
115
|
-
"java-bridge-linux-x64-gnu": "2.2.3
|
|
116
|
-
"java-bridge-darwin-arm64": "2.2.3
|
|
117
|
-
"java-bridge-win32-ia32-msvc": "2.2.3
|
|
118
|
-
"java-bridge-linux-arm64-gnu": "2.2.3
|
|
116
|
+
"java-bridge-win32-x64-msvc": "2.2.3",
|
|
117
|
+
"java-bridge-darwin-x64": "2.2.3",
|
|
118
|
+
"java-bridge-linux-x64-gnu": "2.2.3",
|
|
119
|
+
"java-bridge-darwin-arm64": "2.2.3",
|
|
120
|
+
"java-bridge-win32-ia32-msvc": "2.2.3",
|
|
121
|
+
"java-bridge-linux-arm64-gnu": "2.2.3"
|
|
119
122
|
}
|
|
120
123
|
}
|