@jupyterlite/contents 0.4.0-alpha.1 → 0.4.0-alpha.3

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.
@@ -0,0 +1,244 @@
1
+ import { PathExt } from '@jupyterlab/coreutils';
2
+ import { Contents } from '@jupyterlab/services';
3
+ import { BLOCK_SIZE, TDriveMethod, TDriveRequest, TDriveResponse } from './drivefs';
4
+ import { DIR_MODE, FILE_MODE } from './emscripten';
5
+
6
+ export interface IDriveContentsProcessor {
7
+ /**
8
+ * Process a content request
9
+ *
10
+ * @param request the request
11
+ */
12
+ processDriveRequest<T extends TDriveMethod>(
13
+ request: TDriveRequest<T>,
14
+ ): Promise<TDriveResponse<T>>;
15
+
16
+ /**
17
+ * Process the request to read a directory content
18
+ *
19
+ * @param request the request
20
+ */
21
+ readdir(request: TDriveRequest<'readdir'>): Promise<TDriveResponse<'readdir'>>;
22
+
23
+ /**
24
+ * Process the request to remove a directory
25
+ *
26
+ * @param request the request
27
+ */
28
+ rmdir(request: TDriveRequest<'rmdir'>): Promise<TDriveResponse<'rmdir'>>;
29
+
30
+ /**
31
+ * Process the request to rename a file or directory
32
+ *
33
+ * @param request the request
34
+ */
35
+ rename(request: TDriveRequest<'rename'>): Promise<TDriveResponse<'rename'>>;
36
+
37
+ /**
38
+ * Process the request to get the node mode (file or directory)
39
+ *
40
+ * @param request the request
41
+ */
42
+ getmode(request: TDriveRequest<'getmode'>): Promise<TDriveResponse<'getmode'>>;
43
+
44
+ /**
45
+ * Process the request to check if a node exist
46
+ *
47
+ * @param request the request
48
+ */
49
+ lookup(request: TDriveRequest<'lookup'>): Promise<TDriveResponse<'lookup'>>;
50
+
51
+ /**
52
+ * Process the request to create a directory/file
53
+ *
54
+ * @param request the request
55
+ */
56
+ mknod(request: TDriveRequest<'mknod'>): Promise<TDriveResponse<'mknod'>>;
57
+
58
+ /**
59
+ * Process the request to get a node stats
60
+ *
61
+ * @param request the request
62
+ */
63
+ getattr(request: TDriveRequest<'getattr'>): Promise<TDriveResponse<'getattr'>>;
64
+
65
+ /**
66
+ * Process the request to get the content of a file
67
+ *
68
+ * @param request the request
69
+ */
70
+ get(request: TDriveRequest<'get'>): Promise<TDriveResponse<'get'>>;
71
+
72
+ /**
73
+ * Process the request to write the content of a file
74
+ *
75
+ * @param request the request
76
+ */
77
+ put(request: TDriveRequest<'put'>): Promise<TDriveResponse<'put'>>;
78
+ }
79
+
80
+ /**
81
+ * Class for processing a drive request from the DriveFS.
82
+ */
83
+ export class DriveContentsProcessor implements IDriveContentsProcessor {
84
+ private contentsManager: Contents.IManager;
85
+
86
+ constructor(options: DriveContentsProcessor.IOptions) {
87
+ this.contentsManager = options.contentsManager;
88
+ }
89
+
90
+ async processDriveRequest<T extends TDriveMethod>(
91
+ request: TDriveRequest<T>,
92
+ ): Promise<TDriveResponse<T>> {
93
+ switch (request.method) {
94
+ case 'readdir':
95
+ return this.readdir(request as TDriveRequest<'readdir'>) as Promise<
96
+ TDriveResponse<T>
97
+ >;
98
+ case 'rmdir':
99
+ return this.rmdir(request as TDriveRequest<'rmdir'>) as Promise<
100
+ TDriveResponse<T>
101
+ >;
102
+ case 'rename':
103
+ return this.rename(request as TDriveRequest<'rename'>) as Promise<
104
+ TDriveResponse<T>
105
+ >;
106
+ case 'getmode':
107
+ return this.getmode(request as TDriveRequest<'getmode'>) as Promise<
108
+ TDriveResponse<T>
109
+ >;
110
+ case 'lookup':
111
+ return this.lookup(request as TDriveRequest<'lookup'>) as Promise<
112
+ TDriveResponse<T>
113
+ >;
114
+ case 'mknod':
115
+ return this.mknod(request as TDriveRequest<'mknod'>) as Promise<
116
+ TDriveResponse<T>
117
+ >;
118
+ case 'getattr':
119
+ return this.getattr(request as TDriveRequest<'getattr'>) as Promise<
120
+ TDriveResponse<T>
121
+ >;
122
+ case 'get':
123
+ return this.get(request as TDriveRequest<'get'>) as Promise<TDriveResponse<T>>;
124
+ case 'put':
125
+ return this.put(request as TDriveRequest<'put'>) as Promise<TDriveResponse<T>>;
126
+ }
127
+
128
+ throw `Drive request ${request.method} does not exist.`;
129
+ }
130
+
131
+ async readdir(request: TDriveRequest<'readdir'>): Promise<TDriveResponse<'readdir'>> {
132
+ const model = await this.contentsManager.get(request.path, { content: true });
133
+ let response: string[] = [];
134
+ if (model.type === 'directory' && model.content) {
135
+ response = model.content.map((subcontent: Contents.IModel) => subcontent.name);
136
+ }
137
+ return response;
138
+ }
139
+
140
+ async rmdir(request: TDriveRequest<'rmdir'>): Promise<TDriveResponse<'rmdir'>> {
141
+ await this.contentsManager.delete(request.path);
142
+ }
143
+
144
+ async rename(request: TDriveRequest<'rename'>): Promise<TDriveResponse<'rename'>> {
145
+ await this.contentsManager.rename(request.path, request.data.newPath);
146
+ }
147
+
148
+ async getmode(request: TDriveRequest<'getmode'>): Promise<TDriveResponse<'getmode'>> {
149
+ const model = await this.contentsManager.get(request.path);
150
+ let response: number;
151
+ if (model.type === 'directory') {
152
+ response = DIR_MODE;
153
+ } else {
154
+ response = FILE_MODE;
155
+ }
156
+ return response;
157
+ }
158
+
159
+ async lookup(request: TDriveRequest<'lookup'>): Promise<TDriveResponse<'lookup'>> {
160
+ let response: TDriveResponse<'lookup'>;
161
+
162
+ try {
163
+ const model = await this.contentsManager.get(request.path);
164
+ response = {
165
+ ok: true,
166
+ mode: model.type === 'directory' ? DIR_MODE : FILE_MODE,
167
+ };
168
+ } catch (e) {
169
+ response = { ok: false };
170
+ }
171
+
172
+ return response;
173
+ }
174
+
175
+ async mknod(request: TDriveRequest<'mknod'>): Promise<TDriveResponse<'mknod'>> {
176
+ const model = await this.contentsManager.newUntitled({
177
+ path: PathExt.dirname(request.path),
178
+ type: request.data.mode === DIR_MODE ? 'directory' : 'file',
179
+ ext: PathExt.extname(request.path),
180
+ });
181
+ await this.contentsManager.rename(model.path, request.path);
182
+ }
183
+
184
+ async getattr(request: TDriveRequest<'getattr'>): Promise<TDriveResponse<'getattr'>> {
185
+ const model = await this.contentsManager.get(request.path);
186
+ // create a default date for drives that send incomplete information
187
+ // for nested foldes and files
188
+ const defaultDate = new Date(0).toISOString();
189
+
190
+ return {
191
+ dev: 1,
192
+ nlink: 1,
193
+ uid: 0,
194
+ gid: 0,
195
+ rdev: 0,
196
+ size: model.size || 0,
197
+ blksize: BLOCK_SIZE,
198
+ blocks: Math.ceil(model.size || 0 / BLOCK_SIZE),
199
+ atime: model.last_modified || defaultDate, // TODO Get the proper atime?
200
+ mtime: model.last_modified || defaultDate,
201
+ ctime: model.created || defaultDate,
202
+ timestamp: 0,
203
+ };
204
+ }
205
+
206
+ async get(request: TDriveRequest<'get'>): Promise<TDriveResponse<'get'>> {
207
+ const model = await this.contentsManager.get(request.path, { content: true });
208
+
209
+ let response;
210
+
211
+ if (model.type !== 'directory') {
212
+ response = {
213
+ content:
214
+ model.format === 'json' ? JSON.stringify(model.content) : model.content,
215
+ format: model.format,
216
+ };
217
+ }
218
+
219
+ return response;
220
+ }
221
+
222
+ async put(request: TDriveRequest<'put'>): Promise<TDriveResponse<'put'>> {
223
+ await this.contentsManager.save(request.path, {
224
+ content:
225
+ request.data.format === 'json'
226
+ ? JSON.parse(request.data.data)
227
+ : request.data.data,
228
+ type: 'file',
229
+ format: request.data.format as Contents.FileFormat,
230
+ });
231
+ }
232
+ }
233
+
234
+ /**
235
+ * A namespace for DriveContentsProcessor configurations, etc.
236
+ */
237
+ export namespace DriveContentsProcessor {
238
+ /**
239
+ * Initialization options for a drive;
240
+ */
241
+ export interface IOptions {
242
+ contentsManager: Contents.IManager;
243
+ }
244
+ }
package/src/drivefs.ts CHANGED
@@ -6,6 +6,8 @@
6
6
  // And from https://github.com/gzuidhof/starboard-notebook
