"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var OnlineServerInteraction_exports = {};
__export(OnlineServerInteraction_exports, {
  OnlineServerInteraction: () => OnlineServerInteraction
});
module.exports = __toCommonJS(OnlineServerInteraction_exports);
var import_RemoteActorContext = require("#behavior/context/server/RemoteActorContext.js");
var import_general = require("#general");
var import_protocol = require("#protocol");
class OnlineServerInteraction {
  #interaction;
  constructor(node) {
    this.#interaction = new import_protocol.ServerInteraction(node);
  }
  async *read(request, context) {
    const session = (0, import_RemoteActorContext.RemoteActorContext)(context).beginReadOnly();
    try {
      for await (const report of this.#interaction.read(request, session)) {
        yield report;
      }
    } finally {
      session[Symbol.dispose]();
    }
  }
  subscribe(_request, _context) {
    throw new import_general.NotImplementedError("subscribe not implemented");
  }
  async write(request, context) {
    return (0, import_RemoteActorContext.RemoteActorContext)(context).act((session) => this.#interaction.write(request, session));
  }
  async *invoke(request, context) {
    const session = (0, import_RemoteActorContext.RemoteActorContext)({ ...context, command: true }).open();
    try {
      for await (const chunk of this.#interaction.invoke(request, session)) {
        yield chunk;
      }
    } catch (error) {
      await session.reject(error);
    }
    return session.resolve(void 0);
  }
}
//# sourceMappingURL=OnlineServerInteraction.js.map
