@rool-dev/sdk 6.0.0-dev.ae1efb3 → 6.0.0-dev.d8f25d5
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/README.md +4 -3
- package/dist/account.d.ts +18 -26
- package/dist/account.d.ts.map +1 -1
- package/dist/account.js +21 -34
- package/dist/account.js.map +1 -1
- package/dist/api-tokens.d.ts +33 -2
- package/dist/api-tokens.d.ts.map +1 -1
- package/dist/api-tokens.js +14 -1
- package/dist/api-tokens.js.map +1 -1
- package/dist/client.d.ts +8 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -11
- package/dist/client.js.map +1 -1
- package/dist/conversations.d.ts +18 -6
- package/dist/conversations.d.ts.map +1 -1
- package/dist/conversations.js +18 -8
- package/dist/conversations.js.map +1 -1
- package/dist/events.d.ts +1 -2
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +21 -2
- package/dist/events.js.map +1 -1
- package/dist/file-watch.d.ts +30 -0
- package/dist/file-watch.d.ts.map +1 -0
- package/dist/file-watch.js +205 -0
- package/dist/file-watch.js.map +1 -0
- package/dist/files.d.ts +22 -25
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +40 -270
- package/dist/files.js.map +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/machine.d.ts +15 -15
- package/dist/machine.d.ts.map +1 -1
- package/dist/machine.js +32 -25
- package/dist/machine.js.map +1 -1
- package/dist/search.d.ts +1 -0
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js.map +1 -1
- package/dist/structured.d.ts +3 -2
- package/dist/structured.d.ts.map +1 -1
- package/dist/structured.js +17 -30
- package/dist/structured.js.map +1 -1
- package/dist/types.d.ts +106 -95
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
package/dist/files.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type MachineFilePath =
|
|
1
|
+
export type MachineFilePath = `/${string}`;
|
|
2
2
|
export type MachineFileRange = {
|
|
3
3
|
start: number;
|
|
4
4
|
end?: number;
|
|
@@ -39,11 +39,6 @@ export interface MachineFileCapabilities {
|
|
|
39
39
|
/** Maximum PUT body size for the path's storage root, or null when no single root applies. */
|
|
40
40
|
maxUploadBytes: number | null;
|
|
41
41
|
}
|
|
42
|
-
/** @deprecated Use `MachineStorage` from `machine.getStorage()`. */
|
|
43
|
-
export interface MachineStorageUsage {
|
|
44
|
-
usedBytes: number;
|
|
45
|
-
availableBytes: number;
|
|
46
|
-
}
|
|
47
42
|
export interface MachineFileReadOptions {
|
|
48
43
|
range?: MachineFileRange;
|
|
49
44
|
ifMatch?: string;
|
|
@@ -51,9 +46,13 @@ export interface MachineFileReadOptions {
|
|
|
51
46
|
ifModifiedSince?: string;
|
|
52
47
|
ifUnmodifiedSince?: string;
|
|
53
48
|
ifRange?: string;
|
|
49
|
+
/** Fail with "not found" when any part of the path is a symbolic link. */
|
|
50
|
+
noFollow?: boolean;
|
|
54
51
|
signal?: AbortSignal;
|
|
55
52
|
}
|
|
56
53
|
export interface MachineFileReadMultipleOptions {
|
|
54
|
+
/** Report a path as not found when any part of it is a symbolic link. */
|
|
55
|
+
noFollow?: boolean;
|
|
57
56
|
signal?: AbortSignal;
|
|
58
57
|
}
|
|
59
58
|
export type MachineFileReadResult = {
|
|
@@ -131,30 +130,26 @@ export interface MachineFileTransferResult {
|
|
|
131
130
|
destination: MachineFilePath;
|
|
132
131
|
overwritten: boolean;
|
|
133
132
|
}
|
|
134
|
-
export interface
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
export interface MachineFileView {
|
|
134
|
+
/** Null means absent only once loading is false and error is null. */
|
|
135
|
+
readonly entry: MachineFileInfo | null;
|
|
136
|
+
readonly loading: boolean;
|
|
137
|
+
readonly error: unknown;
|
|
138
138
|
}
|
|
139
|
-
export interface
|
|
140
|
-
|
|
139
|
+
export interface MachineDirectoryView {
|
|
140
|
+
readonly directory: MachineFileInfo | null;
|
|
141
|
+
readonly entries: readonly MachineFileInfo[];
|
|
142
|
+
readonly loading: boolean;
|
|
143
|
+
readonly error: unknown;
|
|
141
144
|
}
|
|
142
|
-
export interface
|
|
143
|
-
|
|
144
|
-
etag(path: MachineFilePath): string | undefined;
|
|
145
|
-
list(path?: MachineFilePath, options?: MachineFileTreeListOptions): MachineFileInfo[];
|
|
146
|
-
subscribe(listener: (change: MachineFileTreeChange) => void): () => void;
|
|
145
|
+
export interface MachineDirectoryWatchOptions {
|
|
146
|
+
recursive?: boolean;
|
|
147
147
|
}
|
|
148
148
|
export interface MachineFiles {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
readonly watchError: unknown;
|
|
152
|
-
watch(): Promise<void>;
|
|
153
|
-
unwatch(): void;
|
|
149
|
+
watchFile(path: MachineFilePath, listener: (view: MachineFileView) => void): () => void;
|
|
150
|
+
watchDirectory(path: MachineFilePath, listener: (view: MachineDirectoryView) => void, options?: MachineDirectoryWatchOptions): () => void;
|
|
154
151
|
href(path?: MachineFilePath): string;
|
|
155
152
|
options(path?: MachineFilePath): Promise<MachineFileCapabilities>;
|
|
156
|
-
/** @deprecated Use `machine.getStorage()`, which also reports the plan and a per-area breakdown. */
|
|
157
|
-
getStorageUsage(signal?: AbortSignal): Promise<MachineStorageUsage>;
|
|
158
153
|
read(path: MachineFilePath, options?: MachineFileReadOptions): Promise<Response>;
|
|
159
154
|
readMultiple(paths: readonly MachineFilePath[], options?: MachineFileReadMultipleOptions): Promise<MachineFileReadResult[]>;
|
|
160
155
|
stat(path: MachineFilePath, signal?: AbortSignal): Promise<MachineFileInfo>;
|
|
@@ -173,6 +168,8 @@ export declare class RoolFileError extends Error {
|
|
|
173
168
|
readonly body: string;
|
|
174
169
|
constructor(response: Response, body: string);
|
|
175
170
|
}
|
|
176
|
-
export declare function createMachineFiles(machineId: string, request: FileRequest): MachineFiles
|
|
171
|
+
export declare function createMachineFiles(machineId: string, request: FileRequest): MachineFiles & {
|
|
172
|
+
dispose(): void;
|
|
173
|
+
};
|
|
177
174
|
export {};
|
|
178
175
|
//# sourceMappingURL=files.d.ts.map
|
package/dist/files.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG,IAAI,MAAM,EAAE,CAAC;AAC3C,MAAM,MAAM,gBAAgB,GAC1B;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,MAAM,MAAM,yBAAyB,GACnC,gBAAgB,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAE9E,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IAC/C,UAAU,EAAE,yBAAyB,EAAE,CAAC;IACxC,UAAU,EAAE,yBAAyB,EAAE,CAAC;CACzC;AAED,UAAU,mBAAmB;IAC3B,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,MAAM,eAAe,GACvB,CAAC,mBAAmB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,GACA,CAAC,mBAAmB,GAAG;IAAE,IAAI,EAA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O,CAAC,EAAE,6BAA6B,GACtC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,IAAI,CACF,MAAM,EAAE,eAAe,EACvB,WAAW,EAAE,eAAe,EAC5B,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACtC,IAAI,CACF,MAAM,EAAE,eAAe,EACvB,WAAW,EAAE,eAAe,EAC5B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,yBAAyB,CAAC,CAAC;CACvC;AAED,KAAK,WAAW,GAAG,CACjB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,sBAAsB,EAC7B,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,yBAAyB,KAAK,IAAI,KAC7D,OAAO,CAAC,QAAQ,CAAC,CAAC;AAoCvB,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAQ3C;CACF;AAoTD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,GACnB,YAAY,GAAG;IAAE,OAAO,IAAI,IAAI,CAAA;CAAE,CAEpC"}
|
package/dist/files.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const SYNC_WAIT_SECONDS = 30;
|
|
3
|
-
const SYNC_RETRY_MAX_MS = 5_000;
|
|
4
|
-
// See events.ts: auth failures need a sign-in or auth-server recovery, so the
|
|
5
|
-
// sync loop backs off much further for them than for transient errors.
|
|
6
|
-
const SYNC_AUTH_RETRY_MS = 60_000;
|
|
1
|
+
import { FileWatches } from "./file-watch.js";
|
|
7
2
|
const DELETE_MULTIPLE_CONCURRENCY = 8;
|
|
8
3
|
const FILE_PROPERTIES = `
|
|
9
4
|
<d:creationdate/>
|
|
@@ -20,13 +15,6 @@ const PROPFIND_BODY = `<?xml version="1.0" encoding="utf-8"?>
|
|
|
20
15
|
<d:prop>${FILE_PROPERTIES}
|
|
21
16
|
</d:prop>
|
|
22
17
|
</d:propfind>`;
|
|
23
|
-
const STORAGE_PROPFIND_BODY = `<?xml version="1.0" encoding="utf-8"?>
|
|
24
|
-
<d:propfind xmlns:d="DAV:">
|
|
25
|
-
<d:prop>
|
|
26
|
-
<d:quota-used-bytes/>
|
|
27
|
-
<d:quota-available-bytes/>
|
|
28
|
-
</d:prop>
|
|
29
|
-
</d:propfind>`;
|
|
30
18
|
function readMultipleBody(hrefs) {
|
|
31
19
|
return `<?xml version="1.0" encoding="utf-8"?>
|
|
32
20
|
<r:read-multiple xmlns:r="urn:rool:dav" xmlns:d="DAV:">
|
|
@@ -37,7 +25,7 @@ function syncCollectionBody(token) {
|
|
|
37
25
|
return `<?xml version="1.0" encoding="utf-8"?>
|
|
38
26
|
<d:sync-collection xmlns:d="DAV:">
|
|
39
27
|
${token ? `<d:sync-token>${encodeXml(token)}</d:sync-token>` : ""}
|
|
40
|
-
<d:sync-level
|
|
28
|
+
<d:sync-level>${token ? "infinite" : "1"}</d:sync-level>
|
|
41
29
|
<d:prop>${FILE_PROPERTIES}
|
|
42
30
|
</d:prop>
|
|
43
31
|
</d:sync-collection>`;
|
|
@@ -54,130 +42,41 @@ export class RoolFileError extends Error {
|
|
|
54
42
|
this.body = body;
|
|
55
43
|
}
|
|
56
44
|
}
|
|
57
|
-
class SyncedMachineFileTree {
|
|
58
|
-
entries = new Map();
|
|
59
|
-
listeners = new Set();
|
|
60
|
-
get(path) {
|
|
61
|
-
const info = this.entries.get(path);
|
|
62
|
-
return info ? cloneFileInfo(info) : undefined;
|
|
63
|
-
}
|
|
64
|
-
etag(path) {
|
|
65
|
-
return this.entries.get(path)?.etag;
|
|
66
|
-
}
|
|
67
|
-
list(path, options = {}) {
|
|
68
|
-
const entries = [...this.entries.values()].filter((entry) => {
|
|
69
|
-
if (!path) {
|
|
70
|
-
return options.recursive || parentPath(entry.path) === undefined;
|
|
71
|
-
}
|
|
72
|
-
if (entry.path === path || !entry.path.startsWith(`${path}/`)) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return options.recursive || parentPath(entry.path) === path;
|
|
76
|
-
});
|
|
77
|
-
return entries
|
|
78
|
-
.sort((left, right) => left.path.localeCompare(right.path))
|
|
79
|
-
.map(cloneFileInfo);
|
|
80
|
-
}
|
|
81
|
-
subscribe(listener) {
|
|
82
|
-
this.listeners.add(listener);
|
|
83
|
-
return () => this.listeners.delete(listener);
|
|
84
|
-
}
|
|
85
|
-
reconcile(nextEntries) {
|
|
86
|
-
const next = new Map(nextEntries.map((entry) => [entry.path, cloneFileInfo(entry)]));
|
|
87
|
-
const changed = nextEntries
|
|
88
|
-
.filter((entry) => !sameFileInfo(this.entries.get(entry.path), entry))
|
|
89
|
-
.map((entry) => entry.path);
|
|
90
|
-
const deleted = [...this.entries.keys()].filter((path) => !next.has(path));
|
|
91
|
-
this.entries = next;
|
|
92
|
-
this.emit({ reset: true, changed, deleted });
|
|
93
|
-
}
|
|
94
|
-
apply(updates) {
|
|
95
|
-
const changed = new Set();
|
|
96
|
-
const deleted = new Set();
|
|
97
|
-
for (const update of updates) {
|
|
98
|
-
if (update.info) {
|
|
99
|
-
if (!sameFileInfo(this.entries.get(update.path), update.info)) {
|
|
100
|
-
this.entries.set(update.path, cloneFileInfo(update.info));
|
|
101
|
-
changed.add(update.path);
|
|
102
|
-
}
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
for (const existingPath of [...this.entries.keys()]) {
|
|
106
|
-
const isDeletedPath = existingPath === update.path ||
|
|
107
|
-
existingPath.startsWith(`${update.path}/`);
|
|
108
|
-
if (!isDeletedPath)
|
|
109
|
-
continue;
|
|
110
|
-
this.entries.delete(existingPath);
|
|
111
|
-
changed.delete(existingPath);
|
|
112
|
-
deleted.add(existingPath);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (changed.size === 0 && deleted.size === 0)
|
|
116
|
-
return;
|
|
117
|
-
this.emit({
|
|
118
|
-
reset: false,
|
|
119
|
-
changed: [...changed],
|
|
120
|
-
deleted: [...deleted],
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
emit(change) {
|
|
124
|
-
for (const listener of this.listeners)
|
|
125
|
-
listener(change);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
45
|
class SyncedMachineFiles {
|
|
129
46
|
machineId;
|
|
47
|
+
watches = new FileWatches((path, depth, signal) => this.propfind(path, depth, signal), (token, signal, wait) => this.syncCollection(token, signal, wait));
|
|
130
48
|
request;
|
|
131
|
-
tree;
|
|
132
|
-
syncedTree = new SyncedMachineFileTree();
|
|
133
|
-
watchController = null;
|
|
134
|
-
startingWatch = null;
|
|
135
|
-
syncToken = null;
|
|
136
|
-
currentSyncError = null;
|
|
137
49
|
constructor(machineId, request) {
|
|
138
50
|
this.machineId = machineId;
|
|
139
|
-
this.request = request;
|
|
140
51
|
if (!machineId)
|
|
141
52
|
throw new Error("machineId is required");
|
|
142
|
-
this.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.watchController = controller;
|
|
157
|
-
const startingWatch = this.initializeSync(controller);
|
|
158
|
-
this.startingWatch = startingWatch;
|
|
159
|
-
try {
|
|
160
|
-
await startingWatch;
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
if (this.watchController === controller)
|
|
164
|
-
this.watchController = null;
|
|
165
|
-
controller.abort();
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
finally {
|
|
169
|
-
if (this.startingWatch === startingWatch)
|
|
170
|
-
this.startingWatch = null;
|
|
171
|
-
}
|
|
53
|
+
this.request = (path, init, onUploadProgress) => {
|
|
54
|
+
if (path !== this.href())
|
|
55
|
+
return request(path, init, onUploadProgress);
|
|
56
|
+
// TODO: Remove this compatibility preference once the backend no longer needs it.
|
|
57
|
+
const headers = new Headers(init?.headers);
|
|
58
|
+
headers.set("Prefer", [headers.get("Prefer"), "rool-include-home"].filter(Boolean).join(", "));
|
|
59
|
+
return request(path, { ...init, headers }, onUploadProgress);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
watchFile(path, listener) {
|
|
63
|
+
this.href(path);
|
|
64
|
+
return this.watches.watch(path, "0", (entries, loading, error) => {
|
|
65
|
+
listener({ entry: entries.find(entry => entry.path === path) ?? null, loading, error });
|
|
66
|
+
});
|
|
172
67
|
}
|
|
173
|
-
|
|
174
|
-
this.
|
|
175
|
-
this.
|
|
176
|
-
|
|
68
|
+
watchDirectory(path, listener, options = {}) {
|
|
69
|
+
this.href(path);
|
|
70
|
+
return this.watches.watch(path, options.recursive ? "infinity" : "1", (entries, loading, error) => {
|
|
71
|
+
listener({ directory: entries.find(entry => entry.path === path) ?? null, entries: entries.filter(entry => entry.path !== path), loading, error });
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
dispose() {
|
|
75
|
+
this.watches.dispose();
|
|
177
76
|
}
|
|
178
77
|
href(path) {
|
|
179
78
|
const prefix = `/v2/machines/${encodeURIComponent(this.machineId)}/dav`;
|
|
180
|
-
if (
|
|
79
|
+
if (path === undefined || path === "/")
|
|
181
80
|
return prefix;
|
|
182
81
|
return `${prefix}/${encodeFilePath(path)}`;
|
|
183
82
|
}
|
|
@@ -205,25 +104,14 @@ class SyncedMachineFiles {
|
|
|
205
104
|
maxUploadBytes: nonnegativeHeaderInteger(response, "Rool-Max-Upload-Bytes"),
|
|
206
105
|
};
|
|
207
106
|
}
|
|
208
|
-
async getStorageUsage(signal) {
|
|
209
|
-
const response = await this.request(this.href(), {
|
|
210
|
-
method: "PROPFIND",
|
|
211
|
-
headers: {
|
|
212
|
-
"Content-Type": "application/xml; charset=utf-8",
|
|
213
|
-
Depth: "0",
|
|
214
|
-
},
|
|
215
|
-
body: STORAGE_PROPFIND_BODY,
|
|
216
|
-
signal,
|
|
217
|
-
});
|
|
218
|
-
await assertStatus(response, 207);
|
|
219
|
-
return parseStorageUsage(await response.text());
|
|
220
|
-
}
|
|
221
107
|
async read(path, options = {}) {
|
|
222
108
|
const headers = conditionHeaders(options);
|
|
223
109
|
if (options.range)
|
|
224
110
|
headers.set("Range", rangeHeader(options.range));
|
|
225
111
|
if (options.ifRange)
|
|
226
112
|
headers.set("If-Range", options.ifRange);
|
|
113
|
+
if (options.noFollow)
|
|
114
|
+
headers.set("Rool-No-Follow", "1");
|
|
227
115
|
const response = await this.request(this.href(path), {
|
|
228
116
|
method: "GET",
|
|
229
117
|
headers,
|
|
@@ -238,7 +126,10 @@ class SyncedMachineFiles {
|
|
|
238
126
|
return [];
|
|
239
127
|
const response = await this.request(this.href(), {
|
|
240
128
|
method: "REPORT",
|
|
241
|
-
headers: {
|
|
129
|
+
headers: {
|
|
130
|
+
"Content-Type": "application/xml; charset=utf-8",
|
|
131
|
+
...(options.noFollow ? { "Rool-No-Follow": "1" } : {}),
|
|
132
|
+
},
|
|
242
133
|
body: readMultipleBody(paths.map((path) => this.href(path))),
|
|
243
134
|
signal: options.signal,
|
|
244
135
|
});
|
|
@@ -255,9 +146,7 @@ class SyncedMachineFiles {
|
|
|
255
146
|
async list(path, options = {}) {
|
|
256
147
|
const depth = options.recursive ? "infinity" : "1";
|
|
257
148
|
const entries = await this.propfind(path, depth, options.signal);
|
|
258
|
-
return path
|
|
259
|
-
? entries.filter((candidate) => candidate.path !== path)
|
|
260
|
-
: entries;
|
|
149
|
+
return entries.filter((candidate) => candidate.path !== (path ?? "/"));
|
|
261
150
|
}
|
|
262
151
|
async write(path, body, options = {}) {
|
|
263
152
|
const headers = conditionHeaders(options);
|
|
@@ -326,59 +215,10 @@ class SyncedMachineFiles {
|
|
|
326
215
|
const depth = options.recursive === false ? "0" : "infinity";
|
|
327
216
|
return this.transfer("COPY", source, destination, options, depth);
|
|
328
217
|
}
|
|
329
|
-
async initializeSync(controller) {
|
|
330
|
-
const report = await this.syncCollection(undefined, controller.signal);
|
|
331
|
-
if (report.status === "invalid") {
|
|
332
|
-
throw new Error("Initial sync-collection returned an invalid token");
|
|
333
|
-
}
|
|
334
|
-
if (controller.signal.aborted)
|
|
335
|
-
return;
|
|
336
|
-
this.syncedTree.reconcile(report.updates.flatMap((update) => (update.info ? [update.info] : [])));
|
|
337
|
-
this.syncToken = report.token;
|
|
338
|
-
this.currentSyncError = null;
|
|
339
|
-
void this.runSyncLoop(controller);
|
|
340
|
-
}
|
|
341
|
-
async runSyncLoop(controller) {
|
|
342
|
-
let retryMs = 250;
|
|
343
|
-
while (this.watchController === controller && !controller.signal.aborted) {
|
|
344
|
-
try {
|
|
345
|
-
const token = this.syncToken;
|
|
346
|
-
if (!token)
|
|
347
|
-
throw new Error("Machine file sync token is missing");
|
|
348
|
-
let report = await this.syncCollection(token, controller.signal, SYNC_WAIT_SECONDS);
|
|
349
|
-
if (report.status === "invalid") {
|
|
350
|
-
report = await this.syncCollection(undefined, controller.signal);
|
|
351
|
-
if (report.status === "invalid") {
|
|
352
|
-
throw new Error("Initial sync-collection returned an invalid token");
|
|
353
|
-
}
|
|
354
|
-
if (controller.signal.aborted)
|
|
355
|
-
return;
|
|
356
|
-
this.syncedTree.reconcile(report.updates.flatMap((update) => update.info ? [update.info] : []));
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
if (controller.signal.aborted)
|
|
360
|
-
return;
|
|
361
|
-
this.syncedTree.apply(report.updates);
|
|
362
|
-
}
|
|
363
|
-
this.syncToken = report.token;
|
|
364
|
-
this.currentSyncError = null;
|
|
365
|
-
retryMs = 250;
|
|
366
|
-
}
|
|
367
|
-
catch (error) {
|
|
368
|
-
if (controller.signal.aborted)
|
|
369
|
-
return;
|
|
370
|
-
this.currentSyncError = error;
|
|
371
|
-
const authShaped = error instanceof RoolAuthUnavailableError ||
|
|
372
|
-
(error instanceof RoolFileError && error.status === 401);
|
|
373
|
-
await abortableDelay(authShaped ? SYNC_AUTH_RETRY_MS : retryMs, controller.signal);
|
|
374
|
-
retryMs = Math.min(retryMs * 2, SYNC_RETRY_MAX_MS);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
218
|
async syncCollection(token, signal, waitSeconds) {
|
|
379
219
|
const headers = new Headers({
|
|
380
220
|
"Content-Type": "application/xml; charset=utf-8",
|
|
381
|
-
Depth: "infinity",
|
|
221
|
+
Depth: token ? "infinity" : "1",
|
|
382
222
|
});
|
|
383
223
|
if (waitSeconds !== undefined) {
|
|
384
224
|
headers.set("Prefer", `wait=${waitSeconds}`);
|
|
@@ -435,11 +275,10 @@ export function createMachineFiles(machineId, request) {
|
|
|
435
275
|
return new SyncedMachineFiles(machineId, request);
|
|
436
276
|
}
|
|
437
277
|
function encodeFilePath(path) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
}
|
|
278
|
+
if (!path.startsWith("/"))
|
|
279
|
+
throw new Error("Machine file paths must be absolute");
|
|
280
|
+
if (path === "/")
|
|
281
|
+
return "";
|
|
443
282
|
const segments = path.slice(1).split("/");
|
|
444
283
|
for (const segment of segments) {
|
|
445
284
|
if (!segment ||
|
|
@@ -639,24 +478,6 @@ function nonnegativeHeaderInteger(response, name) {
|
|
|
639
478
|
}
|
|
640
479
|
return value;
|
|
641
480
|
}
|
|
642
|
-
function parseStorageUsage(xml) {
|
|
643
|
-
const response = xmlElements(xml, "response")[0];
|
|
644
|
-
if (response === undefined) {
|
|
645
|
-
throw new Error("Storage PROPFIND returned no DAV:response");
|
|
646
|
-
}
|
|
647
|
-
return {
|
|
648
|
-
usedBytes: nonnegativeXmlInteger(response, "quota-used-bytes"),
|
|
649
|
-
availableBytes: nonnegativeXmlInteger(response, "quota-available-bytes"),
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
function nonnegativeXmlInteger(xml, name) {
|
|
653
|
-
const raw = requiredXmlText(xml, name);
|
|
654
|
-
const value = Number(raw);
|
|
655
|
-
if (!Number.isSafeInteger(value) || value < 0) {
|
|
656
|
-
throw new Error(`PROPFIND returned invalid DAV:${name}: ${raw}`);
|
|
657
|
-
}
|
|
658
|
-
return value;
|
|
659
|
-
}
|
|
660
481
|
function parseSyncCollection(xml, machineId) {
|
|
661
482
|
const token = requiredXmlText(xml, "sync-token");
|
|
662
483
|
const updates = [];
|
|
@@ -746,12 +567,9 @@ function machinePathFromHref(href, machineId) {
|
|
|
746
567
|
}
|
|
747
568
|
const pathParts = parts.slice(4);
|
|
748
569
|
if (pathParts.length === 0)
|
|
749
|
-
return
|
|
750
|
-
if (pathParts[0] !== "space" && pathParts[0] !== "rool-drive") {
|
|
751
|
-
throw new Error(`PROPFIND returned an unsupported machine path: ${href}`);
|
|
752
|
-
}
|
|
570
|
+
return "/";
|
|
753
571
|
for (const part of pathParts) {
|
|
754
|
-
if (!part || part === "." || part === ".." || part.includes("/")) {
|
|
572
|
+
if (!part || part === "." || part === ".." || part.includes("/") || part.includes("\0")) {
|
|
755
573
|
throw new Error(`PROPFIND returned an invalid machine path: ${href}`);
|
|
756
574
|
}
|
|
757
575
|
}
|
|
@@ -804,54 +622,6 @@ function decodeXml(value) {
|
|
|
804
622
|
.replace(/>/g, ">")
|
|
805
623
|
.replace(/&/g, "&");
|
|
806
624
|
}
|
|
807
|
-
function cloneFileInfo(info) {
|
|
808
|
-
return {
|
|
809
|
-
...info,
|
|
810
|
-
access: {
|
|
811
|
-
currentUser: { ...info.access.currentUser },
|
|
812
|
-
readableBy: [...info.access.readableBy],
|
|
813
|
-
writableBy: [...info.access.writableBy],
|
|
814
|
-
},
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
function sameFileInfo(current, next) {
|
|
818
|
-
if (!current || current.kind !== next.kind)
|
|
819
|
-
return false;
|
|
820
|
-
if (current.etag !== next.etag ||
|
|
821
|
-
current.name !== next.name ||
|
|
822
|
-
current.createdAt !== next.createdAt ||
|
|
823
|
-
current.lastModified !== next.lastModified ||
|
|
824
|
-
current.ownerId !== next.ownerId ||
|
|
825
|
-
current.access.currentUser.read !== next.access.currentUser.read ||
|
|
826
|
-
current.access.currentUser.write !== next.access.currentUser.write ||
|
|
827
|
-
current.access.readableBy.join("\0") !==
|
|
828
|
-
next.access.readableBy.join("\0") ||
|
|
829
|
-
current.access.writableBy.join("\0") !== next.access.writableBy.join("\0")) {
|
|
830
|
-
return false;
|
|
831
|
-
}
|
|
832
|
-
if (current.kind === "directory" || next.kind === "directory")
|
|
833
|
-
return true;
|
|
834
|
-
return current.size === next.size && current.contentType === next.contentType;
|
|
835
|
-
}
|
|
836
|
-
function parentPath(path) {
|
|
837
|
-
const separator = path.lastIndexOf("/");
|
|
838
|
-
if (separator === 0)
|
|
839
|
-
return undefined;
|
|
840
|
-
return path.slice(0, separator);
|
|
841
|
-
}
|
|
842
|
-
async function abortableDelay(milliseconds, signal) {
|
|
843
|
-
if (signal.aborted)
|
|
844
|
-
return;
|
|
845
|
-
await new Promise((resolve) => {
|
|
846
|
-
const timer = setTimeout(finish, milliseconds);
|
|
847
|
-
function finish() {
|
|
848
|
-
clearTimeout(timer);
|
|
849
|
-
signal.removeEventListener("abort", finish);
|
|
850
|
-
resolve();
|
|
851
|
-
}
|
|
852
|
-
signal.addEventListener("abort", finish, { once: true });
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
625
|
async function assertStatus(response, ...statuses) {
|
|
856
626
|
if (statuses.includes(response.status))
|
|
857
627
|
return;
|