7
7
 
8
8
  // LICENSE: https://github.com/gzuidhof/starboard-notebook/blob/cd8d3fc30af4bd29cdd8f6b8c207df8138f5d5dd/LICENSE
9
+ import { Contents } from '@jupyterlab/services';
10
+
9
11
  import {
10
12
  FS,
11
13
  ERRNO_CODES,
@@ -14,6 +16,7 @@ import {
14
16
  SEEK_CUR,
15
17
  SEEK_END,
16
18
  IEmscriptenStream,
19
+ instanceOfStream,
17
20
  IEmscriptenStreamOps,
18
21
  IEmscriptenNodeOps,
19
22
  IEmscriptenFSNode,
@@ -40,13 +43,42 @@ export type TDriveMethod =
40
43
  | 'put';
41
44
 
42
45
  /**
43
- * Interface of a request on the /api/drive endpoint
46
+ * Type of the data argument for the drive request, based on the request name
44
47
  */
45
- export interface IDriveRequest {
48
+ export type TDriveData = {
49
+ rename: {
50
+ /**
51
+ * The new path for the file
52
+ */
53
+ newPath: string;
54
+ };
55
+ mknod: {
56
+ /**
57
+ * The mode of the file to create
58
+ */
59
+ mode: number;
60
+ };
61
+ put: {
62
+ /**
63
+ * The file content to write
64
+ */
65
+ data: any;
66
+
67
+ /**
68
+ * The file content format
69
+ */
70
+ format: Contents.FileFormat;
71
+ };
72
+ };
73
+
74
+ /**
75
+ * Drive request
76
+ */
77
+ export type TDriveRequest<T extends TDriveMethod> = {
46
78
  /**
47
79
  * The method of the request (rmdir, readdir etc)
48
80
  */
49
- method: TDriveMethod;
81
+ method: T;
50
82
 
51
83
  /**
52
84
  * The expected receiver of the request
@@ -57,12 +89,36 @@ export interface IDriveRequest {
57
89
  * The path to the file/directory for which the request was sent
58
90
  */
59
91
  path: string;
92
+ } & (T extends keyof TDriveData ? { data: TDriveData[T] } : object);
93
+
94
+ type TDriveResponses = {
95
+ readdir: string[];
96
+ rmdir: void;
97
+ rename: void;
98
+ getmode: number;
99
+ lookup: DriveFS.ILookup;
100
+ mknod: void;
101
+ getattr: IStats;
102
+ get:
103
+ | {
104
+ /**
105
+ * The returned file content
106
+ */
107
+ content: any;
108
+
109
+ /**
110
+ * The content format
111
+ */
112
+ format: Contents.FileFormat;
113
+ }
114
+ | undefined;
115
+ put: void;
116
+ };
60
117
 
61
- /**
62
- * Extra data on the request
63
- */
64
- data?: any;
65
- }
118
+ /**
119
+ * Drive response
120
+ */
121
+ export type TDriveResponse<T extends TDriveMethod> = TDriveResponses[T];
66
122
 
67
123
  // Mapping flag -> do we need to overwrite the file upon closing it
68
124
  const flagNeedsWrite: { [flag: number]: boolean } = {
@@ -207,7 +263,17 @@ export class DriveFSEmscriptenNodeOps implements IEmscriptenNodeOps {
207
263
  this.fs = fs;
208
264
  }
209
265
 
210
- getattr(node: IEmscriptenFSNode): IStats {
266
+ protected node(
267
+ nodeOrStream: IEmscriptenFSNode | IEmscriptenStream,
268
+ ): IEmscriptenFSNode {
269
+ if (instanceOfStream(nodeOrStream)) {
270
+ return nodeOrStream.node;
271
+ }
272
+ return nodeOrStream;
273
+ }
274
+
275
+ getattr(value: IEmscriptenFSNode | IEmscriptenStream): IStats {
276
+ const node = this.node(value);
211
277
  return {
212
278
  ...this.fs.API.getattr(this.fs.realPath(node)),
213
279
  mode: node.mode,
@@ -215,7 +281,8 @@ export class DriveFSEmscriptenNodeOps implements IEmscriptenNodeOps {
215
281
  };
216
282
  }
217
283
 
218
- setattr(node: IEmscriptenFSNode, attr: IStats): void {
284
+ setattr(value: IEmscriptenFSNode | IEmscriptenStream, attr: IStats): void {
285
+ const node = this.node(value);
219
286
  for (const [key, value] of Object.entries(attr)) {
220
287
  switch (key) {
221
288
  case 'mode':
@@ -231,103 +298,93 @@ export class DriveFSEmscriptenNodeOps implements IEmscriptenNodeOps {
231
298
  }
232
299
  }
233
300
 
234
- lookup(parent: IEmscriptenFSNode, name: string): IEmscriptenFSNode {
235
- const path = this.fs.PATH.join2(this.fs.realPath(parent), name);
301
+ lookup(
302
+ parent: IEmscriptenFSNode | IEmscriptenStream,
303
+ name: string,
304
+ ): IEmscriptenFSNode {
305
+ const node = this.node(parent);
306
+ const path = this.fs.PATH.join2(this.fs.realPath(node), name);
236
307
  const result = this.fs.API.lookup(path);
237
308
  if (!result.ok) {
238
309
  throw this.fs.FS.genericErrors[this.fs.ERRNO_CODES['ENOENT']];
239
310
  }
240
- return this.fs.createNode(parent, name, result.mode, 0);
311
+ return this.fs.createNode(node, name, result.mode!, 0);
241
312
  }
242
313
 
243
314
  mknod(
244
- parent: IEmscriptenFSNode,
315
+ parent: IEmscriptenFSNode | IEmscriptenStream,
245
316
  name: string,
246
317
  mode: number,
247
318
  dev: number,
248
319
  ): IEmscriptenFSNode {
249
- const path = this.fs.PATH.join2(this.fs.realPath(parent), name);
320
+ const node = this.node(parent);
321
+ const path = this.fs.PATH.join2(this.fs.realPath(node), name);
250
322
  this.fs.API.mknod(path, mode);
251
- return this.fs.createNode(parent, name, mode, dev);
323
+ return this.fs.createNode(node, name, mode, dev);
252
324
  }
253
325
 
254
- rename(oldNode: IEmscriptenFSNode, newDir: IEmscriptenFSNode, newName: string): void {
326
+ rename(
327
+ value: IEmscriptenFSNode | IEmscriptenStream,
328
+ newDir: IEmscriptenFSNode | IEmscriptenStream,
329
+ newName: string,
330
+ ): void {
331
+ const oldNode = this.node(value);
332
+ const newDirNode = this.node(newDir);
255
333
  this.fs.API.rename(
256
334
  oldNode.parent
257
335
  ? this.fs.PATH.join2(this.fs.realPath(oldNode.parent), oldNode.name)
258
336
  : oldNode.name,
259
- this.fs.PATH.join2(this.fs.realPath(newDir), newName),
337
+ this.fs.PATH.join2(this.fs.realPath(newDirNode), newName),
260
338
  );
261
339
 
262
340
  // Updating the in-memory node
263
341
  oldNode.name = newName;
264
- oldNode.parent = newDir;
342
+ oldNode.parent = newDirNode;
265
343
  }
266
344
 
267
- unlink(parent: IEmscriptenFSNode, name: string): void {
268
- this.fs.API.rmdir(this.fs.PATH.join2(this.fs.realPath(parent), name));
345
+ unlink(parent: IEmscriptenFSNode | IEmscriptenStream, name: string): void {
346
+ this.fs.API.rmdir(this.fs.PATH.join2(this.fs.realPath(this.node(parent)), name));
269
347
  }
270
348
 
271
- rmdir(parent: IEmscriptenFSNode, name: string) {
272
- this.fs.API.rmdir(this.fs.PATH.join2(this.fs.realPath(parent), name));
349
+ rmdir(parent: IEmscriptenFSNode | IEmscriptenStream, name: string) {
350
+ this.fs.API.rmdir(this.fs.PATH.join2(this.fs.realPath(this.node(parent)), name));
273
351
  }
274
352
 
275
- readdir(node: IEmscriptenFSNode): string[] {
276
- return this.fs.API.readdir(this.fs.realPath(node));
353
+ readdir(value: IEmscriptenFSNode | IEmscriptenStream): string[] {
354
+ return this.fs.API.readdir(this.fs.realPath(this.node(value)));
277
355
  }
278
356
 
279
- symlink(parent: IEmscriptenFSNode, newName: string, oldPath: string): void {
357
+ symlink(
358
+ parent: IEmscriptenFSNode | IEmscriptenStream,
359
+ newName: string,
360
+ oldPath: string,
361
+ ): void {
280
362
  throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['EPERM']);
281
363
  }
282
364
 
283
- readlink(node: IEmscriptenFSNode): string {
365
+ readlink(node: IEmscriptenFSNode | IEmscriptenStream): string {
284
366
  throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['EPERM']);
285
367
  }
286
368
  }
287
369
 
288
370
  /**
289
- * Wrap ServiceWorker requests for an Emscripten-compatible synchronous API.
371
+ * ContentsAPI base class
290
372
  */
291
- export class ContentsAPI {
292
- constructor(
293
- baseUrl: string,
294
- driveName: string,
295
- mountpoint: string,
296
- FS: FS,
297
- ERRNO_CODES: ERRNO_CODES,
298
- ) {
299
- this._baseUrl = baseUrl;
373
+ export abstract class ContentsAPI {
374
+ constructor(driveName: string, mountpoint: string, FS: FS, ERRNO_CODES: ERRNO_CODES) {
300
375
  this._driveName = driveName;
301
376
  this._mountpoint = mountpoint;
377
+
302
378
  this.FS = FS;
303
379
  this.ERRNO_CODES = ERRNO_CODES;
304
380
  }
305
381
 
306
- request(data: IDriveRequest): any {
307
- const xhr = new XMLHttpRequest();
308
- xhr.open('POST', encodeURI(this.endpoint), false);
309
-
310
- try {
311
- xhr.send(JSON.stringify(data));
312
- } catch (e) {
313
- console.error(e);
314
- }
315
-
316
- if (xhr.status >= 400) {
317
- throw new this.FS.ErrnoError(this.ERRNO_CODES['EINVAL']);
318
- }
319
-
320
- return JSON.parse(xhr.responseText);
321
- }
322
-
323
382
  lookup(path: string): DriveFS.ILookup {
324
383
  return this.request({ method: 'lookup', path: this.normalizePath(path) });
325
384
  }
326
385
 
327
386
  getmode(path: string): number {
328
- return Number.parseInt(
329
- this.request({ method: 'getmode', path: this.normalizePath(path) }),
330
- );
387
+ return this.request({ method: 'getmode', path: this.normalizePath(path) });
331
388
  }
332
389
 
333
390
  mknod(path: string, mode: number) {
@@ -361,7 +418,14 @@ export class ContentsAPI {
361
418
  }
362
419
 
363
420
  get(path: string): DriveFS.IFile {
364
- const response = this.request({ method: 'get', path: this.normalizePath(path) });
421
+ const response = this.request({
422
+ method: 'get',
423
+ path: this.normalizePath(path),
424
+ });
425
+
426
+ if (!response) {
427
+ throw new this.FS.ErrnoError(this.ERRNO_CODES['ENOENT']);
428
+ }
365
429
 
366
430
  const serializedContent = response.content;
367
431
  const format: 'json' | 'text' | 'base64' | null = response.format;
@@ -420,14 +484,20 @@ export class ContentsAPI {
420
484
  }
421
485
 
422
486
  getattr(path: string): IStats {
423
- const stats: IStats = this.request({
487
+ const stats = this.request({
424
488
  method: 'getattr',
425
489
  path: this.normalizePath(path),
426
490
  });
427
491
  // Turn datetimes into proper objects
428
- stats.atime = new Date(stats.atime);
429
- stats.mtime = new Date(stats.mtime);
430
- stats.ctime = new Date(stats.ctime);
492
+ if (stats.atime) {
493
+ stats.atime = new Date(stats.atime);
494
+ }
495
+ if (stats.mtime) {
496
+ stats.mtime = new Date(stats.mtime);
497
+ }
498
+ if (stats.ctime) {
499
+ stats.ctime = new Date(stats.ctime);
500
+ }
431
501
  // ensure a non-undefined size (0 isn't great, though)
432
502
  stats.size = stats.size || 0;
433
503
  return stats;
@@ -452,6 +522,48 @@ export class ContentsAPI {
452
522
  return path;
453
523
  }
454
524
 
525
+ abstract request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T>;
526
+
527
+ private _driveName: string;
528
+ private _mountpoint: string;
529
+
530
+ protected FS: FS;
531
+ protected ERRNO_CODES: ERRNO_CODES;
532
+ }
533
+
534
+ /**
535
+ * An Emscripten-compatible synchronous Contents API using the service worker.
536
+ */
537
+ export class ServiceWorkerContentsAPI extends ContentsAPI {
538
+ constructor(
539
+ baseUrl: string,
540
+ driveName: string,
541
+ mountpoint: string,
542
+ FS: FS,
543
+ ERRNO_CODES: ERRNO_CODES,
544
+ ) {
545
+ super(driveName, mountpoint, FS, ERRNO_CODES);
546
+
547
+ this._baseUrl = baseUrl;
548
+ }
549
+
550
+ request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T> {
551
+ const xhr = new XMLHttpRequest();
552
+ xhr.open('POST', encodeURI(this.endpoint), false);
553
+
554
+ try {
555
+ xhr.send(JSON.stringify(data));
556
+ } catch (e) {
557
+ console.error(e);
558
+ }
559
+
560
+ if (xhr.status >= 400) {
561
+ throw new this.FS.ErrnoError(this.ERRNO_CODES['EINVAL']);
562
+ }
563
+
564
+ return JSON.parse(xhr.responseText);
565
+ }
566
+
455
567
  /**
456
568
  * Get the api/drive endpoint
457
569
  */
@@ -460,10 +572,6 @@ export class ContentsAPI {
460
572
  }
461
573
 
462
574
  private _baseUrl: string;
463
- private _driveName: string;
464
- private _mountpoint: string;
465
- private FS: FS;
466
- private ERRNO_CODES: ERRNO_CODES;
467
575
  }
468
576
 
469
577
  export class DriveFS {
@@ -477,13 +585,8 @@ export class DriveFS {
477
585
  this.FS = options.FS;
478
586
  this.PATH = options.PATH;
479
587
  this.ERRNO_CODES = options.ERRNO_CODES;
480
- this.API = new ContentsAPI(
481
- options.baseUrl,
482
- options.driveName,
483
- options.mountpoint,
484
- this.FS,
485
- this.ERRNO_CODES,
486
- );
588
+ this.API = this.createAPI(options);
589
+
487
590
  this.driveName = options.driveName;
488
591
 
489
592
  this.node_ops = new DriveFSEmscriptenNodeOps(this);
@@ -493,6 +596,21 @@ export class DriveFS {
493
596
  node_ops: IEmscriptenNodeOps;
494
597
  stream_ops: IEmscriptenStreamOps;
495
598
 
599
+ /**
600
+ * Create the ContentsAPI.
601
+ *
602
+ * This is supposed to be overwritten if needed.
603
+ */
604
+ createAPI(options: DriveFS.IOptions): ContentsAPI {
605
+ return new ServiceWorkerContentsAPI(
606
+ options.baseUrl,
607
+ options.driveName,
608
+ options.mountpoint,
609
+ options.FS,
610
+ options.ERRNO_CODES,
611
+ );
612
+ }
613
+
496
614
  mount(mount: any): IEmscriptenFSNode {
497
615
  return this.createNode(null, mount.mountpoint, DIR_MODE | 511, 0);
498
616
  }
@@ -549,7 +667,7 @@ export namespace DriveFS {
549
667
  */
550
668
  export interface ILookup {
551
669
  ok: boolean;
552
- mode: number;
670
+ mode?: number;
553
671
  }
554
672
 
555
673
  /**