java-bridge 2.3.0 → 2.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/native.d.ts CHANGED
@@ -3,6 +3,76 @@
3
3
 
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
+ /**
7
+ * Configuration for the Java class proxy.
8
+ *
9
+ * @since 2.4.0
10
+ */
11
+ export interface ClassConfiguration {
12
+ /**
13
+ * If true, the event loop will be run when an interface proxy is active.
14
+ * If not specified, the value from the global configuration will be used.
15
+ */
16
+ runEventLoopWhenInterfaceProxyIsActive?: boolean
17
+ /**
18
+ * If true, the custom inspect method will be used to display the object in the console.
19
+ * If not specified, the value from the global configuration will be used.
20
+ */
21
+ customInspect?: boolean
22
+ /**
23
+ * The suffix to use for synchronous methods.
24
+ * Set this value to an empty string to disable the suffix.
25
+ * The default value is "Sync".
26
+ * Setting this value to the same value as asyncSuffix will result in an error.
27
+ * If not specified, the value from the global configuration will be used.
28
+ */
29
+ syncSuffix?: string
30
+ /**
31
+ * The suffix to use for asynchronous methods.
32
+ * Set this value to an empty string to disable the suffix.
33
+ * The default value is an empty string.
34
+ * Setting this value to the same value as syncSuffix will result in an error.
35
+ * If not specified, the value from the global configuration will be used.
36
+ */
37
+ asyncSuffix?: string
38
+ }
39
+ /**
40
+ * Configuration for the Java class proxy.
41
+ *
42
+ * @since 2.4.0
43
+ */
44
+ export interface Config {
45
+ /**
46
+ * If true, the event loop will be run when an interface proxy is active.
47
+ *
48
+ * @since 2.2.3
49
+ */
50
+ runEventLoopWhenInterfaceProxyIsActive: boolean
51
+ /**
52
+ * If true, the custom inspect method will be used to display the object in the console.
53
+ *
54
+ * @since 2.4.0
55
+ */
56
+ customInspect: boolean
57
+ /**
58
+ * The suffix to use for synchronous methods.
59
+ * Set this value to an empty string to disable the suffix.
60
+ * The default value is "Sync".
61
+ * Setting this value to the same value as asyncSuffix will result in an error.
62
+ *
63
+ * @since 2.4.0
64
+ */
65
+ syncSuffix?: string
66
+ /**
67
+ * The suffix to use for asynchronous methods.
68
+ * Set this value to an empty string to disable the suffix.
69
+ * The default value is an empty string.
70
+ * Setting this value to the same value as syncSuffix will result in an error.
71
+ *
72
+ * @since 2.4.0
73
+ */
74
+ asyncSuffix?: string
75
+ }
6
76
  /** Options for the interface proxies */
