@blaxel/core 0.2.4-preview.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.
|
@@ -6,6 +6,12 @@ export type CopyResponse = {
|
|
|
6
6
|
source: string;
|
|
7
7
|
destination: string;
|
|
8
8
|
};
|
|
9
|
+
export type WatchEvent = {
|
|
10
|
+
op: "CREATE" | "WRITE" | "REMOVE";
|
|
11
|
+
path: string;
|
|
12
|
+
name: string;
|
|
13
|
+
content?: string;
|
|
14
|
+
};
|
|
9
15
|
export declare class SandboxFileSystem extends SandboxAction {
|
|
10
16
|
constructor(sandbox: Sandbox);
|
|
11
17
|
mkdir(path: string, permissions?: string): Promise<SuccessResponse>;
|
|
@@ -14,7 +20,7 @@ export declare class SandboxFileSystem extends SandboxAction {
|
|
|
14
20
|
rm(path: string, recursive?: boolean): Promise<SuccessResponse>;
|
|
15
21
|
ls(path: string): Promise<Directory>;
|
|
16
22
|
cp(source: string, destination: string): Promise<CopyResponse>;
|
|
17
|
-
watch(path: string, callback: (
|
|
23
|
+
watch(path: string, callback: (fileEvent: WatchEvent) => void | Promise<void>, options?: {
|
|
18
24
|
onError?: (error: Error) => void;
|
|
19
25
|
withContent: boolean;
|
|
20
26
|
}): {
|
|
@@ -146,20 +146,29 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
|
146
146
|
let lines = buffer.split('\n');
|
|
147
147
|
buffer = lines.pop();
|
|
148
148
|
for (const line of lines) {
|
|
149
|
-
const
|
|
150
|
-
if (!
|
|
149
|
+
const trimmed = line.trim();
|
|
150
|
+
if (!trimmed)
|
|
151
151
|
continue;
|
|
152
|
-
|
|
152
|
+
const fileEvent = JSON.parse(line.trim());
|
|
153
|
+
if (options?.withContent && ["CREATE", "WRITE"].includes(fileEvent.op)) {
|
|
153
154
|
try {
|
|
155
|
+
let filePath = "";
|
|
156
|
+
if (fileEvent.path.endsWith("/")) {
|
|
157
|
+
filePath = fileEvent.path + fileEvent.name;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
filePath = fileEvent.path + "/" + fileEvent.name;
|
|
161
|
+
}
|
|
154
162
|
const content = await this.read(filePath);
|
|
155
|
-
await callback(
|
|
163
|
+
await callback({ ...fileEvent, content });
|
|
156
164
|
}
|
|
157
165
|
catch (e) {
|
|
158
|
-
|
|
166
|
+
console.log(e);
|
|
167
|
+
await callback({ ...fileEvent, content: undefined });
|
|
159
168
|
}
|
|
160
169
|
}
|
|
161
170
|
else {
|
|
162
|
-
await callback(
|
|
171
|
+
await callback(fileEvent);
|
|
163
172
|
}
|
|
164
173
|
}
|
|
165
174
|
}
|