@phpsandbox/sdk 0.0.51 → 0.0.53

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 (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -6
  3. package/dist/auth.d.ts +0 -1
  4. package/dist/auth.js +0 -1
  5. package/dist/beacon/index.d.ts +4 -5
  6. package/dist/beacon/index.js +11 -12
  7. package/dist/beacon/navigator.d.ts +1 -2
  8. package/dist/beacon/navigator.js +0 -1
  9. package/dist/beacon/types.d.ts +12 -13
  10. package/dist/beacon/types.js +0 -1
  11. package/dist/browser/phpsandbox-sdk.esm.js +313 -481
  12. package/dist/browser/phpsandbox-sdk.esm.min.js +2 -3
  13. package/dist/browser/phpsandbox-sdk.iife.js +308 -481
  14. package/dist/browser/phpsandbox-sdk.iife.min.js +2 -3
  15. package/dist/composer.d.ts +2 -3
  16. package/dist/composer.js +0 -1
  17. package/dist/config.d.ts +0 -1
  18. package/dist/config.js +0 -1
  19. package/dist/container.d.ts +0 -1
  20. package/dist/container.js +0 -1
  21. package/dist/errors/index.d.ts +0 -1
  22. package/dist/errors/index.js +0 -1
  23. package/dist/events/index.d.ts +15 -15
  24. package/dist/events/index.js +16 -9
  25. package/dist/filesystem.d.ts +6 -7
  26. package/dist/filesystem.js +36 -14
  27. package/dist/git.d.ts +20 -9
  28. package/dist/git.js +31 -3
  29. package/dist/index.d.ts +3 -2
  30. package/dist/index.js +38 -25
  31. package/dist/laravel.d.ts +1 -2
  32. package/dist/laravel.js +1 -2
  33. package/dist/log.d.ts +3 -4
  34. package/dist/log.js +1 -2
  35. package/dist/lsp.d.ts +10 -11
  36. package/dist/lsp.js +9 -10
  37. package/dist/repl.d.ts +3 -4
  38. package/dist/repl.js +2 -3
  39. package/dist/services.d.ts +0 -1
  40. package/dist/services.js +0 -1
  41. package/dist/shell.d.ts +1 -2
  42. package/dist/shell.js +1 -2
  43. package/dist/socket/index.d.ts +23 -129
  44. package/dist/socket/index.js +60 -350
  45. package/dist/terminal.d.ts +2 -3
  46. package/dist/terminal.js +45 -26
  47. package/dist/types.d.ts +0 -1
  48. package/dist/types.js +0 -1
  49. package/dist/utils/disposable.d.ts +0 -1
  50. package/dist/utils/disposable.js +0 -1
  51. package/dist/utils/promise.d.ts +0 -1
  52. package/dist/utils/promise.js +0 -1
  53. package/dist/utils/retry.d.ts +0 -1
  54. package/dist/utils/retry.js +0 -1
  55. package/dist/utils/websocket.d.ts +0 -1
  56. package/dist/utils/websocket.js +0 -1
  57. package/docs/api-summary.md +136 -0
  58. package/docs/cdn-usage.md +80 -0
  59. package/docs/getting-started.md +152 -0
  60. package/examples/README.md +206 -0
  61. package/examples/basic.ts +24 -0
  62. package/examples/get.ts +21 -0
  63. package/examples/git-merge-smoke.ts +399 -0
  64. package/examples/laravel-load-test.ts +2829 -0
  65. package/examples/notebook-readonly-smoke.ts +823 -0
  66. package/package.json +13 -7
  67. package/dist/auth.d.ts.map +0 -1
  68. package/dist/auth.js.map +0 -1
  69. package/dist/beacon/index.d.ts.map +0 -1
  70. package/dist/beacon/index.js.map +0 -1
  71. package/dist/beacon/navigator.d.ts.map +0 -1
  72. package/dist/beacon/navigator.js.map +0 -1
  73. package/dist/beacon/types.d.ts.map +0 -1
  74. package/dist/beacon/types.js.map +0 -1
  75. package/dist/browser/phpsandbox-sdk.esm.js.map +0 -7
  76. package/dist/browser/phpsandbox-sdk.esm.min.js.map +0 -7
  77. package/dist/browser/phpsandbox-sdk.iife.js.map +0 -7
  78. package/dist/browser/phpsandbox-sdk.iife.min.js.map +0 -7
  79. package/dist/composer.d.ts.map +0 -1
  80. package/dist/composer.js.map +0 -1
  81. package/dist/config.d.ts.map +0 -1
  82. package/dist/config.js.map +0 -1
  83. package/dist/container.d.ts.map +0 -1
  84. package/dist/container.js.map +0 -1
  85. package/dist/errors/index.d.ts.map +0 -1
  86. package/dist/errors/index.js.map +0 -1
  87. package/dist/events/index.d.ts.map +0 -1
  88. package/dist/events/index.js.map +0 -1
  89. package/dist/filesystem.d.ts.map +0 -1
  90. package/dist/filesystem.js.map +0 -1
  91. package/dist/git.d.ts.map +0 -1
  92. package/dist/git.js.map +0 -1
  93. package/dist/index.d.ts.map +0 -1
  94. package/dist/index.js.map +0 -1
  95. package/dist/laravel.d.ts.map +0 -1
  96. package/dist/laravel.js.map +0 -1
  97. package/dist/log.d.ts.map +0 -1
  98. package/dist/log.js.map +0 -1
  99. package/dist/lsp.d.ts.map +0 -1
  100. package/dist/lsp.js.map +0 -1
  101. package/dist/repl.d.ts.map +0 -1
  102. package/dist/repl.js.map +0 -1
  103. package/dist/services.d.ts.map +0 -1
  104. package/dist/services.js.map +0 -1
  105. package/dist/shell.d.ts.map +0 -1
  106. package/dist/shell.js.map +0 -1
  107. package/dist/socket/index.d.ts.map +0 -1
  108. package/dist/socket/index.js.map +0 -1
  109. package/dist/terminal.d.ts.map +0 -1
  110. package/dist/terminal.js.map +0 -1
  111. package/dist/types.d.ts.map +0 -1
  112. package/dist/types.js.map +0 -1
  113. package/dist/utils/disposable.d.ts.map +0 -1
  114. package/dist/utils/disposable.js.map +0 -1
  115. package/dist/utils/promise.d.ts.map +0 -1
  116. package/dist/utils/promise.js.map +0 -1
  117. package/dist/utils/retry.d.ts.map +0 -1
  118. package/dist/utils/retry.js.map +0 -1
  119. package/dist/utils/websocket.d.ts.map +0 -1
  120. package/dist/utils/websocket.js.map +0 -1
@@ -250,7 +250,7 @@ interface RelativePattern {
250
250
  */
251
251
  readonly pattern: string;
252
252
  }
253
- interface WatchOptionsWithoutCorrelation {
253
+ export interface WatchOptionsWithoutCorrelation {
254
254
  /**
255
255
  * Set to `true` to watch for changes recursively in a folder
256
256
  * and all of its children.
@@ -281,7 +281,7 @@ interface WatchOptionsWithoutCorrelation {
281
281
  */
282
282
  filter?: FileChangeFilter;
283
283
  }
284
- interface WatchOptions extends WatchOptionsWithoutCorrelation {
284
+ export interface WatchOptions extends WatchOptionsWithoutCorrelation {
285
285
  /**
286
286
  * If provided, file change events from the watcher that
287
287
  * are a result of this watch request will carry the same
@@ -289,7 +289,7 @@ interface WatchOptions extends WatchOptionsWithoutCorrelation {
289
289
  */
290
290
  readonly correlationId?: number;
291
291
  }
292
- declare const enum FileChangeFilter {
292
+ export declare enum FileChangeFilter {
293
293
  UPDATED = 2,
294
294
  ADDED = 4,
295
295
  DELETED = 8
@@ -442,10 +442,10 @@ export declare class FilesystemError extends ErrorEvent {
442
442
  constructor(inner: ErrorEvent, name: FilesystemErrorType);
443
443
  }
444
444
  declare class FilesystemSubscription {
445
- private path;
446
- private okra;
447
445
  private disposable;
448
- constructor(path: string, okra: NotebookInstance, disposable: Disposable);
446
+ private onDispose;
447
+ private disposed;
448
+ constructor(disposable: Disposable, onDispose: () => void);
449
449
  dispose(): void;
450
450
  }
451
451
  export declare class Filesystem {
@@ -480,4 +480,3 @@ export declare class Filesystem {
480
480
  protected handleError(e: unknown): never;
481
481
  }
482
482
  export {};
483
- //# sourceMappingURL=filesystem.d.ts.map
@@ -23,6 +23,12 @@ export var FileType;
23
23
  */
24
24
  FileType[FileType["SymbolicLink"] = 64] = "SymbolicLink";
25
25
  })(FileType || (FileType = {}));
26
+ export var FileChangeFilter;
27
+ (function (FileChangeFilter) {
28
+ FileChangeFilter[FileChangeFilter["UPDATED"] = 2] = "UPDATED";
29
+ FileChangeFilter[FileChangeFilter["ADDED"] = 4] = "ADDED";
30
+ FileChangeFilter[FileChangeFilter["DELETED"] = 8] = "DELETED";
31
+ })(FileChangeFilter || (FileChangeFilter = {}));
26
32
  /**
27
33
  * Possible changes that can occur to a file.
28
34
  */
@@ -48,14 +54,18 @@ export class FilesystemError extends ErrorEvent {
48
54
  }
49
55
  }
50
56
  class FilesystemSubscription {
51
- constructor(path, okra, disposable) {
52
- this.path = path;
53
- this.okra = okra;
57
+ constructor(disposable, onDispose) {
54
58
  this.disposable = disposable;
59
+ this.onDispose = onDispose;
60
+ this.disposed = false;
55
61
  }
56
62
  dispose() {
57
- this.okra.invoke('fs.unwatch', { path: this.path });
63
+ if (this.disposed) {
64
+ return;
65
+ }
66
+ this.disposed = true;
58
67
  this.disposable.dispose();
68
+ this.onDispose();
59
69
  }
60
70
  }
61
71
  export class Filesystem {
@@ -66,8 +76,8 @@ export class Filesystem {
66
76
  }
67
77
  watchOkraConnection() {
68
78
  this.okra.onDidConnect(() => {
69
- for (const { path, options, onDidChange } of this.watches.values()) {
70
- this.watch(path, options, onDidChange);
79
+ for (const { path, options } of this.watches.values()) {
80
+ void this.okra.invoke('fs.watch', { path, options }).catch(() => { });
71
81
  }
72
82
  });
73
83
  }
@@ -85,7 +95,7 @@ export class Filesystem {
85
95
  }) {
86
96
  return this.okra.invoke('fs.find', {
87
97
  query,
88
- options: Object.assign(options, {
98
+ options: {
89
99
  includes: [],
90
100
  excludes: [
91
101
  '**/storage',
@@ -103,7 +113,8 @@ export class Filesystem {
103
113
  followSymlinks: false,
104
114
  useGlobalIgnoreFiles: false,
105
115
  useParentIgnoreFiles: false,
106
- }),
116
+ ...options,
117
+ },
107
118
  });
108
119
  }
109
120
  search(query, options, onMatch) {
@@ -214,12 +225,23 @@ export class Filesystem {
214
225
  const wrappedDisposable = {
215
226
  dispose: () => {
216
227
  disposable.dispose();
217
- this.okra.invoke('fs.unwatch', { path });
228
+ void this.okra.invoke('fs.unwatch', { path }).catch(() => { });
218
229
  },
219
230
  };
220
- const subscription = new FilesystemSubscription(path, this.okra, wrappedDisposable);
231
+ const subscription = new FilesystemSubscription(wrappedDisposable, () => {
232
+ const watch = this.watches.get(path);
233
+ if (watch?.onDidChange === onDidChange) {
234
+ this.watches.delete(path);
235
+ }
236
+ });
221
237
  this.watches.set(path, { options, path, onDidChange });
222
- return this.okra.invoke('fs.watch', { path, options }).then(() => subscription);
238
+ return this.okra
239
+ .invoke('fs.watch', { path, options })
240
+ .then(() => subscription)
241
+ .catch((error) => {
242
+ subscription.dispose();
243
+ throw error;
244
+ });
223
245
  }
224
246
  exists(path) {
225
247
  return this.stat(path)
@@ -230,14 +252,15 @@ export class Filesystem {
230
252
  const id = nanoid();
231
253
  const stream = !!chunk;
232
254
  const chunks = [];
233
- this.okra.listen(`fs.download.${id}`, stream
255
+ const disposable = this.okra.listen(`fs.download.${id}`, stream
234
256
  ? chunk
235
257
  : (data) => {
236
258
  chunks.push(data);
237
259
  });
238
260
  return this.okra
239
261
  .invoke('fs.download', { id, exclude, include })
240
- .then(() => new Blob(chunks, { type: 'application/octet-stream' }));
262
+ .then(() => new Blob(chunks, { type: 'application/octet-stream' }))
263
+ .finally(() => disposable.dispose());
241
264
  }
242
265
  tree(path = '/') {
243
266
  return this.okra.invoke('fs.tree', { path });
@@ -249,4 +272,3 @@ export class Filesystem {
249
272
  throw e;
250
273
  }
251
274
  }
252
- //# sourceMappingURL=filesystem.js.map
package/dist/git.d.ts CHANGED
@@ -63,13 +63,24 @@ export interface GitConflict {
63
63
  status: string;
64
64
  markers?: number;
65
65
  }
66
- export interface GitDiffInput {
67
- url?: string;
66
+ type GitRemoteSource = {
67
+ url: string;
68
+ notebookId?: never;
69
+ target?: never;
70
+ } | {
71
+ notebookId: string;
72
+ url?: never;
73
+ target?: never;
74
+ } | {
75
+ target: string;
76
+ url?: never;
77
+ notebookId?: never;
78
+ };
79
+ export type GitDiffInput = GitRemoteSource & {
68
80
  token?: string;
69
81
  ref?: string;
70
82
  base?: string;
71
- target?: string;
72
- }
83
+ };
73
84
  export interface GitDiffPreview {
74
85
  status: 'ready' | 'unrelated';
75
86
  message?: string;
@@ -82,15 +93,13 @@ export interface GitDiffPreview {
82
93
  ahead: number;
83
94
  behind: number;
84
95
  }
85
- export interface GitMergeInput {
86
- url?: string;
96
+ export type GitMergeInput = GitRemoteSource & {
87
97
  token?: string;
88
98
  ref?: string;
89
- target?: string;
90
99
  expectedBaseRef?: string;
91
100
  author?: string;
92
101
  message?: string;
93
- }
102
+ };
94
103
  export type GitMergeResult = {
95
104
  status: 'merged';
96
105
  message: string;
@@ -188,5 +197,7 @@ export default class Git {
188
197
  credentials(): Promise<GitCredentials>;
189
198
  restore(ref: string): Promise<GitRef>;
190
199
  status(): Promise<GitStatus>;
200
+ private normalizeRemoteInput;
201
+ private gitUrlForNotebook;
191
202
  }
192
- //# sourceMappingURL=git.d.ts.map
203
+ export {};
package/dist/git.js CHANGED
@@ -15,10 +15,10 @@ export default class Git {
15
15
  return this.okra.invoke('git.log', { ref });
16
16
  }
17
17
  diff(input) {
18
- return this.okra.invoke('git.diff', input);
18
+ return this.okra.invoke('git.diff', this.normalizeRemoteInput(input));
19
19
  }
20
20
  merge(input) {
21
- return this.okra.invoke('git.merge', input);
21
+ return this.okra.invoke('git.merge', this.normalizeRemoteInput(input));
22
22
  }
23
23
  conflicts() {
24
24
  return this.okra.invoke('git.conflicts', {});
@@ -50,5 +50,33 @@ export default class Git {
50
50
  status() {
51
51
  return this.okra.invoke('git.status', {});
52
52
  }
53
+ normalizeRemoteInput(input) {
54
+ if (input.notebookId === undefined) {
55
+ return input;
56
+ }
57
+ const notebookId = input.notebookId.trim();
58
+ if (!notebookId) {
59
+ throw new Error("'notebookId' cannot be empty.");
60
+ }
61
+ if (input.url?.trim()) {
62
+ throw new Error("Pass either 'url' or 'notebookId', not both.");
63
+ }
64
+ if (input.target?.trim()) {
65
+ throw new Error("Pass either 'target' or 'notebookId', not both.");
66
+ }
67
+ const { notebookId: _notebookId, ...payload } = input;
68
+ return {
69
+ ...payload,
70
+ url: this.gitUrlForNotebook(notebookId),
71
+ };
72
+ }
73
+ gitUrlForNotebook(notebookId) {
74
+ const url = new URL(this.okra.data.gitUrl);
75
+ url.username = '';
76
+ url.password = '';
77
+ url.pathname = `/${encodeURIComponent(notebookId)}.git`;
78
+ url.search = '';
79
+ url.hash = '';
80
+ return url.toString();
81
+ }
53
82
  }
54
- //# sourceMappingURL=git.js.map
package/dist/index.d.ts CHANGED
@@ -226,7 +226,7 @@ export interface PHPSandboxClientOptions {
226
226
  startClosed?: boolean;
227
227
  telemetry?: Set<TelemetryFeature>;
228
228
  fetch?: typeof globalThis.fetch;
229
- webSocket?: typeof globalThis['WebSocket'];
229
+ webSocket?: unknown;
230
230
  }
231
231
  export declare class Client {
232
232
  readonly notebook: NotebookApi;
@@ -323,9 +323,11 @@ export declare class NotebookInstance {
323
323
  send<T extends keyof Invokable>(action: T, data?: Invokable[T]['args']): boolean;
324
324
  ping(): Promise<"pong">;
325
325
  listen<T extends keyof Events>(event: T, handler: (data: Events[T]) => void): Disposable;
326
+ listen(event: string, handler: (data: unknown) => void): Disposable;
326
327
  dispose(): void;
327
328
  connected(): Promise<NotebookInstance>;
328
329
  whenConnected(): Promise<NotebookInstance>;
330
+ private waitForSocketConnection;
329
331
  private watchConnection;
330
332
  onDidConnect(handler: () => void): Disposable;
331
333
  onDidDisconnect(handler: () => void): Disposable;
@@ -365,4 +367,3 @@ export declare class NotebookMail {
365
367
  get(hash: string): Promise<NotebookMailData>;
366
368
  delete(hash: string): Promise<void>;
367
369
  }
368
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -111,12 +111,20 @@ export class NotebookApi {
111
111
  return instance;
112
112
  }
113
113
  }
114
+ function normalizeApiBaseUrl(url) {
115
+ const baseUrl = new URL(url);
116
+ const pathname = baseUrl.pathname.replace(/\/+$/, '');
117
+ baseUrl.pathname = pathname === '' || pathname === '/' ? '/v1/' : `${pathname}/`;
118
+ baseUrl.search = '';
119
+ baseUrl.hash = '';
120
+ return baseUrl.toString();
121
+ }
114
122
  export class Client {
115
123
  constructor(token, url = 'https://api.phpsandbox.io/v1', options = {}) {
116
124
  this.fetch = globalThis.fetch;
117
125
  this.notebook = new NotebookApi(this);
118
126
  this.options = Object.assign({ startClosed: true }, options);
119
- this.baseUrl = url;
127
+ this.baseUrl = normalizeApiBaseUrl(url);
120
128
  if (options.fetch) {
121
129
  this.fetch = options.fetch;
122
130
  }
@@ -130,16 +138,16 @@ export class Client {
130
138
  return this.makeRequest('GET', path);
131
139
  }
132
140
  post(path, body) {
133
- return this.makeRequest('POST', path, { body: body ? JSON.stringify(body) : undefined });
141
+ return this.makeRequest('POST', path, { body: body === undefined ? undefined : JSON.stringify(body) });
134
142
  }
135
143
  delete(path) {
136
144
  return this.makeRequest('DELETE', path);
137
145
  }
138
146
  put(path, body) {
139
- return this.makeRequest('PUT', path, { body: body ? JSON.stringify(body) : undefined });
147
+ return this.makeRequest('PUT', path, { body: body === undefined ? undefined : JSON.stringify(body) });
140
148
  }
141
149
  async makeRequest(method, path, init) {
142
- const response = await this.fetch(new Request(new URL(`v1/${path.replace(/^\//, '')}`, this.baseUrl), {
150
+ const response = await this.fetch(new Request(new URL(path.replace(/^\//, ''), this.baseUrl), {
143
151
  method,
144
152
  ...init,
145
153
  headers: this.headers,
@@ -318,25 +326,12 @@ export class NotebookInstance {
318
326
  !this.socket.isClosed && this.socket.disconnect();
319
327
  }
320
328
  connected() {
321
- const terminalError = this.socket.getTerminalError();
322
- if (terminalError) {
323
- return Promise.reject(terminalError);
324
- }
325
- if (this.socket.isConnected) {
326
- return Promise.resolve(this);
327
- }
328
- return new Promise((resolve, reject) => {
329
- try {
330
- this.socket.onDidConnect(() => resolve(this));
331
- this.socket.onDidClose(() => reject(new Error('Connection closed')));
332
- this.socket.onDidBootError((error) => reject(error));
333
- }
334
- catch (e) {
335
- reject(e);
336
- }
337
- });
329
+ return this.waitForSocketConnection({ rejectOnClose: true });
338
330
  }
339
331
  whenConnected() {
332
+ return this.waitForSocketConnection({ rejectOnClose: false });
333
+ }
334
+ waitForSocketConnection(options) {
340
335
  const terminalError = this.socket.getTerminalError();
341
336
  if (terminalError) {
342
337
  return Promise.reject(terminalError);
@@ -345,12 +340,31 @@ export class NotebookInstance {
345
340
  return Promise.resolve(this);
346
341
  }
347
342
  return new Promise((resolve, reject) => {
343
+ const disposables = [];
344
+ let settled = false;
345
+ const cleanup = () => {
346
+ for (const disposable of disposables) {
347
+ disposable.dispose();
348
+ }
349
+ disposables.length = 0;
350
+ };
351
+ const settle = (callback) => {
352
+ if (settled) {
353
+ return;
354
+ }
355
+ settled = true;
356
+ cleanup();
357
+ callback();
358
+ };
348
359
  try {
349
- this.socket.onDidConnect(() => resolve(this));
350
- this.socket.onDidBootError((error) => reject(error));
360
+ disposables.push(this.socket.onDidConnect(() => settle(() => resolve(this))));
361
+ if (options.rejectOnClose) {
362
+ disposables.push(this.socket.onDidClose(() => settle(() => reject(new Error('Connection closed')))));
363
+ }
364
+ disposables.push(this.socket.onDidBootError((error) => settle(() => reject(error))));
351
365
  }
352
366
  catch (e) {
353
- reject(e);
367
+ settle(() => reject(e));
354
368
  }
355
369
  });
356
370
  }
@@ -511,4 +525,3 @@ function formatQueryString(params) {
511
525
  const query = searchParams.toString();
512
526
  return query === '' ? '' : `?${query}`;
513
527
  }
514
- //# sourceMappingURL=index.js.map
package/dist/laravel.d.ts CHANGED
@@ -14,10 +14,9 @@ export interface LaravelActions {
14
14
  'laravel.maintenance.info': Action<{}, Down>;
15
15
  'laravel.maintenance.toggle': Action<Down | {}, Down>;
16
16
  }
17
- export default class Lravel {
17
+ export default class Laravel {
18
18
  protected okra: NotebookInstance;
19
19
  constructor(okra: NotebookInstance);
20
20
  maintenanceInfo(): Promise<Down>;
21
21
  toggleMaintenance(down: Down | {}): Promise<Down>;
22
22
  }
23
- //# sourceMappingURL=laravel.d.ts.map
package/dist/laravel.js CHANGED
@@ -1,4 +1,4 @@
1
- export default class Lravel {
1
+ export default class Laravel {
2
2
  constructor(okra) {
3
3
  this.okra = okra;
4
4
  }
@@ -9,4 +9,3 @@ export default class Lravel {
9
9
  return this.okra.invoke('laravel.maintenance.toggle', down);
10
10
  }
11
11
  }
12
- //# sourceMappingURL=laravel.js.map
package/dist/log.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NotebookInstance } from './index.js';
1
+ import { Disposable, NotebookInstance } from './index.js';
2
2
  export interface LogEvents {
3
3
  'notebook.log': string;
4
4
  }
@@ -7,7 +7,6 @@ export interface LogActions {
7
7
  export default class Log {
8
8
  protected okra: NotebookInstance;
9
9
  constructor(okra: NotebookInstance);
10
- stream(fn: (data: string) => void): import("./types.js").Disposable;
11
- listen<T extends keyof LogEvents>(event: T, handler: (data: LogEvents[T]) => void): void;
10
+ stream(fn: (data: string) => void): Disposable;
11
+ listen<T extends keyof LogEvents>(event: T, handler: (data: LogEvents[T]) => void): Disposable;
12
12
  }
13
- //# sourceMappingURL=log.d.ts.map
package/dist/log.js CHANGED
@@ -6,7 +6,6 @@ export default class Log {
6
6
  return this.okra.listen('notebook.log', fn);
7
7
  }
8
8
  listen(event, handler) {
9
- this.okra.listen(event, handler);
9
+ return this.okra.listen(event, handler);
10
10
  }
11
11
  }
12
- //# sourceMappingURL=log.js.map
package/dist/lsp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Action, NotebookInstance } from './index.js';
1
+ import { Action, Disposable, NotebookInstance } from './index.js';
2
2
  export interface LspActions {
3
3
  'lsp.message': Action<{
4
4
  message: string;
@@ -29,11 +29,11 @@ export default class Lsp {
29
29
  protected okra: NotebookInstance;
30
30
  constructor(okra: NotebookInstance);
31
31
  message(id: string, message: string): Promise<void>;
32
- listen<T extends keyof LspEventData>(id: string, event: T, cb: (data: LspEventData[T]) => void): void;
33
- onClose(id: string, cb: (code: number, reason: string) => void): void;
34
- onError(id: string, cb: (message: string) => void): void;
35
- onClientDisconnect(cb: (code: number, message: string) => void): void;
36
- onResponse(id: string, cb: (data: string) => void): void;
32
+ listen<T extends keyof LspEventData>(id: string, event: T, cb: (data: LspEventData[T]) => void): Disposable;
33
+ onClose(id: string, cb: (code: number, reason: string) => void): Disposable;
34
+ onError(id: string, cb: (message: string) => void): Disposable;
35
+ onClientDisconnect(cb: (code: number, message: string) => void): Disposable;
36
+ onResponse(id: string, cb: (data: string) => void): Disposable;
37
37
  close(id: string): Promise<void>;
38
38
  start(id: string): Promise<void>;
39
39
  connection(id: string): LspConnection;
@@ -44,14 +44,13 @@ export declare class LspConnection {
44
44
  private readonly lsp;
45
45
  constructor(id: string, lsp: Lsp);
46
46
  send(content: string): Promise<void>;
47
- onMessage(cb: (data: string) => void): void;
48
- onError(cb: (message: string) => void): void;
49
- onClose(cb: (code: number, reason: string) => void): void;
47
+ onMessage(cb: (data: string) => void): Disposable;
48
+ onError(cb: (message: string) => void): Disposable;
49
+ onClose(cb: (code: number, reason: string) => void): Disposable;
50
50
  dispose(): void;
51
51
  start(): void;
52
- onClientDisconnect(cb: (code: number, message: string) => void): void;
52
+ onClientDisconnect(cb: (code: number, message: string) => void): Disposable;
53
53
  whenSocketConnected(): Promise<NotebookInstance>;
54
54
  static create(id: string, lsp: Lsp): LspConnection;
55
55
  }
56
56
  export {};
57
- //# sourceMappingURL=lsp.d.ts.map
package/dist/lsp.js CHANGED
@@ -6,19 +6,19 @@ export default class Lsp {
6
6
  return this.okra.invoke('lsp.message', { id, message });
7
7
  }
8
8
  listen(id, event, cb) {
9
- this.okra.listen(`${event}.${id}`, (e) => cb(e));
9
+ return this.okra.listen(`${event}.${id}`, (e) => cb(e));
10
10
  }
11
11
  onClose(id, cb) {
12
- this.listen(id, 'lsp.closed', (e) => cb(e.code, e.reason));
12
+ return this.listen(id, 'lsp.closed', (e) => cb(e.code, e.reason));
13
13
  }
14
14
  onError(id, cb) {
15
- this.listen(id, 'lsp.error', (e) => cb(e.message));
15
+ return this.listen(id, 'lsp.error', (e) => cb(e.message));
16
16
  }
17
17
  onClientDisconnect(cb) {
18
- this.okra.onDidDisconnect(() => cb(1000, 'OKRA DISCONNECTED'));
18
+ return this.okra.onDidDisconnect(() => cb(1000, 'OKRA DISCONNECTED'));
19
19
  }
20
20
  onResponse(id, cb) {
21
- this.listen(id, 'lsp.response', (e) => cb(JSON.stringify(e)));
21
+ return this.listen(id, 'lsp.response', (e) => cb(JSON.stringify(e)));
22
22
  }
23
23
  close(id) {
24
24
  return this.okra.invoke('lsp.close', { id });
@@ -42,13 +42,13 @@ export class LspConnection {
42
42
  return this.lsp.message(this.id, content);
43
43
  }
44
44
  onMessage(cb) {
45
- this.lsp.onResponse(this.id, cb);
45
+ return this.lsp.onResponse(this.id, cb);
46
46
  }
47
47
  onError(cb) {
48
- this.lsp.onError(this.id, cb);
48
+ return this.lsp.onError(this.id, cb);
49
49
  }
50
50
  onClose(cb) {
51
- this.lsp.onClose(this.id, cb);
51
+ return this.lsp.onClose(this.id, cb);
52
52
  }
53
53
  dispose() {
54
54
  this.lsp.close(this.id);
@@ -57,7 +57,7 @@ export class LspConnection {
57
57
  this.lsp.start(this.id);
58
58
  }
59
59
  onClientDisconnect(cb) {
60
- this.lsp.onClientDisconnect(cb);
60
+ return this.lsp.onClientDisconnect(cb);
61
61
  }
62
62
  whenSocketConnected() {
63
63
  return this.lsp.whenSocketConnected();
@@ -66,4 +66,3 @@ export class LspConnection {
66
66
  return new LspConnection(id, lsp);
67
67
  }
68
68
  }
69
- //# sourceMappingURL=lsp.js.map
package/dist/repl.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Action, NotebookInstance } from './index.js';
1
+ import { Action, Disposable, NotebookInstance } from './index.js';
2
2
  interface ReplOption {
3
3
  prependWith?: string;
4
4
  appendWith?: string;
@@ -34,8 +34,7 @@ export default class Repl {
34
34
  stop(): Promise<void>;
35
35
  start(): Promise<void>;
36
36
  resize(cols: number, rows: number): Promise<void>;
37
- listen<T extends keyof ReplEvents>(event: T, handler: (data: ReplEvents[T]) => void): void;
38
- onOutput(handler: (data: ReplEvents['repl.output']) => void): void;
37
+ listen<T extends keyof ReplEvents>(event: T, handler: (data: ReplEvents[T]) => void): Disposable;
38
+ onOutput(handler: (data: ReplEvents['repl.output']) => void): Disposable;
39
39
  }
40
40
  export {};
41
- //# sourceMappingURL=repl.d.ts.map
package/dist/repl.js CHANGED
@@ -18,10 +18,9 @@ export default class Repl {
18
18
  return this.okra.invoke('repl.resize', { cols, rows });
19
19
  }
20
20
  listen(event, handler) {
21
- this.okra.listen(event, handler);
21
+ return this.okra.listen(event, handler);
22
22
  }
23
23
  onOutput(handler) {
24
- this.okra.listen('repl.output', handler);
24
+ return this.okra.listen('repl.output', handler);
25
25
  }
26
26
  }
27
- //# sourceMappingURL=repl.js.map
@@ -82,4 +82,3 @@ export default class Services {
82
82
  private followLogs;
83
83
  }
84
84
  export {};
85
- //# sourceMappingURL=services.d.ts.map
package/dist/services.js CHANGED
@@ -104,4 +104,3 @@ export default class Services {
104
104
  return { id, output, stop };
105
105
  }
106
106
  }
107
- //# sourceMappingURL=services.js.map
package/dist/shell.d.ts CHANGED
@@ -39,7 +39,7 @@ declare class Result {
39
39
  export default class Shell {
40
40
  protected okra: NotebookInstance;
41
41
  constructor(okra: NotebookInstance);
42
- onOutput(id: string, handler: (data: ShellEvents['shell.output']) => void): void;
42
+ onOutput(id: string, handler: (data: ShellEvents['shell.output']) => void): Disposable;
43
43
  listen<T extends keyof ShellEvents>(event: T, handler: (data: ShellEvents[T]) => void): Disposable;
44
44
  exec(command: string | string[], opts?: SpawnOptions): Promise<Result>;
45
45
  exec(command: string, args: string[], opts?: SpawnOptions): Promise<Result>;
@@ -47,4 +47,3 @@ export default class Shell {
47
47
  execStream(command: string, args: string[], opts?: SpawnOptions): ShellExecution;
48
48
  }
49
49
  export {};
50
- //# sourceMappingURL=shell.d.ts.map
package/dist/shell.js CHANGED
@@ -31,7 +31,7 @@ export default class Shell {
31
31
  this.okra = okra;
32
32
  }
33
33
  onOutput(id, handler) {
34
- this.okra.listen(`shell.output.${id}`, handler);
34
+ return this.okra.listen(`shell.output.${id}`, handler);
35
35
  }
36
36
  listen(event, handler) {
37
37
  return this.okra.listen(event, handler);
@@ -106,4 +106,3 @@ export default class Shell {
106
106
  return { output, result };
107
107
  }
108
108
  }
109
- //# sourceMappingURL=shell.js.map