7
77
  export interface InterfaceProxyOptions {
8
78
  /**
@@ -13,6 +83,14 @@ export interface InterfaceProxyOptions {
13
83
  }
14
84
  /** Clears the list of daemon proxies. */
15
85
  export function clearDaemonProxies(): void
86
+ /**
87
+ * Clear the class proxy cache.
88
+ * Use this method in order to reset the config for all class proxies.
89
+ * The new config will be applied once the class is imported again.
90
+ *
91
+ * @since 2.4.0
92
+ */
93
+ export function clearClassProxies(): void
16
94
  /**
17
95
  * Options for the Java VM.
18
96
  * Not the same as vm arguments.
@@ -54,13 +132,13 @@ export class Java {
54
132
  * Will import the class and parse all of its methods and fields.
55
133
  * The imported class will be cached for future use.
56
134
  */
57
- importClass(className: string): object
135
+ importClass(className: string, config?: ClassConfiguration | undefined | null): object
58
136
  /**
59
137
  * Import a java class (async)
60
138
  * Will return a promise that resolves to the class instance.
61
139
  * @see importClass
62
140
  */
63
- importClassAsync(className: string): Promise<object>
141
+ importClassAsync(className: string, config?: ClassConfiguration | undefined | null): Promise<object>
64
142
  /**
65
143
  * Get the wanted JVM version.
66
144
  * This may not match the actual JVM version.
@@ -83,11 +161,189 @@ export class Java {
83
161
  get classLoader(): object
84
162
  set classLoader(classLoader: object)
85
163
  }
164
+ /**
165
+ * Configuration options for the java bridge.
166
+ *
167
+ * As of version 2.4.0, the options are cached inside the class proxy cache.
168
+ * This means that changing the options will not affect any class proxies
169
+ * that have already been created by importing a class using {@link importClass}
170
+ * or {@link importClassAsync}. You must clear the class proxy cache using the
171
+ * {@link clearClassProxies} method in order to apply the new options to all
172
+ * classes imported at a later date. This does not affect already instantiated
173
+ * or imported classes.
174
+ *
175
+ * Do not instantiate this class. Use the {@link default.config} instance instead.
176
+ *
177
+ * @since 2.2.3
178
+ */
86
179
  export class JavaConfig {
87
- static setRunEventLoopWhenInterfaceProxyIsActive(value: boolean): void
88
- static getRunEventLoopWhenInterfaceProxyIsActive(): boolean
180
+ /**
181
+ * Do not instantiate this class.
182
+ * Use the {@link default.config} instance instead.
183
+ */
184
+ constructor()
185
+ /**
186
+ * **Experimental Feature**
187
+ *
188
+ * Set whether to run the event loop when an interface proxy is active.
189
+ * This is disabled by default. Enabling this will cause the bridge
190
+ * to run the event loop when an interface proxy either as direct
191
+ * proxy or as daemon proxy is active. This is only required if the
192
+ * proxied method calls back into the javascript process in the same thread.
193
+ * If the proxy is used either in an async method or in a different thread,
194
+ * this is not required.
195
+ *
196
+ * **Note:** Enabling this may cause the application to crash. Use with caution.
197
+ *
198
+ * @since 2.2.3
199
+ * @experimental
200
+ * @param value whether to run the event loop when an interface proxy is active
201
+ */
202
+ set runEventLoopWhenInterfaceProxyIsActive(value: boolean)
203
+ /**
204
+ * **Experimental Feature**
205
+ *
206
+ * Get whether to run the event loop when an interface proxy is active.
207
+ * @since 2.2.3
208
+ * @experimental
209
+ */
210
+ get runEventLoopWhenInterfaceProxyIsActive(): boolean
211
+ /**
212
+ * Whether to add custom inspect methods to java objects.
213
+ * This is disabled by default.
214
+ * This allows console.log to print java objects in a more readable way
215
+ * using the `toString` method of the java object.
216
+ *
217
+ * @since 2.4.0
218
+ * @param value whether to add custom inspect methods to java objects
219
+ */
220
+ set customInspect(value: boolean)
221
+ /**
222
+ * Get whether to add custom inspect methods to java objects.
223
+ *
224
+ * @since 2.4.0
225
+ * @returns whether to add custom inspect methods to java objects
226
+ */
227
+ get customInspect(): boolean
228
+ /**
229
+ * Set the suffix for synchronous methods.
230
+ * This is `Sync` by default.
231
+ * Pass `null` or an empty string to disable the suffix.
232
+ * This must not be the same as the {@link asyncSuffix}.
233
+ *
234
+ * This option does not affect standard methods of java classes
235
+ * like `toString`, `toStringSync`, `toStringAsync` and `newInstanceAsync`.
236
+ *
237
+ * ## Example
238
+ * ```ts
239
+ * import { config, clearClassProxies } from 'java-bridge';
240
+ *
241
+ * // Set the async suffix in order to prevent errors
242
+ * config.asyncSuffix = 'Async';
243
+ * // Set the sync suffix to an empty string
244
+ * config.syncSuffix = '';
245
+ * // This would do the same
246
+ * config.syncSuffix = null;
247
+ *
248
+ * // Clear the class proxy cache
249
+ * clearClassProxies();
250
+ *
251
+ * // Import the class
252
+ * const ArrayList = importClass('java.util.ArrayList');
253
+ *
254
+ * // Create a new instance
255
+ * const list = new ArrayList();
256
+ *
257
+ * // Call the method
258
+ * list.add('Hello World!');
259
+ *
260
+ * // Async methods now have the 'Async' suffix
261
+ * await list.addAsync('Hello World!');
262
+ * ```
263
+ *
264
+ * @see asyncSuffix
265
+ * @since 2.4.0
266
+ * @param value the suffix to use for synchronous methods
267
+ */
268
+ set syncSuffix(value: string | undefined | null)
269
+ /**
270
+ * Get the suffix for synchronous methods.
271
+ *
272
+ * @since 2.4.0
273
+ */
274
+ get syncSuffix(): string | null
275
+ /**
276
+ * Set the suffix for asynchronous methods.
277
+ * This is `Async` by default.
278
+ * Pass `null` or an empty string to disable the suffix.
279
+ * This must not be the same as the {@link syncSuffix}.
280
+ *
281
+ * This option does not affect standard methods of java classes
282
+ * like `toString`, `toStringSync`, `toStringAsync` and `newInstanceAsync`.
283
+ *
284
+ * @see syncSuffix
285
+ * @since 2.4.0
286
+ * @param value the suffix to use for asynchronous methods
287
+ */
288
+ set asyncSuffix(value: string | undefined | null)
289
+ /**
290
+ * Get the suffix for asynchronous methods.
291
+ *
292
+ * @since 2.4.0
293
+ */
294
+ get asyncSuffix(): string | null
295
+ /**
296
+ * Override the whole config.
297
+ * If you want to change only a single field, use the static setters instead.
298
+ *
299
+ * @since 2.4.0
300
+ * @param value the config to use
301
+ */
302
+ set config(value: Config)
303
+ /**
304
+ * Get the current config.
305
+ *
306
+ * @since 2.4.0
307
+ */
308
+ get config(): Config
309
+ /**
310
+ * Reset the config to the default values.
311
+ *
312
+ * @since 2.4.0
313
+ */
314
+ reset(): void
89
315
  }
90
316
  export class StdoutRedirect {
91
317
  on(event: string, callback?: ((...args: any[]) => any) | null): void
92
318
  reset(): void
93
319
  }
320
+ export namespace logging {
321
+ /**
322
+ * This method is not supported in this build.
323
+ * It will print a warning to stderr when called.
324
+ *
325
+ * Re-compile the native module with the `log` feature to enable logging.
326
+ */
327
+ export function setLogCallbacks(out: ((data: string | null) => void) | null | undefined, err: ((data: string | null) => void) | null | undefined): void
328
+ /**
329
+ * This method is not supported in this build.
330
+ * It will print a warning to stderr when called.
331
+ *
332
+ * Re-compile the native module with the `log` feature to enable logging.
333
+ */
334
+ export function initLogger(path: string): void
335
+ /**
336
+ * This method is not supported in this build.
337
+ * It will print a warning to stderr when called.
338
+ *
339
+ * Re-compile the native module with the `log` feature to enable logging.
340
+ */
341
+ export function resetLogCallbacks(): void
342
+ /**
343
+ * Whether logging is supported.
344
+ * Logging is disabled by default.
345
+ * This constant currently is set to `false`
346
+ * as logging is not supported in this build.
347
+ */
348
+ export const LOGGING_SUPPORTED: boolean
349
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "java-bridge",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "main": "dist/index.prod.min.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "A bridge between Node.js and Java APIs",
@@ -26,7 +26,8 @@
26
26
  "additional": [
27
27
  "aarch64-apple-darwin",
28
28
  "i686-pc-windows-msvc",
29
- "aarch64-unknown-linux-gnu"
29
+ "aarch64-unknown-linux-gnu",
30
+ "x86_64-unknown-linux-musl"
30
31
  ]
31
32
  }
32
33
  },
