tauri-kargo-tools 0.2.6 → 0.2.7
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/package.json +1 -1
- package/src/api.ts +3 -0
- package/src/test/index.ts +18 -6
- package/src/types.ts +21 -0
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -98,6 +98,9 @@ export class TauriKargoClient {
|
|
|
98
98
|
|
|
99
99
|
typescriptTranspile(src: string): Promise<T.TypeScriptTranspileResponse> {
|
|
100
100
|
return this.postJson<T.TypeScriptTranspileResponse>("/api/typescript/transpile", { src: src });
|
|
101
|
+
}
|
|
102
|
+
typescriptAst(req:T.ApiTypescriptAstRequest): Promise<T.TypescriptAstResp > {
|
|
103
|
+
return this.postJson<T.TypescriptAstResp>("/api/typescript/ast", req);
|
|
101
104
|
}
|
|
102
105
|
/**
|
|
103
106
|
* Lire un fichier texte relatif au répertoire courant.
|
package/src/test/index.ts
CHANGED
|
@@ -91,17 +91,29 @@ test.test("Test schema simple avec deux type", async () => {
|
|
|
91
91
|
|
|
92
92
|
|
|
93
93
|
})
|
|
94
|
-
test.test("Test
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
test.test("Test ast typescript ", async () => {
|
|
95
|
+
const client = api.createClient();
|
|
96
|
+
const config = await client.getConfig()
|
|
97
|
+
const rep = await client.explorer({})
|
|
98
|
+
await client.setCurrentDirectory({ path: config.code })
|
|
99
|
+
|
|
100
|
+
const r = await client.typescriptAst({ path: "src/api.ts" })
|
|
101
|
+
console.log(JSON.stringify(r))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
})
|
|
105
|
+
test.test("Test transpile ", async () => {
|
|
106
|
+
const client = api.createClient();
|
|
107
|
+
const src = ` function m( n:number) { return n+1}`
|
|
108
|
+
const r = await client.typescriptTranspile(src)
|
|
109
|
+
console.log(JSON.stringify(r))
|
|
99
110
|
|
|
100
111
|
|
|
101
112
|
})
|
|
102
113
|
test.test("Test read file", async () => {
|
|
103
114
|
|
|
104
115
|
const client = api.createClient();
|
|
116
|
+
await client.setCurrentDirectory({ path: "." })
|
|
105
117
|
const txt = "hello.world"
|
|
106
118
|
await client.writeFileText("test.txt", txt)
|
|
107
119
|
let rep = await client.explorer({})
|
|
@@ -116,7 +128,7 @@ test.test("Test read file", async () => {
|
|
|
116
128
|
|
|
117
129
|
}), true, "pas dans rep")
|
|
118
130
|
}
|
|
119
|
-
|
|
131
|
+
await client.setCurrentDirectory({ path: "." })
|
|
120
132
|
const r = await client.readFileText("test.txt")
|
|
121
133
|
|
|
122
134
|
test.assertEquals(r, txt)
|
package/src/types.ts
CHANGED
|
@@ -242,3 +242,24 @@ export type Json =
|
|
|
242
242
|
| string
|
|
243
243
|
| Json[]
|
|
244
244
|
| { [k: string]: Json };
|
|
245
|
+
export type Ast = AstNode;
|
|
246
|
+
|
|
247
|
+
export type AstNode = {
|
|
248
|
+
kind: string;
|
|
249
|
+
start: number; // offset byte (0..n)
|
|
250
|
+
end: number; // offset byte (exclu)
|
|
251
|
+
startLine: number; // 1-based
|
|
252
|
+
startColumn: number; // 1-based (selon deno_ast view)
|
|
253
|
+
endLine: number; // 1-based
|
|
254
|
+
endColumn: number; // 1-based
|
|
255
|
+
children: AstNode[];
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export type TypescriptAstOk = { ok: true; ast: Ast };
|
|
259
|
+
export type TypescriptAstKo = { ok: false; error: string; position: number };
|
|
260
|
+
|
|
261
|
+
export type TypescriptAstResp = TypescriptAstOk | TypescriptAstKo;
|
|
262
|
+
export interface ApiTypescriptAstRequest {
|
|
263
|
+
/** Chemin relatif à `state.root` (ex: "src/main.ts") */
|
|
264
|
+
path: string;
|
|
265
|
+
}
|