tauri-kargo-tools 0.2.5 → 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/schema/client.ts +6 -6
- package/src/schema/server.ts +6 -6
- package/src/test/index.ts +22 -10
- package/src/test/worker.ts +3 -3
- 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/schema/client.ts
CHANGED
|
@@ -6,8 +6,8 @@ export interface DataModelProp<T extends { [name: string]: Structure<T>; }, K ex
|
|
|
6
6
|
field: F
|
|
7
7
|
value: ToInterface<T, K>[F]
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
10
|
-
type: "
|
|
9
|
+
export interface DoAction<T extends { [name: string]: Structure<T>; }, K extends keyof T, F extends keyof ToInterface<T, K>> extends DataModelProp<T, K, F> {
|
|
10
|
+
type: "doAction"
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export class DataModelClient<T extends { [name: string]: Structure<T>; }> {
|
|
@@ -15,8 +15,8 @@ export class DataModelClient<T extends { [name: string]: Structure<T>; }> {
|
|
|
15
15
|
resolveDataModel: (dm: DataModel<T>) => void = () => { };
|
|
16
16
|
resolveRefUnion: (ref: RefUnion<T>) => void = () => { };
|
|
17
17
|
|
|
18
|
-
async
|
|
19
|
-
const setDataModelProp:
|
|
18
|
+
async doAction<K extends keyof T, F extends KeysOfType<ToInterface<T, K>, Value>>(dvp: DataModelProp<T, K, F>): Promise<DataModel<T>> {
|
|
19
|
+
const setDataModelProp: DoAction<T, K, F> = { ...dvp, type: "doAction" }
|
|
20
20
|
self.postMessage(JSON.parse(JSON.stringify(setDataModelProp)))
|
|
21
21
|
|
|
22
22
|
const r = new Promise<DataModel<T>>((resolve) => {
|
|
@@ -25,8 +25,8 @@ export class DataModelClient<T extends { [name: string]: Structure<T>; }> {
|
|
|
25
25
|
return r;
|
|
26
26
|
|
|
27
27
|
}
|
|
28
|
-
async
|
|
29
|
-
self.postMessage({ type: "
|
|
28
|
+
async getObservation(): Promise<DataModel<T>> {
|
|
29
|
+
self.postMessage({ type: "getObservation" })
|
|
30
30
|
const r = new Promise<DataModel<T>>((resolve) => {
|
|
31
31
|
this.resolveDataModel = resolve;
|
|
32
32
|
})
|
package/src/schema/server.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { set } from "../container";
|
|
|
2
2
|
import { Ref, Structure, ToInterface, DataModel, DataModelReponse, RefUnion } from "./base";
|
|
3
3
|
import { Value } from "./client";
|
|
4
4
|
|
|
5
|
-
export interface
|
|
6
|
-
type: "
|
|
5
|
+
export interface DoAction {
|
|
6
|
+
type: "doAction",
|
|
7
7
|
ref: { ref: string }
|
|
8
8
|
field: string
|
|
9
9
|
value: Value
|
|
@@ -17,17 +17,17 @@ export class DataModelServer<T extends { [name: string]: Structure<T>; }> extend
|
|
|
17
17
|
constructor(def: T) {
|
|
18
18
|
super(def)
|
|
19
19
|
}
|
|
20
|
-
process(worker: Worker, check: (setDataModelProp:
|
|
20
|
+
process(worker: Worker, check: (setDataModelProp: DoAction) => boolean, ref:SimpleRef) {
|
|
21
21
|
worker.addEventListener("message", async (event) => {
|
|
22
22
|
const data = event.data;
|
|
23
|
-
if (data.type === "
|
|
24
|
-
const setDataModelProp = data as
|
|
23
|
+
if (data.type === "doAction") {
|
|
24
|
+
const setDataModelProp = data as DoAction;
|
|
25
25
|
if (check(setDataModelProp)) {
|
|
26
26
|
this.initField(setDataModelProp.ref.ref, setDataModelProp.field, setDataModelProp.value);
|
|
27
27
|
worker.postMessage(this.cloneMap());
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
if (data.type === "
|
|
30
|
+
if (data.type === "getObservation") {
|
|
31
31
|
worker.postMessage(this.cloneMap());
|
|
32
32
|
}
|
|
33
33
|
if (data.type === "getSelf") {
|
package/src/test/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import * as test from "../test"
|
|
2
2
|
import * as api from '../api'
|
|
3
3
|
import * as schema from "../schema/base"
|
|
4
|
-
import { DataModelServer,
|
|
4
|
+
import { DataModelServer, DoAction } from "../schema/server"
|
|
5
5
|
import { model } from "./data-model"
|
|
6
6
|
test.test("Test schema client server", async () => {
|
|
7
7
|
|
|
8
8
|
const server = new DataModelServer(model)
|
|
9
9
|
const state = server.createValue("Cell", { nom: "A", state: false })
|
|
10
10
|
const groupe = server.createValue("Groupe", { membres: [state], state: false })
|
|
11
|
-
let resolve: (b:
|
|
12
|
-
const p = new Promise<
|
|
11
|
+
let resolve: (b: DoAction[]) => void = () => { }
|
|
12
|
+
const p = new Promise<DoAction[]>((r) => {
|
|
13
13
|
resolve = r
|
|
14
14
|
})
|
|
15
|
-
const m:
|
|
15
|
+
const m: DoAction[] = []
|
|
16
16
|
const worker = new Worker(new URL("./worker.ts", import.meta.url), { type: "module" });
|
|
17
17
|
server.process(worker, (op) => {
|
|
18
18
|
m.push(op)
|
|
@@ -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/test/worker.ts
CHANGED
|
@@ -6,12 +6,12 @@ const client = new DataModelClient(model);
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
(async () => {
|
|
9
|
-
const dm = await client.
|
|
9
|
+
const dm = await client.getObservation();
|
|
10
10
|
for (const o of dm.getValues()) {
|
|
11
11
|
if (dm.is(o, "Groupe")) {
|
|
12
12
|
for (const ref of o.membres) {
|
|
13
13
|
console.log(dm.map)
|
|
14
|
-
const tmp = await client.
|
|
14
|
+
const tmp = await client.doAction({ ref: ref, field: "state", value: true });
|
|
15
15
|
console.log(tmp.map)
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@ const client = new DataModelClient(model);
|
|
|
20
20
|
}
|
|
21
21
|
const selfRef = await client.getSelf();
|
|
22
22
|
if (dm.isRef(selfRef, "Groupe")) {
|
|
23
|
-
await client.
|
|
23
|
+
await client.doAction({ ref: selfRef, field: "state", value: true });
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
|
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
|
+
}
|