@jupyterlite/server 0.1.0-alpha.9 → 0.1.0-beta.2

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/app.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { ServiceManager } from '@jupyterlab/services';
1
2
  import { Application, IPlugin } from '@lumino/application';
2
- import { LiteServiceManager } from './service';
3
+ import { Router } from './router';
3
4
  export declare type JupyterLiteServerPlugin<T> = IPlugin<JupyterLiteServer, T>;
4
5
  /**
5
6
  * Server is the main application class. It is instantiated once and shared.
@@ -23,10 +24,21 @@ export declare class JupyterLiteServer extends Application<never> {
23
24
  * The version of the application.
24
25
  */
25
26
  readonly version = "unknown";
27
+ /**
28
+ * Get the underlying `Router` instance.
29
+ */
30
+ get router(): Router;
26
31
  /**
27
32
  * Get the underlying lite service manager for this app.
28
33
  */
29
- get serviceManager(): LiteServiceManager | null;
34
+ get serviceManager(): ServiceManager;
35
+ /**
36
+ * Handle an incoming request from the client.
37
+ *
38
+ * @param req The incoming request
39
+ * @param init The optional init request
40
+ */
41
+ fetch(req: RequestInfo, init?: RequestInit | null | undefined): Promise<Response>;
30
42
  /**
31
43
  * Attach the application shell to the DOM.
32
44
  *
@@ -55,12 +67,7 @@ export declare class JupyterLiteServer extends Application<never> {
55
67
  * @param mods - The plugin modules to register.
56
68
  */
57
69
  registerPluginModules(mods: JupyterLiteServer.IPluginModule[]): void;
58
- /**
59
- * Register the underlying lite service manager for this app.
60
- *
61
- * @param serviceManager The Service Manager for the app.
62
- */
63
- registerServiceManager(serviceManager: LiteServiceManager): void;
70
+ private _router;
64
71
  private _serviceManager;
65
72
  }
66
73
  /**
package/lib/app.js CHANGED
@@ -1,6 +1,9 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
+ import { ServerConnection, ServiceManager } from '@jupyterlab/services';
3
4
  import { Application } from '@lumino/application';
5
+ import { WebSocket } from 'mock-socket';
6
+ import { Router } from './router';
4
7
  /**
5
8
  * Server is the main application class. It is instantiated once and shared.
6
9
  */