@@ -43,73 +44,75 @@
43
44
  },
44
45
  "scripts": {
45
46
  "artifacts": "napi artifacts",
47
+ "build:all": "npm run build:napi -- --features all && npm run postbuild",
46
48
  "build": "npm run build:napi",
47
- "build:debug": "npm run build:napi:debug && npm run build:ts && npm run build:java",
48
- "postbuild": "npm run build:ts && npm run build:java",
49
- "build:napi": "napi build --platform --release --js native.js --dts native.d.ts",
50
- "build:napi:debug": "napi build --platform --js native.js --dts native.d.ts",
51
- "build:ts": "webpack build && cpy native.d.ts dist",
49
+ "build:debug": "npm run build:napi:debug && npm run build:java && npm run build:ts",
50
+ "postbuild": "npm run build:java && npm run build:ts",
51
+ "build:napi": "napi build --cargo-name java --platform --release --js native.js --dts native.d.ts",
52
+ "build:napi:debug": "napi build --cargo-name java --platform --js native.js --dts native.d.ts",
53
+ "build:ts": "webpack build",
52
54
  "build:java": "run-script-os",
53
55
  "build:java:darwin:linux": "cd java-src && chmod +x gradlew && ./gradlew shadowJar",
54
56
  "build:java:win32": "cd java-src && .\\gradlew.bat shadowJar",
55
57
  "prepublishOnly": "napi prepublish -t npm",
56
58
  "test": "npm run testOnly",
57
59
  "testOnly": "npm run mocha",
58
- "mocha": "mocha -r ts-node/register test/*.test.ts --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
60
+ "mocha": "cross-env NODE_OPTIONS=\"--import tsx\" mocha test/*.test.ts --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
59
61
  "pretest": "npm run build",
60
62
  "version": "napi version",
61
63
  "prettier": "prettier --write .",
64
+ "prettier:check": "prettier --check .",
62
65
  "prebuild": "rimraf dist",
63
66
  "prebuild:debug": "rimraf dist",
64
- "benchmark": "ts-node -P test/tsconfig.json test/benchmark/benchmark.ts",
67
+ "benchmark": "tsx --tsconfig test/tsconfig.json test/benchmark/benchmark.ts",
65
68
  "prebenchmark": "npm run build",
66
69
  "docs": "typedoc --out docs ts-src/index.ts"
67
70
  },
68
- "dependencies": {
69
- "glob": "^10.0.0"
70
- },
71
71
  "devDependencies": {
72
- "@napi-rs/cli": "^2.15.2",
73
- "@types/chai": "^4.3.4",
74
- "@types/folder-hash": "^4.0.2",
72
+ "@napi-rs/cli": "^2.16.2",
73
+ "@types/chai": "^4.3.5",
74
+ "@types/chai-as-promised": "^7.1.5",
75
75
  "@types/is-ci": "^3.0.0",
76
76
  "@types/mocha": "^10.0.1",
77
- "@types/node": "^18.15.11",
78
- "@types/semver": "^7.3.13",
77
+ "@types/node": "^20.4.10",
78
+ "@types/semver": "^7.5.0",
79
+ "@types/webpack-env": "^1.18.1",
79
80
  "@types/webpack-node-externals": "^3.0.0",
80
- "@types/which": "^3.0.0",
81
81
  "@types/yargs": "^17.0.24",
82
- "chai": "^4.3.7",
83
- "cpy-cli": "^4.2.0",
82
+ "chai": "^4.4.1",
83
+ "chai-as-promised": "^7.1.1",
84
+ "copy-webpack-plugin": "^12.0.2",
85
+ "cpy-cli": "^5.0.0",
86
+ "cross-env": "^7.0.3",
84
87
  "expose-gc": "^1.0.0",
85
- "folder-hash": "^4.0.4",
86
88
  "is-ci": "^3.0.1",
87
89
  "mocha": "^10.2.0",
88
- "mocha-junit-reporter": "^2.2.0",
90
+ "mocha-junit-reporter": "^2.2.1",
89
91
  "mocha-multi-reporters": "^1.5.1",
90
92
  "nanobench": "^3.0.0",
91
93
  "node-loader": "^2.0.0",
92
- "prettier": "^2.8.7",
93
- "rimraf": "^5.0.0",
94
+ "prettier": "^3.0.1",
95
+ "rimraf": "^5.0.1",
94
96
  "run-script-os": "^1.1.6",
95
- "semver": "^7.4.0",
97
+ "semver": "^7.5.4",
96
98
  "string-replace-loader": "^3.1.0",
97
- "ts-loader": "^9.4.2",
99
+ "ts-loader": "^9.4.4",
98
100
  "ts-node": "^10.9.1",
99
- "tslib": "^2.5.0",
100
- "typedoc": "^0.24.1",
101
- "typescript": "^5.0.4",
102
- "webpack": "^5.79.0",
103
- "webpack-cli": "^5.0.1",
104
- "webpack-node-externals": "^3.0.0",
105
- "which": "^3.0.0"
101
+ "tslib": "^2.6.1",
102
+ "tsx": "^4.7.1",
103
+ "typedoc": "^0.25.8",
104
+ "typescript": "^5.3.3",
105
+ "webpack": "^5.88.2",
106
+ "webpack-cli": "^5.1.4",
107
+ "webpack-node-externals": "^3.0.0"
106
108
  },
107
109
  "optionalDependencies": {
108
- "java-bridge-win32-x64-msvc": "2.3.0",
109
- "java-bridge-darwin-x64": "2.3.0",
110
- "java-bridge-linux-x64-gnu": "2.3.0",
111
- "java-bridge-darwin-arm64": "2.3.0",
112
- "java-bridge-win32-ia32-msvc": "2.3.0",
113
- "java-bridge-linux-arm64-gnu": "2.3.0"
110
+ "java-bridge-win32-x64-msvc": "2.5.0",
111
+ "java-bridge-darwin-x64": "2.5.0",
112
+ "java-bridge-linux-x64-gnu": "2.5.0",
113
+ "java-bridge-darwin-arm64": "2.5.0",
114
+ "java-bridge-win32-ia32-msvc": "2.5.0",
115
+ "java-bridge-linux-arm64-gnu": "2.5.0",
116
+ "java-bridge-linux-x64-musl": "2.5.0"
114
117
  }
115
118
  }