@jupyterlite/services 0.1.0 → 0.7.0-rc.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.
Files changed (87) hide show
  1. package/lib/contents/drive.d.ts +277 -0
  2. package/lib/contents/drive.js +888 -0
  3. package/lib/contents/drive.js.map +1 -0
  4. package/lib/contents/drivecontents.d.ts +92 -0
  5. package/lib/contents/drivecontents.js +132 -0
  6. package/lib/contents/drivecontents.js.map +1 -0
  7. package/lib/contents/drivefs.d.ts +245 -0
  8. package/lib/contents/drivefs.js +481 -0
  9. package/lib/contents/drivefs.js.map +1 -0
  10. package/lib/contents/emscripten.d.ts +96 -0
  11. package/lib/contents/emscripten.js +10 -0
  12. package/lib/contents/emscripten.js.map +1 -0
  13. package/lib/contents/index.d.ts +5 -0
  14. package/lib/contents/index.js +8 -0
  15. package/lib/contents/index.js.map +1 -0
  16. package/lib/contents/tokens.d.ts +21 -0
  17. package/lib/contents/tokens.js +55 -0
  18. package/lib/contents/tokens.js.map +1 -0
  19. package/lib/index.d.ts +9 -0
  20. package/lib/index.js +12 -0
  21. package/lib/index.js.map +1 -0
  22. package/lib/kernel/base.d.ts +245 -0
  23. package/lib/kernel/base.js +457 -0
  24. package/lib/kernel/base.js.map +1 -0
  25. package/lib/kernel/client.d.ts +114 -0
  26. package/lib/kernel/client.js +375 -0
  27. package/lib/kernel/client.js.map +1 -0
  28. package/lib/kernel/index.d.ts +5 -0
  29. package/lib/kernel/index.js +8 -0
  30. package/lib/kernel/index.js.map +1 -0
  31. package/lib/kernel/kernelspecclient.d.ts +39 -0
  32. package/lib/kernel/kernelspecclient.js +37 -0
  33. package/lib/kernel/kernelspecclient.js.map +1 -0
  34. package/lib/kernel/kernelspecs.d.ts +59 -0
  35. package/lib/kernel/kernelspecs.js +62 -0
  36. package/lib/kernel/kernelspecs.js.map +1 -0
  37. package/lib/kernel/tokens.d.ts +163 -0
  38. package/lib/kernel/tokens.js +20 -0
  39. package/lib/kernel/tokens.js.map +1 -0
  40. package/lib/nbconvert/exporters.d.ts +80 -0
  41. package/lib/nbconvert/exporters.js +154 -0
  42. package/lib/nbconvert/exporters.js.map +1 -0
  43. package/lib/nbconvert/index.d.ts +3 -0
  44. package/lib/nbconvert/index.js +6 -0
  45. package/lib/nbconvert/index.js.map +1 -0
  46. package/lib/nbconvert/manager.d.ts +66 -0
  47. package/lib/nbconvert/manager.js +77 -0
  48. package/lib/nbconvert/manager.js.map +1 -0
  49. package/lib/nbconvert/tokens.d.ts +49 -0
  50. package/lib/nbconvert/tokens.js +8 -0
  51. package/lib/nbconvert/tokens.js.map +1 -0
  52. package/lib/session/client.d.ts +85 -0
  53. package/lib/session/client.js +200 -0
  54. package/lib/session/client.js.map +1 -0
  55. package/lib/session/index.d.ts +1 -0
  56. package/lib/session/index.js +4 -0
  57. package/lib/session/index.js.map +1 -0
  58. package/lib/settings/index.d.ts +1 -0
  59. package/lib/settings/index.js +4 -0
  60. package/lib/settings/index.js.map +1 -0
  61. package/lib/settings/settings.d.ts +91 -0
  62. package/lib/settings/settings.js +185 -0
  63. package/lib/settings/settings.js.map +1 -0
  64. package/package.json +67 -8
  65. package/src/contents/drive.ts +1030 -0
  66. package/src/contents/drivecontents.ts +253 -0
  67. package/src/contents/drivefs.ts +824 -0
  68. package/src/contents/emscripten.ts +148 -0
  69. package/src/contents/index.ts +8 -0
  70. package/src/contents/tokens.ts +61 -0
  71. package/src/index.ts +13 -0
  72. package/src/kernel/base.ts +637 -0
  73. package/src/kernel/client.ts +483 -0
  74. package/src/kernel/index.ts +8 -0
  75. package/src/kernel/kernelspecclient.ts +64 -0
  76. package/src/kernel/kernelspecs.ts +103 -0
  77. package/src/kernel/tokens.ts +222 -0
  78. package/src/nbconvert/exporters.ts +177 -0
  79. package/src/nbconvert/index.ts +6 -0
  80. package/src/nbconvert/manager.ts +105 -0
  81. package/src/nbconvert/tokens.ts +60 -0
  82. package/src/session/client.ts +251 -0
  83. package/src/session/index.ts +4 -0
  84. package/src/settings/index.ts +4 -0
  85. package/src/settings/settings.ts +236 -0
  86. package/style/index.css +6 -0
  87. package/style/index.js +6 -0
