@jupyterlite/contents 0.1.0-beta.2 → 0.1.0-beta.20
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 +25 -0
- package/lib/broadcast.js +139 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/contents.d.ts +38 -3
- package/lib/contents.js +182 -73
- package/lib/contents.js.map +1 -0
- package/lib/drivefs.d.ts +124 -0
- package/lib/drivefs.js +361 -0
- package/lib/drivefs.js.map +1 -0
- package/lib/emscripten.d.ts +89 -0
- package/lib/emscripten.js +8 -0
- package/lib/emscripten.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -0
- package/lib/tokens.d.ts +26 -8
- package/lib/tokens.js +50 -9
- package/lib/tokens.js.map +1 -0
- package/package.json +10 -6
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ContentsManager } from '@jupyterlab/services';
|
|
2
|
+
import { IDriveRequest } from './drivefs';
|
|
3
|
+
import { IBroadcastChannelWrapper } from './tokens';
|
|
4
|
+
/** A broadcaster for the ServiceWorker */
|
|
5
|
+
export declare class BroadcastChannelWrapper implements IBroadcastChannelWrapper {
|
|
6
|
+
isDisposed: boolean;
|
|
7
|
+
constructor(options: BroadcastChannelWrapper.IOptions);
|
|
8
|
+
get enabled(): boolean;
|
|
9
|
+
enable(): void;
|
|
10
|
+
disable(): void;
|
|
11
|
+
/** Clean up the broadcaster. */
|
|
12
|
+
dispose(): void;
|
|
13
|
+
/** Handle a message received on the BroadcastChannel */
|
|
14
|
+
protected _onMessage: (event: MessageEvent<IDriveRequest>) => Promise<void>;
|
|
15
|
+
protected _channel: BroadcastChannel | null;
|
|
16
|
+
protected _contents: ContentsManager;
|
|
17
|
+
protected _enabled: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** A namespace for */
|
|
20
|
+
export declare namespace BroadcastChannelWrapper {
|
|
21
|
+
interface IOptions {
|
|
22
|
+
contents: ContentsManager;
|
|
23
|
+
}
|
|
24
|
+
type TBroadcastResponse = any;
|
|
25
|
+
}
|
package/lib/broadcast.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { PathExt } from '@jupyterlab/coreutils';
|
|
4
|
+
import { DIR_MODE, FILE_MODE } from './emscripten';
|
|
5
|
+
import { BLOCK_SIZE, DRIVE_API_PATH } from './drivefs';
|
|
6
|
+
/** A broadcaster for the ServiceWorker */
|
|
7
|
+
export class BroadcastChannelWrapper {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.isDisposed = false;
|
|
10
|
+
/** Handle a message received on the BroadcastChannel */
|
|
11
|
+
this._onMessage = async (event) => {
|
|
12
|
+
if (!this._channel) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const { _contents } = this;
|
|
16
|
+
const request = event.data;
|
|
17
|
+
const { path } = request;
|
|
18
|
+
// many successful responses default to null
|
|
19
|
+
let response = null;
|
|
20
|
+
// most requests will use a model
|
|
21
|
+
let model;
|
|
22
|
+
switch (request.method) {
|
|
23
|
+
case 'readdir':
|
|
24
|
+
model = await _contents.get(path, { content: true });
|
|
25
|
+
response = [];
|
|
26
|
+
if (model.type === 'directory' && model.content) {
|
|
27
|
+
response = model.content.map((subcontent) => subcontent.name);
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
case 'rmdir':
|
|
31
|
+
await _contents.delete(path);
|
|
32
|
+
break;
|
|
33
|
+
case 'rename':
|
|
34
|
+
await _contents.rename(path, request.data.newPath);
|
|
35
|
+
break;
|
|
36
|
+
case 'getmode':
|
|
37
|
+
model = await _contents.get(path);
|
|
38
|
+
if (model.type === 'directory') {
|
|
39
|
+
response = DIR_MODE;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
response = FILE_MODE;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case 'lookup':
|
|
46
|
+
try {
|
|
47
|
+
model = await _contents.get(path);
|
|
48
|
+
response = {
|
|
49
|
+
ok: true,
|
|
50
|
+
mode: model.type === 'directory' ? DIR_MODE : FILE_MODE,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
response = { ok: false };
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
case 'mknod':
|
|
58
|
+
model = await _contents.newUntitled({
|
|
59
|
+
path: PathExt.dirname(path),
|
|
60
|
+
type: Number.parseInt(request.data.mode) === DIR_MODE ? 'directory' : 'file',
|
|
61
|
+
ext: PathExt.extname(path),
|
|
62
|
+
});
|
|
63
|
+
await _contents.rename(model.path, path);
|
|
64
|
+
break;
|
|
65
|
+
case 'getattr':
|
|
66
|
+
model = await _contents.get(path);
|
|
67
|
+
response = {
|
|
68
|
+
dev: 1,
|
|
69
|
+
nlink: 1,
|
|
70
|
+
uid: 0,
|
|
71
|
+
gid: 0,
|
|
72
|
+
rdev: 0,
|
|
73
|
+
size: model.size || 0,
|
|
74
|
+
blksize: BLOCK_SIZE,
|
|
75
|
+
blocks: Math.ceil(model.size || 0 / BLOCK_SIZE),
|
|
76
|
+
atime: model.last_modified,
|
|
77
|
+
mtime: model.last_modified,
|
|
78
|
+
ctime: model.created,
|
|
79
|
+
timestamp: 0,
|
|
80
|
+
};
|
|
81
|
+
break;
|
|
82
|
+
case 'get':
|
|
83
|
+
model = await _contents.get(path, { content: true });
|
|
84
|
+
if (model.type === 'directory') {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
response = {
|
|
88
|
+
content: model.format === 'json' ? JSON.stringify(model.content) : model.content,
|
|
89
|
+
format: model.format,
|
|
90
|
+
};
|
|
91
|
+
break;
|
|
92
|
+
case 'put':
|
|
93
|
+
await _contents.save(path, {
|
|
94
|
+
content: request.data.format === 'json'
|
|
95
|
+
? JSON.parse(request.data.data)
|
|
96
|
+
: request.data.data,
|
|
97
|
+
type: 'file',
|
|
98
|
+
format: request.data.format,
|
|
99
|
+
});
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
response = null;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
this._channel.postMessage(response);
|
|
106
|
+
};
|
|
107
|
+
this._channel = null;
|
|
108
|
+
this._enabled = false;
|
|
109
|
+
this._contents = options.contents;
|
|
110
|
+
}
|
|
111
|
+
get enabled() {
|
|
112
|
+
return this._enabled;
|
|
113
|
+
}
|
|
114
|
+
enable() {
|
|
115
|
+
if (this._channel) {
|
|
116
|
+
console.warn('BroadcastChannel already created and enabled');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this._channel = new BroadcastChannel(DRIVE_API_PATH);
|
|
120
|
+
this._channel.addEventListener('message', this._onMessage);
|
|
121
|
+
this._enabled = true;
|
|
122
|
+
}
|
|
123
|
+
disable() {
|
|
124
|
+
if (this._channel) {
|
|
125
|
+
this._channel.removeEventListener('message', this._onMessage);
|
|
126
|
+
this._channel = null;
|
|
127
|
+
}
|
|
128
|
+
this._enabled = false;
|
|
129
|
+
}
|
|
130
|
+
/** Clean up the broadcaster. */
|
|
131
|
+
dispose() {
|
|
132
|
+
if (this.isDisposed) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.disable();
|
|
136
|
+
this.isDisposed = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=broadcast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIhD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAiB,cAAc,EAAE,MAAM,WAAW,CAAC;AAMtE,0CAA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IACpC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,OAAO,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;YAC7D,OAAO;SACR;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,gBAAgB,CAAC,cAAc,CAAC,CAAC;QACrD,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9D,IAAI,CAAC,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;CA8GF"}
|
package/lib/contents.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Contents as ServerContents } from '@jupyterlab/services';
|
|
2
|
+
import type localforage from 'localforage';
|
|
2
3
|
import { IContents } from './tokens';
|
|
3
|
-
export
|
|
4
|
+
export type IModel = ServerContents.IModel;
|
|
4
5
|
/**
|
|
5
6
|
* A class to handle requests to /api/contents
|
|
6
7
|
*/
|
|
@@ -8,7 +9,35 @@ export declare class Contents implements IContents {
|
|
|
8
9
|
/**
|
|
9
10
|
* Construct a new localForage-powered contents provider
|
|
10
11
|
*/
|
|
11
|
-
constructor(options
|
|
12
|
+
constructor(options: Contents.IOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Finish any initialization after server has started and all extensions are applied.
|
|
15
|
+
*/
|
|
16
|
+
initialize(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Initialize all storage instances
|
|
19
|
+
*/
|
|
20
|
+
protected initStorage(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* A promise that resolves once all storage is fully initialized.
|
|
23
|
+
*/
|
|
24
|
+
get ready(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* A lazy reference to the underlying storage.
|
|
27
|
+
*/
|
|
28
|
+
protected get storage(): Promise<LocalForage>;
|
|
29
|
+
/**
|
|
30
|
+
* A lazy reference to the underlying counters.
|
|
31
|
+
*/
|
|
32
|
+
protected get counters(): Promise<LocalForage>;
|
|
33
|
+
/**
|
|
34
|
+
* A lazy reference to the underlying checkpoints.
|
|
35
|
+
*/
|
|
36
|
+
protected get checkpoints(): Promise<LocalForage>;
|
|
37
|
+
/**
|
|
38
|
+
* Get default options for localForage instances
|
|
39
|
+
*/
|
|
40
|
+
protected get defaultStorageOptions(): LocalForageOptions;
|
|
12
41
|
/**
|
|
13
42
|
* Initialize the default storage for contents.
|
|
14
43
|
*/
|
|
@@ -69,6 +98,7 @@ export declare class Contents implements IContents {
|
|
|
69
98
|
* @returns A promise which resolves with the file content model when the file is saved.
|
|
70
99
|
*/
|
|
71
100
|
save(path: string, options?: Partial<IModel>): Promise<IModel | null>;
|
|
101
|
+
unescapeContent(content: string): string;
|
|
72
102
|
/**
|
|
73
103
|
* Delete a file from browser storage.
|
|
74
104
|
*
|
|
@@ -158,9 +188,12 @@ export declare class Contents implements IContents {
|
|
|
158
188
|
private _incrementCounter;
|
|
159
189
|
private _serverContents;
|
|
160
190
|
private _storageName;
|
|
191
|
+
private _storageDrivers;
|
|
192
|
+
private _ready;
|
|
161
193
|
private _storage;
|
|
162
194
|
private _counters;
|
|
163
195
|
private _checkpoints;
|
|
196
|
+
private _localforage;
|
|
164
197
|
}
|
|
165
198
|
/**
|
|
166
199
|
* A namespace for contents information.
|
|
@@ -170,6 +203,8 @@ export declare namespace Contents {
|
|
|
170
203
|
/**
|
|
171
204
|
* The name of the storage instance on e.g. IndexedDB, localStorage
|
|
172
205
|
*/
|
|
173
|
-
|
|
206
|
+
storageName?: string | null;
|
|
207
|
+
storageDrivers?: string[] | null;
|
|
208
|
+
localforage: typeof localforage;
|
|
174
209
|
}
|
|
175
210
|
}
|