tauri-kargo-tools 0.2.6 → 0.2.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-kargo-tools",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "",
5
5
  "files": ["src"],
6
6
  "exports": { "./*": "./src/*" },
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.
@@ -10,10 +10,10 @@ export interface DoAction<T extends { [name: string]: Structure<T>; }, K extends
10
10
  type: "doAction"
11
11
  }
12
12
 
13
- export class DataModelClient<T extends { [name: string]: Structure<T>; }> {
13
+ export class DataModelClient<T extends { [name: string]: Structure<T>; },M extends keyof T> {
14
14
  def: T;
15
15
  resolveDataModel: (dm: DataModel<T>) => void = () => { };
16
- resolveRefUnion: (ref: RefUnion<T>) => void = () => { };
16
+ resolveRefUnion: (ref: Ref<T,M>) => void = () => { };
17
17
 
18
18
  async doAction<K extends keyof T, F extends KeysOfType<ToInterface<T, K>, Value>>(dvp: DataModelProp<T, K, F>): Promise<DataModel<T>> {
19
19
  const setDataModelProp: DoAction<T, K, F> = { ...dvp, type: "doAction" }
@@ -32,22 +32,22 @@ export class DataModelClient<T extends { [name: string]: Structure<T>; }> {
32
32
  })
33
33
  return r;
34
34
  }
35
- async getSelf() {
35
+ async getSelf():Promise<Ref<T,M>> {
36
36
  self.postMessage({ type: "getSelf" })
37
- const r = new Promise<RefUnion<T>>((resolve) => {
37
+ const r = new Promise<Ref<T,M>>((resolve) => {
38
38
  this.resolveRefUnion = resolve;
39
39
  })
40
40
  return r;
41
41
 
42
42
 
43
43
  }
44
- constructor(def: T) {
44
+ constructor(def: T, type:M) {
45
45
  this.def = def;
46
46
  self.addEventListener("message", (event) => {
47
47
  const data = event.data;
48
48
  if (data.type === "refReponse") {
49
49
  const refReponse = data as { type: 'refReponse', ref: string };
50
- const r = { ref: refReponse.ref } as RefUnion<T>;
50
+ const r = { ref: refReponse.ref } as Ref<T,M>;
51
51
  this.resolveRefUnion(r);
52
52
  return;
53
53
  }
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 transpile ", async()=> {
95
- const client = api.createClient();
96
- const src = ` function m( n:number) { return n+1}`
97
- const r = await client.typescriptTranspile(src)
98
- console.log(JSON.stringify(r))
94
+ test.test("Test ast typescript ", async () => {
95
+ const client = api.createClient();
96
+ const config = await client.getConfig()
97
+
98
+ const rep = config.code+"\\src\\api.ts"
99
+
100
+ const r = await client.typescriptAst({ path: rep})
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)
@@ -2,7 +2,7 @@ import { DataModelClient } from "../schema/client"
2
2
  import { model } from "./data-model"
3
3
 
4
4
 
5
- const client = new DataModelClient(model);
5
+ const client = new DataModelClient(model, "Groupe");
6
6
 
7
7
 
8
8
  (async () => {
@@ -19,9 +19,9 @@ const client = new DataModelClient(model);
19
19
  }
20
20
  }
21
21
  const selfRef = await client.getSelf();
22
- if (dm.isRef(selfRef, "Groupe")) {
23
- await client.doAction({ ref: selfRef, field: "state", value: true });
24
- }
22
+
23
+ await client.doAction({ ref: selfRef, field: "state", value: true });
24
+
25
25
 
26
26
 
27
27
  })()
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
+ }