grpc-dc 0.37.1 → 0.38.0
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 +85 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grpc-dc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "gRPC in the browser over WebRTC DataChannels: dependency-free generated gRPC clients & servers for JavaScript \u2014 no grpc-web proxy, no external runtime",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"grpc",
|
package/plugin/gen/generators.js
CHANGED
|
@@ -3511,6 +3511,80 @@ function swpMessageClass(model, msg, support, indent, decl) {
|
|
|
3511
3511
|
return runSegments(SEGMENT_PROGRAMS.swiftPbMessage, msg, null, model, [support, indent, decl]);
|
|
3512
3512
|
}
|
|
3513
3513
|
|
|
3514
|
+
// Mirror of publicize-swift in the Racket generator (desc.rkt):
|
|
3515
|
+
// publicize declarations at top level and in public type bodies
|
|
3516
|
+
// so the SwiftPM library product has a public API. The plugin
|
|
3517
|
+
// parity test requires byte-identical output with the Racket
|
|
3518
|
+
// plugins, so keep the two implementations in lockstep.
|
|
3519
|
+
const SWIFT_MODIFIERS = ['private', 'fileprivate', 'internal', 'public', 'open', 'final', 'static', 'override', 'convenience', 'required', 'mutating', 'nonmutating', 'lazy', 'indirect', 'weak', 'unowned', 'class'];
|
|
3520
|
+
const SWIFT_TYPE_KINDS = ['class', 'struct', 'enum', 'protocol', 'extension'];
|
|
3521
|
+
const SWIFT_DECL_KINDS = [...SWIFT_TYPE_KINDS, 'func', 'var', 'let', 'init', 'typealias', 'subscript'];
|
|
3522
|
+
function swiftWord(s) { const m = /^[A-Za-z]+/.exec(s); return m ? m[0] : ''; }
|
|
3523
|
+
function swiftParseDecl(trimmed) {
|
|
3524
|
+
let s = trimmed, priv = false, access = false;
|
|
3525
|
+
for (;;) {
|
|
3526
|
+
if (s === '') return { kind: null, priv, access };
|
|
3527
|
+
if (s.startsWith('@')) {
|
|
3528
|
+
let rest = s.slice(1); const w = swiftWord(rest); let after = rest.slice(w.length);
|
|
3529
|
+
if (after.startsWith('(')) {
|
|
3530
|
+
let d = 0, i = -1;
|
|
3531
|
+
for (let j = 0; j < after.length; j++) { if (after[j] === '(') d++; else if (after[j] === ')') { d--; if (d === 0) { i = j; break; } } }
|
|
3532
|
+
if (i < 0) return { kind: null, priv, access };
|
|
3533
|
+
s = after.slice(i + 1).trim();
|
|
3534
|
+
} else s = after.trim();
|
|
3535
|
+
continue;
|
|
3536
|
+
}
|
|
3537
|
+
const setm = /^(private|internal|public)\(set\)/.exec(s);
|
|
3538
|
+
if (setm) { access = true; s = s.slice(setm[0].length).trim(); continue; }
|
|
3539
|
+
const w = swiftWord(s);
|
|
3540
|
+
if (SWIFT_DECL_KINDS.includes(w)) return { kind: w, priv, access };
|
|
3541
|
+
if (SWIFT_MODIFIERS.includes(w)) {
|
|
3542
|
+
if (w === 'private' || w === 'fileprivate') priv = true;
|
|
3543
|
+
if (w === 'public' || w === 'open' || w === 'internal') access = true;
|
|
3544
|
+
s = s.slice(w.length).trim(); continue;
|
|
3545
|
+
}
|
|
3546
|
+
return { kind: null, priv, access };
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
function swiftNetBraces(line) {
|
|
3550
|
+
let n = 0, inStr = false;
|
|
3551
|
+
for (let i = 0; i < line.length; i++) {
|
|
3552
|
+
const c = line[i];
|
|
3553
|
+
if (inStr) { if (c === '\\') i++; else if (c === '"') inStr = false; continue; }
|
|
3554
|
+
if (c === '"') { inStr = true; continue; }
|
|
3555
|
+
if (c === '/' && line[i + 1] === '/') break;
|
|
3556
|
+
if (c === '{') n++; else if (c === '}') n--;
|
|
3557
|
+
}
|
|
3558
|
+
return n;
|
|
3559
|
+
}
|
|
3560
|
+
function publicizeSwift(text) {
|
|
3561
|
+
const lines = text.split('\n');
|
|
3562
|
+
const out = [];
|
|
3563
|
+
let depth = 0, stack = [], pendingFunc = false;
|
|
3564
|
+
for (const line of lines) {
|
|
3565
|
+
while (stack.length && depth < stack[stack.length - 1][1]) stack.pop();
|
|
3566
|
+
const contextPublic = !stack.length || stack[stack.length - 1][0] === 'type-pub';
|
|
3567
|
+
const trimmed = line.trim();
|
|
3568
|
+
const { kind, priv, access } = swiftParseDecl(trimmed);
|
|
3569
|
+
const net = swiftNetBraces(line);
|
|
3570
|
+
const newDepth = depth + net;
|
|
3571
|
+
const pub = kind && contextPublic && !priv && !access && kind !== 'extension' && !trimmed.startsWith('@');
|
|
3572
|
+
out.push(pub ? line.replace(/^(\s*)/, '$1public ') : line);
|
|
3573
|
+
const inProto = stack.length && stack[stack.length - 1][0] === 'proto';
|
|
3574
|
+
if (kind && SWIFT_TYPE_KINDS.includes(kind) && newDepth > depth) {
|
|
3575
|
+
stack.push([priv ? 'type-priv' : (kind === 'protocol' ? 'proto' : 'type-pub'), newDepth]);
|
|
3576
|
+
} else if (kind && ['func', 'init', 'var', 'let', 'subscript'].includes(kind) && newDepth > depth) {
|
|
3577
|
+
stack.push(['func', newDepth]);
|
|
3578
|
+
} else if (pendingFunc && newDepth > depth) {
|
|
3579
|
+
stack.push(['func', newDepth]);
|
|
3580
|
+
}
|
|
3581
|
+
pendingFunc = !inProto && ((pendingFunc && newDepth <= depth)
|
|
3582
|
+
|| (kind && ['func', 'init', 'subscript'].includes(kind) && newDepth <= depth && !trimmed.endsWith(';')));
|
|
3583
|
+
depth = newDepth;
|
|
3584
|
+
}
|
|
3585
|
+
return out.join('\n');
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3514
3588
|
function emitSwiftPbFile(model) {
|
|
3515
3589
|
if (!model.messages.length && !model.enums.length) return null;
|
|
3516
3590
|
const base = baseName(model.name);
|
|
@@ -3540,7 +3614,7 @@ function emitSwiftPbFile(model) {
|
|
|
3540
3614
|
+ e.values.map((v) => ' case ' + v.name + ' = ' + v.number).join('\n')
|
|
3541
3615
|
+ '\n}\n\n').join('')
|
|
3542
3616
|
+ model.messages.filter((m) => !m.mapEntry).map((m) => swpMessageClass(model, m, support, '', 'final')).join('');
|
|
3543
|
-
return { name: pascalName(base) + 'Messages.swift', content };
|
|
3617
|
+
return { name: pascalName(base) + 'Messages.swift', content: publicizeSwift(content) };
|
|
3544
3618
|
}
|
|
3545
3619
|
|
|
3546
3620
|
function emitSwiftFile(model, params) {
|
|
@@ -3548,13 +3622,13 @@ function emitSwiftFile(model, params) {
|
|
|
3548
3622
|
const enumName = pascalName(base) + 'GrpcDc';
|
|
3549
3623
|
const stub = {
|
|
3550
3624
|
name: pascalName(base) + 'GrpcDc.swift',
|
|
3551
|
-
content: '// @generated by protoc-gen-grpc-dc-swift. DO NOT EDIT.\n'
|
|
3625
|
+
content: publicizeSwift('// @generated by protoc-gen-grpc-dc-swift. DO NOT EDIT.\n'
|
|
3552
3626
|
+ '// source: ' + model.name + '\n\n'
|
|
3553
3627
|
+ '#if canImport(Foundation)\nimport Foundation\n#endif\n\n'
|
|
3554
3628
|
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
3555
3629
|
+ 'enum ' + enumName + ' {\n'
|
|
3556
3630
|
+ model.services.map(swiftService).join('')
|
|
3557
|
-
+ '}\n',
|
|
3631
|
+
+ '}\n'),
|
|
3558
3632
|
};
|
|
3559
3633
|
const pbFile = emitSwiftPbFile(model);
|
|
3560
3634
|
return pbFile ? [stub, pbFile] : stub;
|
|
@@ -4084,18 +4158,20 @@ function dartStubImports(model) {
|
|
|
4084
4158
|
function emitDartFile(model, params) {
|
|
4085
4159
|
const base = baseName(model.name);
|
|
4086
4160
|
const className = pascalName(base) + 'GrpcDc';
|
|
4161
|
+
const body = model.services.map(dartService).join('')
|
|
4162
|
+
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
4163
|
+
+ 'class ' + className + ' {\n'
|
|
4164
|
+
+ model.services.map(dartRegisterService).join('')
|
|
4165
|
+
+ '}\n';
|
|
4087
4166
|
const stub = {
|
|
4088
4167
|
name: base + '_grpc_dc.dart',
|
|
4089
4168
|
content: '// @generated by protoc-gen-grpc-dc-dart. DO NOT EDIT.\n'
|
|
4090
4169
|
+ '// source: ' + model.name + '\n\n'
|
|
4091
4170
|
+ "import 'dart:async';\n\n"
|
|
4092
|
-
+ "import '../grpcdc/channel.dart';\nimport '../grpcdc/endpoint.dart';\nimport '../grpcdc/server.dart';\nimport '../grpcdc/status.dart';\
|
|
4171
|
+
+ "import '../grpcdc/channel.dart';\nimport '../grpcdc/endpoint.dart';\nimport '../grpcdc/server.dart';\nimport '../grpcdc/status.dart';\n"
|
|
4172
|
+
+ (body.includes('Wire.') ? "import '../grpcdc/wire.dart';\n" : '')
|
|
4093
4173
|
+ dartStubImports(model)
|
|
4094
|
-
+
|
|
4095
|
-
+ '/// Generated gRPC-over-DataChannels stubs for ' + model.name + '.\n'
|
|
4096
|
-
+ 'class ' + className + ' {\n'
|
|
4097
|
-
+ model.services.map(dartRegisterService).join('')
|
|
4098
|
-
+ '}\n',
|
|
4174
|
+
+ body,
|
|
4099
4175
|
};
|
|
4100
4176
|
const pbFile = emitDartPbFile(model);
|
|
4101
4177
|
return pbFile ? [stub, pbFile] : stub;
|