import { CancelledError, RestateError, RetryableError, TerminalError, TimeoutError } from "./types/errors.js";
import { isRestatePromise } from "./promises.js";
import { InvocationIdParser, RestatePromise } from "./context.js";
import { Opts, SendOpts, handlers, object, rpc, service, workflow } from "./types/rpc.js";
import { internal_exports } from "./internal.js";
import { CombineablePromise, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, serde } from "./common_api.js";
import { withOptions } from "./endpoint/withOptions.js";
import { NodeEndpoint } from "./endpoint/node_endpoint.js";

//#region src/node.ts
/**
* Create a new {@link RestateEndpoint}.
* @deprecated Please use {@link createEndpointHandler}
*/
function endpoint() {
	return new NodeEndpoint();
}
/**
* Creates a request handler for the provided services.
*
* The returned handler auto-detects the HTTP protocol version per request:
* - HTTP/2+ requests use bidirectional streaming (`BIDI_STREAM`)
* - HTTP/1.1 requests use request-response mode (`REQUEST_RESPONSE`) by default
*
* Set `bidirectional: true` to force `BIDI_STREAM` for all requests, or
* `bidirectional: false` to force `REQUEST_RESPONSE` for all requests.
*
* @example HTTP/2 server
* ```
* const httpServer = http2.createServer(createEndpointHandler({ services: [myService] }));
* httpServer.listen(port);
* ```
*
* @example HTTP/1.1 server
* ```
* const httpServer = http.createServer(createEndpointHandler({ services: [myService] }));
* httpServer.listen(port);
* ```
*
* @param {NodeEndpointOptions} options - Configuration options for the endpoint handler.
* @returns A request handler function compatible with both HTTP/1.1 and HTTP/2 servers.
*/
function createEndpointHandler(options) {
	const { bidirectional,...endpointOptions } = options;
	return withOptions(new NodeEndpoint(), endpointOptions).handler({ bidirectional });
}
/**
* Serves this Restate services as HTTP2 server, listening to the given port.
*
* If the port is undefined, this method will use the port set in the `PORT`
* environment variable. If that variable is undefined as well, the method will
* default to port 9080.
*
* The returned promise resolves with the bound port when the server starts listening, or rejects with a failure otherwise.
*
* If you need to manually control the server lifecycle, we suggest to manually instantiate the http2 server and use {@link createEndpointHandler}.
*
* @param {ServeOptions} options - Configuration options for the endpoint handler.
* @returns a Promise that resolves with the bound port, or rejects with a failure otherwise.
*/
function serve({ port,...options }) {
	return withOptions(new NodeEndpoint(), options).listen(port);
}

//#endregion
export { CancelledError, CombineablePromise, InvocationIdParser, Opts, RestateError, RestatePromise, RetryableError, SendOpts, TerminalError, TimeoutError, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_exports as internal, isRestatePromise, object, rpc, serde, serve, service, workflow };
//# sourceMappingURL=node.js.map