@@ -11,6 +14,7 @@ export class JupyterLiteServer extends Application {
11
14
  * @param options The instantiation options for a JupyterLiteServer application.
12
15
  */
13
16
  constructor(options) {
17
+ var _a;
14
18
  super(options);
15
19
  /**
16
20
  * The name of the application.
@@ -24,7 +28,20 @@ export class JupyterLiteServer extends Application {
24
28
  * The version of the application.
25
29
  */
26
30
  this.version = 'unknown';
27
- this._serviceManager = null;
31
+ this._router = new Router();
32
+ this._serviceManager = new ServiceManager({
33
+ serverSettings: {
34
+ ...ServerConnection.makeSettings(),
35
+ WebSocket,
36
+ fetch: (_a = this.fetch.bind(this)) !== null && _a !== void 0 ? _a : undefined,
37
+ },
38
+ });
39
+ }
40
+ /**
41
+ * Get the underlying `Router` instance.
42
+ */
43
+ get router() {
44
+ return this._router;
28
45
  }
29
46
  /**
30
47
  * Get the underlying lite service manager for this app.
@@ -32,6 +49,18 @@ export class JupyterLiteServer extends Application {
32
49
  get serviceManager() {
33
50
  return this._serviceManager;
34
51
  }
52
+ /**
53
+ * Handle an incoming request from the client.
54
+ *
55
+ * @param req The incoming request
56
+ * @param init The optional init request
57
+ */
58
+ async fetch(req, init) {
59
+ if (!(req instanceof Request)) {
60
+ throw Error('Request info is not a Request');
61
+ }
62
+ return this._router.route(req);
63
+ }
35
64
  /**
36
65
  * Attach the application shell to the DOM.
37
66
  *
@@ -66,7 +95,7 @@ export class JupyterLiteServer extends Application {
66
95
  if (!Array.isArray(data)) {
67
96
  data = [data];
68
97
  }
69
- data.forEach(item => {
98
+ data.forEach((item) => {
70
99
  try {
71
100
  this.registerPlugin(item);
72
101
  }
@@ -81,16 +110,8 @@ export class JupyterLiteServer extends Application {
81
110
  * @param mods - The plugin modules to register.
82
111
  */
83
112
  registerPluginModules(mods) {
84
- mods.forEach(mod => {
113
+ mods.forEach((mod) => {
85
114
  this.registerPluginModule(mod);
86
115
  });
87
116
  }
88
- /**
89
- * Register the underlying lite service manager for this app.
90
- *
91
- * @param serviceManager The Service Manager for the app.
92
- */
93
- registerServiceManager(serviceManager) {
94
- this._serviceManager = serviceManager;
95
- }
96
117
  }
package/lib/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './app';
2
- export * from './server';
3
- export * from './service';
2
+ export * from './router';
package/lib/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
  export * from './app';
4
- export * from './server';
5
- export * from './service';
4
+ export * from './router';
package/lib/router.js CHANGED
@@ -85,7 +85,7 @@ export class Router {
85
85
  return r.callback.call(null, {
86
86
  pathname,
87
87
  body,
88
- query: Object.fromEntries(url.searchParams)
88
+ query: Object.fromEntries(url.searchParams),
89
89
  }, ...matches);
90
90
  }
91
91
  throw new Error('Cannot route ' + req.method + ' ' + req.url);
@@ -104,7 +104,7 @@ export class Router {
104
104
  this._routes.push({
105
105
  method,
106
106
  pattern,
107
- callback
107
+ callback,
108
108
  });
109
109
  }
110
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/server",
3
- "version": "0.1.0-alpha.9",
3
+ "version": "0.1.0-beta.2",
4
4
  "description": "JupyterLite - Server",
5
5
  "homepage": "https://github.com/jupyterlite/jupyterlite",
6
6
  "bugs": {
@@ -42,30 +42,30 @@
42
42
  "watch": "tsc -b --watch"
43
43
  },
44
44
  "dependencies": {
45
- "@jupyterlab/coreutils": "~5.1.12",
46
- "@jupyterlab/nbformat": "~3.1.12",
47
- "@jupyterlab/observables": "~4.1.12",
48
- "@jupyterlab/services": "~6.1.12",
49
- "@jupyterlab/settingregistry": "~3.1.12",
50
- "@jupyterlab/statedb": "~3.1.12",
51
- "@jupyterlite/contents": "^0.1.0-alpha.9",
52
- "@jupyterlite/kernel": "^0.1.0-alpha.9",
53
- "@jupyterlite/session": "^0.1.0-alpha.9",
54
- "@jupyterlite/settings": "^0.1.0-alpha.9",
55
- "@jupyterlite/translation": "^0.1.0-alpha.9",
56
- "@lumino/application": "^1.20.0",
57
- "@lumino/coreutils": "^1.8.0",
58
- "mock-socket": "^9.0.3"
45
+ "@jupyterlab/coreutils": "~5.3.0",
46
+ "@jupyterlab/nbformat": "~3.3.0",
47
+ "@jupyterlab/observables": "~4.3.0",
48
+ "@jupyterlab/services": "~6.3.0",
49
+ "@jupyterlab/settingregistry": "~3.3.0",
50
+ "@jupyterlab/statedb": "~3.3.0",
51
+ "@jupyterlite/contents": "^0.1.0-beta.2",
52
+ "@jupyterlite/kernel": "^0.1.0-beta.2",
53
+ "@jupyterlite/session": "^0.1.0-beta.2",
54
+ "@jupyterlite/settings": "^0.1.0-beta.2",
55
+ "@jupyterlite/translation": "^0.1.0-beta.2",
56
+ "@lumino/application": "^1.28.1",
57
+ "@lumino/coreutils": "^1.12.0",
58
+ "mock-socket": "^9.1.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@babel/core": "^7.11.6",
62
62
  "@babel/preset-env": "^7.12.1",
63
- "@jupyterlab/testutils": "~3.1.12",
63
+ "@jupyterlab/testutils": "~3.3.0",
64
64
  "@types/jest": "^26.0.10",
65
65
  "jest": "^26.4.2",
66
66
  "rimraf": "~3.0.0",
67
67
  "ts-jest": "^26.3.0",
68
- "typescript": "~4.2.3"
68
+ "typescript": "~4.5.2"
69
69
  },
70
70
  "publishConfig": {
71
71
  "access": "public"
package/lib/server.d.ts DELETED
@@ -1,66 +0,0 @@
1
- import { IContents } from '@jupyterlite/contents';
2
- import { IKernels, IKernelSpecs } from '@jupyterlite/kernel';
3
- import { ISessions } from '@jupyterlite/session';
4
- import { ISettings } from '@jupyterlite/settings';
5
- import { ITranslation } from '@jupyterlite/translation';
6
- /**
7
- * A (very, very) simplified Jupyter Server running in the browser.
8
- */
9
- export declare class JupyterServer {
10
- /**
11
- * Construct a new JupyterServer.
12
- */
13
- constructor(options: JupyterServer.IOptions);
14
- /**
15
- * Handle an incoming request from the client.
16
- *
17
- * @param req The incoming request
18
- * @param init The optional init request
19
- */
20
- fetch(req: RequestInfo, init?: RequestInit | null | undefined): Promise<Response>;
21
- /**
22
- * Add the routes.
23
- */
24
- private _addRoutes;
25
- private _router;
26
- private _contents;
27
- private _kernels;
28
- private _kernelspecs;
29
- private _sessions;
30
- private _settings;
31
- private _translation;
32
- }
33
- /**
34
- * A namespace for JupyterServer statics.
35
- */
36
- export declare namespace JupyterServer {
37
- /**
38
- * The instantiation options for a JupyterServer
39
- */
40
- interface IOptions {
41
- /**
42
- * The contents service.
43
- */
44
- contents: IContents;
45
- /**
46
- * The kernels service.
47
- */
48
- kernels: IKernels;
49
- /**
50
- * The kernel specs service.
51
- */
52
- kernelspecs: IKernelSpecs;
53
- /**
54
- * The sessions service.
55
- */
56
- sessions: ISessions;
57
- /**
58
- * The settings service.
59
- */
60
- settings: ISettings;
61
- /**
62
- * The translation service.
63
- */
64
- translation: ITranslation;
65
- }
66
- }
package/lib/server.js DELETED
@@ -1,167 +0,0 @@
1
- import { Router } from './router';
2
- /**
3
- * A (very, very) simplified Jupyter Server running in the browser.
4
- */
5
- export class JupyterServer {
6
- /**
7
- * Construct a new JupyterServer.
8
- */
9
- constructor(options) {
10
- this._router = new Router();
11
- const { contents, kernels, kernelspecs, sessions, settings, translation } = options;
12
- this._contents = contents;
13
- this._kernels = kernels;
14
- this._kernelspecs = kernelspecs;
15
- this._sessions = sessions;
16
- this._settings = settings;
17
- this._translation = translation;
18
- this._addRoutes();
19
- }
20
- /**
21
- * Handle an incoming request from the client.
22
- *
23
- * @param req The incoming request
24
- * @param init The optional init request
25
- */
26
- async fetch(req, init) {
27
- if (!(req instanceof Request)) {
28
- throw Error('Request info is not a Request');
29
- }
30
- return this._router.route(req);
31
- }
32
- /**
33
- * Add the routes.
34
- */
35
- _addRoutes() {
36
- const app = this._router;
37
- // GET /api/contents/{path}/checkpoints - Get a list of checkpoints for a file
38
- app.get('/api/contents/(.+)/checkpoints', async (req, filename) => {
39
- const res = await this._contents.listCheckpoints(filename);
40
- return new Response(JSON.stringify(res));
41
- });
42
- // POST /api/contents/{path}/checkpoints/{checkpoint_id} - Restore a file to a particular checkpointed state
43
- app.post('/api/contents/(.+)/checkpoints/(.*)', async (req, filename, checkpoint) => {
44
- const res = await this._contents.restoreCheckpoint(filename, checkpoint);
45
- return new Response(JSON.stringify(res), { status: 204 });
46
- });
47
- // POST /api/contents/{path}/checkpoints - Create a new checkpoint for a file
48
- app.post('/api/contents/(.+)/checkpoints', async (req, filename) => {
49
- const res = await this._contents.createCheckpoint(filename);
50
- return new Response(JSON.stringify(res), { status: 201 });
51
- });
52
- // DELETE /api/contents/{path}/checkpoints/{checkpoint_id} - Delete a checkpoint
53
- app.delete('/api/contents/(.+)/checkpoints/(.*)', async (req, filename, checkpoint) => {
54
- const res = await this._contents.deleteCheckpoint(filename, checkpoint);
55
- return new Response(JSON.stringify(res), { status: 204 });
56
- });
57
- // GET /api/contents/{path} - Get contents of file or directory
58
- app.get('/api/contents(.*)', async (req, filename) => {
59
- var _a;
60
- const options = {
61
- content: ((_a = req.query) === null || _a === void 0 ? void 0 : _a.content) === '1'
62
- };
63
- const nb = await this._contents.get(filename, options);
64
- return new Response(JSON.stringify(nb));
65
- });
66
- // POST /api/contents/{path} - Create a new file in the specified path
67
- app.post('/api/contents(.*)', async (req, path) => {
68
- const options = req.body;
69
- const copyFrom = options === null || options === void 0 ? void 0 : options.copy_from;
70
- let file;
71
- if (copyFrom) {
72
- file = await this._contents.copy(copyFrom, path);
73
- }
74
- else {
75
- file = await this._contents.newUntitled(options);
76
- }
77
- return new Response(JSON.stringify(file), { status: 201 });
78
- });
79
- // PATCH /api/contents/{path} - Rename a file or directory without re-uploading content
80
- app.patch('/api/contents(.*)', async (req, filename) => {
81
- var _a, _b;
82
- const newPath = (_b = (_a = req.body) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : '';
83
- filename = filename[0] === '/' ? filename.slice(1) : filename;
84
- const nb = await this._contents.rename(filename, newPath);
85
- return new Response(JSON.stringify(nb));
86
- });
87
- // PUT /api/contents/{path} - Save or upload a file
88
- app.put('/api/contents/(.+)', async (req, filename) => {
89
- const body = req.body;
90
- const nb = await this._contents.save(filename, body);
91
- return new Response(JSON.stringify(nb));
92
- });
93
- // DELETE /api/contents/{path} - Delete a file in the given path
94
- app.delete('/api/contents/(.+)', async (req, filename) => {
95
- await this._contents.delete(filename);
96
- return new Response(null, { status: 204 });
97
- });
98
- // POST /api/kernels/{kernel_id} - Restart a kernel
99
- app.post('/api/kernels/(.*)/restart', async (req, kernelId) => {
100
- const res = await this._kernels.restart(kernelId);
101
- return new Response(JSON.stringify(res));
102
- });
103
- // DELETE /api/kernels/{kernel_id} - Kill a kernel and delete the kernel id
104
- app.delete('/api/kernels/(.*)', async (req, kernelId) => {
105
- const res = await this._kernels.shutdown(kernelId);
106
- return new Response(JSON.stringify(res), { status: 204 });
107
- });
108
- // KernelSpecs
109
- app.get('/api/kernelspecs', async (req) => {
110
- const res = this._kernelspecs.specs;
111
- return new Response(JSON.stringify(res));
112
- });
113
- // NbConvert
114
- app.get('/api/nbconvert', async (req) => {
115
- return new Response(JSON.stringify({}));
116
- });
117
- // GET /api/sessions/{session} - Get session
118
- app.get('/api/sessions/(.+)', async (req, id) => {
119
- const session = await this._sessions.get(id);
120
- return new Response(JSON.stringify(session), { status: 200 });
121
- });
122
- // GET /api/sessions - List available sessions
123
- app.get('/api/sessions', async (req) => {
124
- const sessions = await this._sessions.list();
125
- return new Response(JSON.stringify(sessions), { status: 200 });
126
- });
127
- // PATCH /api/sessions/{session} - This can be used to rename a session
128
- app.patch('/api/sessions(.*)', async (req, id) => {
129
- const options = req.body;
130
- const session = await this._sessions.patch(options);
131
- return new Response(JSON.stringify(session), { status: 200 });
132
- });
133
- // DELETE /api/sessions/{session} - Delete a session
134
- app.delete('/api/sessions/(.+)', async (req, id) => {
135
- await this._sessions.shutdown(id);
136
- return new Response(null, { status: 204 });
137
- });
138
- // POST /api/sessions - Create a new session or return an existing session if a session of the same name already exists
139
- app.post('/api/sessions', async (req) => {
140
- const options = req.body;
141
- const session = await this._sessions.startNew(options);
142
- return new Response(JSON.stringify(session), { status: 201 });
143
- });
144
- // Settings
145
- // TODO: improve the regex
146
- // const pluginPattern = new RegExp(/(?:@([^/]+?)[/])?([^/]+?):(\w+)/);
147
- const pluginPattern = '/api/settings/((?:@([^/]+?)[/])?([^/]+?):([^:]+))$';
148
- app.get(pluginPattern, async (req, pluginId) => {
149
- const settings = await this._settings.get(pluginId);
150
- return new Response(JSON.stringify(settings));
151
- });
152
- app.put(pluginPattern, async (req, pluginId) => {
153
- const body = req.body;
154
- const { raw } = body;
155
- await this._settings.save(pluginId, raw);
156
- return new Response(null, { status: 204 });
157
- });
158
- app.get('/api/settings', async (req) => {
159
- const plugins = await this._settings.getAll();
160
- return new Response(JSON.stringify(plugins));
161
- });
162
- app.get('/api/translations/?(.*)', async (req, locale) => {
163
- const data = await this._translation.get(locale || 'all');
164
- return new Response(JSON.stringify(data));
165
- });
166
- }
167
- }
package/lib/service.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import { ServiceManager } from '@jupyterlab/services';
2
- import { JupyterServer } from './server';
3
- /**
4
- * A custom ServiceManager to run in the browser
5
- */
6
- export declare class LiteServiceManager extends ServiceManager {
7
- /**
8
- * Construct a new service provider.
9
- *
10
- * @param options The instantiation options for the service manager.
11
- */
12
- constructor(options: LiteServiceManager.IOptions);
13
- /**
14
- * Get the underlying Jupyter Server
15
- */
16
- get server(): JupyterServer;
17
- private _server;
18
- }
19
- /**
20
- * A namespace for LiteServiceManager statics.
21
- */
22
- export declare namespace LiteServiceManager {
23
- /**
24
- * The instantiation options for a LiteServiceManager.
25
- */
26
- interface IOptions extends ServiceManager.IOptions {
27
- /**
28
- * The JupyterServer
29
- */
30
- server: JupyterServer;
31
- }
32
- }
package/lib/service.js DELETED
@@ -1,31 +0,0 @@
1
- import { ServiceManager, ServerConnection } from '@jupyterlab/services';
2
- import { WebSocket } from 'mock-socket';
3
- /**
4
- * A custom ServiceManager to run in the browser
5
- */
6
- export class LiteServiceManager extends ServiceManager {
7
- /**
8
- * Construct a new service provider.
9
- *
10
- * @param options The instantiation options for the service manager.
11
- */
12
- constructor(options) {
13
- var _a;
14
- const server = options.server;
15
- super({
16
- ...options,
17
- serverSettings: {
18
- ...ServerConnection.makeSettings(),
19
- WebSocket,
20
- fetch: (_a = server.fetch.bind(server)) !== null && _a !== void 0 ? _a : undefined
21
- }
22
- });
23
- this._server = server;
24
- }
25
- /**
26
- * Get the underlying Jupyter Server
27
- */
28
- get server() {
29
- return this._server;
30
- }
31
- }