@arrirpc/codegen-dart 0.58.0 → 0.58.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +40 -6
- package/dist/index.mjs +40 -6
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
@@ -167,6 +167,25 @@ function getDartClassName(schema, context) {
|
|
167
167
|
context.modelPrefix
|
168
168
|
);
|
169
169
|
}
|
170
|
+
function getCodeComments(metadata, leading) {
|
171
|
+
if (!metadata?.description && !metadata?.isDeprecated)
|
172
|
+
return "";
|
173
|
+
if (!metadata.description && metadata.isDeprecated) {
|
174
|
+
return `${leading ?? ""}@deprecated
|
175
|
+
`;
|
176
|
+
}
|
177
|
+
const descriptionString = metadata.description?.split("\n").map((line) => `${leading ?? ""}/// ${line}`).join("\n");
|
178
|
+
if (descriptionString && metadata.isDeprecated) {
|
179
|
+
return `${descriptionString}
|
180
|
+
${leading ?? ""}@deprecated
|
181
|
+
`;
|
182
|
+
}
|
183
|
+
if (descriptionString) {
|
184
|
+
return `${descriptionString}
|
185
|
+
`;
|
186
|
+
}
|
187
|
+
return "";
|
188
|
+
}
|
170
189
|
|
171
190
|
function dartAnyFromSchema(schema, context) {
|
172
191
|
const typeName = `dynamic`;
|
@@ -305,7 +324,12 @@ function dartClassFromSchema(schema, context) {
|
|
305
324
|
});
|
306
325
|
const propName = validDartIdentifier(key);
|
307
326
|
propNames.push(propName);
|
308
|
-
fieldParts.push(
|
327
|
+
fieldParts.push(
|
328
|
+
`${getCodeComments(
|
329
|
+
innerSchema.metadata,
|
330
|
+
" "
|
331
|
+
)} final ${typeResult.typeName} ${propName};`
|
332
|
+
);
|
309
333
|
constructorParts.push(` required this.${propName},`);
|
310
334
|
defaultParts.push(` ${propName}: ${typeResult.defaultValue},`);
|
311
335
|
fromJsonParts.push(
|
@@ -348,7 +372,9 @@ function dartClassFromSchema(schema, context) {
|
|
348
372
|
});
|
349
373
|
const propName = validDartIdentifier(key);
|
350
374
|
propNames.push(propName);
|
351
|
-
fieldParts.push(
|
375
|
+
fieldParts.push(
|
376
|
+
`${getCodeComments(innerSchema.metadata, " ")} final ${typeResult.typeName} ${propName};`
|
377
|
+
);
|
352
378
|
constructorParts.push(` this.${propName},`);
|
353
379
|
fromJsonParts.push(
|
354
380
|
` final ${propName} = ${typeResult.fromJson(`_input_["${key}"]`, key)};`
|
@@ -376,7 +402,7 @@ function dartClassFromSchema(schema, context) {
|
|
376
402
|
String get ${validDartIdentifier(context.discriminatorKey)} => "${context.discriminatorValue}";
|
377
403
|
`;
|
378
404
|
}
|
379
|
-
result.content =
|
405
|
+
result.content = `${getCodeComments(schema.metadata)}class ${finalClassName} implements ${context.discriminatorParentId ?? "ArriModel"} {
|
380
406
|
${fieldParts.join("\n")}
|
381
407
|
const ${finalClassName}({
|
382
408
|
${constructorParts.join("\n")}
|
@@ -803,6 +829,10 @@ function dartRpcFromSchema(schema, context) {
|
|
803
829
|
}
|
804
830
|
function dartHttpRpcFromSchema(schema, context) {
|
805
831
|
const functionName = getFunctionName(context.instancePath);
|
832
|
+
const metadata = {
|
833
|
+
description: schema.description,
|
834
|
+
isDeprecated: schema.isDeprecated
|
835
|
+
};
|
806
836
|
let responseType = "void";
|
807
837
|
let paramsType = "";
|
808
838
|
if (schema.response) {
|
@@ -812,7 +842,7 @@ function dartHttpRpcFromSchema(schema, context) {
|
|
812
842
|
paramsType = `${context.modelPrefix}${validDartClassName(schema.params, context.modelPrefix)}`;
|
813
843
|
}
|
814
844
|
if (schema.isEventStream) {
|
815
|
-
return
|
845
|
+
return `${getCodeComments(metadata)}EventSource<${responseType}> ${functionName}(
|
816
846
|
${paramsType ? `${paramsType} params, ` : ""} {
|
817
847
|
void Function(${responseType} data, EventSource<${responseType}> connection)? onMessage,
|
818
848
|
void Function(http.StreamedResponse response, EventSource<${responseType}> connection)? onOpen,
|
@@ -840,7 +870,7 @@ function dartHttpRpcFromSchema(schema, context) {
|
|
840
870
|
);
|
841
871
|
}`;
|
842
872
|
}
|
843
|
-
return
|
873
|
+
return `${getCodeComments(metadata)}Future<${responseType}> ${functionName}(${paramsType ? `${paramsType} params` : ""}) async {
|
844
874
|
return parsedArriRequest(
|
845
875
|
"$_baseUrl${schema.path}",
|
846
876
|
method: HttpMethod.${schema.method.toLowerCase()},
|
@@ -857,6 +887,10 @@ function getFunctionName(instancePath) {
|
|
857
887
|
return parts.pop() ?? "";
|
858
888
|
}
|
859
889
|
function dartWsRpcFromSchema(schema, context) {
|
890
|
+
const metadata = {
|
891
|
+
description: schema.description,
|
892
|
+
isDeprecated: schema.isDeprecated
|
893
|
+
};
|
860
894
|
const functionName = getFunctionName(context.instancePath);
|
861
895
|
let responseType;
|
862
896
|
let paramsType;
|
@@ -866,7 +900,7 @@ function dartWsRpcFromSchema(schema, context) {
|
|
866
900
|
if (schema.params) {
|
867
901
|
paramsType = `${context.modelPrefix}${validDartClassName(schema.params, context.modelPrefix)}`;
|
868
902
|
}
|
869
|
-
return
|
903
|
+
return `${getCodeComments(metadata)}Future<ArriWebsocketController<${responseType ?? "void"}, ${paramsType ?? "void"}>> ${functionName}() {
|
870
904
|
return arriWebsocketRequest(
|
871
905
|
"$_baseUrl${schema.path}",
|
872
906
|
headers: _headers,
|
package/dist/index.mjs
CHANGED
@@ -160,6 +160,25 @@ function getDartClassName(schema, context) {
|
|
160
160
|
context.modelPrefix
|
161
161
|
);
|
162
162
|
}
|
163
|
+
function getCodeComments(metadata, leading) {
|
164
|
+
if (!metadata?.description && !metadata?.isDeprecated)
|
165
|
+
return "";
|
166
|
+
if (!metadata.description && metadata.isDeprecated) {
|
167
|
+
return `${leading ?? ""}@deprecated
|
168
|
+
`;
|
169
|
+
}
|
170
|
+
const descriptionString = metadata.description?.split("\n").map((line) => `${leading ?? ""}/// ${line}`).join("\n");
|
171
|
+
if (descriptionString && metadata.isDeprecated) {
|
172
|
+
return `${descriptionString}
|
173
|
+
${leading ?? ""}@deprecated
|
174
|
+
`;
|
175
|
+
}
|
176
|
+
if (descriptionString) {
|
177
|
+
return `${descriptionString}
|
178
|
+
`;
|
179
|
+
}
|
180
|
+
return "";
|
181
|
+
}
|
163
182
|
|
164
183
|
function dartAnyFromSchema(schema, context) {
|
165
184
|
const typeName = `dynamic`;
|
@@ -298,7 +317,12 @@ function dartClassFromSchema(schema, context) {
|
|
298
317
|
});
|
299
318
|
const propName = validDartIdentifier(key);
|
300
319
|
propNames.push(propName);
|
301
|
-
fieldParts.push(
|
320
|
+
fieldParts.push(
|
321
|
+
`${getCodeComments(
|
322
|
+
innerSchema.metadata,
|
323
|
+
" "
|
324
|
+
)} final ${typeResult.typeName} ${propName};`
|
325
|
+
);
|
302
326
|
constructorParts.push(` required this.${propName},`);
|
303
327
|
defaultParts.push(` ${propName}: ${typeResult.defaultValue},`);
|
304
328
|
fromJsonParts.push(
|
@@ -341,7 +365,9 @@ function dartClassFromSchema(schema, context) {
|
|
341
365
|
});
|
342
366
|
const propName = validDartIdentifier(key);
|
343
367
|
propNames.push(propName);
|
344
|
-
fieldParts.push(
|
368
|
+
fieldParts.push(
|
369
|
+
`${getCodeComments(innerSchema.metadata, " ")} final ${typeResult.typeName} ${propName};`
|
370
|
+
);
|
345
371
|
constructorParts.push(` this.${propName},`);
|
346
372
|
fromJsonParts.push(
|
347
373
|
` final ${propName} = ${typeResult.fromJson(`_input_["${key}"]`, key)};`
|
@@ -369,7 +395,7 @@ function dartClassFromSchema(schema, context) {
|
|
369
395
|
String get ${validDartIdentifier(context.discriminatorKey)} => "${context.discriminatorValue}";
|
370
396
|
`;
|
371
397
|
}
|
372
|
-
result.content =
|
398
|
+
result.content = `${getCodeComments(schema.metadata)}class ${finalClassName} implements ${context.discriminatorParentId ?? "ArriModel"} {
|
373
399
|
${fieldParts.join("\n")}
|
374
400
|
const ${finalClassName}({
|
375
401
|
${constructorParts.join("\n")}
|
@@ -796,6 +822,10 @@ function dartRpcFromSchema(schema, context) {
|
|
796
822
|
}
|
797
823
|
function dartHttpRpcFromSchema(schema, context) {
|
798
824
|
const functionName = getFunctionName(context.instancePath);
|
825
|
+
const metadata = {
|
826
|
+
description: schema.description,
|
827
|
+
isDeprecated: schema.isDeprecated
|
828
|
+
};
|
799
829
|
let responseType = "void";
|
800
830
|
let paramsType = "";
|
801
831
|
if (schema.response) {
|
@@ -805,7 +835,7 @@ function dartHttpRpcFromSchema(schema, context) {
|
|
805
835
|
paramsType = `${context.modelPrefix}${validDartClassName(schema.params, context.modelPrefix)}`;
|
806
836
|
}
|
807
837
|
if (schema.isEventStream) {
|
808
|
-
return
|
838
|
+
return `${getCodeComments(metadata)}EventSource<${responseType}> ${functionName}(
|
809
839
|
${paramsType ? `${paramsType} params, ` : ""} {
|
810
840
|
void Function(${responseType} data, EventSource<${responseType}> connection)? onMessage,
|
811
841
|
void Function(http.StreamedResponse response, EventSource<${responseType}> connection)? onOpen,
|
@@ -833,7 +863,7 @@ function dartHttpRpcFromSchema(schema, context) {
|
|
833
863
|
);
|
834
864
|
}`;
|
835
865
|
}
|
836
|
-
return
|
866
|
+
return `${getCodeComments(metadata)}Future<${responseType}> ${functionName}(${paramsType ? `${paramsType} params` : ""}) async {
|
837
867
|
return parsedArriRequest(
|
838
868
|
"$_baseUrl${schema.path}",
|
839
869
|
method: HttpMethod.${schema.method.toLowerCase()},
|
@@ -850,6 +880,10 @@ function getFunctionName(instancePath) {
|
|
850
880
|
return parts.pop() ?? "";
|
851
881
|
}
|
852
882
|
function dartWsRpcFromSchema(schema, context) {
|
883
|
+
const metadata = {
|
884
|
+
description: schema.description,
|
885
|
+
isDeprecated: schema.isDeprecated
|
886
|
+
};
|
853
887
|
const functionName = getFunctionName(context.instancePath);
|
854
888
|
let responseType;
|
855
889
|
let paramsType;
|
@@ -859,7 +893,7 @@ function dartWsRpcFromSchema(schema, context) {
|
|
859
893
|
if (schema.params) {
|
860
894
|
paramsType = `${context.modelPrefix}${validDartClassName(schema.params, context.modelPrefix)}`;
|
861
895
|
}
|
862
|
-
return
|
896
|
+
return `${getCodeComments(metadata)}Future<ArriWebsocketController<${responseType ?? "void"}, ${paramsType ?? "void"}>> ${functionName}() {
|
863
897
|
return arriWebsocketRequest(
|
864
898
|
"$_baseUrl${schema.path}",
|
865
899
|
headers: _headers,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arrirpc/codegen-dart",
|
3
|
-
"version": "0.58.
|
3
|
+
"version": "0.58.1",
|
4
4
|
"type": "module",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": {
|
@@ -23,7 +23,7 @@
|
|
23
23
|
],
|
24
24
|
"dependencies": {
|
25
25
|
"pathe": "^1.1.2",
|
26
|
-
"@arrirpc/codegen-utils": "0.58.
|
27
|
-
"@arrirpc/schema": "0.58.
|
26
|
+
"@arrirpc/codegen-utils": "0.58.1",
|
27
|
+
"@arrirpc/schema": "0.58.1"
|
28
28
|
}
|
29
29
|
}
|