@phpsandbox/sdk 0.0.65 → 0.0.67

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(runtimeUrl) {
682
+ const runtimeTicket = new URL(runtimeUrl).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 = {};
@@ -19514,8 +19535,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19514
19535
  if (this.started) {
19515
19536
  return this;
19516
19537
  }
19517
- if (!this.initial.data.okraUrl) {
19518
- throw new Error(`Deployment ${this.initial.data.id} has no okraUrl for SSE streaming`);
19538
+ const eventStreamUrl = this.initial.data.eventStreamUrl ?? this.initial.data.okraUrl;
19539
+ if (!eventStreamUrl) {
19540
+ throw new Error(`Deployment ${this.initial.data.id} has no eventStreamUrl for SSE streaming`);
19519
19541
  }
19520
19542
  this.started = true;
19521
19543
  this.resultPromise = new Promise((resolve, reject) => {
@@ -19523,7 +19545,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19523
19545
  this.rejectResult = reject;
19524
19546
  });
19525
19547
  this.resultPromise.catch(() => void 0);
19526
- void this.consumeStream(this.initial.data.okraUrl);
19548
+ void this.consumeStream(eventStreamUrl);
19527
19549
  return this;
19528
19550
  }
19529
19551
  subscribe() {
@@ -19540,9 +19562,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19540
19562
  }
19541
19563
  return queue;
19542
19564
  }
