-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwatch.ts
More file actions
138 lines (124 loc) · 3.08 KB
/
watch.ts
File metadata and controls
138 lines (124 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../../core/resource';
import { APIPromise } from '../../../core/api-promise';
import { Stream } from '../../../core/streaming';
import { buildHeaders } from '../../../internal/headers';
import { RequestOptions } from '../../../internal/request-options';
import { path } from '../../../internal/utils/path';
/**
* Read, write, and manage files on the browser instance.
*/
export class Watch extends APIResource {
/**
* Stream filesystem events for a watch
*
* @example
* ```ts
* const response = await client.browsers.fs.watch.events(
* 'watch_id',
* { id: 'id' },
* );
* ```
*/
events(
watchID: string,
params: WatchEventsParams,
options?: RequestOptions,
): APIPromise<Stream<WatchEventsResponse>> {
const { id } = params;
return this._client.get(path`/browsers/${id}/fs/watch/${watchID}/events`, {
...options,
headers: buildHeaders([{ Accept: 'text/event-stream' }, options?.headers]),
stream: true,
}) as APIPromise<Stream<WatchEventsResponse>>;
}
/**
* Watch a directory for changes
*
* @example
* ```ts
* const response = await client.browsers.fs.watch.start(
* 'id',
* { path: 'path' },
* );
* ```
*/
start(id: string, body: WatchStartParams, options?: RequestOptions): APIPromise<WatchStartResponse> {
return this._client.post(path`/browsers/${id}/fs/watch`, { body, ...options });
}
/**
* Stop watching a directory
*
* @example
* ```ts
* await client.browsers.fs.watch.stop('watch_id', {
* id: 'id',
* });
* ```
*/
stop(watchID: string, params: WatchStopParams, options?: RequestOptions): APIPromise<void> {
const { id } = params;
return this._client.delete(path`/browsers/${id}/fs/watch/${watchID}`, {
...options,
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
});
}
}
/**
* Filesystem change event.
*/
export interface WatchEventsResponse {
/**
* Absolute path of the file or directory.
*/
path: string;
/**
* Event type.
*/
type: 'CREATE' | 'WRITE' | 'DELETE' | 'RENAME';
/**
* Whether the affected path is a directory.
*/
is_dir?: boolean;
/**
* Base name of the file or directory affected.
*/
name?: string;
}
export interface WatchStartResponse {
/**
* Unique identifier for the directory watch
*/
watch_id?: string;
}
export interface WatchEventsParams {
/**
* Browser session ID
*/
id: string;
}
export interface WatchStartParams {
/**
* Directory to watch.
*/
path: string;
/**
* Whether to watch recursively.
*/
recursive?: boolean;
}
export interface WatchStopParams {
/**
* Browser session ID
*/
id: string;
}
export declare namespace Watch {
export {
type WatchEventsResponse as WatchEventsResponse,
type WatchStartResponse as WatchStartResponse,
type WatchEventsParams as WatchEventsParams,
type WatchStartParams as WatchStartParams,
type WatchStopParams as WatchStopParams,
};
}