tauri-kargo-tools 0.2.4 → 0.2.6
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 +4 -0
- package/src/schema/client.ts +6 -6
- package/src/schema/server.ts +6 -6
- package/src/test/index.ts +12 -4
- package/src/test/worker.ts +3 -3
- package/src/types.ts +7 -0
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -95,6 +95,10 @@ export class TauriKargoClient {
|
|
|
95
95
|
createDirectory(path: string): Promise<T.CreateDirResp> {
|
|
96
96
|
return this.postJson<T.CreateDirResp>("/api/directory/create", { path: path });
|
|
97
97
|
}
|
|
98
|
+
|
|
99
|
+
typescriptTranspile(src: string): Promise<T.TypeScriptTranspileResponse> {
|
|
100
|
+
return this.postJson<T.TypeScriptTranspileResponse>("/api/typescript/transpile", { src: src });
|
|
101
|
+
}
|
|
98
102
|
/**
|
|
99
103
|
* Lire un fichier texte relatif au répertoire courant.
|
|
100
104
|
* (POST sans corps ⇒ READ ; renvoie text/plain ou octet-stream)
|
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)
|
|
@@ -90,6 +90,14 @@ test.test("Test schema simple avec deux type", async () => {
|
|
|
90
90
|
|
|
91
91
|
|
|
92
92
|
|
|
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))
|
|
99
|
+
|
|
100
|
+
|
|
93
101
|
})
|
|
94
102
|
test.test("Test read file", async () => {
|
|
95
103
|
|
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
|
@@ -104,7 +104,14 @@ export interface StopAllResp {
|
|
|
104
104
|
ok: boolean;
|
|
105
105
|
message: string;
|
|
106
106
|
}
|
|
107
|
+
export type TypeScriptTranspileInput = { src: string };
|
|
107
108
|
|
|
109
|
+
export type TypeScriptTranspileSuccess = { ok: true; src: string };
|
|
110
|
+
|
|
111
|
+
export type TypeScriptTranspileError = { ok: false; message: string };
|
|
112
|
+
|
|
113
|
+
export type TypeScriptTranspileResponse = TypeScriptTranspileSuccess | TypeScriptTranspileError;
|
|
114
|
+
|
|
108
115
|
export interface ExplorerReq {
|
|
109
116
|
path?: string;
|
|
110
117
|
}
|