Skip to content

Commit b031c02

Browse files
committed
switch tests to using typescript and add type definitions
1 parent 7e3d64b commit b031c02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1706
-683
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Bridge API to connect with existing Java APIs.
99
### Other projects that might be helpful
1010

1111
* [node-java-maven](https://github.com/joeferner/node-java-maven) - manages your node-java classpath by using maven dependency management.
12+
* [ts-java](https://github.com/RedSeal-co/ts-java) - Create TypeScript declaration files for Java packages.
1213

1314
## Installation
1415

eslint.config.mjs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import js from "@eslint/js";
22
import globals from "globals";
3-
import { defineConfig } from "eslint/config";
3+
import tseslint from "typescript-eslint";
44

5-
export default defineConfig([
5+
export default tseslint.config([
6+
{ ignores: ["build"] },
67
{
78
files: ["**/*.{js,mjs,cjs}"],
89
plugins: { js },
9-
extends: ["js/recommended"],
10+
extends: [js.configs.recommended],
1011
languageOptions: { globals: globals.node },
1112
rules: {
1213
"no-var": ["error"],
@@ -22,4 +23,43 @@ export default defineConfig([
2223
],
2324
},
2425
},
26+
{
27+
extends: [js.configs.recommended, ...tseslint.configs.recommendedTypeChecked],
28+
files: ["**/*.{ts,tsx}"],
29+
languageOptions: {
30+
ecmaVersion: 2020,
31+
globals: globals.browser,
32+
parserOptions: {
33+
projectService: true,
34+
tsconfigRootDir: import.meta.dirname,
35+
},
36+
},
37+
plugins: {},
38+
rules: {
39+
"@typescript-eslint/restrict-template-expressions": [
40+
"error",
41+
{
42+
allowNever: true,
43+
},
44+
],
45+
"@typescript-eslint/require-await": "off",
46+
"@typescript-eslint/no-unsafe-assignment": "off",
47+
"@typescript-eslint/no-unsafe-call": "off",
48+
"@typescript-eslint/no-unsafe-member-access": "off",
49+
"@typescript-eslint/no-unsafe-argument": "off",
50+
"@typescript-eslint/no-unsafe-return": "off",
51+
"@typescript-eslint/no-redundant-type-constituents": "off",
52+
"@typescript-eslint/no-floating-promises": "error",
53+
"@typescript-eslint/explicit-member-accessibility": "error",
54+
"@typescript-eslint/explicit-function-return-type": "error",
55+
"@typescript-eslint/no-unused-vars": [
56+
"warn", // or "error"
57+
{
58+
argsIgnorePattern: "^_",
59+
varsIgnorePattern: "^_",
60+
caughtErrorsIgnorePattern: "^_",
61+
},
62+
],
63+
},
64+
},
2565
]);

java.d.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
// eslint-disable-next-line no-var
4+
declare var NodeJavaCore: NodeJavaCore.NodeAPI;
5+
export = NodeJavaCore;
6+
7+
declare namespace NodeJavaCore {
8+
type JavaObject = any;
9+
type JavaError = Error & { cause?: JavaObject };
10+
11+
export interface Callback<T> {
12+
(err?: Error, result?: T): void;
13+
}
14+
15+
export interface JavaCallback<T> {
16+
(err?: JavaError, result?: T): void;
17+
}
18+
19+
interface Promisify {
20+
(fn: Function, receiver?: any): Function;
21+
}
22+
23+
interface AsyncOptions {
24+
syncSuffix: string;
25+
asyncSuffix?: string | undefined;
26+
promiseSuffix?: string | undefined;
27+
promisify?: Promisify | undefined;
28+
ifReadOnlySuffix?: string | undefined;
29+
}
30+
31+
interface ProxyFunctions {
32+
[index: string]: Function;
33+
}
34+
35+
interface Java {
36+
classpath: string[];
37+
options: string[];
38+
asyncOptions: AsyncOptions;
39+
nativeBindingLocation: string;
40+
41+
callMethod(instance: any, methodName: string, args: any[], callback: JavaError<any>): void;
42+
callMethodSync(instance: any, methodName: string, ...args: any[]): any;
43+
callStaticMethod(className: string, methodName: string, ...args: Array<any | JavaError<any>>): void;
44+
callStaticMethodSync(className: string, methodName: string, ...args: any[]): any;
45+
getStaticFieldValue(className: string, fieldName: string): any;
46+
setStaticFieldValue(className: string, fieldName: string, newValue: any): void;
47+
instanceOf(javaObject: any, className: string): boolean;
48+
registerClient(
49+
before: ((cb: Callback<void>) => void) | undefined | null,
50+
after?: (cb: Callback<void>) => void
51+
): void;
52+
registerClientP(beforeP: (() => Promise<void>) | undefined | null, afterP?: () => Promise<void>): void;
53+
ensureJvm(done: Callback<void>): void;
54+
ensureJvm(): Promise<void>;
55+
isJvmCreated(): boolean;
56+
57+
newByte(val: number): any;
58+
newChar(val: string | number): any;
59+
newDouble(val: number): any;
60+
newShort(val: number): any;
61+
newLong(val: number): any;
62+
newFloat(val: number): any;
63+
newDouble(val: number): any;
64+
65+
import(className: string): any;
66+
newInstance(className: string, ...args: any[]): void;
67+
newInstanceSync(className: string, ...args: any[]): any;
68+
newInstanceP(className: string, ...args: any[]): Promise<any>;
69+
newArray(className: string, arg: any[]): any;
70+
getClassLoader(): any;
71+
72+
newProxy(interfaceName: string, functions: ProxyFunctions): any;
73+
}
74+
}

0 commit comments

Comments
 (0)