ts-proto 1.152.0 → 1.153.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.
Files changed (27) hide show
  1. package/package.json +5 -4
  2. package/build/integration/codegen.js +0 -63
  3. package/build/tests/case-test.js +0 -52
  4. package/build/tests/options-test.js +0 -148
  5. package/build/tests/types-test.js +0 -56
  6. package/build/tests/utils-test.js +0 -65
  7. /package/build/{src/case.js → case.js} +0 -0
  8. /package/build/{src/context.js → context.js} +0 -0
  9. /package/build/{src/encode.js → encode.js} +0 -0
  10. /package/build/{src/enums.js → enums.js} +0 -0
  11. /package/build/{src/generate-async-iterable.js → generate-async-iterable.js} +0 -0
  12. /package/build/{src/generate-generic-service-definition.js → generate-generic-service-definition.js} +0 -0
  13. /package/build/{src/generate-grpc-js.js → generate-grpc-js.js} +0 -0
  14. /package/build/{src/generate-grpc-web.js → generate-grpc-web.js} +0 -0
  15. /package/build/{src/generate-nestjs.js → generate-nestjs.js} +0 -0
  16. /package/build/{src/generate-nice-grpc.js → generate-nice-grpc.js} +0 -0
  17. /package/build/{src/generate-services.js → generate-services.js} +0 -0
  18. /package/build/{src/generate-struct-wrappers.js → generate-struct-wrappers.js} +0 -0
  19. /package/build/{src/generate-type-registry.js → generate-type-registry.js} +0 -0
  20. /package/build/{src/main.js → main.js} +0 -0
  21. /package/build/{src/options.js → options.js} +0 -0
  22. /package/build/{src/plugin.js → plugin.js} +0 -0
  23. /package/build/{src/schema.js → schema.js} +0 -0
  24. /package/build/{src/sourceInfo.js → sourceInfo.js} +0 -0
  25. /package/build/{src/types.js → types.js} +0 -0
  26. /package/build/{src/utils.js → utils.js} +0 -0
  27. /package/build/{src/visit.js → visit.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.152.0",
3
+ "version": "1.153.0",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",
@@ -16,7 +16,7 @@
16
16
  "proto2pbjs": "docker compose run --rm protoc pbjs.sh",
17
17
  "bin2ts": "docker compose run --rm protoc codegen.sh",
18
18
  "test": "yarn jest -c jest.config.js --maxWorkers=2",
19
- "tsc:check": "./tsc-check.sh tsconfig.json integration/tsconfig.json integration/tsconfig.proto.json protos/tsconfig.json",
19
+ "tsc:check": "./tsc-check.sh tsconfig.json tests/tsconfig.json integration/tsconfig.json integration/tsconfig.proto.json protos/tsconfig.json",
20
20
  "format": "prettier --write {src,tests}/**/*.ts integration/*.ts",
21
21
  "format:check": "prettier --list-different {src,tests}/**/*.ts",
22
22
  "setup:docker": "docker compose build",
@@ -30,7 +30,7 @@
30
30
  "license": "ISC",
31
31
  "devDependencies": {
32
32
  "@grpc/grpc-js": "^1.8.14",
33
- "@grpc/proto-loader": "^0.6.13",
33
+ "@grpc/proto-loader": "^0.7.7",
34
34
  "@improbable-eng/grpc-web": "^0.14.0",
35
35
  "@improbable-eng/grpc-web-node-http-transport": "^0.14.0",
36
36
  "@nestjs/common": "^9.4.2",
@@ -52,6 +52,7 @@
52
52
  "mongodb": "^4.3.0",
53
53
  "nice-grpc": "^2.1.4",
54
54
  "prettier": "^2.8.8",
55
+ "protobufjs-cli": "^1.1.1",
55
56
  "reflect-metadata": "^0.1.13",
56
57
  "rxjs": "^7.4.0",
57
58
  "semantic-release": "^21.0.3",
@@ -65,7 +66,7 @@
65
66
  "case-anything": "^2.1.10",
66
67
  "dataloader": "^1.4.0",
67
68
  "object-hash": "^3.0.0",
68
- "protobufjs": "^6.11.3",
69
+ "protobufjs": "^7.2.4",
69
70
  "ts-poet": "^6.4.1",
70
71
  "ts-proto-descriptors": "1.9.0"
71
72
  },
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ts_proto_descriptors_1 = require("ts-proto-descriptors");
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const util_1 = require("util");
7
- const main_1 = require("../src/main");
8
- const types_1 = require("../src/types");
9
- const utils_1 = require("../src/utils");
10
- const options_1 = require("../src/options");
11
- const generate_type_registry_1 = require("../src/generate-type-registry");
12
- /**
13
- * Generates output for our integration tests from their example proto files.
14
- *
15
- * We use snapshots of the protoc CodeGeneratorRequest's that are captured
16
- * by running ./update_proto_bins.sh, just because various machines/CI/etc
17
- * may not have the `protoc` compiler on their path.
18
- */
19
- async function main() {
20
- const dir = process.argv[2];
21
- const file = process.argv[3];
22
- const param = process.argv[4];
23
- await generate(file, dir, param);
24
- }
25
- async function generate(binFile, baseDir, parameter) {
26
- const stdin = await (0, util_1.promisify)(fs_1.readFile)(binFile);
27
- const request = ts_proto_descriptors_1.CodeGeneratorRequest.decode(stdin);
28
- request.parameter = parameter;
29
- const options = (0, options_1.optionsFromParameter)(parameter || "");
30
- const typeMap = (0, types_1.createTypeMap)(request, options);
31
- for (let file of request.protoFile) {
32
- // Make a different utils per file to track per-file usage
33
- if (options.M[file.name]) {
34
- continue;
35
- }
36
- const utils = (0, main_1.makeUtils)(options);
37
- const ctx = { options, typeMap, utils };
38
- const [path, code] = (0, main_1.generateFile)(ctx, file);
39
- const filePath = `${baseDir}/${path}`;
40
- const dirPath = (0, path_1.parse)(filePath).dir;
41
- await (0, util_1.promisify)(fs_1.mkdir)(dirPath, { recursive: true }).catch(() => { });
42
- await (0, util_1.promisify)(fs_1.writeFile)(filePath, code.toString({ ...(0, options_1.getTsPoetOpts)(options), path }));
43
- }
44
- if (options.outputTypeRegistry) {
45
- const utils = (0, main_1.makeUtils)(options);
46
- const ctx = { options, typeMap, utils };
47
- const path = "typeRegistry.ts";
48
- const code = (0, generate_type_registry_1.generateTypeRegistry)(ctx);
49
- const filePath = `${baseDir}/${path}`;
50
- await (0, util_1.promisify)(fs_1.writeFile)(filePath, code.toString({ ...(0, options_1.getTsPoetOpts)(options), path }));
51
- }
52
- if (options.outputIndex) {
53
- for (const [path, code] of (0, utils_1.generateIndexFiles)(request.protoFile, options)) {
54
- const filePath = `${baseDir}/${path}`;
55
- const dirPath = (0, path_1.parse)(filePath).dir;
56
- await (0, util_1.promisify)(fs_1.mkdir)(dirPath, { recursive: true }).catch(() => { });
57
- await (0, util_1.promisify)(fs_1.writeFile)(filePath, code.toString({ ...(0, options_1.getTsPoetOpts)(options), path }));
58
- }
59
- }
60
- }
61
- main().then(() => {
62
- console.log(`${process.argv[3]}: Done`);
63
- });
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const case_1 = require("../src/case");
4
- const options_1 = require("../src/options");
5
- const utils_1 = require("../src/utils");
6
- const keys = (0, options_1.optionsFromParameter)("snakeToCamel=keys");
7
- describe("case", () => {
8
- it("converts snake to camel by default", () => {
9
- expect((0, case_1.maybeSnakeToCamel)("foo_bar", (0, options_1.optionsFromParameter)(undefined))).toEqual("fooBar");
10
- });
11
- it("leaves as-is if snakeToCamel is false", () => {
12
- expect((0, case_1.maybeSnakeToCamel)("foo_bar", (0, options_1.optionsFromParameter)("snakeToCamel=false"))).toEqual("foo_bar");
13
- });
14
- it("de-upper cases", () => {
15
- expect((0, case_1.maybeSnakeToCamel)("FOO_BAR", keys)).toEqual("fooBar");
16
- });
17
- it("leaves existing mixed cases", () => {
18
- expect((0, case_1.maybeSnakeToCamel)("clientI_d", keys)).toEqual("clientID");
19
- expect((0, case_1.maybeSnakeToCamel)("menu_calendarI_d", keys)).toEqual("menuCalendarID");
20
- expect((0, case_1.maybeSnakeToCamel)("display_nameI18n", keys)).toEqual("displayNameI18n");
21
- });
22
- it("leaves the first character as it was", () => {
23
- expect((0, case_1.maybeSnakeToCamel)("Foo_Bar", keys)).toEqual("FooBar");
24
- });
25
- it("does nothing is already camel", () => {
26
- expect((0, case_1.maybeSnakeToCamel)("FooBar", keys)).toEqual("FooBar");
27
- });
28
- // deal with original protoc which converts
29
- // _uuid -> Uuid
30
- // __uuid -> Uuid
31
- // _uuid_foo -> UuidFoo
32
- it("converts snake to camel with first underscore", () => {
33
- expect((0, case_1.maybeSnakeToCamel)("_uuid", { snakeToCamel: ["keys"] })).toEqual("Uuid");
34
- });
35
- it("converts snake to camel with first double underscore", () => {
36
- expect((0, case_1.maybeSnakeToCamel)("__uuid", { snakeToCamel: ["keys"] })).toEqual("Uuid");
37
- });
38
- it("converts snake to camel with first underscore and camelize other", () => {
39
- expect((0, case_1.maybeSnakeToCamel)("_uuid_foo", { snakeToCamel: ["keys"] })).toEqual("UuidFoo");
40
- });
41
- it("converts string to camel case respecting word separation, getAPIValue === getApiValue", () => {
42
- expect((0, case_1.camelCaseGrpc)("GetAPIValue")).toEqual("getApiValue");
43
- });
44
- describe("getFieldJsonName", () => {
45
- it("keeps snake case when jsonName is probably not set", () => {
46
- expect((0, utils_1.getFieldJsonName)({ name: "foo_bar", jsonName: "fooBar" }, { snakeToCamel: [] })).toBe("foo_bar");
47
- });
48
- it("uses jsonName when it is set", () => {
49
- expect((0, utils_1.getFieldJsonName)({ name: "foo_bar", jsonName: "foo" }, { snakeToCamel: [] })).toBe("foo");
50
- });
51
- });
52
- });
@@ -1,148 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const options_1 = require("../src/options");
4
- describe("options", () => {
5
- it("can set outputJsonMethods with nestJs=true", () => {
6
- expect((0, options_1.optionsFromParameter)("nestJs=true,outputJsonMethods=true")).toMatchInlineSnapshot(`
7
- {
8
- "M": {},
9
- "addGrpcMetadata": false,
10
- "addNestjsRestParameter": false,
11
- "constEnums": false,
12
- "context": false,
13
- "emitImportedFiles": true,
14
- "enumsAsLiterals": false,
15
- "env": "both",
16
- "esModuleInterop": false,
17
- "exportCommonSymbols": true,
18
- "fileSuffix": "",
19
- "forceLong": "number",
20
- "importSuffix": "",
21
- "initializeFieldsAsUndefined": false,
22
- "lowerCaseServiceMethods": true,
23
- "metadataType": undefined,
24
- "nestJs": true,
25
- "oneof": "properties",
26
- "onlyTypes": false,
27
- "outputClientImpl": false,
28
- "outputEncodeMethods": false,
29
- "outputExtensions": false,
30
- "outputIndex": false,
31
- "outputJsonMethods": true,
32
- "outputPartialMethods": false,
33
- "outputSchema": false,
34
- "outputServices": [
35
- "default",
36
- ],
37
- "outputTypeAnnotations": false,
38
- "outputTypeRegistry": false,
39
- "removeEnumPrefix": false,
40
- "returnObservable": false,
41
- "snakeToCamel": [
42
- "json",
43
- "keys",
44
- ],
45
- "stringEnums": false,
46
- "unknownFields": false,
47
- "unrecognizedEnum": true,
48
- "useAbortSignal": false,
49
- "useAsyncIterable": false,
50
- "useDate": "timestamp",
51
- "useExactTypes": true,
52
- "useJsonWireFormat": false,
53
- "useMapType": false,
54
- "useMongoObjectId": false,
55
- "useNumericEnumForJson": false,
56
- "useOptionals": "none",
57
- "usePrototypeForDefaults": false,
58
- "useReadonlyTypes": false,
59
- "useSnakeTypeName": true,
60
- }
61
- `);
62
- });
63
- it("can set outputJsonMethods with nestJs=true", () => {
64
- const options = (0, options_1.optionsFromParameter)("outputClientImpl=grpc-web,addGrpcMetadata=false");
65
- expect(options).toMatchObject({
66
- outputClientImpl: "grpc-web",
67
- addGrpcMetadata: false,
68
- });
69
- });
70
- it("can set fileSuffix", () => {
71
- const options = (0, options_1.optionsFromParameter)("fileSuffix=.pb");
72
- expect(options).toMatchObject({
73
- fileSuffix: ".pb",
74
- });
75
- });
76
- it("can set outputServices to false", () => {
77
- const options = (0, options_1.optionsFromParameter)("outputServices=false");
78
- expect(options).toMatchObject({
79
- outputServices: [options_1.ServiceOption.NONE],
80
- });
81
- });
82
- it("can set outputServices to grpc", () => {
83
- const options = (0, options_1.optionsFromParameter)("outputServices=grpc-js");
84
- expect(options).toMatchObject({
85
- outputServices: [options_1.ServiceOption.GRPC],
86
- });
87
- });
88
- it("can set useOptionals to boolean", () => {
89
- const options = (0, options_1.optionsFromParameter)("useOptionals=true");
90
- expect(options).toMatchObject({
91
- useOptionals: true,
92
- });
93
- });
94
- it("can set useOptionals to string", () => {
95
- const options = (0, options_1.optionsFromParameter)("useOptionals=messages");
96
- expect(options).toMatchObject({
97
- useOptionals: "messages",
98
- });
99
- });
100
- it("can set snakeToCamel as string", () => {
101
- const options = (0, options_1.optionsFromParameter)("snakeToCamel=keys");
102
- expect(options).toMatchObject({ snakeToCamel: ["keys"] });
103
- });
104
- it("can set snakeToCamel as two values", () => {
105
- const options = (0, options_1.optionsFromParameter)("snakeToCamel=keys_json");
106
- expect(options).toMatchObject({ snakeToCamel: ["keys", "json"] });
107
- });
108
- it("can set multiple values as an array", () => {
109
- const options = (0, options_1.optionsFromParameter)("foo=one,foo=two");
110
- expect(options).toMatchObject({ foo: ["one", "two"] });
111
- });
112
- it("´output*=false implies onlyTypes", () => {
113
- const options = (0, options_1.optionsFromParameter)("outputJsonMethods=false,outputEncodeMethods=false,outputClientImpl=false");
114
- expect(options).toMatchObject({
115
- onlyTypes: true,
116
- });
117
- });
118
- it("onlyTypes implies output*=false", () => {
119
- const options = (0, options_1.optionsFromParameter)("onlyTypes=true");
120
- expect(options).toMatchObject({
121
- outputJsonMethods: false,
122
- outputEncodeMethods: false,
123
- outputClientImpl: false,
124
- nestJs: false,
125
- });
126
- });
127
- it("useJsonWireFormat requires onlyTypes", () => {
128
- const options = (0, options_1.optionsFromParameter)("useJsonWireFormat=true");
129
- expect(options).toMatchObject({
130
- useJsonWireFormat: false,
131
- });
132
- });
133
- it("useSnakeTypeName", () => {
134
- const options = (0, options_1.optionsFromParameter)("useSnakeTypeName=false");
135
- expect(options).toMatchObject({
136
- useSnakeTypeName: false,
137
- });
138
- });
139
- it("useJsonWireFormat implies useDate=string and stringEnums=true", () => {
140
- const options = (0, options_1.optionsFromParameter)("useJsonWireFormat=true,onlyTypes=true");
141
- expect(options).toMatchObject({
142
- useJsonWireFormat: true,
143
- onlyTypes: true,
144
- stringEnums: true,
145
- useDate: options_1.DateOption.STRING,
146
- });
147
- });
148
- });
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const options_1 = require("../src/options");
4
- const types_1 = require("../src/types");
5
- const ts_poet_1 = require("ts-poet");
6
- const fakeProto = undefined;
7
- describe("types", () => {
8
- describe("messageToTypeName", () => {
9
- const testCases = [
10
- {
11
- descr: "top-level messages",
12
- typeMap: new Map([[".namespace.Message", ["namespace", "Message", fakeProto]]]),
13
- protoType: ".namespace.Message",
14
- expected: (0, ts_poet_1.code) `${(0, ts_poet_1.imp)("Message@./namespace")}`,
15
- },
16
- {
17
- descr: "nested messages",
18
- typeMap: new Map([[".namespace.Message.Inner", ["namespace", "Message_Inner", fakeProto]]]),
19
- protoType: ".namespace.Message.Inner",
20
- expected: (0, ts_poet_1.code) `${(0, ts_poet_1.imp)("Message_Inner@./namespace")}`,
21
- },
22
- {
23
- descr: "nested messages: .js import suffix",
24
- typeMap: new Map([[".namespace.Message.Inner", ["namespace", "Message_Inner", fakeProto]]]),
25
- protoType: ".namespace.Message.Inner",
26
- options: { ...(0, options_1.defaultOptions)(), importSuffix: ".js" },
27
- expected: (0, ts_poet_1.code) `${(0, ts_poet_1.imp)("Message_Inner@./namespace.js")}`,
28
- },
29
- {
30
- descr: "value types",
31
- typeMap: new Map(),
32
- protoType: ".google.protobuf.StringValue",
33
- expected: (0, ts_poet_1.code) `string | undefined`,
34
- },
35
- {
36
- descr: "value types (useOptionals=true)",
37
- typeMap: new Map(),
38
- protoType: ".google.protobuf.StringValue",
39
- options: { ...(0, options_1.defaultOptions)(), useOptionals: true },
40
- expected: (0, ts_poet_1.code) `string | undefined`,
41
- },
42
- {
43
- descr: 'value types (useOptionals="all")',
44
- typeMap: new Map(),
45
- protoType: ".google.protobuf.StringValue",
46
- options: { ...(0, options_1.defaultOptions)(), useOptionals: "all" },
47
- expected: (0, ts_poet_1.code) `string | undefined`,
48
- },
49
- ];
50
- testCases.forEach((t) => it(t.descr, async () => {
51
- const ctx = { options: (0, options_1.defaultOptions)(), utils: undefined, ...t };
52
- const got = (0, types_1.messageToTypeName)(ctx, t.protoType);
53
- expect(got.toString()).toEqual(t.expected.toString());
54
- }));
55
- });
56
- });
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../src/utils");
4
- const ts_poet_1 = require("ts-poet");
5
- describe("utils", () => {
6
- describe("maybeAddComment", () => {
7
- it("handles single-line impl comments", () => {
8
- // Foo
9
- const chunks = [];
10
- (0, utils_1.maybeAddComment)({ leadingComments: " Foo\n" }, chunks);
11
- expect((0, ts_poet_1.joinCode)(chunks).toString()).toMatchInlineSnapshot(`
12
- "/** Foo */
13
- "
14
- `);
15
- });
16
- it("handles single-dot star comments", () => {
17
- // /* Foo */
18
- const chunks = [];
19
- (0, utils_1.maybeAddComment)({ leadingComments: " Foo " }, chunks);
20
- expect((0, ts_poet_1.joinCode)(chunks).toString()).toMatchInlineSnapshot(`
21
- "/** Foo */
22
- "
23
- `);
24
- });
25
- it("handles single-line double-dot star comments", () => {
26
- // /** Foo */
27
- const chunks = [];
28
- (0, utils_1.maybeAddComment)({ leadingComments: " * Foo " }, chunks);
29
- expect((0, ts_poet_1.joinCode)(chunks).toString()).toMatchInlineSnapshot(`
30
- "/** Foo */
31
- "
32
- `);
33
- });
34
- it("handles double-line double-dot star comments", () => {
35
- // /**
36
- // * Foo
37
- // *
38
- // * bar.
39
- // */
40
- const chunks = [];
41
- (0, utils_1.maybeAddComment)({ leadingComments: "*\n Foo\n \n bar.\n" }, chunks);
42
- expect((0, ts_poet_1.joinCode)(chunks).toString()).toMatchInlineSnapshot(`
43
- "/**
44
- * Foo
45
- *
46
- * bar.
47
- */
48
- "
49
- `);
50
- });
51
- it("handles double-line impl comments", () => {
52
- // // Foo
53
- // // Bar
54
- const chunks = [];
55
- (0, utils_1.maybeAddComment)({ leadingComments: " Foo\n Bar\n" }, chunks);
56
- expect((0, ts_poet_1.joinCode)(chunks).toString()).toMatchInlineSnapshot(`
57
- "/**
58
- * Foo
59
- * Bar
60
- */
61
- "
62
- `);
63
- });
64
- });
65
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes