@jupyterlite/contents 0.4.0-alpha.2 → 0.4.0-beta.0
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/lib/broadcast.d.ts +4 -2
- package/lib/broadcast.js +6 -96
- package/lib/broadcast.js.map +1 -1
- package/lib/drivecontents.d.ts +92 -0
- package/lib/drivecontents.js +122 -0
- package/lib/drivecontents.js.map +1 -0
- package/lib/drivefs.d.ts +83 -19
- package/lib/drivefs.js +51 -27
- package/lib/drivefs.js.map +1 -1
- package/lib/emscripten.d.ts +5 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/broadcast.ts +11 -106
- package/src/drivecontents.ts +244 -0
- package/src/drivefs.ts +147 -56
- package/src/emscripten.ts +5 -5
- package/src/index.ts +1 -0
package/lib/broadcast.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Contents as ServerContents } from '@jupyterlab/services';
|
|
2
|
-
import {
|
|
2
|
+
import { TDriveRequest, TDriveMethod } from './drivefs';
|
|
3
3
|
import { IBroadcastChannelWrapper } from './tokens';
|
|
4
|
+
import { IDriveContentsProcessor } from './drivecontents';
|
|
4
5
|
/** A broadcaster for the ServiceWorker */
|
|
5
6
|
export declare class BroadcastChannelWrapper implements IBroadcastChannelWrapper {
|
|
6
7
|
isDisposed: boolean;
|
|
@@ -11,9 +12,10 @@ export declare class BroadcastChannelWrapper implements IBroadcastChannelWrapper
|
|
|
11
12
|
/** Clean up the broadcaster. */
|
|
12
13
|
dispose(): void;
|
|
13
14
|
/** Handle a message received on the BroadcastChannel */
|
|
14
|
-
protected _onMessage: (event: MessageEvent<
|
|
15
|
+
protected _onMessage: <T extends TDriveMethod>(event: MessageEvent<TDriveRequest<T>>) => Promise<void>;
|
|
15
16
|
protected _channel: BroadcastChannel | null;
|
|
16
17
|
protected _contents: ServerContents.IManager;
|
|
18
|
+
protected _driveContentsProcessor: IDriveContentsProcessor;
|
|
17
19
|
protected _enabled: boolean;
|
|
18
20
|
}
|
|
19
21
|
/** A namespace for */
|
package/lib/broadcast.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { BLOCK_SIZE, DRIVE_API_PATH } from './drivefs';
|
|
3
|
+
import { DRIVE_API_PATH } from './drivefs';
|
|
4
|
+
import { DriveContentsProcessor } from './drivecontents';
|
|
6
5
|
/** A broadcaster for the ServiceWorker */
|
|
7
6
|
export class BroadcastChannelWrapper {
|
|
8
7
|
constructor(options) {
|
|
@@ -12,110 +11,21 @@ export class BroadcastChannelWrapper {
|
|
|
12
11
|
if (!this._channel) {
|
|
13
12
|
return;
|
|
14
13
|
}
|
|
15
|
-
const { _contents } = this;
|
|
16
14
|
const request = event.data;
|
|
17
|
-
const path = request === null || request === void 0 ? void 0 : request.path;
|
|
18
15
|
const receiver = request === null || request === void 0 ? void 0 : request.receiver;
|
|
19
16
|
if (receiver !== 'broadcast.ts') {
|
|
20
17
|
// Message is not meant for us
|
|
21
18
|
return;
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
let response = null;
|
|
25
|
-
// most requests will use a model
|
|
26
|
-
let model;
|
|
27
|
-
switch (request === null || request === void 0 ? void 0 : request.method) {
|
|
28
|
-
case 'readdir':
|
|
29
|
-
model = await _contents.get(path, { content: true });
|
|
30
|
-
response = [];
|
|
31
|
-
if (model.type === 'directory' && model.content) {
|
|
32
|
-
response = model.content.map((subcontent) => subcontent.name);
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
case 'rmdir':
|
|
36
|
-
await _contents.delete(path);
|
|
37
|
-
break;
|
|
38
|
-
case 'rename':
|
|
39
|
-
await _contents.rename(path, request.data.newPath);
|
|
40
|
-
break;
|
|
41
|
-
case 'getmode':
|
|
42
|
-
model = await _contents.get(path);
|
|
43
|
-
if (model.type === 'directory') {
|
|
44
|
-
response = DIR_MODE;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
response = FILE_MODE;
|
|
48
|
-
}
|
|
49
|
-
break;
|
|
50
|
-
case 'lookup':
|
|
51
|
-
try {
|
|
52
|
-
model = await _contents.get(path);
|
|
53
|
-
response = {
|
|
54
|
-
ok: true,
|
|
55
|
-
mode: model.type === 'directory' ? DIR_MODE : FILE_MODE,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
response = { ok: false };
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
case 'mknod':
|
|
63
|
-
model = await _contents.newUntitled({
|
|
64
|
-
path: PathExt.dirname(path),
|
|
65
|
-
type: Number.parseInt(request.data.mode) === DIR_MODE ? 'directory' : 'file',
|
|
66
|
-
ext: PathExt.extname(path),
|
|
67
|
-
});
|
|
68
|
-
await _contents.rename(model.path, path);
|
|
69
|
-
break;
|
|
70
|
-
case 'getattr': {
|
|
71
|
-
model = await _contents.get(path);
|
|
72
|
-
// create a default date for drives that send incomplete information
|
|
73
|
-
// for nested foldes and files
|
|
74
|
-
const defaultDate = new Date(0).toISOString();
|
|
75
|
-
response = {
|
|
76
|
-
dev: 1,
|
|
77
|
-
nlink: 1,
|
|
78
|
-
uid: 0,
|
|
79
|
-
gid: 0,
|
|
80
|
-
rdev: 0,
|
|
81
|
-
size: model.size || 0,
|
|
82
|
-
blksize: BLOCK_SIZE,
|
|
83
|
-
blocks: Math.ceil(model.size || 0 / BLOCK_SIZE),
|
|
84
|
-
atime: model.last_modified || defaultDate,
|
|
85
|
-
mtime: model.last_modified || defaultDate,
|
|
86
|
-
ctime: model.created || defaultDate,
|
|
87
|
-
timestamp: 0,
|
|
88
|
-
};
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
case 'get':
|
|
92
|
-
model = await _contents.get(path, { content: true });
|
|
93
|
-
if (model.type === 'directory') {
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
response = {
|
|
97
|
-
content: model.format === 'json' ? JSON.stringify(model.content) : model.content,
|
|
98
|
-
format: model.format,
|
|
99
|
-
};
|
|
100
|
-
break;
|
|
101
|
-
case 'put':
|
|
102
|
-
await _contents.save(path, {
|
|
103
|
-
content: request.data.format === 'json'
|
|
104
|
-
? JSON.parse(request.data.data)
|
|
105
|
-
: request.data.data,
|
|
106
|
-
type: 'file',
|
|
107
|
-
format: request.data.format,
|
|
108
|
-
});
|
|
109
|
-
break;
|
|
110
|
-
default:
|
|
111
|
-
response = null;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
20
|
+
const response = await this._driveContentsProcessor.processDriveRequest(request);
|
|
114
21
|
this._channel.postMessage(response);
|
|
115
22
|
};
|
|
116
23
|
this._channel = null;
|
|
117
24
|
this._enabled = false;
|
|
118
25
|
this._contents = options.contents;
|
|
26
|
+
this._driveContentsProcessor = new DriveContentsProcessor({
|
|
27
|
+
contentsManager: this._contents,
|
|
28
|
+
});
|
|
119
29
|
}
|
|
120
30
|
get enabled() {
|
|
121
31
|
return this._enabled;
|
package/lib/broadcast.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;
|
|
1
|
+
{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAI3D,OAAO,EAAiB,cAAc,EAAgB,MAAM,WAAW,CAAC;AAGxE,OAAO,EAA2B,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAElF,0CAA0C;AAC1C,MAAM,OAAO,uBAAuB;IAGlC,YAAY,OAAyC;QAF9C,eAAU,GAAG,KAAK,CAAC;QAwC1B,wDAAwD;QAC9C,eAAU,GAAG,KAAK,EAC1B,KAAq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C,QAAQ,GAAG,IAAI,CAAC;SACtB;QACD,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,gCAAgC;IAChC,OAAO;QACL,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,OAAO;SACR;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;CA0BF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Contents } from '@jupyterlab/services';
|
|
2
|
+
import { TDriveMethod, TDriveRequest, TDriveResponse } from './drivefs';
|
|
3
|
+
export interface IDriveContentsProcessor {
|
|
4
|
+
/**
|
|
5
|
+
* Process a content request
|
|
6
|
+
*
|
|
7
|
+
* @param request the request
|
|
8
|
+
*/
|
|
9
|
+
processDriveRequest<T extends TDriveMethod>(request: TDriveRequest<T>): Promise<TDriveResponse<T>>;
|
|
10
|
+
/**
|
|
11
|
+
* Process the request to read a directory content
|
|
12
|
+
*
|
|
13
|
+
* @param request the request
|
|
14
|
+
*/
|
|
15
|
+
readdir(request: TDriveRequest<'readdir'>): Promise<TDriveResponse<'readdir'>>;
|
|
16
|
+
/**
|
|
17
|
+
* Process the request to remove a directory
|
|
18
|
+
*
|
|
19
|
+
* @param request the request
|
|
20
|
+
*/
|
|
21
|
+
rmdir(request: TDriveRequest<'rmdir'>): Promise<TDriveResponse<'rmdir'>>;
|
|
22
|
+
/**
|
|
23
|
+
* Process the request to rename a file or directory
|
|
24
|
+
*
|
|
25
|
+
* @param request the request
|
|
26
|
+
*/
|
|
27
|
+
rename(request: TDriveRequest<'rename'>): Promise<TDriveResponse<'rename'>>;
|
|
28
|
+
/**
|
|
29
|
+
* Process the request to get the node mode (file or directory)
|
|
30
|
+
*
|
|
31
|
+
* @param request the request
|
|
32
|
+
*/
|
|
33
|
+
getmode(request: TDriveRequest<'getmode'>): Promise<TDriveResponse<'getmode'>>;
|
|
34
|
+
/**
|
|
35
|
+
* Process the request to check if a node exist
|
|
36
|
+
*
|
|
37
|
+
* @param request the request
|
|
38
|
+
*/
|
|
39
|
+
lookup(request: TDriveRequest<'lookup'>): Promise<TDriveResponse<'lookup'>>;
|
|
40
|
+
/**
|
|
41
|
+
* Process the request to create a directory/file
|
|
42
|
+
*
|
|
43
|
+
* @param request the request
|
|
44
|
+
*/
|
|
45
|
+
mknod(request: TDriveRequest<'mknod'>): Promise<TDriveResponse<'mknod'>>;
|
|
46
|
+
/**
|
|
47
|
+
* Process the request to get a node stats
|
|
48
|
+
*
|
|
49
|
+
* @param request the request
|
|
50
|
+
*/
|
|
51
|
+
getattr(request: TDriveRequest<'getattr'>): Promise<TDriveResponse<'getattr'>>;
|
|
52
|
+
/**
|
|
53
|
+
* Process the request to get the content of a file
|
|
54
|
+
*
|
|
55
|
+
* @param request the request
|
|
56
|
+
*/
|
|
57
|
+
get(request: TDriveRequest<'get'>): Promise<TDriveResponse<'get'>>;
|
|
58
|
+
/**
|
|
59
|
+
* Process the request to write the content of a file
|
|
60
|
+
*
|
|
61
|
+
* @param request the request
|
|
62
|
+
*/
|
|
63
|
+
put(request: TDriveRequest<'put'>): Promise<TDriveResponse<'put'>>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Class for processing a drive request from the DriveFS.
|
|
67
|
+
*/
|
|
68
|
+
export declare class DriveContentsProcessor implements IDriveContentsProcessor {
|
|
69
|
+
private contentsManager;
|
|
70
|
+
constructor(options: DriveContentsProcessor.IOptions);
|
|
71
|
+
processDriveRequest<T extends TDriveMethod>(request: TDriveRequest<T>): Promise<TDriveResponse<T>>;
|
|
72
|
+
readdir(request: TDriveRequest<'readdir'>): Promise<TDriveResponse<'readdir'>>;
|
|
73
|
+
rmdir(request: TDriveRequest<'rmdir'>): Promise<TDriveResponse<'rmdir'>>;
|
|
74
|
+
rename(request: TDriveRequest<'rename'>): Promise<TDriveResponse<'rename'>>;
|
|
75
|
+
getmode(request: TDriveRequest<'getmode'>): Promise<TDriveResponse<'getmode'>>;
|
|
76
|
+
lookup(request: TDriveRequest<'lookup'>): Promise<TDriveResponse<'lookup'>>;
|
|
77
|
+
mknod(request: TDriveRequest<'mknod'>): Promise<TDriveResponse<'mknod'>>;
|
|
78
|
+
getattr(request: TDriveRequest<'getattr'>): Promise<TDriveResponse<'getattr'>>;
|
|
79
|
+
get(request: TDriveRequest<'get'>): Promise<TDriveResponse<'get'>>;
|
|
80
|
+
put(request: TDriveRequest<'put'>): Promise<TDriveResponse<'put'>>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A namespace for DriveContentsProcessor configurations, etc.
|
|
84
|
+
*/
|
|
85
|
+
export declare namespace DriveContentsProcessor {
|
|
86
|
+
/**
|
|
87
|
+
* Initialization options for a drive;
|
|
88
|
+
*/
|
|
89
|
+
interface IOptions {
|
|
90
|
+
contentsManager: Contents.IManager;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { PathExt } from '@jupyterlab/coreutils';
|
|
2
|
+
import { BLOCK_SIZE } from './drivefs';
|
|
3
|
+
import { DIR_MODE, FILE_MODE } from './emscripten';
|
|
4
|
+
/**
|
|
5
|
+
* Class for processing a drive request from the DriveFS.
|
|
6
|
+
*/
|
|
7
|
+
export class DriveContentsProcessor {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.contentsManager = options.contentsManager;
|
|
10
|
+
}
|
|
11
|
+
async processDriveRequest(request) {
|
|
12
|
+
switch (request.method) {
|
|
13
|
+
case 'readdir':
|
|
14
|
+
return this.readdir(request);
|
|
15
|
+
case 'rmdir':
|
|
16
|
+
return this.rmdir(request);
|
|
17
|
+
case 'rename':
|
|
18
|
+
return this.rename(request);
|
|
19
|
+
case 'getmode':
|
|
20
|
+
return this.getmode(request);
|
|
21
|
+
case 'lookup':
|
|
22
|
+
return this.lookup(request);
|
|
23
|
+
case 'mknod':
|
|
24
|
+
return this.mknod(request);
|
|
25
|
+
case 'getattr':
|
|
26
|
+
return this.getattr(request);
|
|
27
|
+
case 'get':
|
|
28
|
+
return this.get(request);
|
|
29
|
+
case 'put':
|
|
30
|
+
return this.put(request);
|
|
31
|
+
}
|
|
32
|
+
throw `Drive request ${request.method} does not exist.`;
|
|
33
|
+
}
|
|
34
|
+
async readdir(request) {
|
|
35
|
+
const model = await this.contentsManager.get(request.path, { content: true });
|
|
36
|
+
let response = [];
|
|
37
|
+
if (model.type === 'directory' && model.content) {
|
|
38
|
+
response = model.content.map((subcontent) => subcontent.name);
|
|
39
|
+
}
|
|
40
|
+
return response;
|
|
41
|
+
}
|
|
42
|
+
async rmdir(request) {
|
|
43
|
+
await this.contentsManager.delete(request.path);
|
|
44
|
+
}
|
|
45
|
+
async rename(request) {
|
|
46
|
+
await this.contentsManager.rename(request.path, request.data.newPath);
|
|
47
|
+
}
|
|
48
|
+
async getmode(request) {
|
|
49
|
+
const model = await this.contentsManager.get(request.path);
|
|
50
|
+
let response;
|
|
51
|
+
if (model.type === 'directory') {
|
|
52
|
+
response = DIR_MODE;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
response = FILE_MODE;
|
|
56
|
+
}
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
async lookup(request) {
|
|
60
|
+
let response;
|
|
61
|
+
try {
|
|
62
|
+
const model = await this.contentsManager.get(request.path);
|
|
63
|
+
response = {
|
|
64
|
+
ok: true,
|
|
65
|
+
mode: model.type === 'directory' ? DIR_MODE : FILE_MODE,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
response = { ok: false };
|
|
70
|
+
}
|
|
71
|
+
return response;
|
|
72
|
+
}
|
|
73
|
+
async mknod(request) {
|
|
74
|
+
const model = await this.contentsManager.newUntitled({
|
|
75
|
+
path: PathExt.dirname(request.path),
|
|
76
|
+
type: request.data.mode === DIR_MODE ? 'directory' : 'file',
|
|
77
|
+
ext: PathExt.extname(request.path),
|
|
78
|
+
});
|
|
79
|
+
await this.contentsManager.rename(model.path, request.path);
|
|
80
|
+
}
|
|
81
|
+
async getattr(request) {
|
|
82
|
+
const model = await this.contentsManager.get(request.path);
|
|
83
|
+
// create a default date for drives that send incomplete information
|
|
84
|
+
// for nested foldes and files
|
|
85
|
+
const defaultDate = new Date(0).toISOString();
|
|
86
|
+
return {
|
|
87
|
+
dev: 1,
|
|
88
|
+
nlink: 1,
|
|
89
|
+
uid: 0,
|
|
90
|
+
gid: 0,
|
|
91
|
+
rdev: 0,
|
|
92
|
+
size: model.size || 0,
|
|
93
|
+
blksize: BLOCK_SIZE,
|
|
94
|
+
blocks: Math.ceil(model.size || 0 / BLOCK_SIZE),
|
|
95
|
+
atime: model.last_modified || defaultDate,
|
|
96
|
+
mtime: model.last_modified || defaultDate,
|
|
97
|
+
ctime: model.created || defaultDate,
|
|
98
|
+
timestamp: 0,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async get(request) {
|
|
102
|
+
const model = await this.contentsManager.get(request.path, { content: true });
|
|
103
|
+
let response;
|
|
104
|
+
if (model.type !== 'directory') {
|
|
105
|
+
response = {
|
|
106
|
+
content: model.format === 'json' ? JSON.stringify(model.content) : model.content,
|
|
107
|
+
format: model.format,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return response;
|
|
111
|
+
}
|
|
112
|
+
async put(request) {
|
|
113
|
+
await this.contentsManager.save(request.path, {
|
|
114
|
+
content: request.data.format === 'json'
|
|
115
|
+
? JSON.parse(request.data.data)
|
|
116
|
+
: request.data.data,
|
|
117
|
+
type: 'file',
|
|
118
|
+
format: request.data.format,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=drivecontents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drivecontents.js","sourceRoot":"","sources":["../src/drivecontents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAA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,OAAO,IAAI,WAAW;YACnC,SAAS,EAAE,CAAC;SACb,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,OAA6B;QACrC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAE9E,IAAI,QAAQ,CAAC;QAEb,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE;YAC9B,QAAQ,GAAG;gBACT,OAAO,EACL,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO;gBACzE,MAAM,EAAE,KAAK,CAAC,MAAM;aACrB,CAAC;SACH;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,OAA6B;QACrC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;YAC5C,OAAO,EACL,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM;gBAC5B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC/B,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;YACvB,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,MAA6B;SACnD,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/lib/drivefs.d.ts
CHANGED
|
@@ -1,16 +1,44 @@
|
|
|
1
|
+
import { Contents } from '@jupyterlab/services';
|
|
1
2
|
import { FS, ERRNO_CODES, PATH, IEmscriptenStream, IEmscriptenStreamOps, IEmscriptenNodeOps, IEmscriptenFSNode, IStats } from './emscripten';
|
|
2
3
|
export declare const DRIVE_SEPARATOR = ":";
|
|
3
4
|
export declare const DRIVE_API_PATH = "/api/drive.v1";
|
|
4
5
|
export declare const BLOCK_SIZE = 4096;
|
|
5
6
|
export type TDriveMethod = 'readdir' | 'rmdir' | 'rename' | 'getmode' | 'lookup' | 'mknod' | 'getattr' | 'get' | 'put';
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* Type of the data argument for the drive request, based on the request name
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
+
export type TDriveData = {
|
|
11
|
+
rename: {
|
|
12
|
+
/**
|
|
13
|
+
* The new path for the file
|
|
14
|
+
*/
|
|
15
|
+
newPath: string;
|
|
16
|
+
};
|
|
17
|
+
mknod: {
|
|
18
|
+
/**
|
|
19
|
+
* The mode of the file to create
|
|
20
|
+
*/
|
|
21
|
+
mode: number;
|
|
22
|
+
};
|
|
23
|
+
put: {
|
|
24
|
+
/**
|
|
25
|
+
* The file content to write
|
|
26
|
+
*/
|
|
27
|
+
data: any;
|
|
28
|
+
/**
|
|
29
|
+
* The file content format
|
|
30
|
+
*/
|
|
31
|
+
format: Contents.FileFormat;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Drive request
|
|
36
|
+
*/
|
|
37
|
+
export type TDriveRequest<T extends TDriveMethod> = {
|
|
10
38
|
/**
|
|
11
39
|
* The method of the request (rmdir, readdir etc)
|
|
12
40
|
*/
|
|
13
|
-
method:
|
|
41
|
+
method: T;
|
|
14
42
|
/**
|
|
15
43
|
* The expected receiver of the request
|
|
16
44
|
*/
|
|
@@ -19,11 +47,33 @@ export interface IDriveRequest {
|
|
|
19
47
|
* The path to the file/directory for which the request was sent
|
|
20
48
|
*/
|
|
21
49
|
path: string;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
50
|
+
} & (T extends keyof TDriveData ? {
|
|
51
|
+
data: TDriveData[T];
|
|
52
|
+
} : object);
|
|
53
|
+
type TDriveResponses = {
|
|
54
|
+
readdir: string[];
|
|
55
|
+
rmdir: void;
|
|
56
|
+
rename: void;
|
|
57
|
+
getmode: number;
|
|
58
|
+
lookup: DriveFS.ILookup;
|
|
59
|
+
mknod: void;
|
|
60
|
+
getattr: IStats;
|
|
61
|
+
get: {
|
|
62
|
+
/**
|
|
63
|
+
* The returned file content
|
|
64
|
+
*/
|
|
65
|
+
content: any;
|
|
66
|
+
/**
|
|
67
|
+
* The content format
|
|
68
|
+
*/
|
|
69
|
+
format: Contents.FileFormat;
|
|
70
|
+
} | undefined;
|
|
71
|
+
put: void;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Drive response
|
|
75
|
+
*/
|
|
76
|
+
export type TDriveResponse<T extends TDriveMethod> = TDriveResponses[T];
|
|
27
77
|
/** Implementation-specifc extension of an open stream, adding the file. */
|
|
28
78
|
export interface IDriveStream extends IEmscriptenStream {
|
|
29
79
|
file?: DriveFS.IFile;
|
|
@@ -53,19 +103,18 @@ export declare class DriveFSEmscriptenNodeOps implements IEmscriptenNodeOps {
|
|
|
53
103
|
readlink(node: IEmscriptenFSNode | IEmscriptenStream): string;
|
|
54
104
|
}
|
|
55
105
|
/**
|
|
56
|
-
*
|
|
106
|
+
* ContentsAPI base class
|
|
57
107
|
*/
|
|
58
|
-
export declare class ContentsAPI {
|
|
59
|
-
constructor(
|
|
60
|
-
request(data: IDriveRequest): any;
|
|
108
|
+
export declare abstract class ContentsAPI {
|
|
109
|
+
constructor(driveName: string, mountpoint: string, FS: FS, ERRNO_CODES: ERRNO_CODES);
|
|
61
110
|
lookup(path: string): DriveFS.ILookup;
|
|
62
111
|
getmode(path: string): number;
|
|
63
|
-
mknod(path: string, mode: number):
|
|
112
|
+
mknod(path: string, mode: number): void;
|
|
64
113
|
rename(oldPath: string, newPath: string): void;
|
|
65
114
|
readdir(path: string): string[];
|
|
66
115
|
rmdir(path: string): void;
|
|
67
116
|
get(path: string): DriveFS.IFile;
|
|
68
|
-
put(path: string, value: DriveFS.IFile):
|
|
117
|
+
put(path: string, value: DriveFS.IFile): void;
|
|
69
118
|
getattr(path: string): IStats;
|
|
70
119
|
/**
|
|
71
120
|
* Normalize a Path by making it compliant for the content manager
|
|
@@ -73,15 +122,23 @@ export declare class ContentsAPI {
|
|
|
73
122
|
* @param path: the path relatively to the Emscripten drive
|
|
74
123
|
*/
|
|
75
124
|
normalizePath(path: string): string;
|
|
125
|
+
abstract request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T>;
|
|
126
|
+
private _driveName;
|
|
127
|
+
private _mountpoint;
|
|
128
|
+
protected FS: FS;
|
|
129
|
+
protected ERRNO_CODES: ERRNO_CODES;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* An Emscripten-compatible synchronous Contents API using the service worker.
|
|
133
|
+
*/
|
|
134
|
+
export declare class ServiceWorkerContentsAPI extends ContentsAPI {
|
|
135
|
+
constructor(baseUrl: string, driveName: string, mountpoint: string, FS: FS, ERRNO_CODES: ERRNO_CODES);
|
|
136
|
+
request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T>;
|
|
76
137
|
/**
|
|
77
138
|
* Get the api/drive endpoint
|
|
78
139
|
*/
|
|
79
140
|
get endpoint(): string;
|
|
80
141
|
private _baseUrl;
|
|
81
|
-
private _driveName;
|
|
82
|
-
private _mountpoint;
|
|
83
|
-
private FS;
|
|
84
|
-
private ERRNO_CODES;
|
|
85
142
|
}
|
|
86
143
|
export declare class DriveFS {
|
|
87
144
|
FS: FS;
|
|
@@ -92,6 +149,12 @@ export declare class DriveFS {
|
|
|
92
149
|
constructor(options: DriveFS.IOptions);
|
|
93
150
|
node_ops: IEmscriptenNodeOps;
|
|
94
151
|
stream_ops: IEmscriptenStreamOps;
|
|
152
|
+
/**
|
|
153
|
+
* Create the ContentsAPI.
|
|
154
|
+
*
|
|
155
|
+
* This is supposed to be overwritten if needed.
|
|
156
|
+
*/
|
|
157
|
+
createAPI(options: DriveFS.IOptions): ContentsAPI;
|
|
95
158
|
mount(mount: any): IEmscriptenFSNode;
|
|
96
159
|
createNode(parent: IEmscriptenFSNode | null, name: string, mode: number, dev: number): IEmscriptenFSNode;
|
|
97
160
|
getMode(path: string): number;
|
|
@@ -113,7 +176,7 @@ export declare namespace DriveFS {
|
|
|
113
176
|
*/
|
|
114
177
|
interface ILookup {
|
|
115
178
|
ok: boolean;
|
|
116
|
-
mode
|
|
179
|
+
mode?: number;
|
|
117
180
|
}
|
|
118
181
|
/**
|
|
119
182
|
* Initialization options for a drive;
|
|
@@ -127,3 +190,4 @@ export declare namespace DriveFS {
|
|
|
127
190
|
mountpoint: string;
|
|
128
191
|
}
|
|
129
192
|
}
|
|
193
|
+
export {};
|