tauri-kargo-tools 0.2.2 → 0.2.4

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.2",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "files": ["src"],
6
6
  "exports": { "./*": "./src/*" },
package/src/api.ts CHANGED
@@ -21,7 +21,7 @@ export class TauriKargoClient {
21
21
 
22
22
  constructor(opts: ClientOptions = {}) {
23
23
  const port = opts.port ?? 8080;
24
- this.baseUrl = opts.baseUrl ?? (opts.port ?`http://127.0.0.1:${port}`:'');
24
+ this.baseUrl = opts.baseUrl ?? (opts.port ? `http://127.0.0.1:${port}` : '');
25
25
  this.headers = opts.headers ?? {};
26
26
  this.fetchImpl = opts.fetchImpl ?? (globalThis.fetch?.bind(globalThis) as FetchLike);
27
27
  if (!this.fetchImpl) throw new Error("No fetch implementation available.");
@@ -29,7 +29,7 @@ export class TauriKargoClient {
29
29
 
30
30
  /* =============== Helpers HTTP =============== */
31
31
 
32
- private req(path: string, init: RequestInit): Promise<Response> {
32
+ private req(path: string, init: RequestInit): Promise<Response> {
33
33
  const url = this.baseUrl + path;
34
34
  const headers = { ...this.headers, ...(init.headers || {}) } as Record<string, string>;
35
35
  return this.fetchImpl(url, { ...init, headers });
@@ -91,7 +91,10 @@ export class TauriKargoClient {
91
91
  setCurrentDirectory(body: T.CurrentDirReq): Promise<T.CurrentDirResp> {
92
92
  return this.postJson<T.CurrentDirResp>("/api/current-directory", body);
93
93
  }
94
-
94
+ /**POST /api/directory/create*/
95
+ createDirectory(path: string): Promise<T.CreateDirResp> {
96
+ return this.postJson<T.CreateDirResp>("/api/directory/create", { path: path });
97
+ }
95
98
  /**
96
99
  * Lire un fichier texte relatif au répertoire courant.
97
100
  * (POST sans corps ⇒ READ ; renvoie text/plain ou octet-stream)
@@ -125,33 +128,33 @@ export class TauriKargoClient {
125
128
  }
126
129
 
127
130
  /** Écrire un fichier binaire */
128
- async writeFileBinary(
129
- file: string,
130
- data: Blob
131
- ): Promise<T.FileWriteResp> {
132
- // Normalise en Blob (OK WebView2/WebKit/Chromium)
133
- const blob = data
134
-
135
- const res = await fetch(`${this.baseUrl}/api/file/${encodeURIComponent(file)}`, {
136
- method: "POST",
137
- // Laisser fetch gérer le Content-Length; Content-Type vient du blob
138
- headers: { "content-type": blob.type || "application/octet-stream" },
139
- body: blob,
140
- });
141
-
142
- if (!res.ok) {
143
- const text = await res.text().catch(() => "<no-body>");
144
- throw new Error(`WRITE ${file} failed: ${res.status} ${text}`);
145
- }
146
-
147
- // La route renvoie du JSON en cas d’écriture
148
- const ct = res.headers.get("content-type") || "";
149
- if (ct.includes("application/json")) {
150
- return (await res.json()) as T.FileWriteResp;
151
- }
152
- // Fallback s'il répond "text/plain" avec un JSON sérialisé
153
- return JSON.parse(await res.text()) as T.FileWriteResp;
154
- }
131
+ async writeFileBinary(
132
+ file: string,
133
+ data: Blob
134
+ ): Promise<T.FileWriteResp> {
135
+ // Normalise en Blob (OK WebView2/WebKit/Chromium)
136
+ const blob = data
137
+
138
+ const res = await fetch(`${this.baseUrl}/api/file/${encodeURIComponent(file)}`, {
139
+ method: "POST",
140
+ // Laisser fetch gérer le Content-Length; Content-Type vient du blob
141
+ headers: { "content-type": blob.type || "application/octet-stream" },
142
+ body: blob,
143
+ });
144
+
145
+ if (!res.ok) {
146
+ const text = await res.text().catch(() => "<no-body>");
147
+ throw new Error(`WRITE ${file} failed: ${res.status} ${text}`);
148
+ }
149
+
150
+ // La route renvoie du JSON en cas d’écriture
151
+ const ct = res.headers.get("content-type") || "";
152
+ if (ct.includes("application/json")) {
153
+ return (await res.json()) as T.FileWriteResp;
154
+ }
155
+ // Fallback s'il répond "text/plain" avec un JSON sérialisé
156
+ return JSON.parse(await res.text()) as T.FileWriteResp;
157
+ }
155
158
 
156
159
  /** DELETE /api/file/{file} */
157
160
  async deleteFile(file: string): Promise<T.FileDeleteResp> {
package/src/test/index.ts CHANGED
@@ -126,6 +126,14 @@ test.test("Test read file", async () => {
126
126
 
127
127
  }), false, "pas dans rep")
128
128
  }
129
+ const repCreateDir = await client.createDirectory("toto/titi");
130
+ rep = await client.explorer({})
131
+ if (rep.type === "directory") {
132
+ test.assertEquals(rep.content.some((e) => e.name === "toto"), true)
133
+
134
+ } else {
135
+ throw new Error('error pas rep')
136
+ }
129
137
  rep = await client.explorer({ type: "array", path: "C:/Users/david/Documents/GitHub/tauriKargoExamples/examples/test-api-file-typescript" })
130
138
  console.log(rep)
131
139
 
package/src/types.ts CHANGED
@@ -45,7 +45,11 @@ export interface CurrentDirResp {
45
45
  message: string;
46
46
  current: string;
47
47
  }
48
-
48
+ export interface CreateDirResp {
49
+ ok: boolean;
50
+ message: string;
51
+ created: string;
52
+ }
49
53
  export interface FileWriteResp {
50
54
  ok: boolean;
51
55
  message: string;
package/src/vue-model.ts CHANGED
@@ -233,6 +233,22 @@ export class Vue<T extends object> {
233
233
  return this;
234
234
  }
235
235
 
236
+ /* ------------ Label ------------ */
237
+ staticLabel(label: string, opt?: {
238
+ /** Identifiants CSS/DOM */
239
+ id?: string; class?: string | string[];
240
+ width?: number | string; height?: number | string;
241
+ visible?: KeysOfType<T, boolean>; enable?: KeysOfType<T, boolean>;
242
+ useVisibility?: boolean;
243
+ }): this {
244
+ const node: StaticLabelNode<T>= {
245
+ kind: 'staticLabel',
246
+ label,
247
+ ...opt
248
+ };
249
+ this.cursor.push(node as unknown as UINode<T>);
250
+ return this;
251
+ }
236
252
 
237
253
 
238
254
  /* ------------ BootVue (label dynamique) ------------ */