@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.
@@ -93,13 +93,16 @@ var FilesystemSubscription = class {
93
93
  }
94
94
  };
95
95
  var Filesystem = class {
96
- constructor(okra) {
96
+ constructor(okra, registerReconnect = (handler) => okra.onDidConnect(handler)) {
97
97
  this.okra = okra;
98
98
  this.watches = /* @__PURE__ */ new Map();
99
- this.watchOkraConnection();
99
+ this.registerReconnectHandler(registerReconnect);
100
100
  }
101
- watchOkraConnection() {
102
- this.okra.onDidConnect(() => {
101
+ registerReconnectHandler(registerReconnect) {
102
+ if (registerReconnect === null) {
103
+ return;
104
+ }
105
+ registerReconnect(() => {
103
106
  for (const { path, options } of this.watches.values()) {
104
107
  void this.okra.invoke("fs.watch", { path, options }).catch(() => {
105
108
  });
@@ -306,6 +309,12 @@ var NotebookUnavailableError = class extends Error {
306
309
  this.name = "NotebookUnavailableError";
307
310
  }
308
311
  };
312
+ var UnsupportedRuntimeTransportError = class extends Error {
313
+ constructor(message) {
314
+ super(message);
315
+ this.name = "UnsupportedRuntimeTransportError";
316
+ }
317
+ };
309
318
 
310
319
  // src/utils/promise.ts
311
320
  var timeout = (prom, time3) => {
@@ -573,10 +582,14 @@ var Auth = class {
573
582
  this.okra = okra;
574
583
  }
575
584
  logout() {
576
- return this.okra.invoke("auth.logout");
585
+ this.okra.dispose();
577
586
  }
578
- login(newConnectionData) {
579
- return this.okra.invoke("auth.login", { newConnectionData });
587
+ login(runtimeUrl) {
588
+ const runtimeTicket = new URL(runtimeUrl).searchParams.get("ticket");
589
+ if (runtimeTicket === null || runtimeTicket === "") {
590
+ throw new TypeError("The notebook connection does not contain a runtime ticket.");
591
+ }
592
+ return this.okra.invoke("auth.login", { runtimeTicket });
580
593
  }
581
594
  };
582
595
 
@@ -3136,11 +3149,12 @@ var Transport = class {
3136
3149
  this.pingIntervalStarted = false;
3137
3150
  this.incomingMessageChain = Promise.resolve();
3138
3151
  this.validateConfiguration(options);
3139
- this.url = new URL(url2);
3152
+ this.url = typeof url2 === "string" ? new URL(url2) : null;
3153
+ const urlProvider = typeof url2 === "string" ? this.url.toString() : async () => new URL(await url2()).toString();
3140
3154
  this.PING_INTERVAL = options.pingInterval ?? 3e4;
3141
3155
  this.CONNECT_WAIT_TIMEOUT = options.connectWaitTimeout ?? 3e4;
3142
3156
  const startClosed = options.startClosed !== false;
3143
- this.rws = new ReconnectingWebSocket2(this.url.toString(), [], {
3157
+ this.rws = new ReconnectingWebSocket2(urlProvider, [], {
3144
3158
  WebSocket: options.webSocket ?? globalThis.WebSocket ?? browser_default,
3145
3159
  connectionTimeout: options.connectionTimeout,
3146
3160
  maxReconnectionDelay: 2e3,
@@ -3150,7 +3164,7 @@ var Transport = class {
3150
3164
  startClosed
3151
3165
  });
3152
3166
  this.log("debug", "Transport initialized", {
3153
- url: this.url.toString(),
3167
+ url: this.url === null ? "dynamic" : transportLogUrl(this.url),
3154
3168
  options
3155
3169
  });
3156
3170
  this.registerWatchers();
@@ -3736,6 +3750,12 @@ startPeriodicPing_fn = function() {
3736
3750
  };
3737
3751
  });
3738
3752
  };
3753
+ function transportLogUrl(url2) {
3754
+ const safeUrl = new URL(url2);
3755
+ safeUrl.search = "";
3756
+ safeUrl.hash = "";
3757
+ return safeUrl.toString();
3758
+ }
3739
3759
 
3740
3760
  // node_modules/mitt/dist/mitt.mjs
3741
3761
  var mitt_exports = {};
@@ -19421,8 +19441,9 @@ var DeploymentRun = class {
19421
19441
  if (this.started) {
19422
19442
  return this;
19423
19443
  }
19424
- if (!this.initial.data.okraUrl) {
19425
- throw new Error(`Deployment ${this.initial.data.id} has no okraUrl for SSE streaming`);
19444
+ const eventStreamUrl = this.initial.data.eventStreamUrl ?? this.initial.data.okraUrl;
19445
+ if (!eventStreamUrl) {
19446
+ throw new Error(`Deployment ${this.initial.data.id} has no eventStreamUrl for SSE streaming`);
19426
19447
  }
19427
19448
  this.started = true;
19428
19449
  this.resultPromise = new Promise((resolve, reject) => {
@@ -19430,7 +19451,7 @@ var DeploymentRun = class {
19430
19451
  this.rejectResult = reject;
19431
19452
  });
19432
19453
  this.resultPromise.catch(() => void 0);
19433
- void this.consumeStream(this.initial.data.okraUrl);
19454
+ void this.consumeStream(eventStreamUrl);
19434
19455
  return this;
19435
19456
  }
19436
19457
  subscribe() {
@@ -19447,9 +19468,9 @@ var DeploymentRun = class {
19447
19468
  }
19448
19469
  return queue;
19449
19470
  }
19450
- async consumeStream(okraUrl) {
19471
+ async consumeStream(eventStreamUrl) {
19451
19472
  try {
19452
- const stream = await this.client.sse(okraUrl);
19473
+ const stream = await this.client.sse(eventStreamUrl);
19453
19474
  for await (const event of readDeployStreamEvents(stream)) {
19454
19475
  this.publish(event);
19455
19476
  if (event.type === "result") {
@@ -19785,6 +19806,231 @@ var ServerInstance = class {
19785
19806
  }
19786
19807
  };
19787
19808
 
19809
+ // src/runtime/rest.ts
19810
+ var restActionRoutes = {
19811
+ "runtime.ready": { method: "GET", path: "/runtime" },
19812
+ ping: { method: "GET", path: "/runtime/ping" },
19813
+ "config.get": { method: "GET", path: "/runtime/config" },
19814
+ "config.update": { method: "PATCH", path: "/runtime/config" },
19815
+ "config.set-ports": { method: "PUT", path: "/runtime/config/ports" },
19816
+ "container.state": { method: "GET", path: "/runtime/container" },
19817
+ "container.start": { method: "POST", path: "/runtime/container/start" },
19818
+ "container.restart": { method: "POST", path: "/runtime/container/restart" },
19819
+ "container.stop": { method: "POST", path: "/runtime/container/stop" },
19820
+ "container.set-php": { method: "PUT", path: "/runtime/container/php" },
19821
+ "container.opened-ports": { method: "GET", path: "/runtime/container/ports" },
19822
+ "terminal.list": { method: "GET", path: "/runtime/terminals" },
19823
+ "shell.exec": { method: "POST", path: "/runtime/executions" },
19824
+ "fs.info": { method: "POST", path: "/runtime/files/info" },
19825
+ "fs.readFile": { method: "GET", path: "/runtime/files/content" },
19826
+ "fs.writeFile": { method: "PUT", path: "/runtime/files/content" },
19827
+ "fs.write": { method: "PUT", path: "/runtime/files/text" },
19828
+ "fs.mkdir": { method: "POST", path: "/runtime/directories" },
19829
+ "fs.createDirectory": { method: "PUT", path: "/runtime/directories" },
19830
+ "fs.readDirectory": { method: "POST", path: "/runtime/directories/read" },
19831
+ "fs.stat": { method: "POST", path: "/runtime/files/stat" },
19832
+ "fs.move": { method: "POST", path: "/runtime/files/move" },
19833
+ "fs.rename": { method: "POST", path: "/runtime/files/rename" },
19834
+ "fs.copy": { method: "POST", path: "/runtime/files/copy" },
19835
+ "fs.remove": { method: "POST", path: "/runtime/files/remove" },
19836
+ "fs.delete": { method: "DELETE", path: "/runtime/files" },
19837
+ "fs.tail": { method: "POST", path: "/runtime/files/tail" },
19838
+ "fs.find": { method: "POST", path: "/runtime/files/find" },
19839
+ "fs.textSearch": { method: "POST", path: "/runtime/files/search" },
19840
+ "fs.tree": { method: "POST", path: "/runtime/files/tree" },
19841
+ "service.list": { method: "GET", path: "/runtime/services" },
19842
+ "service.run": { method: "POST", path: "/runtime/services/run" },
19843
+ "service.stop": { method: "POST", path: "/runtime/services/stop" },
19844
+ "service.logs": { method: "POST", path: "/runtime/services/logs" },
19845
+ "composer.invoke": { method: "POST", path: "/runtime/composer/executions" },
19846
+ "composer.packages": { method: "GET", path: "/runtime/composer/packages" },
19847
+ "composer.dump-autoload": {
19848
+ method: "POST",
19849
+ path: "/runtime/composer/autoload"
19850
+ },
19851
+ "git.checkpoint": { method: "POST", path: "/runtime/git/checkpoints" },
19852
+ "git.checkout": { method: "POST", path: "/runtime/git/checkouts" },
19853
+ "git.log": { method: "POST", path: "/runtime/git/log" },
19854
+ "git.sync": { method: "POST", path: "/runtime/git/sync" },
19855
+ "git.diff": { method: "POST", path: "/runtime/git/diff" },
19856
+ "git.merge": { method: "POST", path: "/runtime/git/merge" },
19857
+ "git.conflicts": { method: "GET", path: "/runtime/git/conflicts" },
19858
+ "git.resolve": { method: "POST", path: "/runtime/git/conflicts/resolve" },
19859
+ "git.restore": { method: "POST", path: "/runtime/git/restore" },
19860
+ "git.status": { method: "GET", path: "/runtime/git/status" },
19861
+ "git.review": { method: "GET", path: "/runtime/git/review" },
19862
+ "git.stage": { method: "POST", path: "/runtime/git/stage" },
19863
+ "git.unstage": { method: "POST", path: "/runtime/git/unstage" },
19864
+ "git.revert": { method: "POST", path: "/runtime/git/revert" }
19865
+ };
19866
+ var RestRuntimeInvoker = class {
19867
+ constructor(data, fetch, refresh) {
19868
+ this.fetch = fetch;
19869
+ this.refresh = refresh;
19870
+ this.refreshPromise = null;
19871
+ this.notebookId = data.id;
19872
+ this.configure(data.runtimeUrl ?? data.okraUrl);
19873
+ }
19874
+ configure(runtimeUrl) {
19875
+ const actionUrl = new URL(runtimeUrl);
19876
+ const ticket = actionUrl.searchParams.get("ticket") ?? "";
19877
+ if (ticket === "") {
19878
+ throw new UnsupportedRuntimeTransportError("The notebook connection does not contain a runtime ticket.");
19879
+ }
19880
+ this.ticket = ticket;
19881
+ actionUrl.protocol = actionUrl.protocol === "wss:" ? "https:" : "http:";
19882
+ actionUrl.pathname = `/api/v1/notebooks/${encodeURIComponent(this.notebookId)}`;
19883
+ actionUrl.searchParams.delete("ticket");
19884
+ actionUrl.hash = "";
19885
+ this.actionUrl = actionUrl;
19886
+ }
19887
+ ready() {
19888
+ return this.invokeRaw("runtime.ready", {}, {});
19889
+ }
19890
+ supports(action) {
19891
+ return action in restActionRoutes;
19892
+ }
19893
+ invoke(action, data = {}, options = {}) {
19894
+ return this.invokeRaw(action, data ?? {}, options);
19895
+ }
19896
+ send() {
19897
+ throw new UnsupportedRuntimeTransportError("Fire-and-forget actions require the realtime transport.");
19898
+ }
19899
+ async invokeRaw(action, data, options) {
19900
+ const abort = runtimeAbort(options);
19901
+ try {
19902
+ for (let attempt = 0; attempt < 2; attempt += 1) {
19903
+ const response = await this.fetch(this.request(action, data, abort.signal));
19904
+ if (response.status === 401 && attempt === 0 && this.refresh !== void 0) {
19905
+ await this.refreshAuthorization();
19906
+ continue;
19907
+ }
19908
+ const payload = await runtimeActionResponse(response);
19909
+ if (!response.ok || payload.error !== void 0) {
19910
+ const error51 = payload.error ?? payload;
19911
+ const message = typeof error51.message === "string" ? error51.message : `Runtime action ${action} failed.`;
19912
+ const code = typeof error51.code === "number" ? error51.code : response.status;
19913
+ throw new ErrorEvent(code, message, error51);
19914
+ }
19915
+ return payload.data;
19916
+ }
19917
+ throw new ErrorEvent(401, `Runtime action ${action} could not be authorized.`, {});
19918
+ } finally {
19919
+ abort.dispose();
19920
+ }
19921
+ }
19922
+ request(action, data, signal) {
19923
+ const route = restActionRoutes[action];
19924
+ if (route === void 0) {
19925
+ throw new UnsupportedRuntimeTransportError(`Runtime action ${action} requires the realtime transport.`);
19926
+ }
19927
+ const url2 = new URL(this.actionUrl);
19928
+ url2.pathname += route.path;
19929
+ const headers = {
19930
+ Accept: "application/json, application/octet-stream",
19931
+ Authorization: `Bearer ${this.ticket}`
19932
+ };
19933
+ const body = runtimeActionRequestBody(action, data, url2, headers);
19934
+ return new Request(url2, {
19935
+ method: route.method,
19936
+ headers,
19937
+ body: route.method === "GET" ? void 0 : body,
19938
+ signal
19939
+ });
19940
+ }
19941
+ async refreshAuthorization() {
19942
+ if (this.refreshPromise === null) {
19943
+ this.refreshPromise = this.refresh().then((runtimeUrl) => this.configure(runtimeUrl));
19944
+ }
19945
+ try {
19946
+ await this.refreshPromise;
19947
+ } finally {
19948
+ this.refreshPromise = null;
19949
+ }
19950
+ }
19951
+ };
19952
+ async function runtimeActionResponse(response) {
19953
+ if (response.ok && response.headers.get("content-type")?.toLowerCase().startsWith("application/octet-stream")) {
19954
+ return { data: new Uint8Array(await response.arrayBuffer()) };
19955
+ }
19956
+ const body = await response.text();
19957
+ if (body === "") {
19958
+ return {};
19959
+ }
19960
+ try {
19961
+ return JSON.parse(body);
19962
+ } catch {
19963
+ return { error: { code: response.status, message: body } };
19964
+ }
19965
+ }
19966
+ function runtimeActionRequestBody(action, data, url2, headers) {
19967
+ const payload = runtimeActionRecord(data);
19968
+ if (action === "fs.readFile") {
19969
+ setRequiredRuntimeQuery(url2, "path", payload.path);
19970
+ const lineRange = runtimeActionRecord(payload.lineRange);
19971
+ if (lineRange.lineStart !== void 0 || lineRange.lineEnd !== void 0) {
19972
+ setRequiredRuntimeQuery(url2, "lineStart", lineRange.lineStart);
19973
+ setRequiredRuntimeQuery(url2, "lineEnd", lineRange.lineEnd);
19974
+ }
19975
+ return void 0;
19976
+ }
19977
+ if (action === "fs.writeFile") {
19978
+ setRequiredRuntimeQuery(url2, "path", payload.path);
19979
+ const options = runtimeActionRecord(payload.options);
19980
+ setBooleanRuntimeQuery(url2, "overwrite", options.overwrite);
19981
+ setBooleanRuntimeQuery(url2, "create", options.create);
19982
+ setBooleanRuntimeQuery(url2, "unlock", options.unlock);
19983
+ const atomic = runtimeActionRecord(options.atomic);
19984
+ if (typeof atomic.postfix === "string" && atomic.postfix !== "") {
19985
+ url2.searchParams.set("atomicPostfix", atomic.postfix);
19986
+ }
19987
+ if (!ArrayBuffer.isView(payload.contents)) {
19988
+ throw new TypeError("Runtime file contents must be binary data.");
19989
+ }
19990
+ headers["Content-Type"] = "application/octet-stream";
19991
+ return Uint8Array.from(
19992
+ new Uint8Array(payload.contents.buffer, payload.contents.byteOffset, payload.contents.byteLength)
19993
+ ).buffer;
19994
+ }
19995
+ headers["Content-Type"] = "application/json";
19996
+ return JSON.stringify(data);
19997
+ }
19998
+ function runtimeActionRecord(value) {
19999
+ return value !== null && typeof value === "object" ? value : {};
20000
+ }
20001
+ function setRequiredRuntimeQuery(url2, name, value) {
20002
+ if (typeof value !== "string" && typeof value !== "number" || String(value) === "") {
20003
+ throw new TypeError(`Runtime file ${name} is required.`);
20004
+ }
20005
+ url2.searchParams.set(name, String(value));
20006
+ }
20007
+ function setBooleanRuntimeQuery(url2, name, value) {
20008
+ url2.searchParams.set(name, value === true ? "true" : "false");
20009
+ }
20010
+ function runtimeAbort(options) {
20011
+ if (options.timeout === void 0 && options.abortSignal === void 0) {
20012
+ return { signal: new AbortController().signal, dispose: () => void 0 };
20013
+ }
20014
+ const controller = new AbortController();
20015
+ const abortFromCaller = () => controller.abort(options.abortSignal?.reason);
20016
+ options.abortSignal?.addEventListener("abort", abortFromCaller, {
20017
+ once: true
20018
+ });
20019
+ if (options.abortSignal?.aborted) {
20020
+ abortFromCaller();
20021
+ }
20022
+ const timeout2 = options.timeout === void 0 ? void 0 : setTimeout(() => controller.abort(), options.timeout);
20023
+ return {
20024
+ signal: controller.signal,
20025
+ dispose: () => {
20026
+ options.abortSignal?.removeEventListener("abort", abortFromCaller);
20027
+ if (timeout2 !== void 0) {
20028
+ clearTimeout(timeout2);
20029
+ }
20030
+ }
20031
+ };
20032
+ }
20033
+
19788
20034
  // src/index.ts
19789
20035
  function normalizeNotebookSecretInputs(input) {
19790
20036
  if (Array.isArray(input)) {
@@ -19892,6 +20138,7 @@ function normalizeApiBaseUrl(url2) {
19892
20138
  }
19893
20139
  var Client2 = class {
19894
20140
  constructor(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20141
+ this.runtimeTransportValue = "realtime";
19895
20142
  this.fetch = globalThis.fetch;
19896
20143
  this.deployments = new DeploymentApi(this);
19897
20144
  this.notebook = new NotebookApi(this);
@@ -19907,6 +20154,9 @@ var Client2 = class {
19907
20154
  "Content-Type": "application/json"
19908
20155
  };
19909
20156
  }
20157
+ get runtimeTransport() {
20158
+ return this.runtimeTransportValue;
20159
+ }
19910
20160
  get(path) {
19911
20161
  return this.makeRequest("GET", path);
19912
20162
  }
@@ -19970,7 +20220,15 @@ var Client2 = class {
19970
20220
  return { data: body === "" ? void 0 : JSON.parse(body) };
19971
20221
  }
19972
20222
  };
19973
- var PHPSandbox = class extends Client2 {
20223
+ var PHPSandbox = class _PHPSandbox extends Client2 {
20224
+ static realtime(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20225
+ return new _PHPSandbox(token, url2, options);
20226
+ }
20227
+ static rest(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20228
+ const client = new _PHPSandbox(token, url2, options);
20229
+ client.runtimeTransportValue = "rest";
20230
+ return client;
20231
+ }
19974
20232
  };
19975
20233
  var NotebookSecretApi = class {
19976
20234
  constructor(client) {
@@ -20076,17 +20334,40 @@ var NotebookInstance2 = class {
20076
20334
  this.client = client;
20077
20335
  __privateAdd(this, _NotebookInstance_instances);
20078
20336
  this.initialized = false;
20079
- __privateAdd(this, _initPromise);
20337
+ __privateAdd(this, _initPromise, null);
20080
20338
  this.disposables = [];
20339
+ const runtimeUrl = data.runtimeUrl ?? data.okraUrl;
20340
+ const runtimeUrlProvider = client.options.runtimeUrlProvider ?? client.options.okraUrlProvider;
20081
20341
  this.emitter = EventManager.createInstance();
20082
- this.socket = new Transport(data.okraUrl, this.emitter, {
20083
- debug: client.options.debug,
20084
- startClosed: client.options.startClosed,
20085
- webSocket: client.options.webSocket
20086
- });
20087
- this.watchConnection();
20088
- __privateSet(this, _initPromise, __privateMethod(this, _NotebookInstance_instances, init_fn).call(this));
20089
- this.file = new Filesystem(this);
20342
+ if (client.runtimeTransport === "rest") {
20343
+ this.socket = null;
20344
+ this.restInvoker = new RestRuntimeInvoker(
20345
+ data,
20346
+ client.options.fetch ?? globalThis.fetch,
20347
+ runtimeUrlProvider === void 0 ? void 0 : () => runtimeUrlProvider(data.id)
20348
+ );
20349
+ } else {
20350
+ this.restInvoker = null;
20351
+ let initialConnection = true;
20352
+ const connectionUrl = runtimeUrlProvider === void 0 ? runtimeUrl : async () => {
20353
+ if (initialConnection) {
20354
+ initialConnection = false;
20355
+ return runtimeUrl;
20356
+ }
20357
+ return runtimeUrlProvider(data.id);
20358
+ };
20359
+ this.socket = new Transport(connectionUrl, this.emitter, {
20360
+ debug: client.options.debug,
20361
+ startClosed: client.options.startClosed,
20362
+ webSocket: client.options.webSocket
20363
+ });
20364
+ this.watchConnection();
20365
+ __privateSet(this, _initPromise, __privateMethod(this, _NotebookInstance_instances, init_fn).call(this));
20366
+ }
20367
+ this.file = new Filesystem(
20368
+ this,
20369
+ this.socket === null ? null : (handler) => this.onDidConnect(handler)
20370
+ );
20090
20371
  this.terminal = new Terminal(this);
20091
20372
  this.auth = new Auth(this);
20092
20373
  this.lsp = new Lsp(this);
@@ -20103,14 +20384,21 @@ var NotebookInstance2 = class {
20103
20384
  this.preview = new NotebookPreview(client, this.data.id);
20104
20385
  this.mail = new NotebookMail(client, this.data.id);
20105
20386
  }
20387
+ get runtimeTransport() {
20388
+ return this.client.runtimeTransport;
20389
+ }
20106
20390
  async ready() {
20107
- const terminalError = this.socket.getTerminalError();
20391
+ if (this.restInvoker !== null) {
20392
+ return this.restInitialization();
20393
+ }
20394
+ const socket = this.realtimeSocket();
20395
+ const terminalError = socket.getTerminalError();
20108
20396
  if (terminalError) {
20109
20397
  throw terminalError;
20110
20398
  }
20111
20399
  const ready = async () => {
20112
- if (this.client.options.startClosed && !this.socket.isConnected) {
20113
- await this.socket.connect();
20400
+ if (this.client.options.startClosed && !socket.isConnected) {
20401
+ await socket.connect();
20114
20402
  }
20115
20403
  return __privateGet(this, _initPromise);
20116
20404
  };
@@ -20130,7 +20418,7 @@ var NotebookInstance2 = class {
20130
20418
  }
20131
20419
  delete() {
20132
20420
  return this.client.notebook.delete(this.data.id).then(() => {
20133
- this.socket.terminate(new NotebookUnavailableError("Notebook has been deleted.", { id: this.data.id }));
20421
+ this.socket?.terminate(new NotebookUnavailableError("Notebook has been deleted.", { id: this.data.id }));
20134
20422
  });
20135
20423
  }
20136
20424
  stop() {
@@ -20140,10 +20428,19 @@ var NotebookInstance2 = class {
20140
20428
  return this.container.restart();
20141
20429
  }
20142
20430
  invoke(action, data = {}, options = {}) {
20143
- return this.socket.invoke(action, data || {}, options);
20431
+ if (this.restInvoker !== null) {
20432
+ if (this.restInvoker.supports(String(action))) {
20433
+ void this.restInitialization();
20434
+ }
20435
+ return this.restInvoker.invoke(action, data || {}, options);
20436
+ }
20437
+ return this.realtimeSocket().invoke(action, data || {}, options);
20144
20438
  }
20145
20439
  send(action, data = {}) {
20146
- return this.socket.send(action, data || {});
20440
+ if (this.restInvoker !== null) {
20441
+ return this.restInvoker.send();
20442
+ }
20443
+ return this.realtimeSocket().send(action, data || {});
20147
20444
  }
20148
20445
  ping() {
20149
20446
  return this.invoke("ping");
@@ -20155,7 +20452,9 @@ var NotebookInstance2 = class {
20155
20452
  }
20156
20453
  dispose() {
20157
20454
  this.disposables.forEach((d) => d.dispose());
20158
- !this.socket.isClosed && this.socket.disconnect();
20455
+ if (this.socket !== null && !this.socket.isClosed) {
20456
+ this.socket.disconnect();
20457
+ }
20159
20458
  }
20160
20459
  connected() {
20161
20460
  return this.waitForSocketConnection({ rejectOnClose: true });
@@ -20164,11 +20463,12 @@ var NotebookInstance2 = class {
20164
20463
  return this.waitForSocketConnection({ rejectOnClose: false });
20165
20464
  }
20166
20465
  waitForSocketConnection(options) {
20167
- const terminalError = this.socket.getTerminalError();
20466
+ const socket = this.realtimeSocket();
20467
+ const terminalError = socket.getTerminalError();
20168
20468
  if (terminalError) {
20169
20469
  return Promise.reject(terminalError);
20170
20470
  }
20171
- if (this.socket.isConnected) {
20471
+ if (socket.isConnected) {
20172
20472
  return Promise.resolve(this);
20173
20473
  }
20174
20474
  return new Promise((resolve, reject) => {
@@ -20189,49 +20489,66 @@ var NotebookInstance2 = class {
20189
20489
  callback();
20190
20490
  };
20191
20491
  try {
20192
- disposables.push(this.socket.onDidConnect(() => settle(() => resolve(this))));
20492
+ disposables.push(socket.onDidConnect(() => settle(() => resolve(this))));
20193
20493
  if (options.rejectOnClose) {
20194
- disposables.push(this.socket.onDidClose(() => settle(() => reject(new Error("Connection closed")))));
20494
+ disposables.push(socket.onDidClose(() => settle(() => reject(new Error("Connection closed")))));
20195
20495
  }
20196
- disposables.push(this.socket.onDidBootError((error51) => settle(() => reject(error51))));
20496
+ disposables.push(socket.onDidBootError((error51) => settle(() => reject(error51))));
20197
20497
  } catch (e) {
20198
20498
  settle(() => reject(e));
20199
20499
  }
20200
20500
  });
20201
20501
  }
20202
20502
  watchConnection() {
20203
- this.socket.onDidConnect(() => {
20204
- this.socket.emit("okra.connected");
20503
+ const socket = this.realtimeSocket();
20504
+ socket.onDidConnect(() => {
20505
+ socket.emit("okra.connected");
20205
20506
  if (this.client.options.telemetry) {
20206
20507
  this.container.enableTelemetry(this.client.options.telemetry);
20207
20508
  }
20208
20509
  });
20209
- this.socket.onDidClose(() => {
20210
- this.socket.emit("okra.disconnected");
20510
+ socket.onDidClose(() => {
20511
+ socket.emit("okra.disconnected");
20211
20512
  this.initialized = false;
20212
20513
  });
20213
- this.socket.onDidBootError((error51) => {
20214
- this.socket.emit("okra.boot_error", error51);
20215
- this.socket.emit("okra.disconnected");
20514
+ socket.onDidBootError((error51) => {
20515
+ socket.emit("okra.boot_error", error51);
20516
+ socket.emit("okra.disconnected");
20216
20517
  this.initialized = false;
20217
20518
  });
20218
20519
  }
20219
20520
  onDidConnect(handler) {
20220
- this.socket.removeListener("okra.connected", handler);
20221
- const disposable = this.socket.listen("okra.connected", handler);
20521
+ const socket = this.realtimeSocket();
20522
+ socket.removeListener("okra.connected", handler);
20523
+ const disposable = socket.listen("okra.connected", handler);
20222
20524
  this.disposables.push(disposable);
20223
20525
  return disposable;
20224
20526
  }
20225
20527
  onDidDisconnect(handler) {
20226
- const disposable = this.socket.listen("okra.disconnected", handler);
20528
+ const disposable = this.realtimeSocket().listen("okra.disconnected", handler);
20227
20529
  this.disposables.push(disposable);
20228
20530
  return disposable;
20229
20531
  }
20230
20532
  onDidBootError(handler) {
20231
- const disposable = this.socket.listen("okra.boot_error", handler);
20533
+ const disposable = this.realtimeSocket().listen("okra.boot_error", handler);
20232
20534
  this.disposables.push(disposable);
20233
20535
  return disposable;
20234
20536
  }
20537
+ restInitialization() {
20538
+ if (this.restInvoker === null) {
20539
+ throw new UnsupportedRuntimeTransportError("This operation requires the REST transport.");
20540
+ }
20541
+ if (__privateGet(this, _initPromise) === null) {
20542
+ __privateSet(this, _initPromise, this.restInvoker.ready().then((result) => {
20543
+ this.initialized = result;
20544
+ this.emitter.emit("notebook.initialized", result);
20545
+ return result;
20546
+ }));
20547
+ void __privateGet(this, _initPromise).catch(() => {
20548
+ });
20549
+ }
20550
+ return __privateGet(this, _initPromise);
20551
+ }
20235
20552
  update(input) {
20236
20553
  return this.client.notebook.update(this.data.id, input);
20237
20554
  }
@@ -20239,8 +20556,9 @@ var NotebookInstance2 = class {
20239
20556
  return this.listen("notebook.initialized", handler);
20240
20557
  }
20241
20558
  async reconnect() {
20559
+ const socket = this.realtimeSocket();
20242
20560
  const whenConnected = this.whenConnected();
20243
- this.socket.reconnect();
20561
+ socket.reconnect();
20244
20562
  this.initialized = false;
20245
20563
  await whenConnected;
20246
20564
  __privateMethod(this, _NotebookInstance_instances, init_fn).call(this);
@@ -20251,6 +20569,12 @@ var NotebookInstance2 = class {
20251
20569
  iframe.src = result.data.previewUrl;
20252
20570
  return createBeacon(iframe, options);
20253
20571
  }
20572
+ realtimeSocket() {
20573
+ if (this.socket === null) {
20574
+ throw new UnsupportedRuntimeTransportError("This operation requires the realtime transport.");
20575
+ }
20576
+ return this.socket;
20577
+ }
20254
20578
  };
20255
20579
  _initPromise = new WeakMap();
20256
20580
  _NotebookInstance_instances = new WeakSet();
@@ -20431,6 +20755,7 @@ export {
20431
20755
  ServerApi,
20432
20756
  ServerInstance,
20433
20757
  Transport,
20758
+ UnsupportedRuntimeTransportError,
20434
20759
  createBeacon,
20435
20760
  isBeaconSupported,
20436
20761
  notebookBuiltinServices,