ts-proto 1.158.1 → 1.159.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/README.markdown +4 -0
- package/build/main.js +5 -4
- package/build/options.js +1 -0
- package/package.json +1 -1
package/README.markdown
CHANGED
|
@@ -289,6 +289,10 @@ Generated code will be placed in the Gradle build directory.
|
|
|
289
289
|
|
|
290
290
|
### Supported options
|
|
291
291
|
|
|
292
|
+
- With `--ts_proto_opt=globalThisPolyfill=true`, ts-proto will include a polyfill for globalThis.
|
|
293
|
+
|
|
294
|
+
Defaults to `false`, i.e. we assume `globalThis` is available.
|
|
295
|
+
|
|
292
296
|
- With `--ts_proto_opt=context=true`, the services will have a Go-style `ctx` parameter, which is useful for tracing/logging/etc. if you're not using node's `async_hooks` api due to performance reasons.
|
|
293
297
|
|
|
294
298
|
- With `--ts_proto_opt=forceLong=long`, all 64-bit numbers will be parsed as instances of `Long` (using the [long](https://www.npmjs.com/package/long) library).
|
package/build/main.js
CHANGED
|
@@ -273,7 +273,7 @@ function generateFile(ctx, fileDesc) {
|
|
|
273
273
|
exports.generateFile = generateFile;
|
|
274
274
|
/** These are runtime utility methods used by the generated code. */
|
|
275
275
|
function makeUtils(options) {
|
|
276
|
-
const bytes = makeByteUtils();
|
|
276
|
+
const bytes = makeByteUtils(options);
|
|
277
277
|
const longs = makeLongUtils(options, bytes);
|
|
278
278
|
return {
|
|
279
279
|
...bytes,
|
|
@@ -354,12 +354,12 @@ function makeLongUtils(options, bytes) {
|
|
|
354
354
|
`);
|
|
355
355
|
return { numberToLong, longToNumber, longToString, longToBigint, Long };
|
|
356
356
|
}
|
|
357
|
-
function makeByteUtils() {
|
|
358
|
-
const
|
|
357
|
+
function makeByteUtils(options) {
|
|
358
|
+
const globalThisPolyfill = (0, ts_poet_1.conditionalOutput)("gt", (0, ts_poet_1.code) `
|
|
359
359
|
declare const self: any | undefined;
|
|
360
360
|
declare const window: any | undefined;
|
|
361
361
|
declare const global: any | undefined;
|
|
362
|
-
const
|
|
362
|
+
const gt: any = (() => {
|
|
363
363
|
if (typeof globalThis !== "undefined") return globalThis;
|
|
364
364
|
if (typeof self !== "undefined") return self;
|
|
365
365
|
if (typeof window !== "undefined") return window;
|
|
@@ -367,6 +367,7 @@ function makeByteUtils() {
|
|
|
367
367
|
throw "Unable to locate global object";
|
|
368
368
|
})();
|
|
369
369
|
`);
|
|
370
|
+
const globalThis = options.globalThisPolyfill ? globalThisPolyfill : (0, ts_poet_1.conditionalOutput)("globalThis", (0, ts_poet_1.code) ``);
|
|
370
371
|
const bytesFromBase64 = (0, ts_poet_1.conditionalOutput)("bytesFromBase64", (0, ts_poet_1.code) `
|
|
371
372
|
function bytesFromBase64(b64: string): Uint8Array {
|
|
372
373
|
if (${globalThis}.Buffer) {
|
package/build/options.js
CHANGED