@arrirpc/codegen-rust 0.54.0 → 0.55.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +77 -34
- package/dist/index.mjs +77 -34
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
@@ -1544,15 +1544,7 @@ function rustRpcFromSchema(schema, context) {
|
|
1544
1544
|
}
|
1545
1545
|
}
|
1546
1546
|
function rustHttpRpcFromSchema(schema, context) {
|
1547
|
-
if (schema.isEventStream) {
|
1548
|
-
console.warn(
|
1549
|
-
`[rust-codegen] SSE is not supported at this time. Skipping ${context.instancePath}.`
|
1550
|
-
);
|
1551
|
-
return "";
|
1552
|
-
}
|
1553
1547
|
const functionName = getFunctionName(context.instancePath);
|
1554
|
-
const params = schema.params ? validRustName(schema.params) : void 0;
|
1555
|
-
const response = schema.response ? validRustName(schema.response) : void 0;
|
1556
1548
|
let leading = "";
|
1557
1549
|
if (schema.description) {
|
1558
1550
|
leading += formatDescriptionComment(schema.description);
|
@@ -1561,16 +1553,44 @@ function rustHttpRpcFromSchema(schema, context) {
|
|
1561
1553
|
if (schema.isDeprecated) {
|
1562
1554
|
leading += "#[deprecated]\n";
|
1563
1555
|
}
|
1564
|
-
|
1565
|
-
|
1556
|
+
const params = schema.params ? validRustName(schema.params) : void 0;
|
1557
|
+
const response = schema.response ? validRustName(schema.response) : void 0;
|
1558
|
+
if (schema.isEventStream) {
|
1559
|
+
return `${leading}pub async fn ${functionName}<OnEvent>(
|
1560
|
+
&self,
|
1561
|
+
${params ? `params: ${context.typeNamePrefix}${params},` : ""}
|
1562
|
+
on_event: &mut OnEvent,
|
1563
|
+
max_retry_count: Option<u64>,
|
1564
|
+
max_retry_interval: Option<u64>,
|
1565
|
+
) where
|
1566
|
+
OnEvent: FnMut(SseEvent<${response ? `${context.typeNamePrefix}${response}` : "EmptyArriModel"}>, &mut SseController) + std::marker::Send + std::marker::Sync,
|
1567
|
+
{
|
1568
|
+
parsed_arri_sse_request(
|
1569
|
+
ArriParsedSseRequestOptions {
|
1570
|
+
client: &self._config.http_client,
|
1571
|
+
url: format!("{}${schema.path}", &self._config.base_url),
|
1572
|
+
method: reqwest::Method::${schema.method.toUpperCase()},
|
1573
|
+
headers: self._config.headers.clone(),
|
1574
|
+
client_version: "${context.clientVersion}".to_string(),
|
1575
|
+
max_retry_count,
|
1576
|
+
max_retry_interval,
|
1577
|
+
},
|
1578
|
+
${params ? `Some(params)` : "None::<EmptyArriModel>"},
|
1579
|
+
on_event,
|
1580
|
+
)
|
1581
|
+
.await;
|
1582
|
+
}`;
|
1583
|
+
}
|
1584
|
+
return `${leading}pub async fn ${functionName}(
|
1585
|
+
&self,
|
1566
1586
|
${params ? `params: ${context.typeNamePrefix}${params},` : ""}
|
1567
1587
|
) -> Result<${context.typeNamePrefix}${response ?? "()"}, ArriServerError> {
|
1568
1588
|
parsed_arri_request(
|
1569
1589
|
ArriParsedRequestOptions {
|
1570
|
-
http_client: &self.
|
1571
|
-
url: format!("{}${schema.path}", &self.
|
1590
|
+
http_client: &self._config.http_client,
|
1591
|
+
url: format!("{}${schema.path}", &self._config.base_url),
|
1572
1592
|
method: reqwest::Method::${schema.method.toUpperCase()},
|
1573
|
-
headers: self.
|
1593
|
+
headers: self._config.headers.clone(),
|
1574
1594
|
client_version: "${context.clientVersion}".to_string(),
|
1575
1595
|
},
|
1576
1596
|
${params ? `Some(params)` : "None::<EmptyArriModel>"},
|
@@ -1637,23 +1657,30 @@ function rustServiceFromSchema(schema, context) {
|
|
1637
1657
|
`[rust-codegen] Invalid schema at /procedures/${context.instancePath}.`
|
1638
1658
|
);
|
1639
1659
|
}
|
1660
|
+
const paramSuffix = subServices.length > 0 ? ".clone()" : "";
|
1640
1661
|
return {
|
1641
1662
|
name: serviceName,
|
1642
|
-
content:
|
1643
|
-
|
1644
|
-
|
1663
|
+
content: `#[derive(Clone)]
|
1664
|
+
pub struct ${serviceName} {
|
1665
|
+
_config: InternalArriClientConfig,
|
1666
|
+
${subServices.map((service) => ` pub ${service.key}: ${service.name},`).join("\n")}
|
1645
1667
|
}
|
1646
1668
|
|
1647
|
-
impl
|
1648
|
-
fn create(config:
|
1669
|
+
impl ArriClientService for ${serviceName} {
|
1670
|
+
fn create(config: ArriClientConfig) -> Self {
|
1649
1671
|
Self {
|
1650
|
-
|
1651
|
-
${subServices.map((service) => ` ${service.key}: ${service.name}::create(config),`).join("\n")}
|
1672
|
+
_config: InternalArriClientConfig::from(config${paramSuffix}),
|
1673
|
+
${subServices.map((service, index) => ` ${service.key}: ${service.name}::create(config${index === subServices.length - 1 ? "" : ".clone()"}),`).join("\n")}
|
1652
1674
|
}
|
1653
1675
|
}
|
1676
|
+
fn update_headers(&self, headers: HashMap<&'static str, String>) {
|
1677
|
+
let mut unwrapped_headers = self._config.headers.write().unwrap();
|
1678
|
+
*unwrapped_headers = headers.clone();
|
1679
|
+
${subServices.map((service, index) => ` self.${service.key}.update_headers(headers${index === subServices.length - 1 ? "" : ".clone()"});`).join("\n")}
|
1680
|
+
}
|
1654
1681
|
}
|
1655
1682
|
|
1656
|
-
impl ${serviceName}
|
1683
|
+
impl ${serviceName} {
|
1657
1684
|
${rpcParts.join("\n")}
|
1658
1685
|
}
|
1659
1686
|
|
@@ -1892,35 +1919,51 @@ use arri_client::{
|
|
1892
1919
|
utils::{serialize_date_time, serialize_string},
|
1893
1920
|
ArriEnum, ArriModel,
|
1894
1921
|
};
|
1895
|
-
use std::collections::BTreeMap;
|
1922
|
+
use std::collections::{BTreeMap, HashMap};
|
1896
1923
|
${modelParts.join("\n\n")}`;
|
1897
1924
|
}
|
1898
1925
|
const clientName = validRustName(context.clientName);
|
1899
|
-
|
1926
|
+
const paramSuffix = subServices.length > 0 ? ".clone()" : "";
|
1927
|
+
return `#![allow(
|
1928
|
+
dead_code,
|
1929
|
+
unused_imports,
|
1930
|
+
unused_variables,
|
1931
|
+
unconditional_recursion,
|
1932
|
+
deprecated
|
1933
|
+
)]
|
1900
1934
|
use arri_client::{
|
1901
1935
|
chrono::{DateTime, FixedOffset},
|
1902
|
-
parsed_arri_request,
|
1936
|
+
parsed_arri_request,
|
1937
|
+
reqwest::{self, Request},
|
1938
|
+
serde_json::{self, Map},
|
1939
|
+
sse::{parsed_arri_sse_request, ArriParsedSseRequestOptions, SseController, SseEvent},
|
1903
1940
|
utils::{serialize_date_time, serialize_string},
|
1904
1941
|
ArriClientConfig, ArriClientService, ArriEnum, ArriModel, ArriParsedRequestOptions,
|
1905
|
-
ArriServerError, EmptyArriModel,
|
1942
|
+
ArriServerError, EmptyArriModel, InternalArriClientConfig,
|
1906
1943
|
};
|
1907
|
-
use std::collections::BTreeMap;
|
1944
|
+
use std::collections::{BTreeMap, HashMap};
|
1908
1945
|
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1946
|
+
#[derive(Clone)]
|
1947
|
+
pub struct ${clientName} {
|
1948
|
+
_config: InternalArriClientConfig,
|
1949
|
+
${subServices.map((service) => ` pub ${service.key}: ${service.name},`).join("\n")}
|
1912
1950
|
}
|
1913
1951
|
|
1914
|
-
impl
|
1915
|
-
fn create(config:
|
1952
|
+
impl ArriClientService for ${clientName} {
|
1953
|
+
fn create(config: ArriClientConfig) -> Self {
|
1916
1954
|
Self {
|
1917
|
-
|
1918
|
-
${subServices.map((service) => ` ${service.key}: ${service.name}::create(config),`).join("\n")}
|
1955
|
+
_config: InternalArriClientConfig::from(config${paramSuffix}),
|
1956
|
+
${subServices.map((service, index) => ` ${service.key}: ${service.name}::create(config${index === subServices.length - 1 ? "" : ".clone()"}),`).join("\n")}
|
1919
1957
|
}
|
1920
1958
|
}
|
1959
|
+
fn update_headers(&self, headers: HashMap<&'static str, String>) {
|
1960
|
+
let mut unwrapped_headers = self._config.headers.write().unwrap();
|
1961
|
+
*unwrapped_headers = headers.clone();
|
1962
|
+
${subServices.map((service, index) => ` self.${service.key}.update_headers(headers${index === subServices.length - 1 ? "" : ".clone()"});`).join("\n")}
|
1963
|
+
}
|
1921
1964
|
}
|
1922
1965
|
|
1923
|
-
impl ${clientName}
|
1966
|
+
impl ${clientName} {
|
1924
1967
|
${rpcParts.join("\n")}
|
1925
1968
|
}
|
1926
1969
|
|
package/dist/index.mjs
CHANGED
@@ -1536,15 +1536,7 @@ function rustRpcFromSchema(schema, context) {
|
|
1536
1536
|
}
|
1537
1537
|
}
|
1538
1538
|
function rustHttpRpcFromSchema(schema, context) {
|
1539
|
-
if (schema.isEventStream) {
|
1540
|
-
console.warn(
|
1541
|
-
`[rust-codegen] SSE is not supported at this time. Skipping ${context.instancePath}.`
|
1542
|
-
);
|
1543
|
-
return "";
|
1544
|
-
}
|
1545
1539
|
const functionName = getFunctionName(context.instancePath);
|
1546
|
-
const params = schema.params ? validRustName(schema.params) : void 0;
|
1547
|
-
const response = schema.response ? validRustName(schema.response) : void 0;
|
1548
1540
|
let leading = "";
|
1549
1541
|
if (schema.description) {
|
1550
1542
|
leading += formatDescriptionComment(schema.description);
|
@@ -1553,16 +1545,44 @@ function rustHttpRpcFromSchema(schema, context) {
|
|
1553
1545
|
if (schema.isDeprecated) {
|
1554
1546
|
leading += "#[deprecated]\n";
|
1555
1547
|
}
|
1556
|
-
|
1557
|
-
|
1548
|
+
const params = schema.params ? validRustName(schema.params) : void 0;
|
1549
|
+
const response = schema.response ? validRustName(schema.response) : void 0;
|
1550
|
+
if (schema.isEventStream) {
|
1551
|
+
return `${leading}pub async fn ${functionName}<OnEvent>(
|
1552
|
+
&self,
|
1553
|
+
${params ? `params: ${context.typeNamePrefix}${params},` : ""}
|
1554
|
+
on_event: &mut OnEvent,
|
1555
|
+
max_retry_count: Option<u64>,
|
1556
|
+
max_retry_interval: Option<u64>,
|
1557
|
+
) where
|
1558
|
+
OnEvent: FnMut(SseEvent<${response ? `${context.typeNamePrefix}${response}` : "EmptyArriModel"}>, &mut SseController) + std::marker::Send + std::marker::Sync,
|
1559
|
+
{
|
1560
|
+
parsed_arri_sse_request(
|
1561
|
+
ArriParsedSseRequestOptions {
|
1562
|
+
client: &self._config.http_client,
|
1563
|
+
url: format!("{}${schema.path}", &self._config.base_url),
|
1564
|
+
method: reqwest::Method::${schema.method.toUpperCase()},
|
1565
|
+
headers: self._config.headers.clone(),
|
1566
|
+
client_version: "${context.clientVersion}".to_string(),
|
1567
|
+
max_retry_count,
|
1568
|
+
max_retry_interval,
|
1569
|
+
},
|
1570
|
+
${params ? `Some(params)` : "None::<EmptyArriModel>"},
|
1571
|
+
on_event,
|
1572
|
+
)
|
1573
|
+
.await;
|
1574
|
+
}`;
|
1575
|
+
}
|
1576
|
+
return `${leading}pub async fn ${functionName}(
|
1577
|
+
&self,
|
1558
1578
|
${params ? `params: ${context.typeNamePrefix}${params},` : ""}
|
1559
1579
|
) -> Result<${context.typeNamePrefix}${response ?? "()"}, ArriServerError> {
|
1560
1580
|
parsed_arri_request(
|
1561
1581
|
ArriParsedRequestOptions {
|
1562
|
-
http_client: &self.
|
1563
|
-
url: format!("{}${schema.path}", &self.
|
1582
|
+
http_client: &self._config.http_client,
|
1583
|
+
url: format!("{}${schema.path}", &self._config.base_url),
|
1564
1584
|
method: reqwest::Method::${schema.method.toUpperCase()},
|
1565
|
-
headers: self.
|
1585
|
+
headers: self._config.headers.clone(),
|
1566
1586
|
client_version: "${context.clientVersion}".to_string(),
|
1567
1587
|
},
|
1568
1588
|
${params ? `Some(params)` : "None::<EmptyArriModel>"},
|
@@ -1629,23 +1649,30 @@ function rustServiceFromSchema(schema, context) {
|
|
1629
1649
|
`[rust-codegen] Invalid schema at /procedures/${context.instancePath}.`
|
1630
1650
|
);
|
1631
1651
|
}
|
1652
|
+
const paramSuffix = subServices.length > 0 ? ".clone()" : "";
|
1632
1653
|
return {
|
1633
1654
|
name: serviceName,
|
1634
|
-
content:
|
1635
|
-
|
1636
|
-
|
1655
|
+
content: `#[derive(Clone)]
|
1656
|
+
pub struct ${serviceName} {
|
1657
|
+
_config: InternalArriClientConfig,
|
1658
|
+
${subServices.map((service) => ` pub ${service.key}: ${service.name},`).join("\n")}
|
1637
1659
|
}
|
1638
1660
|
|
1639
|
-
impl
|
1640
|
-
fn create(config:
|
1661
|
+
impl ArriClientService for ${serviceName} {
|
1662
|
+
fn create(config: ArriClientConfig) -> Self {
|
1641
1663
|
Self {
|
1642
|
-
|
1643
|
-
${subServices.map((service) => ` ${service.key}: ${service.name}::create(config),`).join("\n")}
|
1664
|
+
_config: InternalArriClientConfig::from(config${paramSuffix}),
|
1665
|
+
${subServices.map((service, index) => ` ${service.key}: ${service.name}::create(config${index === subServices.length - 1 ? "" : ".clone()"}),`).join("\n")}
|
1644
1666
|
}
|
1645
1667
|
}
|
1668
|
+
fn update_headers(&self, headers: HashMap<&'static str, String>) {
|
1669
|
+
let mut unwrapped_headers = self._config.headers.write().unwrap();
|
1670
|
+
*unwrapped_headers = headers.clone();
|
1671
|
+
${subServices.map((service, index) => ` self.${service.key}.update_headers(headers${index === subServices.length - 1 ? "" : ".clone()"});`).join("\n")}
|
1672
|
+
}
|
1646
1673
|
}
|
1647
1674
|
|
1648
|
-
impl ${serviceName}
|
1675
|
+
impl ${serviceName} {
|
1649
1676
|
${rpcParts.join("\n")}
|
1650
1677
|
}
|
1651
1678
|
|
@@ -1884,35 +1911,51 @@ use arri_client::{
|
|
1884
1911
|
utils::{serialize_date_time, serialize_string},
|
1885
1912
|
ArriEnum, ArriModel,
|
1886
1913
|
};
|
1887
|
-
use std::collections::BTreeMap;
|
1914
|
+
use std::collections::{BTreeMap, HashMap};
|
1888
1915
|
${modelParts.join("\n\n")}`;
|
1889
1916
|
}
|
1890
1917
|
const clientName = validRustName(context.clientName);
|
1891
|
-
|
1918
|
+
const paramSuffix = subServices.length > 0 ? ".clone()" : "";
|
1919
|
+
return `#![allow(
|
1920
|
+
dead_code,
|
1921
|
+
unused_imports,
|
1922
|
+
unused_variables,
|
1923
|
+
unconditional_recursion,
|
1924
|
+
deprecated
|
1925
|
+
)]
|
1892
1926
|
use arri_client::{
|
1893
1927
|
chrono::{DateTime, FixedOffset},
|
1894
|
-
parsed_arri_request,
|
1928
|
+
parsed_arri_request,
|
1929
|
+
reqwest::{self, Request},
|
1930
|
+
serde_json::{self, Map},
|
1931
|
+
sse::{parsed_arri_sse_request, ArriParsedSseRequestOptions, SseController, SseEvent},
|
1895
1932
|
utils::{serialize_date_time, serialize_string},
|
1896
1933
|
ArriClientConfig, ArriClientService, ArriEnum, ArriModel, ArriParsedRequestOptions,
|
1897
|
-
ArriServerError, EmptyArriModel,
|
1934
|
+
ArriServerError, EmptyArriModel, InternalArriClientConfig,
|
1898
1935
|
};
|
1899
|
-
use std::collections::BTreeMap;
|
1936
|
+
use std::collections::{BTreeMap, HashMap};
|
1900
1937
|
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1938
|
+
#[derive(Clone)]
|
1939
|
+
pub struct ${clientName} {
|
1940
|
+
_config: InternalArriClientConfig,
|
1941
|
+
${subServices.map((service) => ` pub ${service.key}: ${service.name},`).join("\n")}
|
1904
1942
|
}
|
1905
1943
|
|
1906
|
-
impl
|
1907
|
-
fn create(config:
|
1944
|
+
impl ArriClientService for ${clientName} {
|
1945
|
+
fn create(config: ArriClientConfig) -> Self {
|
1908
1946
|
Self {
|
1909
|
-
|
1910
|
-
${subServices.map((service) => ` ${service.key}: ${service.name}::create(config),`).join("\n")}
|
1947
|
+
_config: InternalArriClientConfig::from(config${paramSuffix}),
|
1948
|
+
${subServices.map((service, index) => ` ${service.key}: ${service.name}::create(config${index === subServices.length - 1 ? "" : ".clone()"}),`).join("\n")}
|
1911
1949
|
}
|
1912
1950
|
}
|
1951
|
+
fn update_headers(&self, headers: HashMap<&'static str, String>) {
|
1952
|
+
let mut unwrapped_headers = self._config.headers.write().unwrap();
|
1953
|
+
*unwrapped_headers = headers.clone();
|
1954
|
+
${subServices.map((service, index) => ` self.${service.key}.update_headers(headers${index === subServices.length - 1 ? "" : ".clone()"});`).join("\n")}
|
1955
|
+
}
|
1913
1956
|
}
|
1914
1957
|
|
1915
|
-
impl ${clientName}
|
1958
|
+
impl ${clientName} {
|
1916
1959
|
${rpcParts.join("\n")}
|
1917
1960
|
}
|
1918
1961
|
|
package/package.json
CHANGED
@@ -22,10 +22,10 @@
|
|
22
22
|
],
|
23
23
|
"dependencies": {
|
24
24
|
"pathe": "^1.1.2",
|
25
|
-
"@arrirpc/codegen-utils": "0.
|
25
|
+
"@arrirpc/codegen-utils": "0.55.0"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
|
-
"@arrirpc/schema": "0.
|
28
|
+
"@arrirpc/schema": "0.55.0"
|
29
29
|
},
|
30
|
-
"version": "0.
|
30
|
+
"version": "0.55.0"
|
31
31
|
}
|