@corsa-bind/napi 0.1.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 ADDED
@@ -0,0 +1,36 @@
1
+ # @corsa-bind/napi
2
+
3
+ `@corsa-bind/napi` exposes the `corsa` Rust workspace to Node.js through
4
+ `napi-rs`.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm i @corsa-bind/napi
10
+ ```
11
+
12
+ The published root package stays JS-only and pulls in the matching native
13
+ binary through platform-specific optional dependencies.
14
+
15
+ ## What it ships
16
+
17
+ - native Node.js bindings for the `corsa` API and LSP surface
18
+ - an ESM TypeScript wrapper under `dist/`
19
+ - no bundled `typescript-go` executable
20
+
21
+ ## Runtime requirement
22
+
23
+ You must provide a compatible `typescript-go` (`tsgo`) executable yourself and
24
+ pass its path through `TsgoApiClient.spawn({ executable: "/path/to/tsgo" })`.
25
+
26
+ ## Development
27
+
28
+ ```bash
29
+ vp install
30
+ vp run -w build_wrapper
31
+ vp test run --config ./vite.config.ts src/bindings/nodejs/corsa_node/ts/**/*.test.ts
32
+ ```
33
+
34
+ Repository-level executable examples live under [`examples/`](../../examples/README.md),
35
+ including mock-client, virtual-document, distributed-orchestrator, and
36
+ real-`tsgo` snapshot samples.
@@ -0,0 +1,76 @@
1
+ import { ApiClientOptions, ApiMode, ConfigResponse, FileChangeSummary, FileChanges, InitializeResponse, ProjectResponse, TypeResponse, TypeTextKind, UnsafeTypeFlowInput, UpdateSnapshotParams, UpdateSnapshotResponse, VirtualChange, VirtualDocumentState } from "./types.mjs";
2
+ import * as ___index_js0 from "../index.js";
3
+
4
+ //#region index.d.ts
5
+ declare const binding: typeof ___index_js0;
6
+ declare function isUnsafeAssignment(input: UnsafeTypeFlowInput): boolean;
7
+ declare function isUnsafeReturn(input: UnsafeTypeFlowInput): boolean;
8
+ declare function classifyTypeText(text?: string): TypeTextKind;
9
+ declare function splitTopLevelTypeText(text: string, delimiter: string): string[];
10
+ declare function splitTypeText(text: string): string[];
11
+ declare function isStringLikeTypeTexts(typeTexts: readonly string[]): boolean;
12
+ declare function isNumberLikeTypeTexts(typeTexts: readonly string[]): boolean;
13
+ declare function isBigIntLikeTypeTexts(typeTexts: readonly string[]): boolean;
14
+ declare function isAnyLikeTypeTexts(typeTexts: readonly string[]): boolean;
15
+ declare function isUnknownLikeTypeTexts(typeTexts: readonly string[]): boolean;
16
+ declare function isArrayLikeTypeTexts(typeTexts: readonly string[]): boolean;
17
+ declare function isPromiseLikeTypeTexts(typeTexts: readonly string[], propertyNames?: readonly string[]): boolean;
18
+ declare function isErrorLikeTypeTexts(typeTexts: readonly string[], propertyNames?: readonly string[]): boolean;
19
+ declare const Utils: Readonly<{
20
+ classifyTypeText: typeof classifyTypeText;
21
+ splitTopLevelTypeText: typeof splitTopLevelTypeText;
22
+ splitTypeText: typeof splitTypeText;
23
+ isStringLikeTypeTexts: typeof isStringLikeTypeTexts;
24
+ isNumberLikeTypeTexts: typeof isNumberLikeTypeTexts;
25
+ isBigIntLikeTypeTexts: typeof isBigIntLikeTypeTexts;
26
+ isAnyLikeTypeTexts: typeof isAnyLikeTypeTexts;
27
+ isUnknownLikeTypeTexts: typeof isUnknownLikeTypeTexts;
28
+ isArrayLikeTypeTexts: typeof isArrayLikeTypeTexts;
29
+ isPromiseLikeTypeTexts: typeof isPromiseLikeTypeTexts;
30
+ isErrorLikeTypeTexts: typeof isErrorLikeTypeTexts;
31
+ }>;
32
+ declare class TsgoApiClient {
33
+ #private;
34
+ private constructor();
35
+ static spawn(options: ApiClientOptions): TsgoApiClient;
36
+ initialize(): InitializeResponse;
37
+ parseConfigFile(file: string): ConfigResponse;
38
+ updateSnapshot(params?: UpdateSnapshotParams): UpdateSnapshotResponse;
39
+ getSourceFile(snapshot: string, project: string, file: string): Uint8Array | null;
40
+ getStringType(snapshot: string, project: string): TypeResponse;
41
+ typeToString(snapshot: string, project: string, typeHandle: string, location?: string, flags?: number): string;
42
+ callJson<T>(method: string, params?: unknown): T;
43
+ callBinary(method: string, params?: unknown): Uint8Array | null;
44
+ releaseHandle(handle: string): void;
45
+ close(): void;
46
+ }
47
+ declare class TsgoVirtualDocument {
48
+ #private;
49
+ private constructor();
50
+ static untitled(path: string, languageId: string, text: string): TsgoVirtualDocument;
51
+ static inMemory(authority: string, path: string, languageId: string, text: string): TsgoVirtualDocument;
52
+ get uri(): string;
53
+ get languageId(): string;
54
+ get version(): number;
55
+ get text(): string;
56
+ state(): VirtualDocumentState;
57
+ replace(text: string): void;
58
+ applyChanges(changes: VirtualChange[]): unknown[];
59
+ }
60
+ declare class TsgoDistributedOrchestrator {
61
+ #private;
62
+ constructor(nodeIds: string[]);
63
+ campaign(nodeId: string): number;
64
+ leaderId(): string | undefined;
65
+ state<T>(): T | undefined;
66
+ nodeState<T>(nodeId: string): T | undefined;
67
+ document(nodeId: string, uri: string): VirtualDocumentState | undefined;
68
+ openVirtualDocument(document: VirtualDocumentState): VirtualDocumentState;
69
+ changeVirtualDocument(uri: string, changes: VirtualChange[]): VirtualDocumentState;
70
+ closeVirtualDocument(uri: string): void;
71
+ private requireLeader;
72
+ }
73
+ declare const version: typeof ___index_js0.version;
74
+ //#endregion
75
+ export { ApiClientOptions, ApiMode, ConfigResponse, FileChangeSummary, FileChanges, InitializeResponse, ProjectResponse, TsgoApiClient, TsgoDistributedOrchestrator, TsgoVirtualDocument, TypeResponse, TypeTextKind, UnsafeTypeFlowInput, UpdateSnapshotParams, UpdateSnapshotResponse, Utils, VirtualChange, VirtualDocumentState, classifyTypeText, binding as default, isAnyLikeTypeTexts, isArrayLikeTypeTexts, isBigIntLikeTypeTexts, isErrorLikeTypeTexts, isNumberLikeTypeTexts, isPromiseLikeTypeTexts, isStringLikeTypeTexts, isUnknownLikeTypeTexts, isUnsafeAssignment, isUnsafeReturn, splitTopLevelTypeText, splitTypeText, version };
76
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,176 @@
1
+ import * as nativeModule from "../index.js";
2
+ //#region index.ts
3
+ const binding = "default" in nativeModule ? nativeModule.default : nativeModule;
4
+ function fromJson(value) {
5
+ return JSON.parse(value);
6
+ }
7
+ function toJson(value) {
8
+ return JSON.stringify(value ?? null);
9
+ }
10
+ function isUnsafeAssignment(input) {
11
+ return binding.isUnsafeAssignment(toJson(input));
12
+ }
13
+ function isUnsafeReturn(input) {
14
+ return binding.isUnsafeReturn(toJson(input));
15
+ }
16
+ function classifyTypeText(text) {
17
+ return binding.classifyTypeText(text);
18
+ }
19
+ function splitTopLevelTypeText(text, delimiter) {
20
+ return binding.splitTopLevelTypeText(text, delimiter);
21
+ }
22
+ function splitTypeText(text) {
23
+ return binding.splitTypeText(text);
24
+ }
25
+ function isStringLikeTypeTexts(typeTexts) {
26
+ return binding.isStringLikeTypeTexts([...typeTexts]);
27
+ }
28
+ function isNumberLikeTypeTexts(typeTexts) {
29
+ return binding.isNumberLikeTypeTexts([...typeTexts]);
30
+ }
31
+ function isBigIntLikeTypeTexts(typeTexts) {
32
+ return binding.isBigIntLikeTypeTexts([...typeTexts]);
33
+ }
34
+ function isAnyLikeTypeTexts(typeTexts) {
35
+ return binding.isAnyLikeTypeTexts([...typeTexts]);
36
+ }
37
+ function isUnknownLikeTypeTexts(typeTexts) {
38
+ return binding.isUnknownLikeTypeTexts([...typeTexts]);
39
+ }
40
+ function isArrayLikeTypeTexts(typeTexts) {
41
+ return binding.isArrayLikeTypeTexts([...typeTexts]);
42
+ }
43
+ function isPromiseLikeTypeTexts(typeTexts, propertyNames = []) {
44
+ return binding.isPromiseLikeTypeTexts([...typeTexts], [...propertyNames]);
45
+ }
46
+ function isErrorLikeTypeTexts(typeTexts, propertyNames = []) {
47
+ return binding.isErrorLikeTypeTexts([...typeTexts], [...propertyNames]);
48
+ }
49
+ const Utils = Object.freeze({
50
+ classifyTypeText,
51
+ splitTopLevelTypeText,
52
+ splitTypeText,
53
+ isStringLikeTypeTexts,
54
+ isNumberLikeTypeTexts,
55
+ isBigIntLikeTypeTexts,
56
+ isAnyLikeTypeTexts,
57
+ isUnknownLikeTypeTexts,
58
+ isArrayLikeTypeTexts,
59
+ isPromiseLikeTypeTexts,
60
+ isErrorLikeTypeTexts
61
+ });
62
+ var TsgoApiClient = class TsgoApiClient {
63
+ #inner;
64
+ constructor(inner) {
65
+ this.#inner = inner;
66
+ }
67
+ static spawn(options) {
68
+ return new TsgoApiClient(binding.TsgoApiClient.spawn(toJson(options)));
69
+ }
70
+ initialize() {
71
+ return fromJson(this.#inner.initializeJson());
72
+ }
73
+ parseConfigFile(file) {
74
+ return fromJson(this.#inner.parseConfigFileJson(file));
75
+ }
76
+ updateSnapshot(params) {
77
+ return fromJson(this.#inner.updateSnapshotJson(params ? toJson(params) : void 0));
78
+ }
79
+ getSourceFile(snapshot, project, file) {
80
+ return this.#inner.getSourceFile(snapshot, project, file) ?? null;
81
+ }
82
+ getStringType(snapshot, project) {
83
+ return fromJson(this.#inner.getStringTypeJson(snapshot, project));
84
+ }
85
+ typeToString(snapshot, project, typeHandle, location, flags) {
86
+ return this.#inner.typeToString(snapshot, project, typeHandle, location, flags);
87
+ }
88
+ callJson(method, params) {
89
+ return fromJson(this.#inner.callJson(method, params ? toJson(params) : void 0));
90
+ }
91
+ callBinary(method, params) {
92
+ return this.#inner.callBinary(method, params ? toJson(params) : void 0) ?? null;
93
+ }
94
+ releaseHandle(handle) {
95
+ this.#inner.releaseHandle(handle);
96
+ }
97
+ close() {
98
+ this.#inner.close();
99
+ }
100
+ };
101
+ var TsgoVirtualDocument = class TsgoVirtualDocument {
102
+ #inner;
103
+ constructor(inner) {
104
+ this.#inner = inner;
105
+ }
106
+ static untitled(path, languageId, text) {
107
+ return new TsgoVirtualDocument(binding.TsgoVirtualDocument.untitled(path, languageId, text));
108
+ }
109
+ static inMemory(authority, path, languageId, text) {
110
+ return new TsgoVirtualDocument(binding.TsgoVirtualDocument.inMemory(authority, path, languageId, text));
111
+ }
112
+ get uri() {
113
+ return this.#inner.uri;
114
+ }
115
+ get languageId() {
116
+ return this.#inner.languageId;
117
+ }
118
+ get version() {
119
+ return this.#inner.version;
120
+ }
121
+ get text() {
122
+ return this.#inner.text;
123
+ }
124
+ state() {
125
+ return fromJson(this.#inner.stateJson());
126
+ }
127
+ replace(text) {
128
+ this.#inner.replace(text);
129
+ }
130
+ applyChanges(changes) {
131
+ return fromJson(this.#inner.applyChangesJson(toJson(changes)));
132
+ }
133
+ };
134
+ var TsgoDistributedOrchestrator = class {
135
+ #inner;
136
+ constructor(nodeIds) {
137
+ this.#inner = new binding.TsgoDistributedOrchestrator(nodeIds);
138
+ }
139
+ campaign(nodeId) {
140
+ return this.#inner.campaign(nodeId);
141
+ }
142
+ leaderId() {
143
+ return this.#inner.leaderId() ?? void 0;
144
+ }
145
+ state() {
146
+ const value = this.#inner.stateJson();
147
+ return value ? fromJson(value) : void 0;
148
+ }
149
+ nodeState(nodeId) {
150
+ const value = this.#inner.nodeStateJson(nodeId);
151
+ return value ? fromJson(value) : void 0;
152
+ }
153
+ document(nodeId, uri) {
154
+ const value = this.#inner.documentJson(nodeId, uri);
155
+ return value ? fromJson(value) : void 0;
156
+ }
157
+ openVirtualDocument(document) {
158
+ return fromJson(this.#inner.openVirtualDocumentJson(this.requireLeader(), toJson(document)));
159
+ }
160
+ changeVirtualDocument(uri, changes) {
161
+ return fromJson(this.#inner.changeVirtualDocumentJson(this.requireLeader(), uri, toJson(changes)));
162
+ }
163
+ closeVirtualDocument(uri) {
164
+ this.#inner.closeVirtualDocument(this.requireLeader(), uri);
165
+ }
166
+ requireLeader() {
167
+ const leaderId = this.leaderId();
168
+ if (!leaderId) throw new Error("raft leader has not been elected");
169
+ return leaderId;
170
+ }
171
+ };
172
+ const version = binding.version;
173
+ //#endregion
174
+ export { TsgoApiClient, TsgoDistributedOrchestrator, TsgoVirtualDocument, Utils, classifyTypeText, binding as default, isAnyLikeTypeTexts, isArrayLikeTypeTexts, isBigIntLikeTypeTexts, isErrorLikeTypeTexts, isNumberLikeTypeTexts, isPromiseLikeTypeTexts, isStringLikeTypeTexts, isUnknownLikeTypeTexts, isUnsafeAssignment, isUnsafeReturn, splitTopLevelTypeText, splitTypeText, version };
175
+
176
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["#inner"],"sources":["../ts/index.ts"],"sourcesContent":["import * as nativeModule from \"../index.js\";\n\nimport type {\n ApiClientOptions,\n ConfigResponse,\n InitializeResponse,\n TypeTextKind,\n TypeResponse,\n UnsafeTypeFlowInput,\n UpdateSnapshotParams,\n UpdateSnapshotResponse,\n VirtualChange,\n VirtualDocumentState,\n} from \"./types\";\n\nconst binding = (\n \"default\" in nativeModule ? nativeModule.default : nativeModule\n) as typeof import(\"../index.js\");\n\ntype NativeApiClient = InstanceType<typeof binding.TsgoApiClient>;\ntype NativeDistributedOrchestrator = InstanceType<typeof binding.TsgoDistributedOrchestrator>;\ntype NativeVirtualDocument = InstanceType<typeof binding.TsgoVirtualDocument>;\n\nfunction fromJson<T>(value: string): T {\n return JSON.parse(value) as T;\n}\n\nfunction toJson(value: unknown): string {\n return JSON.stringify(value ?? null);\n}\n\nexport function isUnsafeAssignment(input: UnsafeTypeFlowInput): boolean {\n return binding.isUnsafeAssignment(toJson(input));\n}\n\nexport function isUnsafeReturn(input: UnsafeTypeFlowInput): boolean {\n return binding.isUnsafeReturn(toJson(input));\n}\n\nexport function classifyTypeText(text?: string): TypeTextKind {\n return binding.classifyTypeText(text) as TypeTextKind;\n}\n\nexport function splitTopLevelTypeText(text: string, delimiter: string): string[] {\n return binding.splitTopLevelTypeText(text, delimiter);\n}\n\nexport function splitTypeText(text: string): string[] {\n return binding.splitTypeText(text);\n}\n\nexport function isStringLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isStringLikeTypeTexts([...typeTexts]);\n}\n\nexport function isNumberLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isNumberLikeTypeTexts([...typeTexts]);\n}\n\nexport function isBigIntLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isBigIntLikeTypeTexts([...typeTexts]);\n}\n\nexport function isAnyLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isAnyLikeTypeTexts([...typeTexts]);\n}\n\nexport function isUnknownLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isUnknownLikeTypeTexts([...typeTexts]);\n}\n\nexport function isArrayLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isArrayLikeTypeTexts([...typeTexts]);\n}\n\nexport function isPromiseLikeTypeTexts(\n typeTexts: readonly string[],\n propertyNames: readonly string[] = [],\n): boolean {\n return binding.isPromiseLikeTypeTexts([...typeTexts], [...propertyNames]);\n}\n\nexport function isErrorLikeTypeTexts(\n typeTexts: readonly string[],\n propertyNames: readonly string[] = [],\n): boolean {\n return binding.isErrorLikeTypeTexts([...typeTexts], [...propertyNames]);\n}\n\nexport const Utils = Object.freeze({\n classifyTypeText,\n splitTopLevelTypeText,\n splitTypeText,\n isStringLikeTypeTexts,\n isNumberLikeTypeTexts,\n isBigIntLikeTypeTexts,\n isAnyLikeTypeTexts,\n isUnknownLikeTypeTexts,\n isArrayLikeTypeTexts,\n isPromiseLikeTypeTexts,\n isErrorLikeTypeTexts,\n});\n\nexport class TsgoApiClient {\n readonly #inner: NativeApiClient;\n\n private constructor(inner: NativeApiClient) {\n this.#inner = inner;\n }\n\n static spawn(options: ApiClientOptions): TsgoApiClient {\n return new TsgoApiClient(binding.TsgoApiClient.spawn(toJson(options)));\n }\n\n initialize(): InitializeResponse {\n return fromJson(this.#inner.initializeJson());\n }\n\n parseConfigFile(file: string): ConfigResponse {\n return fromJson(this.#inner.parseConfigFileJson(file));\n }\n\n updateSnapshot(params?: UpdateSnapshotParams): UpdateSnapshotResponse {\n return fromJson(this.#inner.updateSnapshotJson(params ? toJson(params) : undefined));\n }\n\n getSourceFile(snapshot: string, project: string, file: string): Uint8Array | null {\n return this.#inner.getSourceFile(snapshot, project, file) ?? null;\n }\n\n getStringType(snapshot: string, project: string): TypeResponse {\n return fromJson(this.#inner.getStringTypeJson(snapshot, project));\n }\n\n typeToString(\n snapshot: string,\n project: string,\n typeHandle: string,\n location?: string,\n flags?: number,\n ): string {\n return this.#inner.typeToString(snapshot, project, typeHandle, location, flags);\n }\n\n callJson<T>(method: string, params?: unknown): T {\n return fromJson(this.#inner.callJson(method, params ? toJson(params) : undefined));\n }\n\n callBinary(method: string, params?: unknown): Uint8Array | null {\n return this.#inner.callBinary(method, params ? toJson(params) : undefined) ?? null;\n }\n\n releaseHandle(handle: string): void {\n this.#inner.releaseHandle(handle);\n }\n\n close(): void {\n this.#inner.close();\n }\n}\n\nexport class TsgoVirtualDocument {\n readonly #inner: NativeVirtualDocument;\n\n private constructor(inner: NativeVirtualDocument) {\n this.#inner = inner;\n }\n\n static untitled(path: string, languageId: string, text: string): TsgoVirtualDocument {\n return new TsgoVirtualDocument(binding.TsgoVirtualDocument.untitled(path, languageId, text));\n }\n\n static inMemory(\n authority: string,\n path: string,\n languageId: string,\n text: string,\n ): TsgoVirtualDocument {\n return new TsgoVirtualDocument(\n binding.TsgoVirtualDocument.inMemory(authority, path, languageId, text),\n );\n }\n\n get uri(): string {\n return this.#inner.uri;\n }\n\n get languageId(): string {\n return this.#inner.languageId;\n }\n\n get version(): number {\n return this.#inner.version;\n }\n\n get text(): string {\n return this.#inner.text;\n }\n\n state(): VirtualDocumentState {\n return fromJson(this.#inner.stateJson());\n }\n\n replace(text: string): void {\n this.#inner.replace(text);\n }\n\n applyChanges(changes: VirtualChange[]): unknown[] {\n return fromJson(this.#inner.applyChangesJson(toJson(changes)));\n }\n}\n\nexport class TsgoDistributedOrchestrator {\n readonly #inner: NativeDistributedOrchestrator;\n\n constructor(nodeIds: string[]) {\n this.#inner = new binding.TsgoDistributedOrchestrator(nodeIds);\n }\n\n campaign(nodeId: string): number {\n return this.#inner.campaign(nodeId);\n }\n\n leaderId(): string | undefined {\n return this.#inner.leaderId() ?? undefined;\n }\n\n state<T>(): T | undefined {\n const value = this.#inner.stateJson();\n return value ? fromJson<T>(value) : undefined;\n }\n\n nodeState<T>(nodeId: string): T | undefined {\n const value = this.#inner.nodeStateJson(nodeId);\n return value ? fromJson<T>(value) : undefined;\n }\n\n document(nodeId: string, uri: string): VirtualDocumentState | undefined {\n const value = this.#inner.documentJson(nodeId, uri);\n return value ? fromJson<VirtualDocumentState>(value) : undefined;\n }\n\n openVirtualDocument(document: VirtualDocumentState): VirtualDocumentState {\n return fromJson(this.#inner.openVirtualDocumentJson(this.requireLeader(), toJson(document)));\n }\n\n changeVirtualDocument(uri: string, changes: VirtualChange[]): VirtualDocumentState {\n return fromJson(\n this.#inner.changeVirtualDocumentJson(this.requireLeader(), uri, toJson(changes)),\n );\n }\n\n closeVirtualDocument(uri: string): void {\n this.#inner.closeVirtualDocument(this.requireLeader(), uri);\n }\n\n private requireLeader(): string {\n const leaderId = this.leaderId();\n if (!leaderId) {\n throw new Error(\"raft leader has not been elected\");\n }\n return leaderId;\n }\n}\n\nexport default binding;\nexport const version = binding.version;\nexport type * from \"./types\";\n"],"mappings":"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"}
@@ -0,0 +1,78 @@
1
+ //#region types.d.ts
2
+ type ApiMode = "jsonrpc" | "msgpack";
3
+ interface ApiClientOptions {
4
+ executable: string;
5
+ cwd?: string;
6
+ mode?: ApiMode;
7
+ requestTimeoutMs?: number;
8
+ shutdownTimeoutMs?: number;
9
+ outboundCapacity?: number;
10
+ allowUnstableUpstreamCalls?: boolean;
11
+ }
12
+ interface InitializeResponse {
13
+ useCaseSensitiveFileNames: boolean;
14
+ currentDirectory: string;
15
+ }
16
+ interface ConfigResponse {
17
+ options: unknown;
18
+ fileNames: string[];
19
+ }
20
+ interface ProjectResponse {
21
+ id: string;
22
+ configFileName: string;
23
+ compilerOptions: unknown;
24
+ rootFiles: string[];
25
+ }
26
+ interface FileChangeSummary {
27
+ changed?: string[];
28
+ created?: string[];
29
+ deleted?: string[];
30
+ }
31
+ type FileChanges = FileChangeSummary | {
32
+ invalidateAll: boolean;
33
+ };
34
+ interface UpdateSnapshotParams {
35
+ openProject?: string;
36
+ fileChanges?: FileChanges;
37
+ }
38
+ interface UpdateSnapshotResponse {
39
+ snapshot: string;
40
+ projects: ProjectResponse[];
41
+ changes?: unknown;
42
+ }
43
+ interface TypeResponse {
44
+ id: string;
45
+ flags: number;
46
+ objectFlags?: number;
47
+ value?: unknown;
48
+ symbol?: string;
49
+ texts: string[];
50
+ }
51
+ interface UnsafeTypeFlowInput {
52
+ sourceTypeTexts: readonly string[];
53
+ targetTypeTexts?: readonly string[];
54
+ }
55
+ type TypeTextKind = "any" | "bigint" | "boolean" | "nullish" | "number" | "regexp" | "string" | "unknown" | "other";
56
+ interface VirtualChange {
57
+ range?: {
58
+ start: {
59
+ line: number;
60
+ character: number;
61
+ };
62
+ end: {
63
+ line: number;
64
+ character: number;
65
+ };
66
+ };
67
+ rangeLength?: number;
68
+ text: string;
69
+ }
70
+ interface VirtualDocumentState {
71
+ uri: string;
72
+ languageId: string;
73
+ version: number;
74
+ text: string;
75
+ }
76
+ //#endregion
77
+ export { ApiClientOptions, ApiMode, ConfigResponse, FileChangeSummary, FileChanges, InitializeResponse, ProjectResponse, TypeResponse, TypeTextKind, UnsafeTypeFlowInput, UpdateSnapshotParams, UpdateSnapshotResponse, VirtualChange, VirtualDocumentState };
78
+ //# sourceMappingURL=types.d.mts.map
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export {};
package/index.d.ts ADDED
@@ -0,0 +1,95 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export declare function isUnsafeAssignment(inputJson: string): boolean
7
+ export declare function isUnsafeReturn(inputJson: string): boolean
8
+ export declare function classifyTypeText(text?: string | undefined | null): string
9
+ export declare function splitTopLevelTypeText(text: string, delimiter: string): Array<string>
10
+ export declare function splitTypeText(text: string): Array<string>
11
+ export declare function isStringLikeTypeTexts(typeTexts: Array<string>): boolean
12
+ export declare function isNumberLikeTypeTexts(typeTexts: Array<string>): boolean
13
+ export declare function isBigIntLikeTypeTexts(typeTexts: Array<string>): boolean
14
+ export declare function isAnyLikeTypeTexts(typeTexts: Array<string>): boolean
15
+ export declare function isUnknownLikeTypeTexts(typeTexts: Array<string>): boolean
16
+ export declare function isArrayLikeTypeTexts(typeTexts: Array<string>): boolean
17
+ export declare function isPromiseLikeTypeTexts(typeTexts: Array<string>, propertyNames?: Array<string> | undefined | null): boolean
18
+ export declare function isErrorLikeTypeTexts(typeTexts: Array<string>, propertyNames?: Array<string> | undefined | null): boolean
19
+ /**
20
+ * Returns the package version exposed by the native addon.
21
+ *
22
+ * # Examples
23
+ *
24
+ * ```
25
+ * assert_eq!(corsa_node::version(), env!("CARGO_PKG_VERSION"));
26
+ * ```
27
+ */
28
+ export declare function version(): string
29
+ /** Thin synchronous wrapper around the Rust stdio API client. */
30
+ export declare class TsgoApiClient {
31
+ /** Spawns a new client from a JSON-encoded spawn config. */
32
+ static spawn(optionsJson: string): TsgoApiClient
33
+ /** Calls `initialize` and returns the raw JSON response. */
34
+ initializeJson(): string
35
+ /** Parses a `tsconfig` through tsgo and returns the JSON response. */
36
+ parseConfigFileJson(file: string): string
37
+ /** Applies file changes and returns a serialized snapshot record. */
38
+ updateSnapshotJson(paramsJson?: string | undefined | null): string
39
+ /** Fetches a source file through the binary endpoint. */
40
+ getSourceFile(snapshot: string, project: string, file: string): Buffer | null
41
+ /** Resolves the intrinsic string type for a project. */
42
+ getStringTypeJson(snapshot: string, project: string): string
43
+ /** Renders a type back to a string representation. */
44
+ typeToString(snapshot: string, project: string, typeHandle: string, location?: string | undefined | null, flags?: number | undefined | null): string
45
+ /** Sends an arbitrary JSON endpoint request. */
46
+ callJson(method: string, paramsJson?: string | undefined | null): string
47
+ /** Sends an arbitrary binary endpoint request. */
48
+ callBinary(method: string, paramsJson?: string | undefined | null): Buffer | null
49
+ /** Releases a tsgo handle explicitly. */
50
+ releaseHandle(handle: string): void
51
+ /** Closes the underlying worker process. */
52
+ close(): void
53
+ }
54
+ /** Mutable virtual document mirrored through the LSP overlay layer. */
55
+ export declare class TsgoVirtualDocument {
56
+ /** Creates an `untitled:` document. */
57
+ static untitled(path: string, languageId: string, text: string): TsgoVirtualDocument
58
+ /** Creates an in-memory `tsgo://` document. */
59
+ static inMemory(authority: string, path: string, languageId: string, text: string): TsgoVirtualDocument
60
+ /** Returns the document URI. */
61
+ get uri(): string
62
+ /** Returns the language identifier. */
63
+ get languageId(): string
64
+ /** Returns the current version number. */
65
+ get version(): number
66
+ /** Returns the current full text. */
67
+ get text(): string
68
+ /** Serializes the full document state. */
69
+ stateJson(): string
70
+ /** Replaces the entire document text. */
71
+ replace(text: string): void
72
+ /** Applies a batch of JSON-encoded LSP changes. */
73
+ applyChangesJson(changesJson: string): string
74
+ }
75
+ /** N-API wrapper for the distributed orchestration layer. */
76
+ export declare class TsgoDistributedOrchestrator {
77
+ /** Creates a new in-process Raft cluster. */
78
+ constructor(nodeIds: Array<string>)
79
+ /** Starts a leader election and returns the resulting term. */
80
+ campaign(nodeId: string): number
81
+ /** Returns the current leader identifier. */
82
+ leaderId(): string | null
83
+ /** Serializes the leader state. */
84
+ stateJson(): string | null
85
+ /** Serializes the state for a single node. */
86
+ nodeStateJson(nodeId: string): string | null
87
+ /** Serializes a replicated document if it exists. */
88
+ documentJson(nodeId: string, uri: string): string | null
89
+ /** Replicates an opened document and returns the serialized state. */
90
+ openVirtualDocumentJson(leaderId: string, documentJson: string): string
91
+ /** Applies replicated incremental changes and returns the serialized state. */
92
+ changeVirtualDocumentJson(leaderId: string, uri: string, changesJson: string): string
93
+ /** Removes a replicated document. */
94
+ closeVirtualDocument(leaderId: string, uri: string): void
95
+ }
package/index.js ADDED
@@ -0,0 +1,331 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /* prettier-ignore */
4
+
5
+ /* auto-generated by NAPI-RS */
6
+
7
+ const { existsSync, readFileSync } = require('fs')
8
+ const { join } = require('path')
9
+
10
+ const { platform, arch } = process
11
+
12
+ let nativeBinding = null
13
+ let localFileExisted = false
14
+ let loadError = null
15
+
16
+ function isMusl() {
17
+ // For Node 10
18
+ if (!process.report || typeof process.report.getReport !== 'function') {
19
+ try {
20
+ const lddPath = require('child_process').execSync('which ldd').toString().trim()
21
+ return readFileSync(lddPath, 'utf8').includes('musl')
22
+ } catch (e) {
23
+ return true
24
+ }
25
+ } else {
26
+ const { glibcVersionRuntime } = process.report.getReport().header
27
+ return !glibcVersionRuntime
28
+ }
29
+ }
30
+
31
+ switch (platform) {
32
+ case 'android':
33
+ switch (arch) {
34
+ case 'arm64':
35
+ localFileExisted = existsSync(join(__dirname, 'corsa_node.android-arm64.node'))
36
+ try {
37
+ if (localFileExisted) {
38
+ nativeBinding = require('./corsa_node.android-arm64.node')
39
+ } else {
40
+ nativeBinding = require('@corsa-bind/napi-android-arm64')
41
+ }
42
+ } catch (e) {
43
+ loadError = e
44
+ }
45
+ break
46
+ case 'arm':
47
+ localFileExisted = existsSync(join(__dirname, 'corsa_node.android-arm-eabi.node'))
48
+ try {
49
+ if (localFileExisted) {
50
+ nativeBinding = require('./corsa_node.android-arm-eabi.node')
51
+ } else {
52
+ nativeBinding = require('@corsa-bind/napi-android-arm-eabi')
53
+ }
54
+ } catch (e) {
55
+ loadError = e
56
+ }
57
+ break
58
+ default:
59
+ throw new Error(`Unsupported architecture on Android ${arch}`)
60
+ }
61
+ break
62
+ case 'win32':
63
+ switch (arch) {
64
+ case 'x64':
65
+ localFileExisted = existsSync(
66
+ join(__dirname, 'corsa_node.win32-x64-msvc.node')
67
+ )
68
+ try {
69
+ if (localFileExisted) {
70
+ nativeBinding = require('./corsa_node.win32-x64-msvc.node')
71
+ } else {
72
+ nativeBinding = require('@corsa-bind/napi-win32-x64-msvc')
73
+ }
74
+ } catch (e) {
75
+ loadError = e
76
+ }
77
+ break
78
+ case 'ia32':
79
+ localFileExisted = existsSync(
80
+ join(__dirname, 'corsa_node.win32-ia32-msvc.node')
81
+ )
82
+ try {
83
+ if (localFileExisted) {
84
+ nativeBinding = require('./corsa_node.win32-ia32-msvc.node')
85
+ } else {
86
+ nativeBinding = require('@corsa-bind/napi-win32-ia32-msvc')
87
+ }
88
+ } catch (e) {
89
+ loadError = e
90
+ }
91
+ break
92
+ case 'arm64':
93
+ localFileExisted = existsSync(
94
+ join(__dirname, 'corsa_node.win32-arm64-msvc.node')
95
+ )
96
+ try {
97
+ if (localFileExisted) {
98
+ nativeBinding = require('./corsa_node.win32-arm64-msvc.node')
99
+ } else {
100
+ nativeBinding = require('@corsa-bind/napi-win32-arm64-msvc')
101
+ }
102
+ } catch (e) {
103
+ loadError = e
104
+ }
105
+ break
106
+ default:
107
+ throw new Error(`Unsupported architecture on Windows: ${arch}`)
108
+ }
109
+ break
110
+ case 'darwin':
111
+ localFileExisted = existsSync(join(__dirname, 'corsa_node.darwin-universal.node'))
112
+ try {
113
+ if (localFileExisted) {
114
+ nativeBinding = require('./corsa_node.darwin-universal.node')
115
+ } else {
116
+ nativeBinding = require('@corsa-bind/napi-darwin-universal')
117
+ }
118
+ break
119
+ } catch {}
120
+ switch (arch) {
121
+ case 'x64':
122
+ localFileExisted = existsSync(join(__dirname, 'corsa_node.darwin-x64.node'))
123
+ try {
124
+ if (localFileExisted) {
125
+ nativeBinding = require('./corsa_node.darwin-x64.node')
126
+ } else {
127
+ nativeBinding = require('@corsa-bind/napi-darwin-x64')
128
+ }
129
+ } catch (e) {
130
+ loadError = e
131
+ }
132
+ break
133
+ case 'arm64':
134
+ localFileExisted = existsSync(
135
+ join(__dirname, 'corsa_node.darwin-arm64.node')
136
+ )
137
+ try {
138
+ if (localFileExisted) {
139
+ nativeBinding = require('./corsa_node.darwin-arm64.node')
140
+ } else {
141
+ nativeBinding = require('@corsa-bind/napi-darwin-arm64')
142
+ }
143
+ } catch (e) {
144
+ loadError = e
145
+ }
146
+ break
147
+ default:
148
+ throw new Error(`Unsupported architecture on macOS: ${arch}`)
149
+ }
150
+ break
151
+ case 'freebsd':
152
+ if (arch !== 'x64') {
153
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
154
+ }
155
+ localFileExisted = existsSync(join(__dirname, 'corsa_node.freebsd-x64.node'))
156
+ try {
157
+ if (localFileExisted) {
158
+ nativeBinding = require('./corsa_node.freebsd-x64.node')
159
+ } else {
160
+ nativeBinding = require('@corsa-bind/napi-freebsd-x64')
161
+ }
162
+ } catch (e) {
163
+ loadError = e
164
+ }
165
+ break
166
+ case 'linux':
167
+ switch (arch) {
168
+ case 'x64':
169
+ if (isMusl()) {
170
+ localFileExisted = existsSync(
171
+ join(__dirname, 'corsa_node.linux-x64-musl.node')
172
+ )
173
+ try {
174
+ if (localFileExisted) {
175
+ nativeBinding = require('./corsa_node.linux-x64-musl.node')
176
+ } else {
177
+ nativeBinding = require('@corsa-bind/napi-linux-x64-musl')
178
+ }
179
+ } catch (e) {
180
+ loadError = e
181
+ }
182
+ } else {
183
+ localFileExisted = existsSync(
184
+ join(__dirname, 'corsa_node.linux-x64-gnu.node')
185
+ )
186
+ try {
187
+ if (localFileExisted) {
188
+ nativeBinding = require('./corsa_node.linux-x64-gnu.node')
189
+ } else {
190
+ nativeBinding = require('@corsa-bind/napi-linux-x64-gnu')
191
+ }
192
+ } catch (e) {
193
+ loadError = e
194
+ }
195
+ }
196
+ break
197
+ case 'arm64':
198
+ if (isMusl()) {
199
+ localFileExisted = existsSync(
200
+ join(__dirname, 'corsa_node.linux-arm64-musl.node')
201
+ )
202
+ try {
203
+ if (localFileExisted) {
204
+ nativeBinding = require('./corsa_node.linux-arm64-musl.node')
205
+ } else {
206
+ nativeBinding = require('@corsa-bind/napi-linux-arm64-musl')
207
+ }
208
+ } catch (e) {
209
+ loadError = e
210
+ }
211
+ } else {
212
+ localFileExisted = existsSync(
213
+ join(__dirname, 'corsa_node.linux-arm64-gnu.node')
214
+ )
215
+ try {
216
+ if (localFileExisted) {
217
+ nativeBinding = require('./corsa_node.linux-arm64-gnu.node')
218
+ } else {
219
+ nativeBinding = require('@corsa-bind/napi-linux-arm64-gnu')
220
+ }
221
+ } catch (e) {
222
+ loadError = e
223
+ }
224
+ }
225
+ break
226
+ case 'arm':
227
+ if (isMusl()) {
228
+ localFileExisted = existsSync(
229
+ join(__dirname, 'corsa_node.linux-arm-musleabihf.node')
230
+ )
231
+ try {
232
+ if (localFileExisted) {
233
+ nativeBinding = require('./corsa_node.linux-arm-musleabihf.node')
234
+ } else {
235
+ nativeBinding = require('@corsa-bind/napi-linux-arm-musleabihf')
236
+ }
237
+ } catch (e) {
238
+ loadError = e
239
+ }
240
+ } else {
241
+ localFileExisted = existsSync(
242
+ join(__dirname, 'corsa_node.linux-arm-gnueabihf.node')
243
+ )
244
+ try {
245
+ if (localFileExisted) {
246
+ nativeBinding = require('./corsa_node.linux-arm-gnueabihf.node')
247
+ } else {
248
+ nativeBinding = require('@corsa-bind/napi-linux-arm-gnueabihf')
249
+ }
250
+ } catch (e) {
251
+ loadError = e
252
+ }
253
+ }
254
+ break
255
+ case 'riscv64':
256
+ if (isMusl()) {
257
+ localFileExisted = existsSync(
258
+ join(__dirname, 'corsa_node.linux-riscv64-musl.node')
259
+ )
260
+ try {
261
+ if (localFileExisted) {
262
+ nativeBinding = require('./corsa_node.linux-riscv64-musl.node')
263
+ } else {
264
+ nativeBinding = require('@corsa-bind/napi-linux-riscv64-musl')
265
+ }
266
+ } catch (e) {
267
+ loadError = e
268
+ }
269
+ } else {
270
+ localFileExisted = existsSync(
271
+ join(__dirname, 'corsa_node.linux-riscv64-gnu.node')
272
+ )
273
+ try {
274
+ if (localFileExisted) {
275
+ nativeBinding = require('./corsa_node.linux-riscv64-gnu.node')
276
+ } else {
277
+ nativeBinding = require('@corsa-bind/napi-linux-riscv64-gnu')
278
+ }
279
+ } catch (e) {
280
+ loadError = e
281
+ }
282
+ }
283
+ break
284
+ case 's390x':
285
+ localFileExisted = existsSync(
286
+ join(__dirname, 'corsa_node.linux-s390x-gnu.node')
287
+ )
288
+ try {
289
+ if (localFileExisted) {
290
+ nativeBinding = require('./corsa_node.linux-s390x-gnu.node')
291
+ } else {
292
+ nativeBinding = require('@corsa-bind/napi-linux-s390x-gnu')
293
+ }
294
+ } catch (e) {
295
+ loadError = e
296
+ }
297
+ break
298
+ default:
299
+ throw new Error(`Unsupported architecture on Linux: ${arch}`)
300
+ }
301
+ break
302
+ default:
303
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
304
+ }
305
+
306
+ if (!nativeBinding) {
307
+ if (loadError) {
308
+ throw loadError
309
+ }
310
+ throw new Error(`Failed to load native binding`)
311
+ }
312
+
313
+ const { TsgoApiClient, TsgoVirtualDocument, TsgoDistributedOrchestrator, isUnsafeAssignment, isUnsafeReturn, classifyTypeText, splitTopLevelTypeText, splitTypeText, isStringLikeTypeTexts, isNumberLikeTypeTexts, isBigIntLikeTypeTexts, isAnyLikeTypeTexts, isUnknownLikeTypeTexts, isArrayLikeTypeTexts, isPromiseLikeTypeTexts, isErrorLikeTypeTexts, version } = nativeBinding
314
+
315
+ module.exports.TsgoApiClient = TsgoApiClient
316
+ module.exports.TsgoVirtualDocument = TsgoVirtualDocument
317
+ module.exports.TsgoDistributedOrchestrator = TsgoDistributedOrchestrator
318
+ module.exports.isUnsafeAssignment = isUnsafeAssignment
319
+ module.exports.isUnsafeReturn = isUnsafeReturn
320
+ module.exports.classifyTypeText = classifyTypeText
321
+ module.exports.splitTopLevelTypeText = splitTopLevelTypeText
322
+ module.exports.splitTypeText = splitTypeText
323
+ module.exports.isStringLikeTypeTexts = isStringLikeTypeTexts
324
+ module.exports.isNumberLikeTypeTexts = isNumberLikeTypeTexts
325
+ module.exports.isBigIntLikeTypeTexts = isBigIntLikeTypeTexts
326
+ module.exports.isAnyLikeTypeTexts = isAnyLikeTypeTexts
327
+ module.exports.isUnknownLikeTypeTexts = isUnknownLikeTypeTexts
328
+ module.exports.isArrayLikeTypeTexts = isArrayLikeTypeTexts
329
+ module.exports.isPromiseLikeTypeTexts = isPromiseLikeTypeTexts
330
+ module.exports.isErrorLikeTypeTexts = isErrorLikeTypeTexts
331
+ module.exports.version = version
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@corsa-bind/napi",
3
+ "version": "0.1.0",
4
+ "description": "Native Node.js bindings for corsa and typescript-go stdio workflows",
5
+ "homepage": "https://github.com/ubugeeei/corsa-bind/tree/main/src/bindings/nodejs/corsa_node",
6
+ "bugs": {
7
+ "url": "https://github.com/ubugeeei/corsa-bind/issues"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/ubugeeei/corsa-bind.git",
13
+ "directory": "src/bindings/nodejs/corsa_node"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "index.d.ts",
19
+ "index.js"
20
+ ],
21
+ "main": "./dist/index.mjs",
22
+ "types": "./dist/index.d.mts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.mts",
26
+ "default": "./dist/index.mjs",
27
+ "import": "./dist/index.mjs"
28
+ }
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "napi": {
34
+ "name": "corsa_node",
35
+ "triples": {
36
+ "additional": [
37
+ "aarch64-apple-darwin",
38
+ "aarch64-pc-windows-msvc",
39
+ "x86_64-unknown-linux-musl",
40
+ "aarch64-unknown-linux-gnu",
41
+ "aarch64-unknown-linux-musl"
42
+ ]
43
+ }
44
+ },
45
+ "engines": {
46
+ "node": ">=22"
47
+ },
48
+ "optionalDependencies": {
49
+ "@corsa-bind/napi-win32-x64-msvc": "0.1.0",
50
+ "@corsa-bind/napi-darwin-x64": "0.1.0",
51
+ "@corsa-bind/napi-linux-x64-gnu": "0.1.0",
52
+ "@corsa-bind/napi-darwin-arm64": "0.1.0",
53
+ "@corsa-bind/napi-win32-arm64-msvc": "0.1.0",
54
+ "@corsa-bind/napi-linux-x64-musl": "0.1.0",
55
+ "@corsa-bind/napi-linux-arm64-gnu": "0.1.0",
56
+ "@corsa-bind/napi-linux-arm64-musl": "0.1.0"
57
+ }
58
+ }