Server Test Typescript

Server Test Typescript

rev. dfb5149b65b7bcc09edd15b8e071ad43b5ac5943 (ignoring whitespace)

Files changed:

tmp-codegen-diff/codegen-server-test-typescript/simple/rust-server-codegen-typescript/src/service.rs

@@ -1,1 +31,32 @@
    1      1   
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
/* ServerServiceGenerator.kt:795 */
    2      3   
/// The service builder for [`SimpleService`].
    3      4   
///
    4      5   
/// Constructed via [`SimpleService::builder`].
    5      6   
pub struct SimpleServiceBuilder<Body, L, HttpPl, ModelPl> {
    6      7   
    operation: Option<::aws_smithy_http_server::routing::Route<Body>>,
    7      8   
    layer: L,
    8      9   
    http_plugin: HttpPl,
    9     10   
    model_plugin: ModelPl,
   10     11   
}
   11     12   
@@ -475,476 +534,536 @@
  495    496   
            "com.amazonaws.simple",
  496    497   
            "SimpleService",
  497    498   
        );
  498    499   
  499    500   
    const VERSION: Option<&'static str> = Some("");
  500    501   
  501    502   
    type Protocol = ::aws_smithy_http_server::protocol::rest_json_1::RestJson1;
  502    503   
  503    504   
    type Operations = Operation;
  504    505   
}
         506  +
/* ServiceConfigGenerator.kt:178 */
  505    507   
/// Configuration for the [`SimpleService`]. This is the central place where to register and
  506    508   
/// configure [`::tower::Layer`]s, HTTP plugins, and model plugins.
  507    509   
///
  508    510   
/// ```rust,no_run
  509    511   
/// # use simple::SimpleServiceConfig;
  510    512   
/// # use ::aws_smithy_http_server::plugin::IdentityPlugin;
  511    513   
/// # use ::tower::layer::util::Identity;
  512    514   
/// # let authentication_plugin = IdentityPlugin;
  513    515   
/// # let authorization_plugin = IdentityPlugin;
  514    516   
/// # let server_request_id_provider_layer = Identity::new();
@@ -590,592 +649,652 @@
  610    612   
  611    613   
    /// Build the configuration.
  612    614   
    pub fn build(self) -> super::SimpleServiceConfig<L, H, M> {
  613    615   
        super::SimpleServiceConfig {
  614    616   
            layers: self.layers,
  615    617   
            http_plugins: self.http_plugins,
  616    618   
            model_plugins: self.model_plugins,
  617    619   
        }
  618    620   
    }
  619    621   
}
         622  +
/* ScopeMacroGenerator.kt:81 */
  620    623   
/// A macro to help with scoping [plugins](crate::server::plugin) to a subset of all operations.
  621    624   
///
  622    625   
/// In contrast to [`crate::server::scope`](crate::server::scope), this macro has knowledge
  623    626   
/// of the service and any operations _not_ specified will be placed in the opposing group.
  624    627   
///
  625    628   
/// # Example
  626    629   
///
  627    630   
/// ```rust
  628    631   
/// scope! {
  629    632   
///     /// Includes [`Operation`], excluding all other operations.

tmp-codegen-diff/codegen-server-test-typescript/simple/rust-server-codegen-typescript/src/ts_operation_adaptor.rs

@@ -1,1 +13,14 @@
    1      1   
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
/* TsServerOperationHandlerGenerator.kt:45 */
    2      3   
/// Typescript handler for operation `Operation`.
    3      4   