19543
- async consumeStream(okraUrl) {
19565
+ async consumeStream(eventStreamUrl) {
19544
19566
  try {
19545
- const stream = await this.client.sse(okraUrl);
19567
+ const stream = await this.client.sse(eventStreamUrl);
19546
19568
  for await (const event of readDeployStreamEvents(stream)) {
19547
19569
  this.publish(event);
19548
19570
  if (event.type === "result") {
@@ -19878,6 +19900,231 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19878
19900
  }
19879
19901
  };
19880
19902
 
19903
+ // src/runtime/rest.ts
19904
+ var restActionRoutes = {
19905
+ "runtime.ready": { method: "GET", path: "/runtime" },
19906
+ ping: { method: "GET", path: "/runtime/ping" },
19907
+ "config.get": { method: "GET", path: "/runtime/config" },
19908
+ "config.update": { method: "PATCH", path: "/runtime/config" },
19909
+ "config.set-ports": { method: "PUT", path: "/runtime/config/ports" },
19910
+ "container.state": { method: "GET", path: "/runtime/container" },
19911
+ "container.start": { method: "POST", path: "/runtime/container/start" },
19912
+ "container.restart": { method: "POST", path: "/runtime/container/restart" },
19913
+ "container.stop": { method: "POST", path: "/runtime/container/stop" },
19914
+ "container.set-php": { method: "PUT", path: "/runtime/container/php" },
19915
+ "container.opened-ports": { method: "GET", path: "/runtime/container/ports" },
19916
+ "terminal.list": { method: "GET", path: "/runtime/terminals" },
19917
+ "shell.exec": { method: "POST", path: "/runtime/executions" },
19918
+ "fs.info": { method: "POST", path: "/runtime/files/info" },
19919
+ "fs.readFile": { method: "GET", path: "/runtime/files/content" },
19920
+ "fs.writeFile": { method: "PUT", path: "/runtime/files/content" },
19921
+ "fs.write": { method: "PUT", path: "/runtime/files/text" },
19922
+ "fs.mkdir": { method: "POST", path: "/runtime/directories" },
19923
+ "fs.createDirectory": { method: "PUT", path: "/runtime/directories" },
19924
+ "fs.readDirectory": { method: "POST", path: "/runtime/directories/read" },
19925
+ "fs.stat": { method: "POST", path: "/runtime/files/stat" },
19926
+ "fs.move": { method: "POST", path: "/runtime/files/move" },
19927
+ "fs.rename": { method: "POST", path: "/runtime/files/rename" },
19928
+ "fs.copy": { method: "POST", path: "/runtime/files/copy" },
19929
+ "fs.remove": { method: "POST", path: "/runtime/files/remove" },
19930
+ "fs.delete": { method: "DELETE", path: "/runtime/files" },
19931
+ "fs.tail": { method: "POST", path: "/runtime/files/tail" },
19932
+ "fs.find": { method: "POST", path: "/runtime/files/find" },
19933
+ "fs.textSearch": { method: "POST", path: "/runtime/files/search" },
19934
+ "fs.tree": { method: "POST", path: "/runtime/files/tree" },
19935
+ "service.list": { method: "GET", path: "/runtime/services" },
19936
+ "service.run": { method: "POST", path: "/runtime/services/run" },
19937
+ "service.stop": { method: "POST", path: "/runtime/services/stop" },
19938
+ "service.logs": { method: "POST", path: "/runtime/services/logs" },
19939
+ "composer.invoke": { method: "POST", path: "/runtime/composer/executions" },
19940
+ "composer.packages": { method: "GET", path: "/runtime/composer/packages" },
19941
+ "composer.dump-autoload": {
19942
+ method: "POST",
19943
+ path: "/runtime/composer/autoload"
19944
+ },
19945
+ "git.checkpoint": { method: "POST", path: "/runtime/git/checkpoints" },
19946
+ "git.checkout": { method: "POST", path: "/runtime/git/checkouts" },
19947
+ "git.log": { method: "POST", path: "/runtime/git/log" },
19948
+ "git.sync": { method: "POST", path: "/runtime/git/sync" },
19949
+ "git.diff": { method: "POST", path: "/runtime/git/diff" },
19950
+ "git.merge": { method: "POST", path: "/runtime/git/merge" },
19951
+ "git.conflicts": { method: "GET", path: "/runtime/git/conflicts" },
19952
+ "git.resolve": { method: "POST", path: "/runtime/git/conflicts/resolve" },
19953
+ "git.restore": { method: "POST", path: "/runtime/git/restore" },
19954
+ "git.status": { method: "GET", path: "/runtime/git/status" },
19955
+ "git.review": { method: "GET", path: "/runtime/git/review" },
19956
+ "git.stage": { method: "POST", path: "/runtime/git/stage" },
19957
+ "git.unstage": { method: "POST", path: "/runtime/git/unstage" },
19958
+ "git.revert": { method: "POST", path: "/runtime/git/revert" }
19959
+ };
19960
+ var RestRuntimeInvoker = class {
19961
+ constructor(data, fetch, refresh) {
19962
+ this.fetch = fetch;
19963
+ this.refresh = refresh;
19964
+ this.refreshPromise = null;
19965
+ this.notebookId = data.id;
19966
+ this.configure(data.runtimeUrl ?? data.okraUrl);
19967
+ }
19968
+ configure(runtimeUrl) {
19969
+ const actionUrl = new URL(runtimeUrl);
19970
+ const ticket = actionUrl.searchParams.get("ticket") ?? "";
19971
+ if (ticket === "") {
19972
+ throw new UnsupportedRuntimeTransportError("The notebook connection does not contain a runtime ticket.");
19973
+ }
19974
+ this.ticket = ticket;
19975
+ actionUrl.protocol = actionUrl.protocol === "wss:" ? "https:" : "http:";
19976
+ actionUrl.pathname = `/api/v1/notebooks/${encodeURIComponent(this.notebookId)}`;
19977
+ actionUrl.searchParams.delete("ticket");
19978
+ actionUrl.hash = "";
19979
+ this.actionUrl = actionUrl;
19980
+ }
19981
+ ready() {
19982
+ return this.invokeRaw("runtime.ready", {}, {});
19983
+ }
19984
+ supports(action) {
19985
+ return action in restActionRoutes;
19986
+ }
19987
+ invoke(action, data = {}, options = {}) {
19988
+ return this.invokeRaw(action, data ?? {}, options);
19989
+ }
19990
+ send() {
19991
+ throw new UnsupportedRuntimeTransportError("Fire-and-forget actions require the realtime transport.");
19992
+ }
19993
+ async invokeRaw(action, data, options) {
19994
+ const abort = runtimeAbort(options);
19995
+ try {
19996
+ for (let attempt = 0; attempt < 2; attempt += 1) {
19997
+ const response = await this.fetch(this.request(action, data, abort.signal));
19998
+ if (response.status === 401 && attempt === 0 && this.refresh !== void 0) {
19999
+ await this.refreshAuthorization();
20000
+ continue;
20001
+ }
20002
+ const payload = await runtimeActionResponse(response);
20003
+ if (!response.ok || payload.error !== void 0) {
20004
+ const error51 = payload.error ?? payload;
20005
+ const message = typeof error51.message === "string" ? error51.message : `Runtime action ${action} failed.`;
20006
+ const code = typeof error51.code === "number" ? error51.code : response.status;
20007
+ throw new ErrorEvent(code, message, error51);
20008
+ }
20009
+ return payload.data;
20010
+ }
20011
+ throw new ErrorEvent(401, `Runtime action ${action} could not be authorized.`, {});
20012
+ } finally {
20013
+ abort.dispose();
20014
+ }
20015
+ }
20016
+ request(action, data, signal) {
20017
+ const route = restActionRoutes[action];
20018
+ if (route === void 0) {
20019
+ throw new UnsupportedRuntimeTransportError(`Runtime action ${action} requires the realtime transport.`);
20020
+ }
20021
+ const url2 = new URL(this.actionUrl);
20022
+ url2.pathname += route.path;
20023
+ const headers = {
20024
+ Accept: "application/json, application/octet-stream",
20025
+ Authorization: `Bearer ${this.ticket}`
20026
+ };
20027
+ const body = runtimeActionRequestBody(action, data, url2, headers);
20028
+ return new Request(url2, {
20029
+ method: route.method,
20030
+ headers,
20031
+ body: route.method === "GET" ? void 0 : body,
20032
+ signal
20033
+ });
20034
+ }
20035
+ async refreshAuthorization() {
20036
+ if (this.refreshPromise === null) {
20037
+ this.refreshPromise = this.refresh().then((runtimeUrl) => this.configure(runtimeUrl));
20038
+ }
20039
+ try {
20040
+ await this.refreshPromise;
20041
+ } finally {
20042
+ this.refreshPromise = null;
20043
+ }
20044
+ }
20045
+ };
20046
+ async function runtimeActionResponse(response) {
20047
+ if (response.ok && response.headers.get("content-type")?.toLowerCase().startsWith("application/octet-stream")) {
20048
+ return { data: new Uint8Array(await response.arrayBuffer()) };
20049
+ }
20050
+ const body = await response.text();
20051
+ if (body === "") {
20052
+ return {};
20053
+ }
20054
+ try {
20055
+ return JSON.parse(body);
20056
+ } catch {
20057
+ return { error: { code: response.status, message: body } };
20058
+ }
20059
+ }
20060
+ function runtimeActionRequestBody(action, data, url2, headers) {
20061
+ const payload = runtimeActionRecord(data);
20062
+ if (action === "fs.readFile") {
20063
+ setRequiredRuntimeQuery(url2, "path", payload.path);
20064
+ const lineRange = runtimeActionRecord(payload.lineRange);
20065
+ if (lineRange.lineStart !== void 0 || lineRange.lineEnd !== void 0) {
20066
+ setRequiredRuntimeQuery(url2, "lineStart", lineRange.lineStart);
20067
+ setRequiredRuntimeQuery(url2, "lineEnd", lineRange.lineEnd);
20068
+ }
20069
+ return void 0;
20070
+ }
20071
+ if (action === "fs.writeFile") {
20072
+ setRequiredRuntimeQuery(url2, "path", payload.path);
20073
+ const options = runtimeActionRecord(payload.options);
20074
+ setBooleanRuntimeQuery(url2, "overwrite", options.overwrite);
20075
+ setBooleanRuntimeQuery(url2, "create", options.create);
20076
+ setBooleanRuntimeQuery(url2, "unlock", options.unlock);
20077
+ const atomic = runtimeActionRecord(options.atomic);
20078
+ if (typeof atomic.postfix === "string" && atomic.postfix !== "") {
20079
+ url2.searchParams.set("atomicPostfix", atomic.postfix);
20080
+ }
20081
+ if (!ArrayBuffer.isView(payload.contents)) {
20082
+ throw new TypeError("Runtime file contents must be binary data.");
20083
+ }
20084
+ headers["Content-Type"] = "application/octet-stream";
20085
+ return Uint8Array.from(
20086
+ new Uint8Array(payload.contents.buffer, payload.contents.byteOffset, payload.contents.byteLength)
20087
+ ).buffer;
20088
+ }
20089
+ headers["Content-Type"] = "application/json";
20090
+ return JSON.stringify(data);
20091
+ }
20092
+ function runtimeActionRecord(value) {
20093
+ return value !== null && typeof value === "object" ? value : {};
20094
+ }
20095
+ function setRequiredRuntimeQuery(url2, name, value) {
20096
+ if (typeof value !== "string" && typeof value !== "number" || String(value) === "") {
20097
+ throw new TypeError(`Runtime file ${name} is required.`);
20098
+ }
20099
+ url2.searchParams.set(name, String(value));
20100
+ }
20101
+ function setBooleanRuntimeQuery(url2, name, value) {
20102
+ url2.searchParams.set(name, value === true ? "true" : "false");
20103
+ }
20104
+ function runtimeAbort(options) {
20105
+ if (options.timeout === void 0 && options.abortSignal === void 0) {
20106
+ return { signal: new AbortController().signal, dispose: () => void 0 };
20107
+ }
20108
+ const controller = new AbortController();
20109
+ const abortFromCaller = () => controller.abort(options.abortSignal?.reason);
20110
+ options.abortSignal?.addEventListener("abort", abortFromCaller, {
20111
+ once: true
20112
+ });
20113
+ if (options.abortSignal?.aborted) {
20114
+ abortFromCaller();
20115
+ }
20116
+ const timeout2 = options.timeout === void 0 ? void 0 : setTimeout(() => controller.abort(), options.timeout);
20117
+ return {
20118
+ signal: controller.signal,
20119
+ dispose: () => {
20120
+ options.abortSignal?.removeEventListener("abort", abortFromCaller);
20121
+ if (timeout2 !== void 0) {
20122
+ clearTimeout(timeout2);
20123
+ }
20124
+ }
20125
+ };
20126
+ }
20127
+
19881
20128
  // src/index.ts
19882
20129
  function normalizeNotebookSecretInputs(input) {
19883
20130
  if (Array.isArray(input)) {
@@ -19985,6 +20232,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19985
20232
  }
19986
20233
  var Client2 = class {
19987
20234
  constructor(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20235
+ this.runtimeTransportValue = "realtime";
19988
20236
  this.fetch = globalThis.fetch;
19989
20237
  this.deployments = new DeploymentApi(this);
19990
20238
  this.notebook = new NotebookApi(this);
@@ -20000,6 +20248,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20000
20248
  "Content-Type": "application/json"
20001
20249
  };
20002
20250
  }
20251
+ get runtimeTransport() {
20252
+ return this.runtimeTransportValue;
20253
+ }
20003
20254
  get(path) {
20004
20255
  return this.makeRequest("GET", path);
20005
20256
  }
@@ -20063,7 +20314,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20063
20314
  return { data: body === "" ? void 0 : JSON.parse(body) };
20064
20315
  }
20065
20316
  };
20066
- var PHPSandbox = class extends Client2 {
20317
+ var PHPSandbox = class _PHPSandbox extends Client2 {
20318
+ static realtime(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20319
+ return new _PHPSandbox(token, url2, options);
20320
+ }
20321
+ static rest(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20322
+ const client = new _PHPSandbox(token, url2, options);
20323
+ client.runtimeTransportValue = "rest";
20324
+ return client;
20325
+ }
20067
20326
  };
20068
20327
  var NotebookSecretApi = class {
20069
20328
  constructor(client) {
@@ -20169,17 +20428,40 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20169
20428
  this.client = client;
20170
20429
  __privateAdd(this, _NotebookInstance_instances);
20171
20430
  this.initialized = false;
20172
- __privateAdd(this, _initPromise);
20431
+ __privateAdd(this, _initPromise, null);
20173
20432
  this.disposables = [];
20433
+ const runtimeUrl = data.runtimeUrl ?? data.okraUrl;
20434
+ const runtimeUrlProvider = client.options.runtimeUrlProvider ?? client.options.okraUrlProvider;
20174
20435
  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);
20436
+ if (client.runtimeTransport === "rest") {
20437
+ this.socket = null;
20438
+ this.restInvoker = new RestRuntimeInvoker(
20439
+ data,
20440
+ client.options.fetch ?? globalThis.fetch,
20441
+ runtimeUrlProvider === void 0 ? void 0 : () => runtimeUrlProvider(data.id)
20442
+ );
20443
+ } else {
20444
+ this.restInvoker = null;
20445
+ let initialConnection = true;
20446
+ const connectionUrl = runtimeUrlProvider === void 0 ? runtimeUrl : async () => {
20447
+ if (initialConnection) {
20448
+ initialConnection = false;
20449
+ return runtimeUrl;
20450
+ }
20451
+ return runtimeUrlProvider(data.id);
20452
+ };
20453
+ this.socket = new Transport(connectionUrl, this.emitter, {
20454
+ debug: client.options.debug,
20455
+ startClosed: client.options.startClosed,
20456
+ webSocket: client.options.webSocket
20457
+ });
20458
+ this.watchConnection();
20459
+ __privateSet(this, _initPromise, __privateMethod(this, _NotebookInstance_instances, init_fn).call(this));
20460
+ }
20461
+ this.file = new Filesystem(
20462
+ this,
20463
+ this.socket === null ? null : (handler) => this.onDidConnect(handler)
20464
+ );
20183
20465
  this.terminal = new Terminal(this);
20184
20466
  this.auth = new Auth(this);
20185
20467
  this.lsp = new Lsp(this);
@@ -20196,14 +20478,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20196
20478
  this.preview = new NotebookPreview(client, this.data.id);
20197
20479
  this.mail = new NotebookMail(client, this.data.id);
20198
20480
  }
20481
+ get runtimeTransport() {
20482
+ return this.client.runtimeTransport;
20483
+ }
20199
20484
  async ready() {
20200
- const terminalError = this.socket.getTerminalError();
20485
+ if (this.restInvoker !== null) {
20486
+ return this.restInitialization();
20487
+ }
20488
+ const socket = this.realtimeSocket();
20489
+ const terminalError = socket.getTerminalError();
20201
20490
  if (terminalError) {
20202
20491
  throw terminalError;
20203
20492
  }
20204
20493
  const ready = async () => {
20205
- if (this.client.options.startClosed && !this.socket.isConnected) {
20206
- await this.socket.connect();
20494
+ if (this.client.options.startClosed && !socket.isConnected) {
20495
+ await socket.connect();
20207
20496
  }
20208
20497
  return __privateGet(this, _initPromise);
20209
20498
  };
@@ -20223,7 +20512,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20223
20512
  }
20224
20513
  delete() {
20225
20514
  return this.client.notebook.delete(this.data.id).then(() => {
20226
- this.socket.terminate(new NotebookUnavailableError("Notebook has been deleted.", { id: this.data.id }));
20515
+ this.socket?.terminate(new NotebookUnavailableError("Notebook has been deleted.", { id: this.data.id }));
20227
20516
  });
20228
20517
  }
20229
20518
  stop() {
@@ -20233,10 +20522,19 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20233
20522
  return this.container.restart();
20234
20523
  }
20235
20524
  invoke(action, data = {}, options = {}) {
20236
- return this.socket.invoke(action, data || {}, options);
20525
+ if (this.restInvoker !== null) {
20526
+ if (this.restInvoker.supports(String(action))) {
20527
+ void this.restInitialization();
20528
+ }
20529
+ return this.restInvoker.invoke(action, data || {}, options);
20530
+ }
20531
+ return this.realtimeSocket().invoke(action, data || {}, options);
20237
20532
  }
20238
20533
  send(action, data = {}) {
20239
- return this.socket.send(action, data || {});
20534
+ if (this.restInvoker !== null) {
20535
+ return this.restInvoker.send();
20536
+ }
20537
+ return this.realtimeSocket().send(action, data || {});
20240
20538
  }
20241
20539
  ping() {
20242
20540
  return this.invoke("ping");
@@ -20248,7 +20546,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20248
20546
  }
20249
20547
  dispose() {
20250
20548
  this.disposables.forEach((d) => d.dispose());
20251
- !this.socket.isClosed && this.socket.disconnect();
20549
+ if (this.socket !== null && !this.socket.isClosed) {
20550
+ this.socket.disconnect();
20551
+ }
20252
20552
  }
20253
20553
  connected() {
20254
20554
  return this.waitForSocketConnection({ rejectOnClose: true });
@@ -20257,11 +20557,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20257
20557
  return this.waitForSocketConnection({ rejectOnClose: false });
20258
20558
  }
20259
20559
  waitForSocketConnection(options) {
20260
- const terminalError = this.socket.getTerminalError();
20560
+ const socket = this.realtimeSocket();
20561
+ const terminalError = socket.getTerminalError();
20261
20562
  if (terminalError) {
20262
20563
  return Promise.reject(terminalError);
20263
20564
  }
20264
- if (this.socket.isConnected) {
20565
+ if (socket.isConnected) {
20265
20566
  return Promise.resolve(this);
20266
20567
  }
20267
20568
  return new Promise((resolve, reject) => {
@@ -20282,49 +20583,66 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20282
20583
  callback();
20283
20584
  };
20284
20585
  try {
20285
- disposables.push(this.socket.onDidConnect(() => settle(() => resolve(this))));
20586
+ disposables.push(socket.onDidConnect(() => settle(() => resolve(this))));
20286
20587
  if (options.rejectOnClose) {
20287
- disposables.push(this.socket.onDidClose(() => settle(() => reject(new Error("Connection closed")))));
20588
+ disposables.push(socket.onDidClose(() => settle(() => reject(new Error("Connection closed")))));
20288
20589
  }
20289
- disposables.push(this.socket.onDidBootError((error51) => settle(() => reject(error51))));
20590
+ disposables.push(socket.onDidBootError((error51) => settle(() => reject(error51))));
20290
20591
  } catch (e) {
20291
20592
  settle(() => reject(e));
20292
20593
  }
20293
20594
  });
20294
20595
  }
20295
20596
  watchConnection() {
20296
- this.socket.onDidConnect(() => {
20297
- this.socket.emit("okra.connected");
20597
+ const socket = this.realtimeSocket();
20598
+ socket.onDidConnect(() => {
20599
+ socket.emit("okra.connected");
20298
20600
  if (this.client.options.telemetry) {
20299
20601
  this.container.enableTelemetry(this.client.options.telemetry);
20300
20602
  }
20301
20603
  });
20302
- this.socket.onDidClose(() => {
20303
- this.socket.emit("okra.disconnected");
20604
+ socket.onDidClose(() => {
20605
+ socket.emit("okra.disconnected");
20304
20606
  this.initialized = false;
20305
20607
  });
20306
- this.socket.onDidBootError((error51) => {
20307
- this.socket.emit("okra.boot_error", error51);
20308
- this.socket.emit("okra.disconnected");
20608
+ socket.onDidBootError((error51) => {
20609
+ socket.emit("okra.boot_error", error51);
20610
+ socket.emit("okra.disconnected");
20309
20611
  this.initialized = false;
20310
20612
  });
20311
20613
  }
20312
20614
  onDidConnect(handler) {
20313
- this.socket.removeListener("okra.connected", handler);
20314
- const disposable = this.socket.listen("okra.connected", handler);
20615
+ const socket = this.realtimeSocket();
20616
+ socket.removeListener("okra.connected", handler);
20617
+ const disposable = socket.listen("okra.connected", handler);
20315
20618
  this.disposables.push(disposable);
20316
20619
  return disposable;
20317
20620
  }
20318
20621
  onDidDisconnect(handler) {
20319
- const disposable = this.socket.listen("okra.disconnected", handler);
20622
+ const disposable = this.realtimeSocket().listen("okra.disconnected", handler);
20320
20623
  this.disposables.push(disposable);
20321
20624
  return disposable;
20322
20625
  }
20323
20626
  onDidBootError(handler) {
20324
- const disposable = this.socket.listen("okra.boot_error", handler);
20627
+ const disposable = this.realtimeSocket().listen("okra.boot_error", handler);
20325
20628
  this.disposables.push(disposable);
20326
20629
  return disposable;
20327
20630
  }
20631
+ restInitialization() {
20632
+ if (this.restInvoker === null) {
20633
+ throw new UnsupportedRuntimeTransportError("This operation requires the REST transport.");
20634
+ }
20635
+ if (__privateGet(this, _initPromise) === null) {
20636
+ __privateSet(this, _initPromise, this.restInvoker.ready().then((result) => {
20637
+ this.initialized = result;
20638
+ this.emitter.emit("notebook.initialized", result);
20639
+ return result;
20640
+ }));
20641
+ void __privateGet(this, _initPromise).catch(() => {
20642
+ });
20643
+ }
20644
+ return __privateGet(this, _initPromise);
20645
+ }
20328
20646
  update(input) {
20329
20647
  return this.client.notebook.update(this.data.id, input);
20330
20648
  }
@@ -20332,8 +20650,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20332
20650
  return this.listen("notebook.initialized", handler);
20333
20651
  }
20334
20652
  async reconnect() {
20653
+ const socket = this.realtimeSocket();
20335
20654
  const whenConnected = this.whenConnected();
20336
- this.socket.reconnect();
20655
+ socket.reconnect();
20337
20656
  this.initialized = false;
20338
20657
  await whenConnected;
20339
20658
  __privateMethod(this, _NotebookInstance_instances, init_fn).call(this);
@@ -20344,6 +20663,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20344
20663
  iframe.src = result.data.previewUrl;
20345
20664
  return createBeacon(iframe, options);
20346
20665
  }
20666
+ realtimeSocket() {
20667
+ if (this.socket === null) {
20668
+ throw new UnsupportedRuntimeTransportError("This operation requires the realtime transport.");
20669
+ }
20670
+ return this.socket;
20671
+ }
20347
20672
  };
20348
20673
  _initPromise = new WeakMap();
20349
20674
  _NotebookInstance_instances = new WeakSet();