@dxos/protobuf-compiler 2.33.9-dev.6b3d59af → 2.33.9-dev.6efa8ddf
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/dist/src/generator/context.d.ts +6 -0
- package/dist/src/generator/context.d.ts.map +1 -0
- package/dist/src/generator/context.js +6 -0
- package/dist/src/generator/context.js.map +1 -0
- package/dist/src/generator/declaration-generator.d.ts +2 -2
- package/dist/src/generator/declaration-generator.d.ts.map +1 -1
- package/dist/src/generator/declaration-generator.js +6 -6
- package/dist/src/generator/declaration-generator.js.map +1 -1
- package/dist/src/generator/enum.d.ts +2 -1
- package/dist/src/generator/enum.d.ts.map +1 -1
- package/dist/src/generator/enum.js +13 -1
- package/dist/src/generator/enum.js.map +1 -1
- package/dist/src/generator/field.js +2 -2
- package/dist/src/generator/field.js.map +1 -1
- package/dist/src/generator/file-generator.d.ts.map +1 -1
- package/dist/src/generator/file-generator.js +5 -1
- package/dist/src/generator/file-generator.js.map +1 -1
- package/dist/src/generator/message.d.ts +5 -2
- package/dist/src/generator/message.d.ts.map +1 -1
- package/dist/src/generator/message.js +13 -4
- package/dist/src/generator/message.js.map +1 -1
- package/dist/src/generator/serializer-definition-generator.d.ts +1 -0
- package/dist/src/generator/serializer-definition-generator.d.ts.map +1 -1
- package/dist/src/generator/service.d.ts +2 -2
- package/dist/src/generator/service.d.ts.map +1 -1
- package/dist/src/generator/service.js +13 -5
- package/dist/src/generator/service.js.map +1 -1
- package/dist/src/module-specifier.js +2 -2
- package/dist/src/module-specifier.js.map +1 -1
- package/dist/src/namespaces.js +2 -2
- package/dist/src/namespaces.js.map +1 -1
- package/dist/test/proto/gen/dxos/test/another.d.ts +4 -0
- package/dist/test/proto/gen/dxos/test/another.d.ts.map +1 -1
- package/dist/test/proto/gen/dxos/test/any.d.ts +5 -1
- package/dist/test/proto/gen/dxos/test/any.d.ts.map +1 -1
- package/dist/test/proto/gen/dxos/test/extensions.d.ts +14 -2
- package/dist/test/proto/gen/dxos/test/extensions.d.ts.map +1 -1
- package/dist/test/proto/gen/dxos/test/testfoo.d.ts +6 -2
- package/dist/test/proto/gen/dxos/test/testfoo.d.ts.map +1 -1
- package/dist/test/proto/gen/dxos/test.d.ts +106 -29
- package/dist/test/proto/gen/dxos/test.d.ts.map +1 -1
- package/dist/test/proto/gen/dxos/test.js +8 -0
- package/dist/test/proto/gen/dxos/test.js.map +1 -1
- package/dist/test/proto/gen/google/protobuf.d.ts +82 -82
- package/dist/test/proto/gen/google/protobuf.d.ts.map +1 -1
- package/dist/test/proto/gen/index.d.ts.map +1 -1
- package/dist/test/proto/gen/index.js +1 -1
- package/dist/test/proto/gen/index.js.map +1 -1
- package/dist/test/schema.test.js +18 -1
- package/dist/test/schema.test.js.map +1 -1
- package/dist/test/service.test.js +1 -0
- package/dist/test/service.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/generator/context.ts +10 -0
- package/src/generator/declaration-generator.ts +7 -7
- package/src/generator/enum.ts +26 -9
- package/src/generator/field.ts +1 -1
- package/src/generator/file-generator.ts +7 -1
- package/src/generator/message.ts +17 -6
- package/src/generator/service.ts +15 -4
- package/src/module-specifier.ts +1 -1
- package/src/namespaces.ts +1 -1
|
@@ -9,6 +9,7 @@ import * as ts from 'typescript';
|
|
|
9
9
|
import { CODEC_MODULE, ModuleSpecifier } from '../module-specifier';
|
|
10
10
|
import { getSafeNamespaceIdentifier, parseFullyQualifiedName } from '../namespaces';
|
|
11
11
|
import { SubstitutionsMap } from '../parser';
|
|
12
|
+
import { GeneratorContext } from './context';
|
|
12
13
|
import { createDeclarations, createTypeDictionary } from './declaration-generator';
|
|
13
14
|
import { createSerializerDefinition } from './serializer-definition-generator';
|
|
14
15
|
import { createServicesDictionary } from './service';
|
|
@@ -24,7 +25,12 @@ const createSubstitutionsImport = (substitutionsModule: ModuleSpecifier, context
|
|
|
24
25
|
|
|
25
26
|
export const createNamespaceSourceFile = (types: pb.ReflectionObject[], substitutions: SubstitutionsMap, outDir: string, namespace: string, substitutionsModule: ModuleSpecifier | undefined, otherNamespaces: string[]) => {
|
|
26
27
|
const outFile = join(outDir, getFileNameForNamespace(namespace));
|
|
27
|
-
const
|
|
28
|
+
const ctx: GeneratorContext = {
|
|
29
|
+
outputFilename: outFile,
|
|
30
|
+
subs: substitutions
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const declarations: ts.Statement[] = Array.from(createDeclarations(types, ctx));
|
|
28
34
|
|
|
29
35
|
const substitutionsImport = substitutionsModule && createSubstitutionsImport(substitutionsModule, dirname(outFile));
|
|
30
36
|
|
package/src/generator/message.ts
CHANGED
|
@@ -2,16 +2,20 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { dirname, relative } from 'path';
|
|
5
6
|
import * as protobufjs from 'protobufjs';
|
|
6
7
|
import * as ts from 'typescript';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import { GeneratorContext } from './context';
|
|
9
10
|
import { attachDocComment } from './doc-comment';
|
|
10
11
|
import { getFieldType } from './field';
|
|
11
12
|
|
|
12
13
|
const f = ts.factory;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* {@link file://./../configure.ts#l5}
|
|
17
|
+
*/
|
|
18
|
+
export const createMessageDeclaration = (type: protobufjs.Type, ctx: GeneratorContext) => {
|
|
15
19
|
const declaration = f.createInterfaceDeclaration(
|
|
16
20
|
undefined,
|
|
17
21
|
[f.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
@@ -19,11 +23,13 @@ export const createMessageDeclaration = (type: protobufjs.Type, subs: Substituti
|
|
|
19
23
|
undefined,
|
|
20
24
|
undefined,
|
|
21
25
|
type.fieldsArray.map(field => {
|
|
26
|
+
const isRequired = field.required || (!field.getOption('proto3_optional') && !field.repeated && !field.map && !field.partOf);
|
|
27
|
+
|
|
22
28
|
const signature = f.createPropertySignature(
|
|
23
29
|
undefined,
|
|
24
30
|
field.name.includes('.') ? f.createStringLiteral(field.name) : field.name,
|
|
25
|
-
|
|
26
|
-
getFieldType(field, subs)
|
|
31
|
+
isRequired ? undefined : f.createToken(ts.SyntaxKind.QuestionToken),
|
|
32
|
+
getFieldType(field, ctx.subs)
|
|
27
33
|
);
|
|
28
34
|
|
|
29
35
|
const docComment = getFieldDocComment(field);
|
|
@@ -31,11 +37,16 @@ export const createMessageDeclaration = (type: protobufjs.Type, subs: Substituti
|
|
|
31
37
|
})
|
|
32
38
|
);
|
|
33
39
|
|
|
34
|
-
|
|
40
|
+
const commentSections = type.comment ? [type.comment] : [];
|
|
41
|
+
if (type.filename) {
|
|
42
|
+
commentSections.push(`Defined in:\n {@link file://./${relative(dirname(ctx.outputFilename), type.filename)}}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (commentSections.length === 0) {
|
|
35
46
|
return declaration;
|
|
36
47
|
}
|
|
37
48
|
|
|
38
|
-
return attachDocComment(declaration,
|
|
49
|
+
return attachDocComment(declaration, commentSections.join('\n\n'));
|
|
39
50
|
};
|
|
40
51
|
|
|
41
52
|
const getFieldDocComment = (field: protobufjs.Field) => {
|
package/src/generator/service.ts
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import assert from 'assert';
|
|
5
|
+
import assert from 'node:assert';
|
|
6
|
+
import { dirname, relative } from 'path';
|
|
6
7
|
import * as protobufjs from 'protobufjs';
|
|
7
8
|
import * as ts from 'typescript';
|
|
8
9
|
|
|
9
10
|
import { normalizeFullyQualifiedName } from '../namespaces';
|
|
10
11
|
import { SubstitutionsMap } from '../parser';
|
|
12
|
+
import { GeneratorContext } from './context';
|
|
11
13
|
import { attachDocComment } from './doc-comment';
|
|
12
14
|
import { types, getTypeReference } from './types';
|
|
13
15
|
|
|
@@ -45,7 +47,7 @@ const createRpcMethodType = (method: protobufjs.Method, service: protobufjs.Serv
|
|
|
45
47
|
);
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
export const createServiceDeclaration = (type: protobufjs.Service,
|
|
50
|
+
export const createServiceDeclaration = (type: protobufjs.Service, ctx: GeneratorContext): ts.InterfaceDeclaration => {
|
|
49
51
|
const declaration = f.createInterfaceDeclaration(
|
|
50
52
|
undefined,
|
|
51
53
|
[f.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
@@ -59,14 +61,23 @@ export const createServiceDeclaration = (type: protobufjs.Service, subs: Substit
|
|
|
59
61
|
undefined,
|
|
60
62
|
mapRpcMethodName(method.name),
|
|
61
63
|
undefined,
|
|
62
|
-
createRpcMethodType(method, type, subs)
|
|
64
|
+
createRpcMethodType(method, type, ctx.subs)
|
|
63
65
|
);
|
|
64
66
|
|
|
65
67
|
return method.comment ? attachDocComment(sig, method.comment) : sig;
|
|
66
68
|
})
|
|
67
69
|
);
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
const commentSections = type.comment ? [type.comment] : [];
|
|
72
|
+
if (type.filename) {
|
|
73
|
+
commentSections.push(`Defined in:\n {@link file://./${relative(dirname(ctx.outputFilename), type.filename)}}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (commentSections.length === 0) {
|
|
77
|
+
return declaration;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return attachDocComment(declaration, commentSections.join('\n\n'));
|
|
70
81
|
};
|
|
71
82
|
|
|
72
83
|
function * getServices (root: protobufjs.NamespaceBase): Generator<protobufjs.Service> {
|
package/src/module-specifier.ts
CHANGED