ts-proto 1.116.0 → 1.117.1
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/CHANGELOG.md +21 -0
- package/README.markdown +2 -0
- package/build/generate-services.js +2 -2
- package/build/generate-type-registry.js +3 -2
- package/build/main.js +5 -5
- package/build/options.js +4 -2
- package/build/schema.js +1 -1
- package/build/utils.js +6 -2
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.117.1](https://github.com/stephenh/ts-proto/compare/v1.117.0...v1.117.1) (2022-07-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* import protobufjs/minimal with importSuffix ([#616](https://github.com/stephenh/ts-proto/issues/616)) ([b86291c](https://github.com/stephenh/ts-proto/commit/b86291c58b1cb9d4064944a6371e928b564aef7f))
|
|
7
|
+
|
|
8
|
+
# [1.117.0](https://github.com/stephenh/ts-proto/compare/v1.116.1...v1.117.0) (2022-07-05)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add importSuffix option and remove default .js suffix ([#612](https://github.com/stephenh/ts-proto/issues/612)) ([63a8895](https://github.com/stephenh/ts-proto/commit/63a8895f5a3a38fa3d5c0868f44e950e137fb697))
|
|
14
|
+
|
|
15
|
+
## [1.116.1](https://github.com/stephenh/ts-proto/compare/v1.116.0...v1.116.1) (2022-07-02)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* add .js suffix to proto cross-reference imports ([#602](https://github.com/stephenh/ts-proto/issues/602)) ([8dc38af](https://github.com/stephenh/ts-proto/commit/8dc38af40e68262cd53469ce3dc4dcac670365da)), closes [#601](https://github.com/stephenh/ts-proto/issues/601) [/github.com/kulshekhar/ts-jest/issues/1057#issuecomment-481406624](https://github.com//github.com/kulshekhar/ts-jest/issues/1057/issues/issuecomment-481406624)
|
|
21
|
+
|
|
1
22
|
# [1.116.0](https://github.com/stephenh/ts-proto/compare/v1.115.5...v1.116.0) (2022-07-01)
|
|
2
23
|
|
|
3
24
|
|
package/README.markdown
CHANGED
|
@@ -388,6 +388,8 @@ Generated code will be placed in the Gradle build directory.
|
|
|
388
388
|
|
|
389
389
|
- With `--ts_proto_opt=fileSuffix=<SUFFIX>`, ts-proto will emit generated files using the specified suffix. A `helloworld.proto` file with `fileSuffix=.pb` would be generated as `helloworld.pb.ts`. This is common behavior in other protoc plugins and provides a way to quickly glob all the generated files.
|
|
390
390
|
|
|
391
|
+
- With `--ts_proto_opt=importSuffix=<SUFFIX>`, ts-proto will emit file imports using the specified suffix. An import of `helloworld.ts` with `fileSuffix=.js` would generate `import "helloworld.js"`. The default is to import without a file extension. Supported by TypeScript 4.7.x and up.
|
|
392
|
+
|
|
391
393
|
- With `--ts_proto_opt=enumsAsLiterals=true`, the generated enum types will be enum-ish object with `as const`.
|
|
392
394
|
|
|
393
395
|
- With `--ts_proto_opt=useExactTypes=false`, the generated `fromPartial` method will not use Exact types.
|
|
@@ -8,7 +8,6 @@ const sourceInfo_1 = require("./sourceInfo");
|
|
|
8
8
|
const main_1 = require("./main");
|
|
9
9
|
const hash = (0, ts_poet_1.imp)('hash*object-hash');
|
|
10
10
|
const dataloader = (0, ts_poet_1.imp)('DataLoader*dataloader');
|
|
11
|
-
const Reader = (0, ts_poet_1.imp)('Reader@protobufjs/minimal');
|
|
12
11
|
/**
|
|
13
12
|
* Generates an interface for `serviceDesc`.
|
|
14
13
|
*
|
|
@@ -76,7 +75,7 @@ exports.generateService = generateService;
|
|
|
76
75
|
function generateRegularRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
77
76
|
(0, utils_1.assertInstanceOf)(methodDesc, utils_1.FormattedMethodDescriptor);
|
|
78
77
|
const { options, utils } = ctx;
|
|
79
|
-
const Reader = (0,
|
|
78
|
+
const Reader = (0, utils_1.impFile)(ctx.options, 'Reader@protobufjs/minimal');
|
|
80
79
|
const rawInputType = (0, types_1.rawRequestType)(ctx, methodDesc);
|
|
81
80
|
const inputType = (0, types_1.requestType)(ctx, methodDesc);
|
|
82
81
|
const outputType = (0, types_1.responseType)(ctx, methodDesc);
|
|
@@ -223,6 +222,7 @@ function generateCachingRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
|
223
222
|
const inputType = (0, types_1.requestType)(ctx, methodDesc);
|
|
224
223
|
const outputType = (0, types_1.responseType)(ctx, methodDesc);
|
|
225
224
|
const uniqueIdentifier = `${(0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name)}.${methodDesc.name}`;
|
|
225
|
+
const Reader = (0, utils_1.impFile)(ctx.options, 'Reader@protobufjs/minimal');
|
|
226
226
|
const lambda = (0, ts_poet_1.code) `
|
|
227
227
|
(requests) => {
|
|
228
228
|
const responses = requests.map(async request => {
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateTypeRegistry = void 0;
|
|
4
4
|
const ts_poet_1 = require("ts-poet");
|
|
5
|
-
const
|
|
6
|
-
const Reader = (0, ts_poet_1.imp)('Reader@protobufjs/minimal');
|
|
5
|
+
const utils_1 = require("./utils");
|
|
7
6
|
function generateTypeRegistry(ctx) {
|
|
8
7
|
const chunks = [];
|
|
9
8
|
chunks.push(generateMessageType(ctx));
|
|
@@ -22,6 +21,8 @@ function generateMessageType(ctx) {
|
|
|
22
21
|
chunks.push((0, ts_poet_1.code) `export interface MessageType<Message extends UnknownMessage = UnknownMessage> {`);
|
|
23
22
|
chunks.push((0, ts_poet_1.code) `$type: Message['$type'];`);
|
|
24
23
|
if (ctx.options.outputEncodeMethods) {
|
|
24
|
+
const Writer = (0, utils_1.impFile)(ctx.options, 'Writer@protobufjs/minimal');
|
|
25
|
+
const Reader = (0, utils_1.impFile)(ctx.options, 'Reader@protobufjs/minimal');
|
|
25
26
|
chunks.push((0, ts_poet_1.code) `encode(message: Message, writer?: ${Writer}): ${Writer};`);
|
|
26
27
|
chunks.push((0, ts_poet_1.code) `decode(input: ${Reader} | Uint8Array, length?: number): Message;`);
|
|
27
28
|
}
|
package/build/main.js
CHANGED
|
@@ -108,7 +108,7 @@ function generateFile(ctx, fileDesc) {
|
|
|
108
108
|
};
|
|
109
109
|
`);
|
|
110
110
|
if (options.outputTypeRegistry) {
|
|
111
|
-
const messageTypeRegistry = (0,
|
|
111
|
+
const messageTypeRegistry = (0, utils_1.impFile)(options, 'messageTypeRegistry@./typeRegistry');
|
|
112
112
|
chunks.push((0, ts_poet_1.code) `
|
|
113
113
|
${messageTypeRegistry}.set(${fullName}.$type, ${fullName});
|
|
114
114
|
`);
|
|
@@ -227,8 +227,8 @@ exports.makeUtils = makeUtils;
|
|
|
227
227
|
function makeLongUtils(options, bytes) {
|
|
228
228
|
// Regardless of which `forceLong` config option we're using, we always use
|
|
229
229
|
// the `long` library to either represent or at least sanity-check 64-bit values
|
|
230
|
-
const util = (0,
|
|
231
|
-
const configure = (0,
|
|
230
|
+
const util = (0, utils_1.impFile)(options, 'util@protobufjs/minimal');
|
|
231
|
+
const configure = (0, utils_1.impFile)(options, 'configure@protobufjs/minimal');
|
|
232
232
|
// Before esModuleInterop, we had to use 'import * as Long from long` b/c long is
|
|
233
233
|
// an `export =` module and exports only the Long constructor (which is callable).
|
|
234
234
|
// See https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require.
|
|
@@ -572,6 +572,7 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
572
572
|
if (options.usePrototypeForDefaults) {
|
|
573
573
|
createBase = (0, ts_poet_1.code) `Object.create(${createBase}) as ${fullName}`;
|
|
574
574
|
}
|
|
575
|
+
const Reader = (0, utils_1.impFile)(ctx.options, 'Reader@protobufjs/minimal');
|
|
575
576
|
// create the basic function declaration
|
|
576
577
|
chunks.push((0, ts_poet_1.code) `
|
|
577
578
|
decode(
|
|
@@ -712,12 +713,11 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
712
713
|
chunks.push((0, ts_poet_1.code) `}`);
|
|
713
714
|
return (0, ts_poet_1.joinCode)(chunks, { on: '\n' });
|
|
714
715
|
}
|
|
715
|
-
const Writer = (0, ts_poet_1.imp)('Writer@protobufjs/minimal');
|
|
716
|
-
const Reader = (0, ts_poet_1.imp)('Reader@protobufjs/minimal');
|
|
717
716
|
/** Creates a function to encode a message by loop overing the tags. */
|
|
718
717
|
function generateEncode(ctx, fullName, messageDesc) {
|
|
719
718
|
const { options, utils, typeMap } = ctx;
|
|
720
719
|
const chunks = [];
|
|
720
|
+
const Writer = (0, utils_1.impFile)(ctx.options, 'Writer@protobufjs/minimal');
|
|
721
721
|
// create the basic function declaration
|
|
722
722
|
chunks.push((0, ts_poet_1.code) `
|
|
723
723
|
encode(
|
package/build/options.js
CHANGED
|
@@ -43,6 +43,7 @@ function defaultOptions() {
|
|
|
43
43
|
oneof: OneofOption.PROPERTIES,
|
|
44
44
|
esModuleInterop: false,
|
|
45
45
|
fileSuffix: '',
|
|
46
|
+
importSuffix: '',
|
|
46
47
|
lowerCaseServiceMethods: false,
|
|
47
48
|
outputEncodeMethods: true,
|
|
48
49
|
outputJsonMethods: true,
|
|
@@ -163,7 +164,8 @@ function parseParameter(parameter) {
|
|
|
163
164
|
});
|
|
164
165
|
return options;
|
|
165
166
|
}
|
|
166
|
-
function getTsPoetOpts(
|
|
167
|
-
|
|
167
|
+
function getTsPoetOpts(_options) {
|
|
168
|
+
const imports = ['protobufjs/minimal' + _options.importSuffix];
|
|
169
|
+
return _options.esModuleInterop ? { forceDefaultImport: imports } : { forceModuleImport: imports };
|
|
168
170
|
}
|
|
169
171
|
exports.getTsPoetOpts = getTsPoetOpts;
|
package/build/schema.js
CHANGED
|
@@ -68,7 +68,7 @@ function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
const dependencies = fileDesc.dependency.map((dep) => {
|
|
71
|
-
return (0, ts_poet_1.code) `${(0,
|
|
71
|
+
return (0, ts_poet_1.code) `${(0, utils_1.impFile)(options, `protoMetadata@./${dep.replace('.proto', '')}`)}`;
|
|
72
72
|
});
|
|
73
73
|
// Use toObject so that we get enums as numbers (instead of the default toJSON behavior)
|
|
74
74
|
const descriptor = ts_proto_descriptors_1.FileDescriptorProto.fromPartial(fileDesc);
|
package/build/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.impProto = exports.getPropertyAccessor = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.protoFilesToGenerate = void 0;
|
|
3
|
+
exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.protoFilesToGenerate = void 0;
|
|
4
4
|
const ts_poet_1 = require("ts-poet");
|
|
5
5
|
const options_1 = require("./options");
|
|
6
6
|
const case_1 = require("./case");
|
|
@@ -169,8 +169,12 @@ function getPropertyAccessor(objectName, propertyName, optional = false) {
|
|
|
169
169
|
: `${objectName}${optional ? '?.' : ''}[${JSON.stringify(propertyName)}]`;
|
|
170
170
|
}
|
|
171
171
|
exports.getPropertyAccessor = getPropertyAccessor;
|
|
172
|
+
function impFile(options, spec) {
|
|
173
|
+
return (0, ts_poet_1.imp)(`${spec}${options.importSuffix}`);
|
|
174
|
+
}
|
|
175
|
+
exports.impFile = impFile;
|
|
172
176
|
function impProto(options, module, type) {
|
|
173
|
-
const importString = `${type}@./${module}${options.fileSuffix}`;
|
|
177
|
+
const importString = `${type}@./${module}${options.fileSuffix}${options.importSuffix}`;
|
|
174
178
|
if (options.onlyTypes) {
|
|
175
179
|
return (0, ts_poet_1.imp)('t:' + importString);
|
|
176
180
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.117.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -49,24 +49,25 @@
|
|
|
49
49
|
"@types/jest": "^26.0.22",
|
|
50
50
|
"@types/node": "^14.14.37",
|
|
51
51
|
"chokidar": "^3.5.2",
|
|
52
|
-
"jest": "^
|
|
52
|
+
"jest": "^28.1.2",
|
|
53
|
+
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
53
54
|
"mongodb": "^4.3.0",
|
|
54
55
|
"nice-grpc": "^1.1.1",
|
|
55
|
-
"prettier": "^2.
|
|
56
|
+
"prettier": "^2.7.1",
|
|
56
57
|
"reflect-metadata": "^0.1.13",
|
|
57
58
|
"rxjs": "^7.4.0",
|
|
58
59
|
"semantic-release": "^19.0.3",
|
|
59
|
-
"ts-jest": "^
|
|
60
|
+
"ts-jest": "^28.0.5",
|
|
60
61
|
"ts-node": "^10.8.1",
|
|
61
62
|
"typescript": "^4.7.4",
|
|
62
|
-
"uglify-js": "^3.
|
|
63
|
+
"uglify-js": "^3.16.1"
|
|
63
64
|
},
|
|
64
65
|
"dependencies": {
|
|
65
66
|
"@types/object-hash": "^1.3.0",
|
|
66
67
|
"dataloader": "^1.4.0",
|
|
67
68
|
"object-hash": "^1.3.1",
|
|
68
69
|
"protobufjs": "^6.11.3",
|
|
69
|
-
"ts-poet": "^4.
|
|
70
|
-
"ts-proto-descriptors": "1.7.
|
|
70
|
+
"ts-poet": "^4.15.0",
|
|
71
|
+
"ts-proto-descriptors": "1.7.1"
|
|
71
72
|
}
|
|
72
73
|
}
|