@@ -0,0 +1,253 @@
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
+ return null;
143
+ }
144
+
145
+ async rename(request: TDriveRequest<'rename'>): Promise<TDriveResponse<'rename'>> {
146
+ await this.contentsManager.rename(request.path, request.data.newPath);
147
+ return null;
148
+ }
149
+
150
+ async getmode(request: TDriveRequest<'getmode'>): Promise<TDriveResponse<'getmode'>> {
151
+ const model = await this.contentsManager.get(request.path);
152
+ let response: number;
153
+ if (model.type === 'directory') {
154
+ response = DIR_MODE;
155
+ } else {
156
+ response = FILE_MODE;
157
+ }
158
+ return response;
159
+ }
160
+
161
+ async lookup(request: TDriveRequest<'lookup'>): Promise<TDriveResponse<'lookup'>> {
162
+ let response: TDriveResponse<'lookup'>;
163
+
164
+ try {
165
+ const model = await this.contentsManager.get(request.path);
166
+ response = {
167
+ ok: true,
168
+ mode: model.type === 'directory' ? DIR_MODE : FILE_MODE,
169
+ };
170
+ } catch (e) {
171
+ response = { ok: false };
172
+ }
173
+
174
+ return response;
175
+ }
176
+
177
+ async mknod(request: TDriveRequest<'mknod'>): Promise<TDriveResponse<'mknod'>> {
178
+ const model = await this.contentsManager.newUntitled({
179
+ path: PathExt.dirname(request.path),
180
+ type: request.data.mode === DIR_MODE ? 'directory' : 'file',
181
+ ext: PathExt.extname(request.path),
182
+ });
183
+ await this.contentsManager.rename(model.path, request.path);
184
+ return null;
185
+ }
186
+
187
+ async getattr(request: TDriveRequest<'getattr'>): Promise<TDriveResponse<'getattr'>> {
188
+ const model = await this.contentsManager.get(request.path);
189
+ // create a default date for drives that send incomplete information
190
+ // for nested foldes and files
191
+ const defaultDate = new Date(0).toISOString();
192
+
193
+ return {
194
+ dev: 1,
195
+ nlink: 1,
196
+ uid: 0,
197
+ gid: 0,
198
+ rdev: 0,
199
+ size: model.size || 0,
200
+ blksize: BLOCK_SIZE,
201
+ blocks: Math.ceil(model.size || 0 / BLOCK_SIZE),
202
+ atime: model.last_modified || defaultDate, // TODO Get the proper atime?
203
+ mtime: model.last_modified || defaultDate,
204
+ ctime: model.created || defaultDate,
205
+ timestamp: 0,
206
+ };
207
+ }
208
+
209
+ async get(request: TDriveRequest<'get'>): Promise<TDriveResponse<'get'>> {
210
+ let model: Contents.IModel;
211
+ try {
212
+ model = await this.contentsManager.get(request.path, { content: true });
213
+ } catch (e) {
214
+ return null;
215
+ }
216
+
217
+ let response = null;
218
+
219
+ if (model.type !== 'directory') {
220
+ response = {
221
+ content:
222
+ model.format === 'json' ? JSON.stringify(model.content) : model.content,
223
+ format: model.format,
224
+ };
225
+ }
226
+
227
+ return response;
228
+ }
229
+
230
+ async put(request: TDriveRequest<'put'>): Promise<TDriveResponse<'put'>> {
231
+ await this.contentsManager.save(request.path, {
232
+ content:
233
+ request.data.format === 'json' && request.data.data
234
+ ? JSON.parse(request.data.data)
235
+ : request.data.data,
236
+ type: 'file',
237
+ format: request.data.format as Contents.FileFormat,
238
+ });
239
+ return null;
240
+ }
241
+ }
242
+
243
+ /**
244
+ * A namespace for DriveContentsProcessor configurations, etc.
245
+ */
246
+ export namespace DriveContentsProcessor {
247
+ /**
248
+ * Initialization options for a drive;
249
+ */
250
+ export interface IOptions {
251
+ contentsManager: Contents.IManager;
252
+ }
253
+ }