grpc-dc 0.32.11 → 0.32.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin/gen/generators.js +109 -11
package/package.json
CHANGED
package/plugin/gen/generators.js
CHANGED
|
@@ -3628,6 +3628,12 @@ function javaClientStreamClass(m, svc) {
|
|
|
3628
3628
|
+ ' public ' + m.output + ' recv() throws Exception {\n'
|
|
3629
3629
|
+ ' ' + m.output + ' resp = new ' + m.output + '();\n'
|
|
3630
3630
|
+ ' stream.recv(resp);\n return resp;\n }\n\n'
|
|
3631
|
+
+ ' /** Initial metadata (response headers); null until they arrive. */\n'
|
|
3632
|
+
+ ' public Map<String, String> headers() {\n'
|
|
3633
|
+
+ ' return stream.headers() == null ? null : stream.headers().metadata;\n }\n\n'
|
|
3634
|
+
+ ' /** Trailing metadata of the terminal status; null until it arrives. */\n'
|
|
3635
|
+
+ ' public Map<String, String> trailers() {\n'
|
|
3636
|
+
+ ' return stream.trailers();\n }\n\n'
|
|
3631
3637
|
+ ' /** Abort this stream (sends RST, wakes a pending recv). */\n'
|
|
3632
3638
|
+ ' public void cancel() {\n'
|
|
3633
3639
|
+ ' stream.cancel();\n }\n\n'
|
|
@@ -3959,6 +3965,12 @@ function jpExplicitLiteral(model, f) {
|
|
|
3959
3965
|
}
|
|
3960
3966
|
}
|
|
3961
3967
|
|
|
3968
|
+
function jpBoxedDefault(model, f) {
|
|
3969
|
+
if (f.type === 1) return '0.0';
|
|
3970
|
+
if (f.type === 2) return '0.0f';
|
|
3971
|
+
return jpDefault(model, f);
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3962
3974
|
function jpDefault(model, f) {
|
|
3963
3975
|
const lit = jpExplicitLiteral(model, f);
|
|
3964
3976
|
if (lit !== null) return lit;
|
|
@@ -4194,8 +4206,8 @@ function jpMapHelpers(model, entry, support) {
|
|
|
4194
4206
|
+ jpEncodeSingular(model, { ...valF, label: 1 }, 'value', ' ', support)
|
|
4195
4207
|
+ ' return w.toBytes();\n }\n\n'
|
|
4196
4208
|
+ ' static Object[] ' + base + 'Decode(byte[] bytes) {\n'
|
|
4197
|
-
+ ' ' + kt + ' key = ' +
|
|
4198
|
-
+ ' ' + vt + ' value = ' +
|
|
4209
|
+
+ ' ' + kt + ' key = ' + jpBoxedDefault(model, { ...keyF, label: 1 }) + ';\n'
|
|
4210
|
+
+ ' ' + vt + ' value = ' + jpBoxedDefault(model, { ...valF, label: 1 }) + ';\n'
|
|
4199
4211
|
+ ' Reader r = new Reader(bytes);\n Field field;\n while ((field = r.next()) != null) {\n switch (field.number) {\n'
|
|
4200
4212
|
+ ' case ' + keyF.number + ': ' + jpDecodeSingularStmt(model, { ...keyF, label: 1 }, 'key') + ' break;\n'
|
|
4201
4213
|
+ ' case ' + valF.number + ': ' + jpDecodeSingularStmt(model, { ...valF, label: 1 }, 'value') + ' break;\n'
|
|
@@ -4377,6 +4389,22 @@ function emitJavaPbFiles(model) {
|
|
|
4377
4389
|
return files;
|
|
4378
4390
|
}
|
|
4379
4391
|
|
|
4392
|
+
function javaQualifyType(pkg, simple, full) {
|
|
4393
|
+
if (!full || !pkg || full.startsWith(pkg + '.')) return simple;
|
|
4394
|
+
return full.split('.').slice(0, -1).join('.') + '.' + simple;
|
|
4395
|
+
}
|
|
4396
|
+
|
|
4397
|
+
function javaQualifyServices(pkg, services) {
|
|
4398
|
+
return services.map((svc) => ({
|
|
4399
|
+
...svc,
|
|
4400
|
+
methods: svc.methods.map((m) => ({
|
|
4401
|
+
...m,
|
|
4402
|
+
input: javaQualifyType(pkg, m.input, m.inputFull),
|
|
4403
|
+
output: javaQualifyType(pkg, m.output, m.outputFull),
|
|
4404
|
+
})),
|
|
4405
|
+
}));
|
|
4406
|
+
}
|
|
4407
|
+
|
|
4380
4408
|
function emitJavaFile(model, params) {
|
|
4381
4409
|
const base = baseName(model.name);
|
|
4382
4410
|
const className = pascalName(base) + 'GrpcDc';
|
|
@@ -4391,7 +4419,7 @@ function emitJavaFile(model, params) {
|
|
|
4391
4419
|
+ 'import java.util.concurrent.CompletableFuture;\nimport java.util.concurrent.CompletionException;\n\n'
|
|
4392
4420
|
+ '/** Generated gRPC-over-DataChannels stubs for ' + model.name + '. */\n'
|
|
4393
4421
|
+ 'public final class ' + className + ' {\n private ' + className + '() {}\n\n'
|
|
4394
|
-
+ model.services.map(javaService).join('')
|
|
4422
|
+
+ javaQualifyServices(pkg, model.services).map(javaService).join('')
|
|
4395
4423
|
+ '}\n',
|
|
4396
4424
|
};
|
|
4397
4425
|
const pbFiles = emitJavaPbFiles(model);
|
|
@@ -4441,6 +4469,10 @@ function csClientStreamClass(m, svc) {
|
|
|
4441
4469
|
+ ' public ' + m.output + ' Recv()\n {\n'
|
|
4442
4470
|
+ ' var resp = new ' + m.output + '();\n'
|
|
4443
4471
|
+ ' _stream.Recv(resp);\n return resp;\n }\n\n'
|
|
4472
|
+
+ ' /// <summary>Initial metadata (response headers); null until they arrive.</summary>\n'
|
|
4473
|
+
+ ' public Dictionary<string, string> Headers => _stream.Headers?.Metadata;\n\n'
|
|
4474
|
+
+ ' /// <summary>Trailing metadata of the terminal status; null until it arrives.</summary>\n'
|
|
4475
|
+
+ ' public Dictionary<string, string> Trailers => _stream.Trailers;\n\n'
|
|
4444
4476
|
+ ' /// <summary>Abort this stream (sends RST, wakes a pending Recv).</summary>\n'
|
|
4445
4477
|
+ ' public void Cancel() => _stream.Cancel();\n\n'
|
|
4446
4478
|
+ ' /// <summary>Abandon the call if still live (RST); no-op once terminated.</summary>\n'
|
|
@@ -4670,10 +4702,26 @@ function cspFindOwner(model, f) {
|
|
|
4670
4702
|
function cspFieldName(model, f) {
|
|
4671
4703
|
const n = cspPascal(f.name);
|
|
4672
4704
|
const owner = cspFindOwner(model, f);
|
|
4673
|
-
if (owner && (owner.nested.some((m) => m.name === n) || owner.enums.some((e) => e.name === n))) return n + '_';
|
|
4705
|
+
if (owner && (owner.name === n || owner.nested.some((m) => m.name === n) || owner.enums.some((e) => e.name === n))) return n + '_';
|
|
4674
4706
|
return n;
|
|
4675
4707
|
}
|
|
4676
4708
|
|
|
4709
|
+
function csQualifyType(pkg, simple, full) {
|
|
4710
|
+
if (!full || !pkg || full.startsWith(pkg + '.')) return simple;
|
|
4711
|
+
return full[0].toUpperCase() + full.slice(1);
|
|
4712
|
+
}
|
|
4713
|
+
|
|
4714
|
+
function csQualifyServices(pkg, services) {
|
|
4715
|
+
return services.map((svc) => ({
|
|
4716
|
+
...svc,
|
|
4717
|
+
methods: svc.methods.map((m) => ({
|
|
4718
|
+
...m,
|
|
4719
|
+
input: csQualifyType(pkg, m.input, m.inputFull),
|
|
4720
|
+
output: csQualifyType(pkg, m.output, m.outputFull),
|
|
4721
|
+
})),
|
|
4722
|
+
}));
|
|
4723
|
+
}
|
|
4724
|
+
|
|
4677
4725
|
function cspResolve(model, typeName) {
|
|
4678
4726
|
const entry = model.types.get(typeName);
|
|
4679
4727
|
if (!entry) throw new Error('unresolved type ' + typeName);
|
|
@@ -5153,7 +5201,7 @@ function emitCsharpFile(model, params) {
|
|
|
5153
5201
|
+ 'namespace ' + ns + ';\n\n'
|
|
5154
5202
|
+ '/// <summary>Generated gRPC-over-DataChannels stubs for ' + model.name + '.</summary>\n'
|
|
5155
5203
|
+ 'public static class ' + className + '\n{\n'
|
|
5156
|
-
+ model.services.map(csService).join('')
|
|
5204
|
+
+ csQualifyServices(model.package, model.services).map(csService).join('')
|
|
5157
5205
|
+ '}\n',
|
|
5158
5206
|
};
|
|
5159
5207
|
const pbFiles = emitCsharpPbFiles(model);
|
|
@@ -6799,6 +6847,10 @@ function kotlinClientStreamClass(m, svc) {
|
|
|
6799
6847
|
+ ' fun recv(): ' + m.output + ' {\n'
|
|
6800
6848
|
+ ' val resp = ' + m.output + '()\n'
|
|
6801
6849
|
+ ' stream.recv(resp)\n return resp\n }\n\n'
|
|
6850
|
+
+ ' /** Initial metadata (response headers); null until they arrive. */\n'
|
|
6851
|
+
+ ' fun headers(): Map<String, String>? = stream.headers?.metadata\n\n'
|
|
6852
|
+
+ ' /** Trailing metadata of the terminal status; null until it arrives. */\n'
|
|
6853
|
+
+ ' fun trailers(): Map<String, String>? = stream.trailers\n\n'
|
|
6802
6854
|
+ ' /** Abort this stream (sends RST, wakes a pending recv). */\n'
|
|
6803
6855
|
+ ' fun cancel() = stream.cancel()\n\n'
|
|
6804
6856
|
+ ' /** Abandon the call if still live (RST); no-op once terminated. */\n'
|
|
@@ -7008,9 +7060,9 @@ function kotlinService(svc) {
|
|
|
7008
7060
|
+ ' // Adapters are retained for the process lifetime: registration is\n'
|
|
7009
7061
|
+ ' // once-per-process and bounded by service count.\n'
|
|
7010
7062
|
+ ' val adapter = ' + sname + 'ServerAsyncAdapter(impl)\n'
|
|
7011
|
-
+ '
|
|
7063
|
+
+ ' ' + lowerFirst(sname) + 'Adapters.add(adapter)\n'
|
|
7012
7064
|
+ ' register' + sname + 'Server(server, adapter)\n }\n\n'
|
|
7013
|
-
+ ' private val
|
|
7065
|
+
+ ' private val ' + lowerFirst(sname) + 'Adapters = ArrayList<' + sname + 'ServerAsyncAdapter>()\n');
|
|
7014
7066
|
}
|
|
7015
7067
|
|
|
7016
7068
|
|
|
@@ -7488,6 +7540,22 @@ function emitKotlinPbFile(model) {
|
|
|
7488
7540
|
return { name: pascalName(base) + 'Messages.kt', content };
|
|
7489
7541
|
}
|
|
7490
7542
|
|
|
7543
|
+
function kotlinQualifyType(pkg, simple, full) {
|
|
7544
|
+
if (!full || !pkg || full.startsWith(pkg + '.')) return simple;
|
|
7545
|
+
return full;
|
|
7546
|
+
}
|
|
7547
|
+
|
|
7548
|
+
function kotlinQualifyServices(pkg, services) {
|
|
7549
|
+
return services.map((svc) => ({
|
|
7550
|
+
...svc,
|
|
7551
|
+
methods: svc.methods.map((m) => ({
|
|
7552
|
+
...m,
|
|
7553
|
+
input: kotlinQualifyType(pkg, m.input, m.inputFull),
|
|
7554
|
+
output: kotlinQualifyType(pkg, m.output, m.outputFull),
|
|
7555
|
+
})),
|
|
7556
|
+
}));
|
|
7557
|
+
}
|
|
7558
|
+
|
|
7491
7559
|
function emitKotlinFile(model, params) {
|
|
7492
7560
|
const base = baseName(model.name);
|
|
7493
7561
|
const objectName = pascalName(base) + 'GrpcDc';
|
|
@@ -7501,7 +7569,7 @@ function emitKotlinFile(model, params) {
|
|
|
7501
7569
|
+ 'import java.io.EOFException\nimport java.util.concurrent.CompletableFuture\n\n'
|
|
7502
7570
|
+ '/** Generated gRPC-over-DataChannels stubs for ' + model.name + '. */\n'
|
|
7503
7571
|
+ 'object ' + objectName + ' {\n'
|
|
7504
|
-
+ model.services.map(kotlinService).join('')
|
|
7572
|
+
+ kotlinQualifyServices(model.package, model.services).map(kotlinService).join('')
|
|
7505
7573
|
+ '}\n',
|
|
7506
7574
|
};
|
|
7507
7575
|
const pbFile = emitKotlinPbFile(model);
|
|
@@ -11054,7 +11122,11 @@ function scalaService(svc) {
|
|
|
11054
11122
|
+ ' out\n'
|
|
11055
11123
|
+ ' }\n'
|
|
11056
11124
|
+ ' def cancel(): Unit = stream.cancel()\n'
|
|
11057
|
-
+ ' def close(): Unit = stream.close()\n
|
|
11125
|
+
+ ' def close(): Unit = stream.close()\n'
|
|
11126
|
+
+ ' /** Initial metadata (response headers); null until they arrive. */\n'
|
|
11127
|
+
+ ' def headers: Map[String, String] = if (stream.headers == null) null else stream.headers.metadata\n'
|
|
11128
|
+
+ ' /** Trailing metadata of the terminal status; null until it arrives. */\n'
|
|
11129
|
+
+ ' def trailers: Map[String, String] = stream.trailers\n }\n\n';
|
|
11058
11130
|
return ' /** Client for ' + svc.fullName + '. */\n'
|
|
11059
11131
|
+ ' class ' + sname + 'Client(private val channel: grpcdc.Channel) {\n'
|
|
11060
11132
|
+ classOutputs('server-streaming').map((out) => streamClass('server-streaming', out)).join('')
|
|
@@ -11118,8 +11190,18 @@ function scpCamel(s) {
|
|
|
11118
11190
|
return parts[0] + parts.slice(1).map((p) => (p ? p[0].toUpperCase() + p.slice(1) : '')).join('');
|
|
11119
11191
|
}
|
|
11120
11192
|
|
|
11193
|
+
const SCP_KEYWORDS = new Set([
|
|
11194
|
+
'abstract', 'case', 'catch', 'class', 'def', 'do', 'else', 'extends',
|
|
11195
|
+
'false', 'final', 'finally', 'for', 'forSome', 'if', 'implicit',
|
|
11196
|
+
'import', 'lazy', 'match', 'new', 'null', 'object', 'override',
|
|
11197
|
+
'package', 'private', 'protected', 'return', 'sealed', 'super',
|
|
11198
|
+
'this', 'throw', 'trait', 'try', 'true', 'type', 'val', 'var',
|
|
11199
|
+
'while', 'with', 'yield',
|
|
11200
|
+
]);
|
|
11201
|
+
|
|
11121
11202
|
function scpFieldName(f) {
|
|
11122
|
-
|
|
11203
|
+
const n = f.jsonName ? f.jsonName : scpCamel(f.name);
|
|
11204
|
+
return SCP_KEYWORDS.has(n) ? '`' + n + '`' : n;
|
|
11123
11205
|
}
|
|
11124
11206
|
|
|
11125
11207
|
function scpFlat(pkg, full) {
|
|
@@ -11502,6 +11584,22 @@ function emitScalaPbFile(model) {
|
|
|
11502
11584
|
return { name: pascalName(base) + 'Messages.scala', content };
|
|
11503
11585
|
}
|
|
11504
11586
|
|
|
11587
|
+
function scalaQualifyType(pkg, simple, full) {
|
|
11588
|
+
if (!full || !pkg || full.startsWith(pkg + '.')) return simple;
|
|
11589
|
+
return full;
|
|
11590
|
+
}
|
|
11591
|
+
|
|
11592
|
+
function scalaQualifyServices(pkg, services) {
|
|
11593
|
+
return services.map((svc) => ({
|
|
11594
|
+
...svc,
|
|
11595
|
+
methods: svc.methods.map((m) => ({
|
|
11596
|
+
...m,
|
|
11597
|
+
input: scalaQualifyType(pkg, m.input, m.inputFull),
|
|
11598
|
+
output: scalaQualifyType(pkg, m.output, m.outputFull),
|
|
11599
|
+
})),
|
|
11600
|
+
}));
|
|
11601
|
+
}
|
|
11602
|
+
|
|
11505
11603
|
function emitScalaFile(model, params) {
|
|
11506
11604
|
const base = baseName(model.name);
|
|
11507
11605
|
const objName = camelName(base) + 'GrpcDc';
|
|
@@ -11512,7 +11610,7 @@ function emitScalaFile(model, params) {
|
|
|
11512
11610
|
+ 'package ' + model.package + '\n\n'
|
|
11513
11611
|
+ '/** Generated gRPC-over-DataChannels stubs. */\n'
|
|
11514
11612
|
+ 'object ' + objName + ' {\n'
|
|
11515
|
-
+ model.services.map(scalaService).join('')
|
|
11613
|
+
+ scalaQualifyServices(model.package, model.services).map(scalaService).join('')
|
|
11516
11614
|
+ '}\n',
|
|
11517
11615
|
};
|
|
11518
11616
|
const pbFile = emitScalaPbFile(model);
|