@arrirpc/codegen-rust 0.72.0 → 0.73.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +95 -69
- package/dist/index.d.cts +5 -1
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +95 -69
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
@@ -117,7 +117,8 @@ function formatDescriptionComment(description, leading = "") {
|
|
117
117
|
|
118
118
|
function rustAnyFromSchema(schema, context) {
|
119
119
|
return {
|
120
|
-
|
120
|
+
typeId: context.isOptional ? `Option<serde_json::Value>` : "serde_json::Value",
|
121
|
+
finalTypeName: context.isOptional ? `Option<serde_json::Value>` : "serde_json::Value",
|
121
122
|
defaultValue: context.isOptional ? `None` : `serde_json::Value::Null`,
|
122
123
|
isNullable: false,
|
123
124
|
fromJsonTemplate(input, key) {
|
@@ -157,10 +158,11 @@ function rustArrayFromSchema(schema, context) {
|
|
157
158
|
generatedTypes: context.generatedTypes
|
158
159
|
});
|
159
160
|
const isOptionType = outputIsOptionType(schema, context);
|
160
|
-
const typeName = isOptionType ? `Option<Vec<${innerType.
|
161
|
+
const typeName = isOptionType ? `Option<Vec<${innerType.finalTypeName}>>` : `Vec<${innerType.finalTypeName}>`;
|
161
162
|
const defaultValue = isOptionType ? `None` : `Vec::new()`;
|
162
163
|
return {
|
163
|
-
typeName,
|
164
|
+
typeId: typeName,
|
165
|
+
finalTypeName: typeName,
|
164
166
|
defaultValue,
|
165
167
|
isNullable: schema.nullable ?? false,
|
166
168
|
fromJsonTemplate(input, key) {
|
@@ -168,7 +170,7 @@ function rustArrayFromSchema(schema, context) {
|
|
168
170
|
if (isOptionType) {
|
169
171
|
return `match ${input} {
|
170
172
|
Some(serde_json::Value::Array(${innerKey})) => {
|
171
|
-
let mut ${innerKey}_result: Vec<${innerType.
|
173
|
+
let mut ${innerKey}_result: Vec<${innerType.finalTypeName}> = Vec::new();
|
172
174
|
for ${innerKey}_element in ${innerKey} {
|
173
175
|
${innerKey}_result.push(${innerType.fromJsonTemplate(`Some(${innerKey}_element)`, `${innerKey}_element`)});
|
174
176
|
}
|
@@ -179,7 +181,7 @@ function rustArrayFromSchema(schema, context) {
|
|
179
181
|
}
|
180
182
|
return `match ${input} {
|
181
183
|
Some(serde_json::Value::Array(${innerKey})) => {
|
182
|
-
let mut ${innerKey}_result: Vec<${innerType.
|
184
|
+
let mut ${innerKey}_result: Vec<${innerType.finalTypeName}> = Vec::new();
|
183
185
|
for ${innerKey}_element in ${innerKey} {
|
184
186
|
${innerKey}_result.push(${innerType.fromJsonTemplate(`Some(${innerKey}_element)`, `${innerKey}_element`)});
|
185
187
|
}
|
@@ -217,11 +219,13 @@ function rustArrayFromSchema(schema, context) {
|
|
217
219
|
}
|
218
220
|
|
219
221
|
function rustTaggedUnionFromSchema(schema, context) {
|
220
|
-
const enumName =
|
222
|
+
const enumName = getTypeName(schema, context);
|
223
|
+
const prefixedEnumName = `${context.typeNamePrefix}${enumName}`;
|
221
224
|
const isOptionType = outputIsOptionType(schema, context);
|
222
|
-
const defaultValue = isOptionType ? "None" : `${
|
225
|
+
const defaultValue = isOptionType ? "None" : `${prefixedEnumName}::new()`;
|
223
226
|
const result = {
|
224
|
-
|
227
|
+
typeId: enumName,
|
228
|
+
finalTypeName: isOptionType ? `Option<${prefixedEnumName}>` : prefixedEnumName,
|
225
229
|
defaultValue,
|
226
230
|
isNullable: isOptionType,
|
227
231
|
fromJsonTemplate(input, key) {
|
@@ -230,7 +234,7 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
230
234
|
return `match ${input} {
|
231
235
|
Some(${innerKey}) => match ${innerKey} {
|
232
236
|
serde_json::Value::Object(_) => {
|
233
|
-
Some(${
|
237
|
+
Some(${prefixedEnumName}::from_json(${innerKey}.to_owned()))
|
234
238
|
}
|
235
239
|
_ => None,
|
236
240
|
},
|
@@ -240,11 +244,11 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
240
244
|
return `match ${input} {
|
241
245
|
Some(${innerKey}) => match ${innerKey} {
|
242
246
|
serde_json::Value::Object(_) => {
|
243
|
-
${
|
247
|
+
${prefixedEnumName}::from_json(${innerKey}.to_owned())
|
244
248
|
}
|
245
|
-
_ => ${
|
249
|
+
_ => ${prefixedEnumName}::new(),
|
246
250
|
},
|
247
|
-
_ => ${
|
251
|
+
_ => ${prefixedEnumName}::new(),
|
248
252
|
}`;
|
249
253
|
},
|
250
254
|
toJsonTemplate(input, target) {
|
@@ -303,7 +307,8 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
303
307
|
subType.properties.push({
|
304
308
|
name: keyName,
|
305
309
|
defaultValue: keyType.defaultValue,
|
306
|
-
typeName: keyType.
|
310
|
+
typeName: keyType.typeId,
|
311
|
+
prefixedTypeName: keyType.finalTypeName,
|
307
312
|
isDeprecated: keySchema.metadata?.isDeprecated ?? false,
|
308
313
|
description: keySchema.metadata?.description ?? ""
|
309
314
|
});
|
@@ -349,7 +354,8 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
349
354
|
subType.properties.push({
|
350
355
|
name: keyName,
|
351
356
|
defaultValue: keyType.defaultValue,
|
352
|
-
typeName: keyType.
|
357
|
+
typeName: keyType.typeId,
|
358
|
+
prefixedTypeName: keyType.finalTypeName,
|
353
359
|
isDeprecated: keySchema.metadata?.isDeprecated ?? false,
|
354
360
|
description: keySchema.metadata?.description ?? ""
|
355
361
|
});
|
@@ -390,7 +396,7 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
390
396
|
leading += "#[deprecated]\n";
|
391
397
|
}
|
392
398
|
result.content = `${leading}#[derive(Clone, Debug, PartialEq)]
|
393
|
-
pub enum ${
|
399
|
+
pub enum ${prefixedEnumName} {
|
394
400
|
${subTypes.map((type) => {
|
395
401
|
let leading2 = "";
|
396
402
|
if (type.description) {
|
@@ -410,13 +416,13 @@ pub enum ${enumName} {
|
|
410
416
|
if (prop.isDeprecated) {
|
411
417
|
leading3 += "#[deprecated]\n";
|
412
418
|
}
|
413
|
-
return `${leading3}${prop.name}: ${prop.
|
419
|
+
return `${leading3}${prop.name}: ${prop.prefixedTypeName},`;
|
414
420
|
}).join("\n")}
|
415
421
|
},`;
|
416
422
|
}).join("\n")}
|
417
423
|
}
|
418
424
|
|
419
|
-
impl ArriModel for ${
|
425
|
+
impl ArriModel for ${prefixedEnumName} {
|
420
426
|
fn new() -> Self {
|
421
427
|
Self::${subTypes[0].name} {
|
422
428
|
${subTypes[0]?.properties.map((prop) => `${prop.name}: ${prop.defaultValue},`).join("\n")}
|
@@ -478,12 +484,14 @@ ${subTypeContent.join("\n\n")}`;
|
|
478
484
|
}
|
479
485
|
|
480
486
|
function rustEnumFromSchema(schema, context) {
|
481
|
-
const enumName =
|
487
|
+
const enumName = getTypeName(schema, context);
|
488
|
+
const prefixedEnumName = `${context.typeNamePrefix}${enumName}`;
|
482
489
|
const isOptionType = outputIsOptionType(schema, context);
|
483
|
-
const typeName = isOptionType ? `Option<${
|
484
|
-
const defaultValue = isOptionType ? "None" : `${
|
490
|
+
const typeName = isOptionType ? `Option<${prefixedEnumName}>` : prefixedEnumName;
|
491
|
+
const defaultValue = isOptionType ? "None" : `${prefixedEnumName}::default()`;
|
485
492
|
const result = {
|
486
|
-
|
493
|
+
typeId: enumName,
|
494
|
+
finalTypeName: typeName,
|
487
495
|
defaultValue,
|
488
496
|
isNullable: schema.nullable ?? false,
|
489
497
|
fromJsonTemplate(input, key) {
|
@@ -491,16 +499,16 @@ function rustEnumFromSchema(schema, context) {
|
|
491
499
|
if (isOptionType) {
|
492
500
|
return `match ${input} {
|
493
501
|
Some(serde_json::Value::String(${innerKey})) => {
|
494
|
-
Some(${
|
502
|
+
Some(${prefixedEnumName}::from_string(${innerKey}.to_owned()))
|
495
503
|
}
|
496
504
|
_ => None,
|
497
505
|
}`;
|
498
506
|
}
|
499
507
|
return `match ${input} {
|
500
508
|
Some(serde_json::Value::String(${innerKey})) => {
|
501
|
-
${
|
509
|
+
${prefixedEnumName}::from_string(${innerKey}.to_owned())
|
502
510
|
}
|
503
|
-
_ => ${
|
511
|
+
_ => ${prefixedEnumName}::default(),
|
504
512
|
}`;
|
505
513
|
},
|
506
514
|
toJsonTemplate(input, target) {
|
@@ -546,7 +554,7 @@ function rustEnumFromSchema(schema, context) {
|
|
546
554
|
initializationParts.push(` ${valName},`);
|
547
555
|
fromStringParts.push(` "${val}" => Self::${valName},`);
|
548
556
|
serialValueParts.push(
|
549
|
-
` ${
|
557
|
+
` ${prefixedEnumName}::${valName} => "${val}".to_string(),`
|
550
558
|
);
|
551
559
|
}
|
552
560
|
let leading = "";
|
@@ -559,13 +567,13 @@ function rustEnumFromSchema(schema, context) {
|
|
559
567
|
`;
|
560
568
|
}
|
561
569
|
result.content = `${leading}#[derive(Clone, Debug, PartialEq)]
|
562
|
-
pub enum ${
|
570
|
+
pub enum ${prefixedEnumName} {
|
563
571
|
${initializationParts.join("\n")}
|
564
572
|
}
|
565
573
|
|
566
|
-
impl ArriEnum for ${
|
574
|
+
impl ArriEnum for ${prefixedEnumName} {
|
567
575
|
fn default() -> Self {
|
568
|
-
${
|
576
|
+
${prefixedEnumName}::${defaultEnumValue}
|
569
577
|
}
|
570
578
|
fn from_string(input: String) -> Self {
|
571
579
|
match input.as_str() {
|
@@ -585,11 +593,13 @@ ${serialValueParts.join("\n")}
|
|
585
593
|
|
586
594
|
function rustObjectFromSchema(schema, context) {
|
587
595
|
const isOptionType = outputIsOptionType(schema, context);
|
588
|
-
const structName =
|
589
|
-
const
|
590
|
-
const
|
596
|
+
const structName = getTypeName(schema, context);
|
597
|
+
const prefixedStructName = `${context.typeNamePrefix}${structName}`;
|
598
|
+
const typeName = isOptionType ? `Option<${prefixedStructName}>` : prefixedStructName;
|
599
|
+
const defaultValue = isOptionType ? `None` : `${prefixedStructName}::new()`;
|
591
600
|
const result = {
|
592
|
-
|
601
|
+
typeId: structName,
|
602
|
+
finalTypeName: typeName,
|
593
603
|
defaultValue,
|
594
604
|
isNullable: schema.nullable ?? false,
|
595
605
|
fromJsonTemplate(input, key) {
|
@@ -598,7 +608,7 @@ function rustObjectFromSchema(schema, context) {
|
|
598
608
|
return `match ${input} {
|
599
609
|
Some(${innerKey}) => match ${innerKey} {
|
600
610
|
serde_json::Value::Object(_) => {
|
601
|
-
Some(${
|
611
|
+
Some(${prefixedStructName}::from_json(${innerKey}.to_owned()))
|
602
612
|
}
|
603
613
|
_ => None,
|
604
614
|
},
|
@@ -606,8 +616,8 @@ function rustObjectFromSchema(schema, context) {
|
|
606
616
|
}`;
|
607
617
|
}
|
608
618
|
return `match ${input} {
|
609
|
-
Some(${innerKey}) => ${
|
610
|
-
_ => ${
|
619
|
+
Some(${innerKey}) => ${prefixedStructName}::from_json(${innerKey}.to_owned()),
|
620
|
+
_ => ${prefixedStructName}::new(),
|
611
621
|
}`;
|
612
622
|
},
|
613
623
|
toJsonTemplate(input, target) {
|
@@ -657,7 +667,7 @@ function rustObjectFromSchema(schema, context) {
|
|
657
667
|
`;
|
658
668
|
}
|
659
669
|
fieldDeclarationParts.push(
|
660
|
-
`${leading2} pub ${fieldName}: ${innerType.
|
670
|
+
`${leading2} pub ${fieldName}: ${innerType.finalTypeName}`
|
661
671
|
);
|
662
672
|
defaultParts.push(` ${fieldName}: ${innerType.defaultValue}`);
|
663
673
|
fromJsonParts.push(
|
@@ -712,7 +722,7 @@ function rustObjectFromSchema(schema, context) {
|
|
712
722
|
`;
|
713
723
|
}
|
714
724
|
fieldDeclarationParts.push(
|
715
|
-
`${leading2} pub ${fieldName}: ${innerType.
|
725
|
+
`${leading2} pub ${fieldName}: ${innerType.finalTypeName}`
|
716
726
|
);
|
717
727
|
defaultParts.push(` ${fieldName}: ${innerType.defaultValue}`);
|
718
728
|
fromJsonParts.push(
|
@@ -762,11 +772,11 @@ function rustObjectFromSchema(schema, context) {
|
|
762
772
|
`;
|
763
773
|
}
|
764
774
|
result.content = `${leading}#[derive(Clone, Debug, PartialEq)]
|
765
|
-
pub struct ${
|
775
|
+
pub struct ${prefixedStructName} {
|
766
776
|
${fieldDeclarationParts.join(",\n")},
|
767
777
|
}
|
768
778
|
|
769
|
-
impl ArriModel for ${
|
779
|
+
impl ArriModel for ${prefixedStructName} {
|
770
780
|
fn new() -> Self {
|
771
781
|
Self {
|
772
782
|
${defaultParts.join(",\n")},
|
@@ -810,7 +820,8 @@ function rustStringFromSchema(schema, context) {
|
|
810
820
|
const defaultValue = isOptionType ? "None" : '"".to_string()';
|
811
821
|
const typeName = isOptionType ? "Option<String>" : "String";
|
812
822
|
return {
|
813
|
-
typeName,
|
823
|
+
typeId: typeName,
|
824
|
+
finalTypeName: typeName,
|
814
825
|
defaultValue,
|
815
826
|
isNullable: schema.nullable ?? false,
|
816
827
|
fromJsonTemplate(input, key) {
|
@@ -859,7 +870,8 @@ function rustBooleanFromSchema(schema, context) {
|
|
859
870
|
const defaultValue = isOptionType ? "None" : "false";
|
860
871
|
const typeName = isOptionType ? "Option<bool>" : "bool";
|
861
872
|
return {
|
862
|
-
typeName,
|
873
|
+
typeId: typeName,
|
874
|
+
finalTypeName: typeName,
|
863
875
|
defaultValue,
|
864
876
|
isNullable: schema.nullable ?? false,
|
865
877
|
fromJsonTemplate(input, key) {
|
@@ -908,7 +920,8 @@ function rustTimestampFromSchema(schema, context) {
|
|
908
920
|
const typeName = isOptionType ? "Option<DateTime<FixedOffset>>" : "DateTime<FixedOffset>";
|
909
921
|
const defaultValue = isOptionType ? "None" : "DateTime::default()";
|
910
922
|
return {
|
911
|
-
typeName,
|
923
|
+
typeId: typeName,
|
924
|
+
finalTypeName: typeName,
|
912
925
|
defaultValue,
|
913
926
|
isNullable: schema.nullable ?? false,
|
914
927
|
fromJsonTemplate(input, key) {
|
@@ -974,7 +987,8 @@ function rustF32FromSchema(schema, context) {
|
|
974
987
|
const typeName = isOptionType ? `Option<f32>` : "f32";
|
975
988
|
const defaultValue = isOptionType ? `None` : "0.0";
|
976
989
|
return {
|
977
|
-
typeName,
|
990
|
+
typeId: typeName,
|
991
|
+
finalTypeName: typeName,
|
978
992
|
defaultValue,
|
979
993
|
isNullable: schema.nullable ?? false,
|
980
994
|
fromJsonTemplate(input, key) {
|
@@ -1028,7 +1042,8 @@ function rustF64FromSchema(schema, context) {
|
|
1028
1042
|
const typeName = isOptionType ? `Option<f64>` : "f64";
|
1029
1043
|
const defaultValue = isOptionType ? `None` : "0.0";
|
1030
1044
|
return {
|
1031
|
-
typeName,
|
1045
|
+
typeId: typeName,
|
1046
|
+
finalTypeName: typeName,
|
1032
1047
|
defaultValue,
|
1033
1048
|
isNullable: schema.nullable ?? false,
|
1034
1049
|
fromJsonTemplate(input, key) {
|
@@ -1082,7 +1097,8 @@ function rustI8FromSchema(schema, context) {
|
|
1082
1097
|
const typeName = isOptionType ? `Option<i8>` : "i8";
|
1083
1098
|
const defaultValue = isOptionType ? `None` : "0";
|
1084
1099
|
return {
|
1085
|
-
typeName,
|
1100
|
+
typeId: typeName,
|
1101
|
+
finalTypeName: typeName,
|
1086
1102
|
defaultValue,
|
1087
1103
|
isNullable: schema.nullable ?? false,
|
1088
1104
|
fromJsonTemplate(input, key) {
|
@@ -1139,7 +1155,8 @@ function rustU8FromSchema(schema, context) {
|
|
1139
1155
|
const typeName = isOptionType ? "Option<u8>" : "u8";
|
1140
1156
|
const defaultValue = isOptionType ? "None" : "0";
|
1141
1157
|
return {
|
1142
|
-
typeName,
|
1158
|
+
typeId: typeName,
|
1159
|
+
finalTypeName: typeName,
|
1143
1160
|
defaultValue,
|
1144
1161
|
isNullable: schema.nullable ?? false,
|
1145
1162
|
fromJsonTemplate(input, key) {
|
@@ -1196,7 +1213,8 @@ function rustI16FromSchema(schema, context) {
|
|
1196
1213
|
const typeName = isOptionType ? "Option<i16>" : "i16";
|
1197
1214
|
const defaultValue = isOptionType ? "None" : "0";
|
1198
1215
|
return {
|
1199
|
-
typeName,
|
1216
|
+
typeId: typeName,
|
1217
|
+
finalTypeName: typeName,
|
1200
1218
|
defaultValue,
|
1201
1219
|
isNullable: schema.nullable ?? false,
|
1202
1220
|
fromJsonTemplate(input, key) {
|
@@ -1253,7 +1271,8 @@ function rustU16FromSchema(schema, context) {
|
|
1253
1271
|
const typeName = isOptionType ? "Option<u16>" : "u16";
|
1254
1272
|
const defaultValue = isOptionType ? "None" : "0";
|
1255
1273
|
return {
|
1256
|
-
typeName,
|
1274
|
+
typeId: typeName,
|
1275
|
+
finalTypeName: typeName,
|
1257
1276
|
defaultValue,
|
1258
1277
|
isNullable: schema.nullable ?? false,
|
1259
1278
|
fromJsonTemplate(input, key) {
|
@@ -1310,7 +1329,8 @@ function rustI32FromSchema(schema, context) {
|
|
1310
1329
|
const typeName = isOptionType ? "Option<i32>" : "i32";
|
1311
1330
|
const defaultValue = isOptionType ? "None" : "0";
|
1312
1331
|
return {
|
1313
|
-
typeName,
|
1332
|
+
typeId: typeName,
|
1333
|
+
finalTypeName: typeName,
|
1314
1334
|
defaultValue,
|
1315
1335
|
isNullable: schema.nullable ?? false,
|
1316
1336
|
fromJsonTemplate(input, key) {
|
@@ -1367,7 +1387,8 @@ function rustU32FromSchema(schema, context) {
|
|
1367
1387
|
const typeName = isOptionType ? "Option<u32>" : "u32";
|
1368
1388
|
const defaultValue = isOptionType ? "None" : "0";
|
1369
1389
|
return {
|
1370
|
-
typeName,
|
1390
|
+
typeId: typeName,
|
1391
|
+
finalTypeName: typeName,
|
1371
1392
|
defaultValue,
|
1372
1393
|
isNullable: schema.nullable ?? false,
|
1373
1394
|
fromJsonTemplate(input, key) {
|
@@ -1424,7 +1445,8 @@ function rustI64FromSchema(schema, context) {
|
|
1424
1445
|
const typeName = isOptionType ? "Option<i64>" : "i64";
|
1425
1446
|
const defaultValue = isOptionType ? "None" : "0";
|
1426
1447
|
return {
|
1427
|
-
typeName,
|
1448
|
+
typeId: typeName,
|
1449
|
+
finalTypeName: typeName,
|
1428
1450
|
defaultValue,
|
1429
1451
|
isNullable: schema.nullable ?? false,
|
1430
1452
|
fromJsonTemplate(input, key) {
|
@@ -1478,7 +1500,8 @@ function rustU64FromSchema(schema, context) {
|
|
1478
1500
|
const typeName = isOptionType ? "Option<u64>" : "u64";
|
1479
1501
|
const defaultValue = isOptionType ? "None" : "0";
|
1480
1502
|
return {
|
1481
|
-
typeName,
|
1503
|
+
typeId: typeName,
|
1504
|
+
finalTypeName: typeName,
|
1482
1505
|
defaultValue,
|
1483
1506
|
isNullable: schema.nullable ?? false,
|
1484
1507
|
fromJsonTemplate(input, key) {
|
@@ -1551,17 +1574,17 @@ function rustHttpRpcFromSchema(schema, context) {
|
|
1551
1574
|
if (schema.isDeprecated) {
|
1552
1575
|
leading += "#[deprecated]\n";
|
1553
1576
|
}
|
1554
|
-
const params = schema.params ? validRustName(schema.params) : undefined;
|
1555
|
-
const response = schema.response ? validRustName(schema.response) : undefined;
|
1577
|
+
const params = schema.params ? context.typeNamePrefix + validRustName(schema.params) : undefined;
|
1578
|
+
const response = schema.response ? context.typeNamePrefix + validRustName(schema.response) : undefined;
|
1556
1579
|
if (schema.isEventStream) {
|
1557
1580
|
return `${leading}pub async fn ${functionName}<OnEvent>(
|
1558
1581
|
&self,
|
1559
|
-
${params ? `params: ${
|
1582
|
+
${params ? `params: ${params},` : ""}
|
1560
1583
|
on_event: &mut OnEvent,
|
1561
1584
|
max_retry_count: Option<u64>,
|
1562
1585
|
max_retry_interval: Option<u64>,
|
1563
1586
|
) where
|
1564
|
-
OnEvent: FnMut(SseEvent<${response ?
|
1587
|
+
OnEvent: FnMut(SseEvent<${response ? response : "EmptyArriModel"}>, &mut SseController) + std::marker::Send + std::marker::Sync,
|
1565
1588
|
{
|
1566
1589
|
parsed_arri_sse_request(
|
1567
1590
|
ArriParsedSseRequestOptions {
|
@@ -1581,8 +1604,8 @@ function rustHttpRpcFromSchema(schema, context) {
|
|
1581
1604
|
}
|
1582
1605
|
return `${leading}pub async fn ${functionName}(
|
1583
1606
|
&self,
|
1584
|
-
${params ? `params: ${
|
1585
|
-
) -> Result<${
|
1607
|
+
${params ? `params: ${params},` : ""}
|
1608
|
+
) -> Result<${response ?? "()"}, ArriError> {
|
1586
1609
|
parsed_arri_request(
|
1587
1610
|
ArriParsedRequestOptions {
|
1588
1611
|
http_client: &self._config.http_client,
|
@@ -1592,7 +1615,7 @@ function rustHttpRpcFromSchema(schema, context) {
|
|
1592
1615
|
client_version: "${context.clientVersion}".to_string(),
|
1593
1616
|
},
|
1594
1617
|
${params ? `Some(params)` : "None::<EmptyArriModel>"},
|
1595
|
-
|body| ${response ? `return ${
|
1618
|
+
|body| ${response ? `return ${response}::from_json_string(body)` : "{}"},
|
1596
1619
|
)
|
1597
1620
|
.await
|
1598
1621
|
}`;
|
@@ -1697,10 +1720,11 @@ function rustRecordFromSchema(schema, context) {
|
|
1697
1720
|
generatedTypes: context.generatedTypes
|
1698
1721
|
});
|
1699
1722
|
const isOptionType = outputIsOptionType(schema, context);
|
1700
|
-
const typeName = isOptionType ? `Option<BTreeMap<String, ${innerType.
|
1723
|
+
const typeName = isOptionType ? `Option<BTreeMap<String, ${innerType.finalTypeName}>>` : `BTreeMap<String, ${innerType.finalTypeName}>`;
|
1701
1724
|
const defaultValue = isOptionType ? `None` : `BTreeMap::new()`;
|
1702
1725
|
return {
|
1703
|
-
typeName,
|
1726
|
+
typeId: typeName,
|
1727
|
+
finalTypeName: typeName,
|
1704
1728
|
defaultValue,
|
1705
1729
|
isNullable: schema.nullable ?? false,
|
1706
1730
|
fromJsonTemplate(input, key) {
|
@@ -1708,7 +1732,7 @@ function rustRecordFromSchema(schema, context) {
|
|
1708
1732
|
if (isOptionType) {
|
1709
1733
|
return `match ${input} {
|
1710
1734
|
Some(serde_json::Value::Object(${innerKey})) => {
|
1711
|
-
let mut ${innerKey}_result: BTreeMap<String, ${innerType.
|
1735
|
+
let mut ${innerKey}_result: BTreeMap<String, ${innerType.finalTypeName}> = BTreeMap::new();
|
1712
1736
|
for (_key_, _value_) in ${innerKey}.into_iter() {
|
1713
1737
|
${innerKey}_result.insert(
|
1714
1738
|
_key_.to_owned(),
|
@@ -1722,7 +1746,7 @@ function rustRecordFromSchema(schema, context) {
|
|
1722
1746
|
}
|
1723
1747
|
return `match ${input} {
|
1724
1748
|
Some(serde_json::Value::Object(${innerKey})) => {
|
1725
|
-
let mut ${innerKey}_result: BTreeMap<String, ${innerType.
|
1749
|
+
let mut ${innerKey}_result: BTreeMap<String, ${innerType.finalTypeName}> = BTreeMap::new();
|
1726
1750
|
for (_key_, _value_) in ${innerKey}.into_iter() {
|
1727
1751
|
${innerKey}_result.insert(
|
1728
1752
|
_key_.to_owned(),
|
@@ -1771,9 +1795,10 @@ function rustRecordFromSchema(schema, context) {
|
|
1771
1795
|
}
|
1772
1796
|
|
1773
1797
|
function rustRefFromSchema(schema, context) {
|
1774
|
-
const innerTypeName =
|
1798
|
+
const innerTypeName = validRustName(schema.ref);
|
1799
|
+
const prefixedInnerTypeName = `${context.typeNamePrefix}${innerTypeName}`;
|
1775
1800
|
const isOptionType = outputIsOptionType(schema, context);
|
1776
|
-
let typeName = `Box<${
|
1801
|
+
let typeName = `Box<${prefixedInnerTypeName}>`;
|
1777
1802
|
if (isOptionType) {
|
1778
1803
|
typeName = `Option<${typeName}>`;
|
1779
1804
|
}
|
@@ -1781,17 +1806,18 @@ function rustRefFromSchema(schema, context) {
|
|
1781
1806
|
if (isOptionType) {
|
1782
1807
|
defaultValue = "None";
|
1783
1808
|
} else {
|
1784
|
-
defaultValue = `Box::new(${
|
1809
|
+
defaultValue = `Box::new(${prefixedInnerTypeName}::new())`;
|
1785
1810
|
}
|
1786
1811
|
return {
|
1787
|
-
typeName,
|
1812
|
+
typeId: typeName,
|
1813
|
+
finalTypeName: typeName,
|
1788
1814
|
defaultValue,
|
1789
1815
|
isNullable: schema.nullable ?? false,
|
1790
1816
|
fromJsonTemplate(input, key) {
|
1791
1817
|
const innerKey = validRustIdentifier(`${key}_val`);
|
1792
1818
|
const valFromJson = (input2) => {
|
1793
1819
|
{
|
1794
|
-
return `Box::new(${
|
1820
|
+
return `Box::new(${prefixedInnerTypeName}::from_json(${input2}.to_owned()))`;
|
1795
1821
|
}
|
1796
1822
|
};
|
1797
1823
|
if (isOptionType) {
|
@@ -1812,7 +1838,7 @@ function rustRefFromSchema(schema, context) {
|
|
1812
1838
|
}
|
1813
1839
|
_ => ${valFromJson(innerKey)},
|
1814
1840
|
},
|
1815
|
-
_ => Box::new(${
|
1841
|
+
_ => Box::new(${prefixedInnerTypeName}::new()),
|
1816
1842
|
}`;
|
1817
1843
|
},
|
1818
1844
|
toJsonTemplate(input, target) {
|
package/dist/index.d.cts
CHANGED
@@ -13,7 +13,11 @@ interface GeneratorContext {
|
|
13
13
|
isOptional?: boolean;
|
14
14
|
}
|
15
15
|
interface RustProperty {
|
16
|
-
|
16
|
+
typeId: string;
|
17
|
+
/**
|
18
|
+
* The type name with the optional typePrefix
|
19
|
+
*/
|
20
|
+
finalTypeName: string;
|
17
21
|
defaultValue: string;
|
18
22
|
isNullable: boolean;
|
19
23
|
fromJsonTemplate: (input: string, key: string) => string;
|
package/dist/index.d.mts
CHANGED
@@ -13,7 +13,11 @@ interface GeneratorContext {
|
|
13
13
|
isOptional?: boolean;
|
14
14
|
}
|
15
15
|
interface RustProperty {
|
16
|
-
|
16
|
+
typeId: string;
|
17
|
+
/**
|
18
|
+
* The type name with the optional typePrefix
|
19
|
+
*/
|
20
|
+
finalTypeName: string;
|
17
21
|
defaultValue: string;
|
18
22
|
isNullable: boolean;
|
19
23
|
fromJsonTemplate: (input: string, key: string) => string;
|
package/dist/index.d.ts
CHANGED
@@ -13,7 +13,11 @@ interface GeneratorContext {
|
|
13
13
|
isOptional?: boolean;
|
14
14
|
}
|
15
15
|
interface RustProperty {
|
16
|
-
|
16
|
+
typeId: string;
|
17
|
+
/**
|
18
|
+
* The type name with the optional typePrefix
|
19
|
+
*/
|
20
|
+
finalTypeName: string;
|
17
21
|
defaultValue: string;
|
18
22
|
isNullable: boolean;
|
19
23
|
fromJsonTemplate: (input: string, key: string) => string;
|
package/dist/index.mjs
CHANGED
@@ -109,7 +109,8 @@ function formatDescriptionComment(description, leading = "") {
|
|
109
109
|
|
110
110
|
function rustAnyFromSchema(schema, context) {
|
111
111
|
return {
|
112
|
-
|
112
|
+
typeId: context.isOptional ? `Option<serde_json::Value>` : "serde_json::Value",
|
113
|
+
finalTypeName: context.isOptional ? `Option<serde_json::Value>` : "serde_json::Value",
|
113
114
|
defaultValue: context.isOptional ? `None` : `serde_json::Value::Null`,
|
114
115
|
isNullable: false,
|
115
116
|
fromJsonTemplate(input, key) {
|
@@ -149,10 +150,11 @@ function rustArrayFromSchema(schema, context) {
|
|
149
150
|
generatedTypes: context.generatedTypes
|
150
151
|
});
|
151
152
|
const isOptionType = outputIsOptionType(schema, context);
|
152
|
-
const typeName = isOptionType ? `Option<Vec<${innerType.
|
153
|
+
const typeName = isOptionType ? `Option<Vec<${innerType.finalTypeName}>>` : `Vec<${innerType.finalTypeName}>`;
|
153
154
|
const defaultValue = isOptionType ? `None` : `Vec::new()`;
|
154
155
|
return {
|
155
|
-
typeName,
|
156
|
+
typeId: typeName,
|
157
|
+
finalTypeName: typeName,
|
156
158
|
defaultValue,
|
157
159
|
isNullable: schema.nullable ?? false,
|
158
160
|
fromJsonTemplate(input, key) {
|
@@ -160,7 +162,7 @@ function rustArrayFromSchema(schema, context) {
|
|
160
162
|
if (isOptionType) {
|
161
163
|
return `match ${input} {
|
162
164
|
Some(serde_json::Value::Array(${innerKey})) => {
|
163
|
-
let mut ${innerKey}_result: Vec<${innerType.
|
165
|
+
let mut ${innerKey}_result: Vec<${innerType.finalTypeName}> = Vec::new();
|
164
166
|
for ${innerKey}_element in ${innerKey} {
|
165
167
|
${innerKey}_result.push(${innerType.fromJsonTemplate(`Some(${innerKey}_element)`, `${innerKey}_element`)});
|
166
168
|
}
|
@@ -171,7 +173,7 @@ function rustArrayFromSchema(schema, context) {
|
|
171
173
|
}
|
172
174
|
return `match ${input} {
|
173
175
|
Some(serde_json::Value::Array(${innerKey})) => {
|
174
|
-
let mut ${innerKey}_result: Vec<${innerType.
|
176
|
+
let mut ${innerKey}_result: Vec<${innerType.finalTypeName}> = Vec::new();
|
175
177
|
for ${innerKey}_element in ${innerKey} {
|
176
178
|
${innerKey}_result.push(${innerType.fromJsonTemplate(`Some(${innerKey}_element)`, `${innerKey}_element`)});
|
177
179
|
}
|
@@ -209,11 +211,13 @@ function rustArrayFromSchema(schema, context) {
|
|
209
211
|
}
|
210
212
|
|
211
213
|
function rustTaggedUnionFromSchema(schema, context) {
|
212
|
-
const enumName =
|
214
|
+
const enumName = getTypeName(schema, context);
|
215
|
+
const prefixedEnumName = `${context.typeNamePrefix}${enumName}`;
|
213
216
|
const isOptionType = outputIsOptionType(schema, context);
|
214
|
-
const defaultValue = isOptionType ? "None" : `${
|
217
|
+
const defaultValue = isOptionType ? "None" : `${prefixedEnumName}::new()`;
|
215
218
|
const result = {
|
216
|
-
|
219
|
+
typeId: enumName,
|
220
|
+
finalTypeName: isOptionType ? `Option<${prefixedEnumName}>` : prefixedEnumName,
|
217
221
|
defaultValue,
|
218
222
|
isNullable: isOptionType,
|
219
223
|
fromJsonTemplate(input, key) {
|
@@ -222,7 +226,7 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
222
226
|
return `match ${input} {
|
223
227
|
Some(${innerKey}) => match ${innerKey} {
|
224
228
|
serde_json::Value::Object(_) => {
|
225
|
-
Some(${
|
229
|
+
Some(${prefixedEnumName}::from_json(${innerKey}.to_owned()))
|
226
230
|
}
|
227
231
|
_ => None,
|
228
232
|
},
|
@@ -232,11 +236,11 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
232
236
|
return `match ${input} {
|
233
237
|
Some(${innerKey}) => match ${innerKey} {
|
234
238
|
serde_json::Value::Object(_) => {
|
235
|
-
${
|
239
|
+
${prefixedEnumName}::from_json(${innerKey}.to_owned())
|
236
240
|
}
|
237
|
-
_ => ${
|
241
|
+
_ => ${prefixedEnumName}::new(),
|
238
242
|
},
|
239
|
-
_ => ${
|
243
|
+
_ => ${prefixedEnumName}::new(),
|
240
244
|
}`;
|
241
245
|
},
|
242
246
|
toJsonTemplate(input, target) {
|
@@ -295,7 +299,8 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
295
299
|
subType.properties.push({
|
296
300
|
name: keyName,
|
297
301
|
defaultValue: keyType.defaultValue,
|
298
|
-
typeName: keyType.
|
302
|
+
typeName: keyType.typeId,
|
303
|
+
prefixedTypeName: keyType.finalTypeName,
|
299
304
|
isDeprecated: keySchema.metadata?.isDeprecated ?? false,
|
300
305
|
description: keySchema.metadata?.description ?? ""
|
301
306
|
});
|
@@ -341,7 +346,8 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
341
346
|
subType.properties.push({
|
342
347
|
name: keyName,
|
343
348
|
defaultValue: keyType.defaultValue,
|
344
|
-
typeName: keyType.
|
349
|
+
typeName: keyType.typeId,
|
350
|
+
prefixedTypeName: keyType.finalTypeName,
|
345
351
|
isDeprecated: keySchema.metadata?.isDeprecated ?? false,
|
346
352
|
description: keySchema.metadata?.description ?? ""
|
347
353
|
});
|
@@ -382,7 +388,7 @@ function rustTaggedUnionFromSchema(schema, context) {
|
|
382
388
|
leading += "#[deprecated]\n";
|
383
389
|
}
|
384
390
|
result.content = `${leading}#[derive(Clone, Debug, PartialEq)]
|
385
|
-
pub enum ${
|
391
|
+
pub enum ${prefixedEnumName} {
|
386
392
|
${subTypes.map((type) => {
|
387
393
|
let leading2 = "";
|
388
394
|
if (type.description) {
|
@@ -402,13 +408,13 @@ pub enum ${enumName} {
|
|
402
408
|
if (prop.isDeprecated) {
|
403
409
|
leading3 += "#[deprecated]\n";
|
404
410
|
}
|
405
|
-
return `${leading3}${prop.name}: ${prop.
|
411
|
+
return `${leading3}${prop.name}: ${prop.prefixedTypeName},`;
|
406
412
|
}).join("\n")}
|
407
413
|
},`;
|
408
414
|
}).join("\n")}
|
409
415
|
}
|
410
416
|
|
411
|
-
impl ArriModel for ${
|
417
|
+
impl ArriModel for ${prefixedEnumName} {
|
412
418
|
fn new() -> Self {
|
413
419
|
Self::${subTypes[0].name} {
|
414
420
|
${subTypes[0]?.properties.map((prop) => `${prop.name}: ${prop.defaultValue},`).join("\n")}
|
@@ -470,12 +476,14 @@ ${subTypeContent.join("\n\n")}`;
|
|
470
476
|
}
|
471
477
|
|
472
478
|
function rustEnumFromSchema(schema, context) {
|
473
|
-
const enumName =
|
479
|
+
const enumName = getTypeName(schema, context);
|
480
|
+
const prefixedEnumName = `${context.typeNamePrefix}${enumName}`;
|
474
481
|
const isOptionType = outputIsOptionType(schema, context);
|
475
|
-
const typeName = isOptionType ? `Option<${
|
476
|
-
const defaultValue = isOptionType ? "None" : `${
|
482
|
+
const typeName = isOptionType ? `Option<${prefixedEnumName}>` : prefixedEnumName;
|
483
|
+
const defaultValue = isOptionType ? "None" : `${prefixedEnumName}::default()`;
|
477
484
|
const result = {
|
478
|
-
|
485
|
+
typeId: enumName,
|
486
|
+
finalTypeName: typeName,
|
479
487
|
defaultValue,
|
480
488
|
isNullable: schema.nullable ?? false,
|
481
489
|
fromJsonTemplate(input, key) {
|
@@ -483,16 +491,16 @@ function rustEnumFromSchema(schema, context) {
|
|
483
491
|
if (isOptionType) {
|
484
492
|
return `match ${input} {
|
485
493
|
Some(serde_json::Value::String(${innerKey})) => {
|
486
|
-
Some(${
|
494
|
+
Some(${prefixedEnumName}::from_string(${innerKey}.to_owned()))
|
487
495
|
}
|
488
496
|
_ => None,
|
489
497
|
}`;
|
490
498
|
}
|
491
499
|
return `match ${input} {
|
492
500
|
Some(serde_json::Value::String(${innerKey})) => {
|
493
|
-
${
|
501
|
+
${prefixedEnumName}::from_string(${innerKey}.to_owned())
|
494
502
|
}
|
495
|
-
_ => ${
|
503
|
+
_ => ${prefixedEnumName}::default(),
|
496
504
|
}`;
|
497
505
|
},
|
498
506
|
toJsonTemplate(input, target) {
|
@@ -538,7 +546,7 @@ function rustEnumFromSchema(schema, context) {
|
|
538
546
|
initializationParts.push(` ${valName},`);
|
539
547
|
fromStringParts.push(` "${val}" => Self::${valName},`);
|
540
548
|
serialValueParts.push(
|
541
|
-
` ${
|
549
|
+
` ${prefixedEnumName}::${valName} => "${val}".to_string(),`
|
542
550
|
);
|
543
551
|
}
|
544
552
|
let leading = "";
|
@@ -551,13 +559,13 @@ function rustEnumFromSchema(schema, context) {
|
|
551
559
|
`;
|
552
560
|
}
|
553
561
|
result.content = `${leading}#[derive(Clone, Debug, PartialEq)]
|
554
|
-
pub enum ${
|
562
|
+
pub enum ${prefixedEnumName} {
|
555
563
|
${initializationParts.join("\n")}
|
556
564
|
}
|
557
565
|
|
558
|
-
impl ArriEnum for ${
|
566
|
+
impl ArriEnum for ${prefixedEnumName} {
|
559
567
|
fn default() -> Self {
|
560
|
-
${
|
568
|
+
${prefixedEnumName}::${defaultEnumValue}
|
561
569
|
}
|
562
570
|
fn from_string(input: String) -> Self {
|
563
571
|
match input.as_str() {
|
@@ -577,11 +585,13 @@ ${serialValueParts.join("\n")}
|
|
577
585
|
|
578
586
|
function rustObjectFromSchema(schema, context) {
|
579
587
|
const isOptionType = outputIsOptionType(schema, context);
|
580
|
-
const structName =
|
581
|
-
const
|
582
|
-
const
|
588
|
+
const structName = getTypeName(schema, context);
|
589
|
+
const prefixedStructName = `${context.typeNamePrefix}${structName}`;
|
590
|
+
const typeName = isOptionType ? `Option<${prefixedStructName}>` : prefixedStructName;
|
591
|
+
const defaultValue = isOptionType ? `None` : `${prefixedStructName}::new()`;
|
583
592
|
const result = {
|
584
|
-
|
593
|
+
typeId: structName,
|
594
|
+
finalTypeName: typeName,
|
585
595
|
defaultValue,
|
586
596
|
isNullable: schema.nullable ?? false,
|
587
597
|
fromJsonTemplate(input, key) {
|
@@ -590,7 +600,7 @@ function rustObjectFromSchema(schema, context) {
|
|
590
600
|
return `match ${input} {
|
591
601
|
Some(${innerKey}) => match ${innerKey} {
|
592
602
|
serde_json::Value::Object(_) => {
|
593
|
-
Some(${
|
603
|
+
Some(${prefixedStructName}::from_json(${innerKey}.to_owned()))
|
594
604
|
}
|
595
605
|
_ => None,
|
596
606
|
},
|
@@ -598,8 +608,8 @@ function rustObjectFromSchema(schema, context) {
|
|
598
608
|
}`;
|
599
609
|
}
|
600
610
|
return `match ${input} {
|
601
|
-
Some(${innerKey}) => ${
|
602
|
-
_ => ${
|
611
|
+
Some(${innerKey}) => ${prefixedStructName}::from_json(${innerKey}.to_owned()),
|
612
|
+
_ => ${prefixedStructName}::new(),
|
603
613
|
}`;
|
604
614
|
},
|
605
615
|
toJsonTemplate(input, target) {
|
@@ -649,7 +659,7 @@ function rustObjectFromSchema(schema, context) {
|
|
649
659
|
`;
|
650
660
|
}
|
651
661
|
fieldDeclarationParts.push(
|
652
|
-
`${leading2} pub ${fieldName}: ${innerType.
|
662
|
+
`${leading2} pub ${fieldName}: ${innerType.finalTypeName}`
|
653
663
|
);
|
654
664
|
defaultParts.push(` ${fieldName}: ${innerType.defaultValue}`);
|
655
665
|
fromJsonParts.push(
|
@@ -704,7 +714,7 @@ function rustObjectFromSchema(schema, context) {
|
|
704
714
|
`;
|
705
715
|
}
|
706
716
|
fieldDeclarationParts.push(
|
707
|
-
`${leading2} pub ${fieldName}: ${innerType.
|
717
|
+
`${leading2} pub ${fieldName}: ${innerType.finalTypeName}`
|
708
718
|
);
|
709
719
|
defaultParts.push(` ${fieldName}: ${innerType.defaultValue}`);
|
710
720
|
fromJsonParts.push(
|
@@ -754,11 +764,11 @@ function rustObjectFromSchema(schema, context) {
|
|
754
764
|
`;
|
755
765
|
}
|
756
766
|
result.content = `${leading}#[derive(Clone, Debug, PartialEq)]
|
757
|
-
pub struct ${
|
767
|
+
pub struct ${prefixedStructName} {
|
758
768
|
${fieldDeclarationParts.join(",\n")},
|
759
769
|
}
|
760
770
|
|
761
|
-
impl ArriModel for ${
|
771
|
+
impl ArriModel for ${prefixedStructName} {
|
762
772
|
fn new() -> Self {
|
763
773
|
Self {
|
764
774
|
${defaultParts.join(",\n")},
|
@@ -802,7 +812,8 @@ function rustStringFromSchema(schema, context) {
|
|
802
812
|
const defaultValue = isOptionType ? "None" : '"".to_string()';
|
803
813
|
const typeName = isOptionType ? "Option<String>" : "String";
|
804
814
|
return {
|
805
|
-
typeName,
|
815
|
+
typeId: typeName,
|
816
|
+
finalTypeName: typeName,
|
806
817
|
defaultValue,
|
807
818
|
isNullable: schema.nullable ?? false,
|
808
819
|
fromJsonTemplate(input, key) {
|
@@ -851,7 +862,8 @@ function rustBooleanFromSchema(schema, context) {
|
|
851
862
|
const defaultValue = isOptionType ? "None" : "false";
|
852
863
|
const typeName = isOptionType ? "Option<bool>" : "bool";
|
853
864
|
return {
|
854
|
-
typeName,
|
865
|
+
typeId: typeName,
|
866
|
+
finalTypeName: typeName,
|
855
867
|
defaultValue,
|
856
868
|
isNullable: schema.nullable ?? false,
|
857
869
|
fromJsonTemplate(input, key) {
|
@@ -900,7 +912,8 @@ function rustTimestampFromSchema(schema, context) {
|
|
900
912
|
const typeName = isOptionType ? "Option<DateTime<FixedOffset>>" : "DateTime<FixedOffset>";
|
901
913
|
const defaultValue = isOptionType ? "None" : "DateTime::default()";
|
902
914
|
return {
|
903
|
-
typeName,
|
915
|
+
typeId: typeName,
|
916
|
+
finalTypeName: typeName,
|
904
917
|
defaultValue,
|
905
918
|
isNullable: schema.nullable ?? false,
|
906
919
|
fromJsonTemplate(input, key) {
|
@@ -966,7 +979,8 @@ function rustF32FromSchema(schema, context) {
|
|
966
979
|
const typeName = isOptionType ? `Option<f32>` : "f32";
|
967
980
|
const defaultValue = isOptionType ? `None` : "0.0";
|
968
981
|
return {
|
969
|
-
typeName,
|
982
|
+
typeId: typeName,
|
983
|
+
finalTypeName: typeName,
|
970
984
|
defaultValue,
|
971
985
|
isNullable: schema.nullable ?? false,
|
972
986
|
fromJsonTemplate(input, key) {
|
@@ -1020,7 +1034,8 @@ function rustF64FromSchema(schema, context) {
|
|
1020
1034
|
const typeName = isOptionType ? `Option<f64>` : "f64";
|
1021
1035
|
const defaultValue = isOptionType ? `None` : "0.0";
|
1022
1036
|
return {
|
1023
|
-
typeName,
|
1037
|
+
typeId: typeName,
|
1038
|
+
finalTypeName: typeName,
|
1024
1039
|
defaultValue,
|
1025
1040
|
isNullable: schema.nullable ?? false,
|
1026
1041
|
fromJsonTemplate(input, key) {
|
@@ -1074,7 +1089,8 @@ function rustI8FromSchema(schema, context) {
|
|
1074
1089
|
const typeName = isOptionType ? `Option<i8>` : "i8";
|
1075
1090
|
const defaultValue = isOptionType ? `None` : "0";
|
1076
1091
|
return {
|
1077
|
-
typeName,
|
1092
|
+
typeId: typeName,
|
1093
|
+
finalTypeName: typeName,
|
1078
1094
|
defaultValue,
|
1079
1095
|
isNullable: schema.nullable ?? false,
|
1080
1096
|
fromJsonTemplate(input, key) {
|
@@ -1131,7 +1147,8 @@ function rustU8FromSchema(schema, context) {
|
|
1131
1147
|
const typeName = isOptionType ? "Option<u8>" : "u8";
|
1132
1148
|
const defaultValue = isOptionType ? "None" : "0";
|
1133
1149
|
return {
|
1134
|
-
typeName,
|
1150
|
+
typeId: typeName,
|
1151
|
+
finalTypeName: typeName,
|
1135
1152
|
defaultValue,
|
1136
1153
|
isNullable: schema.nullable ?? false,
|
1137
1154
|
fromJsonTemplate(input, key) {
|
@@ -1188,7 +1205,8 @@ function rustI16FromSchema(schema, context) {
|
|
1188
1205
|
const typeName = isOptionType ? "Option<i16>" : "i16";
|
1189
1206
|
const defaultValue = isOptionType ? "None" : "0";
|
1190
1207
|
return {
|
1191
|
-
typeName,
|
1208
|
+
typeId: typeName,
|
1209
|
+
finalTypeName: typeName,
|
1192
1210
|
defaultValue,
|
1193
1211
|
isNullable: schema.nullable ?? false,
|
1194
1212
|
fromJsonTemplate(input, key) {
|
@@ -1245,7 +1263,8 @@ function rustU16FromSchema(schema, context) {
|
|
1245
1263
|
const typeName = isOptionType ? "Option<u16>" : "u16";
|
1246
1264
|
const defaultValue = isOptionType ? "None" : "0";
|
1247
1265
|
return {
|
1248
|
-
typeName,
|
1266
|
+
typeId: typeName,
|
1267
|
+
finalTypeName: typeName,
|
1249
1268
|
defaultValue,
|
1250
1269
|
isNullable: schema.nullable ?? false,
|
1251
1270
|
fromJsonTemplate(input, key) {
|
@@ -1302,7 +1321,8 @@ function rustI32FromSchema(schema, context) {
|
|
1302
1321
|
const typeName = isOptionType ? "Option<i32>" : "i32";
|
1303
1322
|
const defaultValue = isOptionType ? "None" : "0";
|
1304
1323
|
return {
|
1305
|
-
typeName,
|
1324
|
+
typeId: typeName,
|
1325
|
+
finalTypeName: typeName,
|
1306
1326
|
defaultValue,
|
1307
1327
|
isNullable: schema.nullable ?? false,
|
1308
1328
|
fromJsonTemplate(input, key) {
|
@@ -1359,7 +1379,8 @@ function rustU32FromSchema(schema, context) {
|
|
1359
1379
|
const typeName = isOptionType ? "Option<u32>" : "u32";
|
1360
1380
|
const defaultValue = isOptionType ? "None" : "0";
|
1361
1381
|
return {
|
1362
|
-
typeName,
|
1382
|
+
typeId: typeName,
|
1383
|
+
finalTypeName: typeName,
|
1363
1384
|
defaultValue,
|
1364
1385
|
isNullable: schema.nullable ?? false,
|
1365
1386
|
fromJsonTemplate(input, key) {
|
@@ -1416,7 +1437,8 @@ function rustI64FromSchema(schema, context) {
|
|
1416
1437
|
const typeName = isOptionType ? "Option<i64>" : "i64";
|
1417
1438
|
const defaultValue = isOptionType ? "None" : "0";
|
1418
1439
|
return {
|
1419
|
-
typeName,
|
1440
|
+
typeId: typeName,
|
1441
|
+
finalTypeName: typeName,
|
1420
1442
|
defaultValue,
|
1421
1443
|
isNullable: schema.nullable ?? false,
|
1422
1444
|
fromJsonTemplate(input, key) {
|
@@ -1470,7 +1492,8 @@ function rustU64FromSchema(schema, context) {
|
|
1470
1492
|
const typeName = isOptionType ? "Option<u64>" : "u64";
|
1471
1493
|
const defaultValue = isOptionType ? "None" : "0";
|
1472
1494
|
return {
|
1473
|
-
typeName,
|
1495
|
+
typeId: typeName,
|
1496
|
+
finalTypeName: typeName,
|
1474
1497
|
defaultValue,
|
1475
1498
|
isNullable: schema.nullable ?? false,
|
1476
1499
|
fromJsonTemplate(input, key) {
|
@@ -1543,17 +1566,17 @@ function rustHttpRpcFromSchema(schema, context) {
|
|
1543
1566
|
if (schema.isDeprecated) {
|
1544
1567
|
leading += "#[deprecated]\n";
|
1545
1568
|
}
|
1546
|
-
const params = schema.params ? validRustName(schema.params) : undefined;
|
1547
|
-
const response = schema.response ? validRustName(schema.response) : undefined;
|
1569
|
+
const params = schema.params ? context.typeNamePrefix + validRustName(schema.params) : undefined;
|
1570
|
+
const response = schema.response ? context.typeNamePrefix + validRustName(schema.response) : undefined;
|
1548
1571
|
if (schema.isEventStream) {
|
1549
1572
|
return `${leading}pub async fn ${functionName}<OnEvent>(
|
1550
1573
|
&self,
|
1551
|
-
${params ? `params: ${
|
1574
|
+
${params ? `params: ${params},` : ""}
|
1552
1575
|
on_event: &mut OnEvent,
|
1553
1576
|
max_retry_count: Option<u64>,
|
1554
1577
|
max_retry_interval: Option<u64>,
|
1555
1578
|
) where
|
1556
|
-
OnEvent: FnMut(SseEvent<${response ?
|
1579
|
+
OnEvent: FnMut(SseEvent<${response ? response : "EmptyArriModel"}>, &mut SseController) + std::marker::Send + std::marker::Sync,
|
1557
1580
|
{
|
1558
1581
|
parsed_arri_sse_request(
|
1559
1582
|
ArriParsedSseRequestOptions {
|
@@ -1573,8 +1596,8 @@ function rustHttpRpcFromSchema(schema, context) {
|
|
1573
1596
|
}
|
1574
1597
|
return `${leading}pub async fn ${functionName}(
|
1575
1598
|
&self,
|
1576
|
-
${params ? `params: ${
|
1577
|
-
) -> Result<${
|
1599
|
+
${params ? `params: ${params},` : ""}
|
1600
|
+
) -> Result<${response ?? "()"}, ArriError> {
|
1578
1601
|
parsed_arri_request(
|
1579
1602
|
ArriParsedRequestOptions {
|
1580
1603
|
http_client: &self._config.http_client,
|
@@ -1584,7 +1607,7 @@ function rustHttpRpcFromSchema(schema, context) {
|
|
1584
1607
|
client_version: "${context.clientVersion}".to_string(),
|
1585
1608
|
},
|
1586
1609
|
${params ? `Some(params)` : "None::<EmptyArriModel>"},
|
1587
|
-
|body| ${response ? `return ${
|
1610
|
+
|body| ${response ? `return ${response}::from_json_string(body)` : "{}"},
|
1588
1611
|
)
|
1589
1612
|
.await
|
1590
1613
|
}`;
|
@@ -1689,10 +1712,11 @@ function rustRecordFromSchema(schema, context) {
|
|
1689
1712
|
generatedTypes: context.generatedTypes
|
1690
1713
|
});
|
1691
1714
|
const isOptionType = outputIsOptionType(schema, context);
|
1692
|
-
const typeName = isOptionType ? `Option<BTreeMap<String, ${innerType.
|
1715
|
+
const typeName = isOptionType ? `Option<BTreeMap<String, ${innerType.finalTypeName}>>` : `BTreeMap<String, ${innerType.finalTypeName}>`;
|
1693
1716
|
const defaultValue = isOptionType ? `None` : `BTreeMap::new()`;
|
1694
1717
|
return {
|
1695
|
-
typeName,
|
1718
|
+
typeId: typeName,
|
1719
|
+
finalTypeName: typeName,
|
1696
1720
|
defaultValue,
|
1697
1721
|
isNullable: schema.nullable ?? false,
|
1698
1722
|
fromJsonTemplate(input, key) {
|
@@ -1700,7 +1724,7 @@ function rustRecordFromSchema(schema, context) {
|
|
1700
1724
|
if (isOptionType) {
|
1701
1725
|
return `match ${input} {
|
1702
1726
|
Some(serde_json::Value::Object(${innerKey})) => {
|
1703
|
-
let mut ${innerKey}_result: BTreeMap<String, ${innerType.
|
1727
|
+
let mut ${innerKey}_result: BTreeMap<String, ${innerType.finalTypeName}> = BTreeMap::new();
|
1704
1728
|
for (_key_, _value_) in ${innerKey}.into_iter() {
|
1705
1729
|
${innerKey}_result.insert(
|
1706
1730
|
_key_.to_owned(),
|
@@ -1714,7 +1738,7 @@ function rustRecordFromSchema(schema, context) {
|
|
1714
1738
|
}
|
1715
1739
|
return `match ${input} {
|
1716
1740
|
Some(serde_json::Value::Object(${innerKey})) => {
|
1717
|
-
let mut ${innerKey}_result: BTreeMap<String, ${innerType.
|
1741
|
+
let mut ${innerKey}_result: BTreeMap<String, ${innerType.finalTypeName}> = BTreeMap::new();
|
1718
1742
|
for (_key_, _value_) in ${innerKey}.into_iter() {
|
1719
1743
|
${innerKey}_result.insert(
|
1720
1744
|
_key_.to_owned(),
|
@@ -1763,9 +1787,10 @@ function rustRecordFromSchema(schema, context) {
|
|
1763
1787
|
}
|
1764
1788
|
|
1765
1789
|
function rustRefFromSchema(schema, context) {
|
1766
|
-
const innerTypeName =
|
1790
|
+
const innerTypeName = validRustName(schema.ref);
|
1791
|
+
const prefixedInnerTypeName = `${context.typeNamePrefix}${innerTypeName}`;
|
1767
1792
|
const isOptionType = outputIsOptionType(schema, context);
|
1768
|
-
let typeName = `Box<${
|
1793
|
+
let typeName = `Box<${prefixedInnerTypeName}>`;
|
1769
1794
|
if (isOptionType) {
|
1770
1795
|
typeName = `Option<${typeName}>`;
|
1771
1796
|
}
|
@@ -1773,17 +1798,18 @@ function rustRefFromSchema(schema, context) {
|
|
1773
1798
|
if (isOptionType) {
|
1774
1799
|
defaultValue = "None";
|
1775
1800
|
} else {
|
1776
|
-
defaultValue = `Box::new(${
|
1801
|
+
defaultValue = `Box::new(${prefixedInnerTypeName}::new())`;
|
1777
1802
|
}
|
1778
1803
|
return {
|
1779
|
-
typeName,
|
1804
|
+
typeId: typeName,
|
1805
|
+
finalTypeName: typeName,
|
1780
1806
|
defaultValue,
|
1781
1807
|
isNullable: schema.nullable ?? false,
|
1782
1808
|
fromJsonTemplate(input, key) {
|
1783
1809
|
const innerKey = validRustIdentifier(`${key}_val`);
|
1784
1810
|
const valFromJson = (input2) => {
|
1785
1811
|
{
|
1786
|
-
return `Box::new(${
|
1812
|
+
return `Box::new(${prefixedInnerTypeName}::from_json(${input2}.to_owned()))`;
|
1787
1813
|
}
|
1788
1814
|
};
|
1789
1815
|
if (isOptionType) {
|
@@ -1804,7 +1830,7 @@ function rustRefFromSchema(schema, context) {
|
|
1804
1830
|
}
|
1805
1831
|
_ => ${valFromJson(innerKey)},
|
1806
1832
|
},
|
1807
|
-
_ => Box::new(${
|
1833
|
+
_ => Box::new(${prefixedInnerTypeName}::new()),
|
1808
1834
|
}`;
|
1809
1835
|
},
|
1810
1836
|
toJsonTemplate(input, target) {
|