pub(crate) async fn operation(
    4      5   
    input: crate::input::OperationInput,
    5      6   
    handlers: ::aws_smithy_http_server::Extension<crate::ts_server_application::Handlers>,
    6      7   
) -> std::result::Result<crate::output::OperationOutput, crate::error::OperationError> {
    7      8   
    handlers
    8      9   
        .operation
    9     10   
        .call_async::<::napi::bindgen_prelude::Promise<crate::output::OperationOutput>>(input)
   10     11   
        .await?
   11     12   
        .await

tmp-codegen-diff/codegen-server-test-typescript/simple/rust-server-codegen-typescript/src/ts_server_application.rs

@@ -1,1 +131,184 @@
    1      1   
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
/* TsApplicationGenerator.kt:62 */
    2      3   
use napi_derive::napi;
           4  +
/* RustType.kt:516 */
    3      5   
#[derive(::std::clone::Clone)]
           6  +
/* TsApplicationGenerator.kt:73 */
    4      7   
pub struct Handlers {
           8  +
    /* TsApplicationGenerator.kt:78 */
    5      9   
    pub(crate) operation: ::napi::threadsafe_function::ThreadsafeFunction<
    6     10   
        crate::input::OperationInput,
    7     11   
        ::napi::threadsafe_function::ErrorStrategy::Fatal,
    8     12   
    >,
          13  +
    /* TsApplicationGenerator.kt:73 */
    9     14   
}
          15  +
/* RustType.kt:516 */
   10     16   
#[napi(object)]
          17  +
/* TsApplicationGenerator.kt:90 */
   11     18   
pub struct TsHandlers {
          19  +
    /* TsApplicationGenerator.kt:96 */
   12     20   
    #[napi(ts_type = "(input: OperationInput) => Promise<OperationOutput>")]
   13     21   
    pub operation: ::napi::JsFunction,
          22  +
    /* TsApplicationGenerator.kt:90 */
   14     23   
}
          24  +
/* RustType.kt:516 */
   15     25   
#[napi]
          26  +
/* TsApplicationGenerator.kt:109 */
   16     27   
pub struct App {
   17     28   
    handlers: Handlers,
   18     29   
}
          30  +
/* RustType.kt:516 */
   19     31   
#[napi]
          32  +
/* TsApplicationGenerator.kt:117 */
   20     33   
impl App {
          34  +
    /* RustType.kt:516 */
   21     35   
    #[napi(constructor)]
          36  +
    /* TsApplicationGenerator.kt:125 */
   22     37   
    pub fn create(ts_handlers: TsHandlers) -> ::napi::Result<Self> {
          38  +
        /* TsApplicationGenerator.kt:133 */
   23     39   
        let operation: ::napi::threadsafe_function::ThreadsafeFunction<
   24     40   
            crate::input::OperationInput,
   25     41   
            ::napi::threadsafe_function::ErrorStrategy::Fatal,
   26     42   
        > = ts_handlers
   27     43   
            .operation
   28     44   
            .create_threadsafe_function(0, |ctx| Ok(vec![ctx.value]))?;
          45  +
        /* TsApplicationGenerator.kt:142 */
   29     46   
        let handlers = Handlers {
          47  +
            /* TsApplicationGenerator.kt:145 */
   30     48   
            operation: operation.clone(),
          49  +
            /* TsApplicationGenerator.kt:147 */
   31     50   
        };
          51  +
        /* TsApplicationGenerator.kt:148 */
   32     52   
        Ok(Self { handlers })
          53  +
        /* TsApplicationGenerator.kt:125 */
   33     54   
    }
          55  +
    /* RustType.kt:516 */
   34     56   
    #[napi]
          57  +
    /* TsApplicationGenerator.kt:154 */
   35     58   
    pub fn start(&self, socket: &TsSocket) -> ::napi::Result<()> {
          59  +
        /* TsApplicationGenerator.kt:158 */
   36     60   
        let plugins = ::aws_smithy_http_server::plugin::PluginPipeline::new();
   37     61   
        let builder = crate::service::SimpleService::builder_with_plugins(plugins);
          62  +
        /* TsApplicationGenerator.kt:167 */
   38     63   
        let builder = builder.operation(crate::ts_operation_adaptor::operation);
          64  +
        /* TsApplicationGenerator.kt:169 */
   39     65   
        let app = builder
   40     66   
            .build()
   41     67   
            .expect("failed to build instance of SimpleService")
   42     68   
            .layer(&::aws_smithy_http_server::AddExtensionLayer::new(
   43     69   
                self.handlers.clone(),
   44     70   
            ));
   45     71   
        let service = ::tower::util::BoxCloneService::new(app);
   46     72   
        start_hyper_worker(socket, service).expect("failed to start the hyper server");
   47     73   
        Ok(())
          74  +
        /* TsApplicationGenerator.kt:154 */
   48     75   
    }
          76  +
    /* TsApplicationGenerator.kt:117 */
   49     77   
}
          78  +
/* RustType.kt:516 */
   50     79   
#[napi]
          80  +
/* RustType.kt:516 */
   51     81   
#[derive(::std::fmt::Debug)]
          82  +
/* TsApplicationGenerator.kt:185 */
   52     83   
pub struct TsSocket(::socket2::Socket);
          84  +
/* RustType.kt:516 */
   53     85   
#[napi]
          86  +
/* TsApplicationGenerator.kt:193 */
   54     87   
impl TsSocket {
          88  +
    /* TsApplicationGenerator.kt:194 */
   55     89   
    /// Create a new UNIX `Socket` from an address, port and backlog.
   56     90   
    /// If not specified, the backlog defaults to 1024 connections.
          91  +
    /* RustType.kt:516 */
   57     92   
    #[napi(constructor)]
          93  +
    /* TsApplicationGenerator.kt:201 */
   58     94   
    pub fn new(address: String, port: i32, backlog: Option<i32>) -> ::napi::Result<Self> {
          95  +
        /* TsApplicationGenerator.kt:205 */
   59     96   
        let socket = Self::new_socket(address, port, backlog)
   60     97   
            .map_err(|e| ::napi::Error::from_reason(e.to_string()))?;
   61     98   
        Ok(Self(socket))
          99  +
        /* TsApplicationGenerator.kt:201 */
   62    100   
    }
         101  +
    /* TsApplicationGenerator.kt:214 */
   63    102   
    pub fn new_socket(
   64    103   
        address: String,
   65    104   
        port: i32,
   66    105   
        backlog: Option<i32>,
   67    106   
    ) -> Result<::socket2::Socket, Box<dyn std::error::Error>> {
         107  +
        /* TsApplicationGenerator.kt:218 */
   68    108   
        let address: std::net::SocketAddr = format!("{}:{}", address, port).parse()?;
   69    109   
        let domain = if address.is_ipv6() {
   70    110   
            ::socket2::Domain::IPV6
   71    111   
        } else {
   72    112   
            ::socket2::Domain::IPV4
   73    113   
        };
   74    114   
        let socket = ::socket2::Socket::new(
   75    115   
            domain,
   76    116   
            ::socket2::Type::STREAM,
   77    117   
            Some(::socket2::Protocol::TCP),
   78    118   
        )?;
   79    119   
        // Set value for the `SO_REUSEPORT` and `SO_REUSEADDR` options on this socket.
   80    120   
        // This indicates that further calls to `bind` may allow reuse of local
   81    121   
        // addresses. For IPv4 sockets this means that a socket may bind even when
   82    122   
        // there's a socket already listening on this port.
   83    123   
        socket.set_reuse_port(true)?;
   84    124   
        socket.set_reuse_address(true)?;
   85    125   
        socket.bind(&address.into())?;
   86    126   
        socket.listen(backlog.unwrap_or(1024))?;
   87    127   
        Ok(socket)
         128  +
        /* TsApplicationGenerator.kt:214 */
   88    129   
    }
         130  +
    /* TsApplicationGenerator.kt:241 */
   89    131   
    /// Clone the inner socket allowing it to be shared between multiple
   90    132   
    /// Nodejs processes.
         133  +
    /* RustType.kt:516 */
   91    134   
    #[napi]
         135  +
    /* TsApplicationGenerator.kt:248 */
   92    136   
    pub fn try_clone(&self) -> ::napi::Result<Self> {
         137  +
        /* TsApplicationGenerator.kt:252 */
   93    138   
        Ok(TsSocket(
   94    139   
            self.0
   95    140   
                .try_clone()
   96    141   
                .map_err(|e| ::napi::Error::from_reason(e.to_string()))?,
   97    142   
        ))
         143  +
        /* TsApplicationGenerator.kt:248 */
   98    144   
    }
         145  +
    /* TsApplicationGenerator.kt:193 */
   99    146   
}
         147  +
/* TsApplicationGenerator.kt:265 */
  100    148   
impl TsSocket {
         149  +
    /* TsApplicationGenerator.kt:266 */
  101    150   
    pub fn to_raw_socket(&self) -> ::napi::Result<::socket2::Socket> {
  102    151   
        self.0
  103    152   
            .try_clone()
  104    153   
            .map_err(|e| ::napi::Error::from_reason(e.to_string()))
  105    154   
    }
         155  +
    /* TsApplicationGenerator.kt:265 */
  106    156   
}
         157  +
/* TsApplicationGenerator.kt:281 */
  107    158   
pub fn start_hyper_worker(
  108    159   
    socket: &TsSocket,
  109    160   
    app: ::tower::util::BoxCloneService<
  110    161   
        ::http::Request<::aws_smithy_http_server::body::Body>,
  111    162   
        ::http::Response<::aws_smithy_http_server::body::BoxBody>,
  112    163   
        std::convert::Infallible,
  113    164   
    >,
  114    165   
) -> ::napi::Result<()> {
         166  +
    /* TsApplicationGenerator.kt:294 */
  115    167   
    let server = ::hyper::Server::from_tcp(
  116    168   
        socket
  117    169   
            .to_raw_socket()?
  118    170   
            .try_into()
  119    171   
            .expect("Unable to convert socket2::Socket into std::net::TcpListener"),
  120    172   
    )
  121    173   
    .expect("Unable to create hyper server from shared socket")
  122    174   
    .serve(::aws_smithy_http_server::routing::IntoMakeService::new(app));
  123    175   
  124    176   
    let handle = ::tokio::runtime::Handle::current();
  125    177   
    handle.spawn(async move {
  126    178   
        // Process each socket concurrently.
  127    179   
        server.await
  128    180   
    });
  129    181   
  130    182   
    Ok(())
         183  +
    /* TsApplicationGenerator.kt:281 */
  131    184   
}

tmp-codegen-diff/codegen-server-test-typescript/simple/rust-server-codegen-typescript/src/types.rs

@@ -1,1 +0,7 @@
    1      1   
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
/* SmithyTypesPubUseExtra.kt:66 */
    2      3   
pub use ::aws_smithy_types::date_time::Format as DateTimeFormat;
           4  +
/* ServerRequiredCustomizations.kt:69 */
    3      5   
pub use ::aws_smithy_types::error::display::DisplayErrorContext;
    4      6   
pub use ::aws_smithy_types::Blob;
    5         -
pub use ::aws_smithy_types::DateTime;
           7  +
/* SmithyTypesPubUseExtra.kt:69 */ pub use ::aws_smithy_types::DateTime;