@phpsandbox/sdk 0.0.65 → 0.0.66

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.
@@ -97,6 +97,7 @@ var PHPSandbox = (() => {
97
97
  ServerApi: () => ServerApi,
98
98
  ServerInstance: () => ServerInstance,
99
99
  Transport: () => Transport,
100
+ UnsupportedRuntimeTransportError: () => UnsupportedRuntimeTransportError,
100
101
  createBeacon: () => createBeacon,
101
102
  isBeaconSupported: () => isBeaconSupported,
102
103
  notebookBuiltinServices: () => notebookBuiltinServices,
@@ -186,13 +187,16 @@ var PHPSandbox = (() => {
186
187
  }
187
188
  };
188
189
  var Filesystem = class {
189
- constructor(okra) {
190
+ constructor(okra, registerReconnect = (handler) => okra.onDidConnect(handler)) {
190
191
  this.okra = okra;
191
192
  this.watches = /* @__PURE__ */ new Map();
192
- this.watchOkraConnection();
193
+ this.registerReconnectHandler(registerReconnect);
193
194
  }
194
- watchOkraConnection() {
195
- this.okra.onDidConnect(() => {
195
+ registerReconnectHandler(registerReconnect) {
196
+ if (registerReconnect === null) {
197
+ return;
198
+ }
199
+ registerReconnect(() => {
196
200
  for (const { path, options } of this.watches.values()) {
197
201
  void this.okra.invoke("fs.watch", { path, options }).catch(() => {
198
202
  });
@@ -399,6 +403,12 @@ var PHPSandbox = (() => {
399
403
  this.name = "NotebookUnavailableError";
400
404
  }
401
405
  };
406
+ var UnsupportedRuntimeTransportError = class extends Error {
407
+ constructor(message) {
408
+ super(message);
409
+ this.name = "UnsupportedRuntimeTransportError";
410
+ }
411
+ };
402
412
 
403
413
  // src/utils/promise.ts
404
414
  var timeout = (prom, time3) => {
@@ -666,10 +676,14 @@ var PHPSandbox = (() => {
666
676
  this.okra = okra;
667
677
  }
668
678
  logout() {
669
- return this.okra.invoke("auth.logout");
679
+ this.okra.dispose();
670
680
  }
671
- login(newConnectionData) {
672
- return this.okra.invoke("auth.login", { newConnectionData });
681
+ login(okraUrl) {
682
+ const runtimeTicket = new URL(okraUrl).searchParams.get("ticket");
683
+ if (runtimeTicket === null || runtimeTicket === "") {
684
+ throw new TypeError("The notebook connection does not contain a runtime ticket.");
685
+ }
686
+ return this.okra.invoke("auth.login", { runtimeTicket });
673
687
  }
674
688
  };
675
689
 
@@ -3229,11 +3243,12 @@ var PHPSandbox = (() => {
3229
3243
  this.pingIntervalStarted = false;
3230
3244
  this.incomingMessageChain = Promise.resolve();
3231
3245
  this.validateConfiguration(options);
3232
- this.url = new URL(url2);
3246
+ this.url = typeof url2 === "string" ? new URL(url2) : null;
3247
+ const urlProvider = typeof url2 === "string" ? this.url.toString() : async () => new URL(await url2()).toString();
3233
3248
  this.PING_INTERVAL = options.pingInterval ?? 3e4;
3234
3249
  this.CONNECT_WAIT_TIMEOUT = options.connectWaitTimeout ?? 3e4;
3235
3250
  const startClosed = options.startClosed !== false;
3236
- this.rws = new ReconnectingWebSocket2(this.url.toString(), [], {
3251
+ this.rws = new ReconnectingWebSocket2(urlProvider, [], {
3237
3252
  WebSocket: options.webSocket ?? globalThis.WebSocket ?? browser_default,
3238
3253
  connectionTimeout: options.connectionTimeout,
3239
3254
  maxReconnectionDelay: 2e3,
@@ -3243,7 +3258,7 @@ var PHPSandbox = (() => {
3243
3258
  startClosed
3244
3259
  });
3245
3260
  this.log("debug", "Transport initialized", {
3246
- url: this.url.toString(),
3261
+ url: this.url === null ? "dynamic" : transportLogUrl(this.url),
3247
3262
  options
3248
3263
  });
3249
3264
  this.registerWatchers();
@@ -3829,6 +3844,12 @@ var PHPSandbox = (() => {
3829
3844
  };
3830
3845
  });
3831
3846
  };
3847
+ function transportLogUrl(url2) {
3848
+ const safeUrl = new URL(url2);
3849
+ safeUrl.search = "";
3850
+ safeUrl.hash = "";
3851
+ return safeUrl.toString();
3852
+ }
3832
3853
 
3833
3854
  // node_modules/mitt/dist/mitt.mjs
3834
3855
  var mitt_exports = {};
@@ -19878,6 +19899,231 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19878
19899
  }
19879
19900
  };
19880
19901
 
19902
+ // src/runtime/rest.ts
19903
+ var restActionRoutes = {
19904
+ "runtime.ready": { method: "GET", path: "/runtime" },
19905
+ ping: { method: "GET", path: "/runtime/ping" },
19906
+ "config.get": { method: "GET", path: "/runtime/config" },
19907
+ "config.update": { method: "PATCH", path: "/runtime/config" },
19908
+ "config.set-ports": { method: "PUT", path: "/runtime/config/ports" },
19909
+ "container.state": { method: "GET", path: "/runtime/container" },
19910
+ "container.start": { method: "POST", path: "/runtime/container/start" },
19911
+ "container.restart": { method: "POST", path: "/runtime/container/restart" },
19912
+ "container.stop": { method: "POST", path: "/runtime/container/stop" },
19913
+ "container.set-php": { method: "PUT", path: "/runtime/container/php" },
19914
+ "container.opened-ports": { method: "GET", path: "/runtime/container/ports" },
19915
+ "terminal.list": { method: "GET", path: "/runtime/terminals" },
19916
+ "shell.exec": { method: "POST", path: "/runtime/executions" },
19917
+ "fs.info": { method: "POST", path: "/runtime/files/info" },
19918
+ "fs.readFile": { method: "GET", path: "/runtime/files/content" },
19919
+ "fs.writeFile": { method: "PUT", path: "/runtime/files/content" },
19920
+ "fs.write": { method: "PUT", path: "/runtime/files/text" },
19921
+ "fs.mkdir": { method: "POST", path: "/runtime/directories" },
19922
+ "fs.createDirectory": { method: "PUT", path: "/runtime/directories" },
19923
+ "fs.readDirectory": { method: "POST", path: "/runtime/directories/read" },
19924
+ "fs.stat": { method: "POST", path: "/runtime/files/stat" },
19925
+ "fs.move": { method: "POST", path: "/runtime/files/move" },
19926
+ "fs.rename": { method: "POST", path: "/runtime/files/rename" },
19927
+ "fs.copy": { method: "POST", path: "/runtime/files/copy" },
19928
+ "fs.remove": { method: "POST", path: "/runtime/files/remove" },
19929
+ "fs.delete": { method: "DELETE", path: "/runtime/files" },
19930
+ "fs.tail": { method: "POST", path: "/runtime/files/tail" },
19931
+ "fs.find": { method: "POST", path: "/runtime/files/find" },
19932
+ "fs.textSearch": { method: "POST", path: "/runtime/files/search" },
19933
+ "fs.tree": { method: "POST", path: "/runtime/files/tree" },
19934
+ "service.list": { method: "GET", path: "/runtime/services" },
19935
+ "service.run": { method: "POST", path: "/runtime/services/run" },
19936
+ "service.stop": { method: "POST", path: "/runtime/services/stop" },
19937
+ "service.logs": { method: "POST", path: "/runtime/services/logs" },
19938
+ "composer.invoke": { method: "POST", path: "/runtime/composer/executions" },
19939
+ "composer.packages": { method: "GET", path: "/runtime/composer/packages" },
19940
+ "composer.dump-autoload": {
19941
+ method: "POST",
19942
+ path: "/runtime/composer/autoload"
19943
+ },
19944
+ "git.checkpoint": { method: "POST", path: "/runtime/git/checkpoints" },
19945
+ "git.checkout": { method: "POST", path: "/runtime/git/checkouts" },
19946
+ "git.log": { method: "POST", path: "/runtime/git/log" },
19947
+ "git.sync": { method: "POST", path: "/runtime/git/sync" },
19948
+ "git.diff": { method: "POST", path: "/runtime/git/diff" },
19949
+ "git.merge": { method: "POST", path: "/runtime/git/merge" },
19950
+ "git.conflicts": { method: "GET", path: "/runtime/git/conflicts" },
19951
+ "git.resolve": { method: "POST", path: "/runtime/git/conflicts/resolve" },
19952
+ "git.restore": { method: "POST", path: "/runtime/git/restore" },
19953
+ "git.status": { method: "GET", path: "/runtime/git/status" },
19954
+ "git.review": { method: "GET", path: "/runtime/git/review" },
19955
+ "git.stage": { method: "POST", path: "/runtime/git/stage" },
19956
+ "git.unstage": { method: "POST", path: "/runtime/git/unstage" },
19957
+ "git.revert": { method: "POST", path: "/runtime/git/revert" }
19958
+ };
19959
+ var RestRuntimeInvoker = class {
19960
+ constructor(data, fetch, refresh) {
19961
+ this.fetch = fetch;
19962
+ this.refresh = refresh;
19963
+ this.refreshPromise = null;
19964
+ this.notebookId = data.id;
19965
+ this.configure(data.okraUrl);
19966
+ }
19967
+ configure(connectionUrl) {
19968
+ const okraUrl = new URL(connectionUrl);
19969
+ const ticket = okraUrl.searchParams.get("ticket") ?? "";
19970
+ if (ticket === "") {
19971
+ throw new UnsupportedRuntimeTransportError("The notebook connection does not contain a runtime ticket.");
19972
+ }
19973
+ this.ticket = ticket;
19974
+ okraUrl.protocol = okraUrl.protocol === "wss:" ? "https:" : "http:";
19975
+ okraUrl.pathname = `/api/v1/notebooks/${encodeURIComponent(this.notebookId)}`;
19976
+ okraUrl.searchParams.delete("ticket");
19977
+ okraUrl.hash = "";
19978
+ this.actionUrl = okraUrl;
19979
+ }
19980
+ ready() {
19981
+ return this.invokeRaw("runtime.ready", {}, {});
19982
+ }
19983
+ supports(action) {
19984
+ return action in restActionRoutes;
19985
+ }
19986
+ invoke(action, data = {}, options = {}) {
19987
+ return this.invokeRaw(action, data ?? {}, options);
19988
+ }
19989
+ send() {
19990
+ throw new UnsupportedRuntimeTransportError("Fire-and-forget actions require the realtime transport.");
19991
+ }
19992
+ async invokeRaw(action, data, options) {
19993
+ const abort = runtimeAbort(options);
19994
+ try {
19995
+ for (let attempt = 0; attempt < 2; attempt += 1) {
19996
+ const response = await this.fetch(this.request(action, data, abort.signal));
19997
+ if (response.status === 401 && attempt === 0 && this.refresh !== void 0) {
19998
+ await this.refreshAuthorization();
19999
+ continue;
20000
+ }
20001
+ const payload = await runtimeActionResponse(response);
20002
+ if (!response.ok || payload.error !== void 0) {
20003
+ const error51 = payload.error ?? payload;
20004
+ const message = typeof error51.message === "string" ? error51.message : `Runtime action ${action} failed.`;
20005
+ const code = typeof error51.code === "number" ? error51.code : response.status;
20006
+ throw new ErrorEvent(code, message, error51);
20007
+ }
20008
+ return payload.data;
20009
+ }
20010
+ throw new ErrorEvent(401, `Runtime action ${action} could not be authorized.`, {});
20011
+ } finally {
20012
+ abort.dispose();
20013
+ }
20014
+ }
20015
+ request(action, data, signal) {
20016
+ const route = restActionRoutes[action];
20017
+ if (route === void 0) {
20018
+ throw new UnsupportedRuntimeTransportError(`Runtime action ${action} requires the realtime transport.`);
20019
+ }
20020
+ const url2 = new URL(this.actionUrl);
20021
+ url2.pathname += route.path;
20022
+ const headers = {
20023
+ Accept: "application/json, application/octet-stream",
20024
+ Authorization: `Bearer ${this.ticket}`
20025
+ };
20026
+ const body = runtimeActionRequestBody(action, data, url2, headers);
20027
+ return new Request(url2, {
20028
+ method: route.method,
20029
+ headers,
20030
+ body: route.method === "GET" ? void 0 : body,
20031
+ signal
20032
+ });
20033
+ }
20034
+ async refreshAuthorization() {
20035
+ if (this.refreshPromise === null) {
20036
+ this.refreshPromise = this.refresh().then((okraUrl) => this.configure(okraUrl));
20037
+ }
20038
+ try {
20039
+ await this.refreshPromise;
20040
+ } finally {
20041
+ this.refreshPromise = null;
20042
+ }
20043
+ }
20044
+ };
20045
+ async function runtimeActionResponse(response) {
20046
+ if (response.ok && response.headers.get("content-type")?.toLowerCase().startsWith("application/octet-stream")) {
20047
+ return { data: new Uint8Array(await response.arrayBuffer()) };
20048
+ }
20049
+ const body = await response.text();
20050
+ if (body === "") {
20051
+ return {};
20052
+ }
20053
+ try {
20054
+ return JSON.parse(body);
20055
+ } catch {
20056
+ return { error: { code: response.status, message: body } };
20057
+ }
20058
+ }
20059
+ function runtimeActionRequestBody(action, data, url2, headers) {
20060
+ const payload = runtimeActionRecord(data);
20061
+ if (action === "fs.readFile") {
20062
+ setRequiredRuntimeQuery(url2, "path", payload.path);
20063
+ const lineRange = runtimeActionRecord(payload.lineRange);
20064
+ if (lineRange.lineStart !== void 0 || lineRange.lineEnd !== void 0) {
20065
+ setRequiredRuntimeQuery(url2, "lineStart", lineRange.lineStart);
20066
+ setRequiredRuntimeQuery(url2, "lineEnd", lineRange.lineEnd);
20067
+ }
20068
+ return void 0;
20069
+ }
20070
+ if (action === "fs.writeFile") {
20071
+ setRequiredRuntimeQuery(url2, "path", payload.path);
20072
+ const options = runtimeActionRecord(payload.options);
20073
+ setBooleanRuntimeQuery(url2, "overwrite", options.overwrite);
20074
+ setBooleanRuntimeQuery(url2, "create", options.create);
20075
+ setBooleanRuntimeQuery(url2, "unlock", options.unlock);
20076
+ const atomic = runtimeActionRecord(options.atomic);
20077
+ if (typeof atomic.postfix === "string" && atomic.postfix !== "") {
20078
+ url2.searchParams.set("atomicPostfix", atomic.postfix);
20079
+ }
20080
+ if (!ArrayBuffer.isView(payload.contents)) {
20081
+ throw new TypeError("Runtime file contents must be binary data.");
20082
+ }
20083
+ headers["Content-Type"] = "application/octet-stream";
20084
+ return Uint8Array.from(
20085
+ new Uint8Array(payload.contents.buffer, payload.contents.byteOffset, payload.contents.byteLength)
20086
+ ).buffer;
20087
+ }
20088
+ headers["Content-Type"] = "application/json";
20089
+ return JSON.stringify(data);
20090
+ }
20091
+ function runtimeActionRecord(value) {
20092
+ return value !== null && typeof value === "object" ? value : {};
20093
+ }
20094
+ function setRequiredRuntimeQuery(url2, name, value) {
20095
+ if (typeof value !== "string" && typeof value !== "number" || String(value) === "") {
20096
+ throw new TypeError(`Runtime file ${name} is required.`);
20097
+ }
20098
+ url2.searchParams.set(name, String(value));
20099
+ }
20100
+ function setBooleanRuntimeQuery(url2, name, value) {
20101
+ url2.searchParams.set(name, value === true ? "true" : "false");
20102
+ }
20103
+ function runtimeAbort(options) {
20104
+ if (options.timeout === void 0 && options.abortSignal === void 0) {
20105
+ return { signal: new AbortController().signal, dispose: () => void 0 };
20106
+ }
20107
+ const controller = new AbortController();
20108
+ const abortFromCaller = () => controller.abort(options.abortSignal?.reason);
20109
+ options.abortSignal?.addEventListener("abort", abortFromCaller, {
20110
+ once: true
20111
+ });
20112
+ if (options.abortSignal?.aborted) {
20113
+ abortFromCaller();
20114
+ }
20115
+ const timeout2 = options.timeout === void 0 ? void 0 : setTimeout(() => controller.abort(), options.timeout);
20116
+ return {
20117
+ signal: controller.signal,
20118
+ dispose: () => {
20119
+ options.abortSignal?.removeEventListener("abort", abortFromCaller);
20120
+ if (timeout2 !== void 0) {
20121
+ clearTimeout(timeout2);
20122
+ }
20123
+ }
20124
+ };
20125
+ }
20126
+
19881
20127
  // src/index.ts
19882
20128
  function normalizeNotebookSecretInputs(input) {
19883
20129
  if (Array.isArray(input)) {
@@ -19985,6 +20231,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19985
20231
  }
19986
20232
  var Client2 = class {
19987
20233
  constructor(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20234
+ this.runtimeTransportValue = "realtime";
19988
20235
  this.fetch = globalThis.fetch;
19989
20236
  this.deployments = new DeploymentApi(this);
19990
20237
  this.notebook = new NotebookApi(this);
@@ -20000,6 +20247,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20000
20247
  "Content-Type": "application/json"
20001
20248
  };
20002
20249
  }
20250
+ get runtimeTransport() {
20251
+ return this.runtimeTransportValue;
20252
+ }
20003
20253
  get(path) {
20004
20254
  return this.makeRequest("GET", path);
20005
20255
  }
@@ -20063,7 +20313,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20063
20313
  return { data: body === "" ? void 0 : JSON.parse(body) };
20064
20314
  }
20065
20315
  };
20066
- var PHPSandbox = class extends Client2 {
20316
+ var PHPSandbox = class _PHPSandbox extends Client2 {
20317
+ static realtime(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20318
+ return new _PHPSandbox(token, url2, options);
20319
+ }
20320
+ static rest(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20321
+ const client = new _PHPSandbox(token, url2, options);
20322
+ client.runtimeTransportValue = "rest";
20323
+ return client;
20324
+ }
20067
20325
  };
20068
20326
  var NotebookSecretApi = class {
20069
20327
  constructor(client) {
@@ -20169,17 +20427,38 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20169
20427
  this.client = client;
20170
20428
  __privateAdd(this, _NotebookInstance_instances);
20171
20429
  this.initialized = false;
20172
- __privateAdd(this, _initPromise);
20430
+ __privateAdd(this, _initPromise, null);
20173
20431
  this.disposables = [];
20174
20432
  this.emitter = EventManager.createInstance();
20175
- this.socket = new Transport(data.okraUrl, this.emitter, {
20176
- debug: client.options.debug,
20177
- startClosed: client.options.startClosed,
20178
- webSocket: client.options.webSocket
20179
- });
20180
- this.watchConnection();
20181
- __privateSet(this, _initPromise, __privateMethod(this, _NotebookInstance_instances, init_fn).call(this));
20182
- this.file = new Filesystem(this);
20433
+ if (client.runtimeTransport === "rest") {
20434
+ this.socket = null;
20435
+ this.restInvoker = new RestRuntimeInvoker(
20436
+ data,
20437
+ client.options.fetch ?? globalThis.fetch,
20438
+ client.options.okraUrlProvider === void 0 ? void 0 : () => client.options.okraUrlProvider(data.id)
20439
+ );
20440
+ } else {
20441
+ this.restInvoker = null;
20442
+ let initialConnection = true;
20443
+ const connectionUrl = client.options.okraUrlProvider === void 0 ? data.okraUrl : async () => {
20444
+ if (initialConnection) {
20445
+ initialConnection = false;
20446
+ return data.okraUrl;
20447
+ }
20448
+ return client.options.okraUrlProvider(data.id);
20449
+ };
20450
+ this.socket = new Transport(connectionUrl, this.emitter, {
20451
+ debug: client.options.debug,
20452
+ startClosed: client.options.startClosed,
20453
+ webSocket: client.options.webSocket
20454
+ });
20455
+ this.watchConnection();
20456
+ __privateSet(this, _initPromise, __privateMethod(this, _NotebookInstance_instances, init_fn).call(this));
20457
+ }
20458
+ this.file = new Filesystem(
20459
+ this,
20460
+ this.socket === null ? null : (handler) => this.onDidConnect(handler)
20461
+ );
20183
20462
  this.terminal = new Terminal(this);
20184
20463
  this.auth = new Auth(this);
20185
20464
  this.lsp = new Lsp(this);
@@ -20196,14 +20475,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20196
20475
  this.preview = new NotebookPreview(client, this.data.id);
20197
20476
  this.mail = new NotebookMail(client, this.data.id);
20198
20477
  }
20478
+ get runtimeTransport() {
20479
+ return this.client.runtimeTransport;
20480
+ }
20199
20481
  async ready() {
20200
- const terminalError = this.socket.getTerminalError();
20482
+ if (this.restInvoker !== null) {
20483
+ return this.restInitialization();
20484
+ }
20485
+ const socket = this.realtimeSocket();
20486
+ const terminalError = socket.getTerminalError();
20201
20487
  if (terminalError) {
20202
20488
  throw terminalError;
20203
20489
  }
20204
20490
  const ready = async () => {
20205
- if (this.client.options.startClosed && !this.socket.isConnected) {
20206
- await this.socket.connect();
20491
+ if (this.client.options.startClosed && !socket.isConnected) {
20492
+ await socket.connect();
20207
20493
  }
20208
20494
  return __privateGet(this, _initPromise);
20209
20495
  };
@@ -20223,7 +20509,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20223
20509
  }
20224
20510
  delete() {
20225
20511
  return this.client.notebook.delete(this.data.id).then(() => {
20226
- this.socket.terminate(new NotebookUnavailableError("Notebook has been deleted.", { id: this.data.id }));
20512
+ this.socket?.terminate(new NotebookUnavailableError("Notebook has been deleted.", { id: this.data.id }));
20227
20513
  });
20228
20514
  }
20229
20515
  stop() {
@@ -20233,10 +20519,19 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20233
20519
  return this.container.restart();
20234
20520
  }
20235
20521
  invoke(action, data = {}, options = {}) {
20236
- return this.socket.invoke(action, data || {}, options);
20522
+ if (this.restInvoker !== null) {
20523
+ if (this.restInvoker.supports(String(action))) {
20524
+ void this.restInitialization();
20525
+ }
20526
+ return this.restInvoker.invoke(action, data || {}, options);
20527
+ }
20528
+ return this.realtimeSocket().invoke(action, data || {}, options);
20237
20529
  }
20238
20530
  send(action, data = {}) {
20239
- return this.socket.send(action, data || {});
20531
+ if (this.restInvoker !== null) {
20532
+ return this.restInvoker.send();
20533
+ }
20534
+ return this.realtimeSocket().send(action, data || {});
20240
20535
  }
20241
20536
  ping() {
20242
20537
  return this.invoke("ping");
@@ -20248,7 +20543,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20248
20543
  }
20249
20544
  dispose() {
20250
20545
  this.disposables.forEach((d) => d.dispose());
20251
- !this.socket.isClosed && this.socket.disconnect();
20546
+ if (this.socket !== null && !this.socket.isClosed) {
20547
+ this.socket.disconnect();
20548
+ }
20252
20549
  }
20253
20550
  connected() {
20254
20551
  return this.waitForSocketConnection({ rejectOnClose: true });
@@ -20257,11 +20554,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20257
20554
  return this.waitForSocketConnection({ rejectOnClose: false });
20258
20555
  }
20259
20556
  waitForSocketConnection(options) {
20260
- const terminalError = this.socket.getTerminalError();
20557
+ const socket = this.realtimeSocket();
20558
+ const terminalError = socket.getTerminalError();
20261
20559
  if (terminalError) {
20262
20560
  return Promise.reject(terminalError);
20263
20561
  }
20264
- if (this.socket.isConnected) {
20562
+ if (socket.isConnected) {
20265
20563
  return Promise.resolve(this);
20266
20564
  }
20267
20565
  return new Promise((resolve, reject) => {
@@ -20282,49 +20580,66 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20282
20580
  callback();
20283
20581
  };
20284
20582
  try {
20285
- disposables.push(this.socket.onDidConnect(() => settle(() => resolve(this))));
20583
+ disposables.push(socket.onDidConnect(() => settle(() => resolve(this))));
20286
20584
  if (options.rejectOnClose) {
20287
- disposables.push(this.socket.onDidClose(() => settle(() => reject(new Error("Connection closed")))));
20585
+ disposables.push(socket.onDidClose(() => settle(() => reject(new Error("Connection closed")))));
20288
20586
  }
20289
- disposables.push(this.socket.onDidBootError((error51) => settle(() => reject(error51))));
20587
+ disposables.push(socket.onDidBootError((error51) => settle(() => reject(error51))));
20290
20588
  } catch (e) {
20291
20589
  settle(() => reject(e));
20292
20590
  }
20293
20591
  });
20294
20592
  }
20295
20593
  watchConnection() {
20296
- this.socket.onDidConnect(() => {
20297
- this.socket.emit("okra.connected");
20594
+ const socket = this.realtimeSocket();
20595
+ socket.onDidConnect(() => {
20596
+ socket.emit("okra.connected");
20298
20597
  if (this.client.options.telemetry) {
20299
20598
  this.container.enableTelemetry(this.client.options.telemetry);
20300
20599
  }
20301
20600
  });
20302
- this.socket.onDidClose(() => {
20303
- this.socket.emit("okra.disconnected");
20601
+ socket.onDidClose(() => {
20602
+ socket.emit("okra.disconnected");
20304
20603
  this.initialized = false;
20305
20604
  });
20306
- this.socket.onDidBootError((error51) => {
20307
- this.socket.emit("okra.boot_error", error51);
20308
- this.socket.emit("okra.disconnected");
20605
+ socket.onDidBootError((error51) => {
20606
+ socket.emit("okra.boot_error", error51);
20607
+ socket.emit("okra.disconnected");
20309
20608
  this.initialized = false;
20310
20609
  });
20311
20610
  }
20312
20611
  onDidConnect(handler) {
20313
- this.socket.removeListener("okra.connected", handler);
20314
- const disposable = this.socket.listen("okra.connected", handler);
20612
+ const socket = this.realtimeSocket();
20613
+ socket.removeListener("okra.connected", handler);
20614
+ const disposable = socket.listen("okra.connected", handler);
20315
20615
  this.disposables.push(disposable);
20316
20616
  return disposable;
20317
20617
  }
20318
20618
  onDidDisconnect(handler) {
20319
- const disposable = this.socket.listen("okra.disconnected", handler);
20619
+ const disposable = this.realtimeSocket().listen("okra.disconnected", handler);
20320
20620
  this.disposables.push(disposable);
20321
20621
  return disposable;
20322
20622
  }
20323
20623
  onDidBootError(handler) {
20324
- const disposable = this.socket.listen("okra.boot_error", handler);
20624
+ const disposable = this.realtimeSocket().listen("okra.boot_error", handler);
20325
20625
  this.disposables.push(disposable);
20326
20626
  return disposable;
20327
20627
  }
20628
+ restInitialization() {
20629
+ if (this.restInvoker === null) {
20630
+ throw new UnsupportedRuntimeTransportError("This operation requires the REST transport.");
20631
+ }
20632
+ if (__privateGet(this, _initPromise) === null) {
20633
+ __privateSet(this, _initPromise, this.restInvoker.ready().then((result) => {
20634
+ this.initialized = result;
20635
+ this.emitter.emit("notebook.initialized", result);
20636
+ return result;
20637
+ }));
20638
+ void __privateGet(this, _initPromise).catch(() => {
20639
+ });
20640
+ }
20641
+ return __privateGet(this, _initPromise);
20642
+ }
20328
20643
  update(input) {
20329
20644
  return this.client.notebook.update(this.data.id, input);
20330
20645
  }
@@ -20332,8 +20647,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20332
20647
  return this.listen("notebook.initialized", handler);
20333
20648
  }
20334
20649
  async reconnect() {
20650
+ const socket = this.realtimeSocket();
20335
20651
  const whenConnected = this.whenConnected();
20336
- this.socket.reconnect();
20652
+ socket.reconnect();
20337
20653
  this.initialized = false;
20338
20654
  await whenConnected;
20339
20655
  __privateMethod(this, _NotebookInstance_instances, init_fn).call(this);
@@ -20344,6 +20660,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20344
20660
  iframe.src = result.data.previewUrl;
20345
20661
  return createBeacon(iframe, options);
20346
20662
  }
20663
+ realtimeSocket() {
20664
+ if (this.socket === null) {
20665
+ throw new UnsupportedRuntimeTransportError("This operation requires the realtime transport.");
20666
+ }
20667
+ return this.socket;
20668
+ }
20347
20669
  };
20348
20670
  _initPromise = new WeakMap();
20349
20671
  _NotebookInstance_instances = new WeakSet();