ts-proto 1.171.0 → 1.172.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/build/case.d.ts +8 -0
- package/build/context.d.ts +19 -0
- package/build/encode.d.ts +4 -0
- package/build/enums.d.ts +19 -0
- package/build/generate-async-iterable.d.ts +6 -0
- package/build/generate-generic-service-definition.d.ts +8 -0
- package/build/generate-grpc-js.d.ts +9 -0
- package/build/generate-grpc-web.d.ts +17 -0
- package/build/generate-nestjs.d.ts +7 -0
- package/build/generate-nice-grpc.d.ts +8 -0
- package/build/generate-services.d.ts +31 -0
- package/build/generate-struct-wrappers.d.ts +36 -0
- package/build/generate-type-registry.d.ts +3 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +10 -0
- package/build/main.d.ts +54 -0
- package/build/options.d.ts +101 -0
- package/build/plugin.d.ts +1 -0
- package/build/schema.d.ts +5 -0
- package/build/sourceInfo.d.ts +78 -0
- package/build/types.d.ts +103 -0
- package/build/utils.d.ts +80 -0
- package/build/visit.d.ts +8 -0
- package/package.json +2 -1
package/build/case.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Options } from "./options";
|
|
2
|
+
/** Converts `key` to TS/JS camel-case idiom, unless overridden not to. */
|
|
3
|
+
export declare function maybeSnakeToCamel(key: string, options: Pick<Options, "snakeToCamel">): string;
|
|
4
|
+
export declare function snakeToCamel(s: string): string;
|
|
5
|
+
export declare function camelToSnake(s: string): string;
|
|
6
|
+
export declare function capitalize(s: string): string;
|
|
7
|
+
export declare function uncapitalize(s: string): string;
|
|
8
|
+
export declare function camelCaseGrpc(s: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TypeMap } from "./types";
|
|
2
|
+
import { Utils } from "./main";
|
|
3
|
+
import { Options } from "./options";
|
|
4
|
+
import { FileDescriptorProto } from "ts-proto-descriptors";
|
|
5
|
+
/** Provides a parameter object for passing around the various context/config data. */
|
|
6
|
+
export interface BaseContext {
|
|
7
|
+
options: Options;
|
|
8
|
+
typeMap: TypeMap;
|
|
9
|
+
utils: Utils;
|
|
10
|
+
}
|
|
11
|
+
export interface Context extends BaseContext {
|
|
12
|
+
currentFile: FileContext;
|
|
13
|
+
}
|
|
14
|
+
export interface FileContext {
|
|
15
|
+
isProto3Syntax: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function createFileContext(file: FileDescriptorProto): {
|
|
18
|
+
isProto3Syntax: boolean;
|
|
19
|
+
};
|
package/build/enums.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Code } from "ts-poet";
|
|
2
|
+
import { EnumDescriptorProto, EnumValueDescriptorProto } from "ts-proto-descriptors";
|
|
3
|
+
import SourceInfo from "./sourceInfo";
|
|
4
|
+
import { Context } from "./context";
|
|
5
|
+
type UnrecognizedEnum = {
|
|
6
|
+
present: false;
|
|
7
|
+
} | {
|
|
8
|
+
present: true;
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function generateEnum(ctx: Context, fullName: string, enumDesc: EnumDescriptorProto, sourceInfo: SourceInfo): Code;
|
|
12
|
+
/** Generates a function with a big switch statement to decode JSON -> our enum. */
|
|
13
|
+
export declare function generateEnumFromJson(ctx: Context, fullName: string, enumDesc: EnumDescriptorProto, unrecognizedEnum: UnrecognizedEnum): Code;
|
|
14
|
+
/** Generates a function with a big switch statement to encode our enum -> JSON. */
|
|
15
|
+
export declare function generateEnumToJson(ctx: Context, fullName: string, enumDesc: EnumDescriptorProto, unrecognizedEnum: UnrecognizedEnum): Code;
|
|
16
|
+
/** Generates a function with a big switch statement to encode our string enum -> int value. */
|
|
17
|
+
export declare function generateEnumToNumber(ctx: Context, fullName: string, enumDesc: EnumDescriptorProto, unrecognizedEnum: UnrecognizedEnum): Code;
|
|
18
|
+
export declare function getMemberName(ctx: Context, enumDesc: EnumDescriptorProto, valueDesc: EnumValueDescriptorProto): string;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Code } from "ts-poet";
|
|
2
|
+
import { Utils } from "./main";
|
|
3
|
+
/** Creates a function to transform a message Source to a Uint8Array Source. */
|
|
4
|
+
export declare function generateEncodeTransform(utils: Utils, fullName: string): Code;
|
|
5
|
+
/** Creates a function to transform a Uint8Array Source to a message Source. */
|
|
6
|
+
export declare function generateDecodeTransform(utils: Utils, fullName: string): Code;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Code } from "ts-poet";
|
|
2
|
+
import { FileDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
|
|
3
|
+
import { Context } from "./context";
|
|
4
|
+
import SourceInfo from "./sourceInfo";
|
|
5
|
+
/**
|
|
6
|
+
* Generates a framework-agnostic service descriptor.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateGenericServiceDefinition(ctx: Context, fileDesc: FileDescriptorProto, sourceInfo: SourceInfo, serviceDesc: ServiceDescriptorProto): Code;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Code } from "ts-poet";
|
|
2
|
+
import { FileDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
|
|
3
|
+
import { Context } from "./context";
|
|
4
|
+
import SourceInfo from "./sourceInfo";
|
|
5
|
+
/**
|
|
6
|
+
* Generates a service definition and server / client stubs for the
|
|
7
|
+
* `@grpc/grpc-js` library.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateGrpcJsService(ctx: Context, fileDesc: FileDescriptorProto, sourceInfo: SourceInfo, serviceDesc: ServiceDescriptorProto): Code;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MethodDescriptorProto, FileDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
|
|
2
|
+
import { Code } from "ts-poet";
|
|
3
|
+
import { Context } from "./context";
|
|
4
|
+
/** Generates a client that uses the `@improbable-web/grpc-web` library. */
|
|
5
|
+
export declare function generateGrpcClientImpl(ctx: Context, _fileDesc: FileDescriptorProto, serviceDesc: ServiceDescriptorProto): Code;
|
|
6
|
+
/** Creates the service descriptor that grpc-web needs at runtime. */
|
|
7
|
+
export declare function generateGrpcServiceDesc(fileDesc: FileDescriptorProto, serviceDesc: ServiceDescriptorProto): Code;
|
|
8
|
+
/**
|
|
9
|
+
* Creates the method descriptor that grpc-web needs at runtime to make `unary` calls.
|
|
10
|
+
*
|
|
11
|
+
* Note that we take a few liberties in the implementation give we don't 100% match
|
|
12
|
+
* what grpc-web's existing output is, but it works out; see comments in the method
|
|
13
|
+
* implementation.
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateGrpcMethodDesc(ctx: Context, serviceDesc: ServiceDescriptorProto, methodDesc: MethodDescriptorProto): Code;
|
|
16
|
+
/** Adds misc top-level definitions for grpc-web functionality. */
|
|
17
|
+
export declare function addGrpcWebMisc(ctx: Context, hasStreamingMethods: boolean): Code;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FileDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
|
|
2
|
+
import { Code } from "ts-poet";
|
|
3
|
+
import SourceInfo from "./sourceInfo";
|
|
4
|
+
import { Context } from "./context";
|
|
5
|
+
export declare function generateNestjsServiceController(ctx: Context, fileDesc: FileDescriptorProto, sourceInfo: SourceInfo, serviceDesc: ServiceDescriptorProto): Code;
|
|
6
|
+
export declare function generateNestjsServiceClient(ctx: Context, fileDesc: FileDescriptorProto, sourceInfo: SourceInfo, serviceDesc: ServiceDescriptorProto): Code;
|
|
7
|
+
export declare function generateNestjsGrpcServiceMethodsDecorator(ctx: Context, serviceDesc: ServiceDescriptorProto): Code;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Code } from "ts-poet";
|
|
2
|
+
import { FileDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
|
|
3
|
+
import { Context } from "./context";
|
|
4
|
+
import SourceInfo from "./sourceInfo";
|
|
5
|
+
/**
|
|
6
|
+
* Generates server / client stubs for `nice-grpc` library.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateNiceGrpcService(ctx: Context, fileDesc: FileDescriptorProto, sourceInfo: SourceInfo, serviceDesc: ServiceDescriptorProto): Code;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FileDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
|
|
2
|
+
import { Code } from "ts-poet";
|
|
3
|
+
import SourceInfo from "./sourceInfo";
|
|
4
|
+
import { Context } from "./context";
|
|
5
|
+
/**
|
|
6
|
+
* Generates an interface for `serviceDesc`.
|
|
7
|
+
*
|
|
8
|
+
* Some RPC frameworks (i.e. Twirp) can use the same interface, i.e.
|
|
9
|
+
* `getFoo(req): Promise<res>` for the client-side and server-side,
|
|
10
|
+
* which is the intent for this interface.
|
|
11
|
+
*
|
|
12
|
+
* Other RPC frameworks (i.e. NestJS) that need different client-side
|
|
13
|
+
* vs. server-side code/interfaces are handled separately.
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateService(ctx: Context, fileDesc: FileDescriptorProto, sourceInfo: SourceInfo, serviceDesc: ServiceDescriptorProto): Code;
|
|
16
|
+
export declare function generateServiceClientImpl(ctx: Context, fileDesc: FileDescriptorProto, serviceDesc: ServiceDescriptorProto): Code;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an `Rpc.request(service, method, data)` abstraction.
|
|
19
|
+
*
|
|
20
|
+
* This lets clients pass in their own request-promise-ish client.
|
|
21
|
+
*
|
|
22
|
+
* This also requires clientStreamingRequest, serverStreamingRequest and
|
|
23
|
+
* bidirectionalStreamingRequest methods if any of the RPCs is streaming.
|
|
24
|
+
*
|
|
25
|
+
* We don't export this because if a project uses multiple `*.proto` files,
|
|
26
|
+
* we don't want our the barrel imports in `index.ts` to have multiple `Rpc`
|
|
27
|
+
* types.
|
|
28
|
+
*/
|
|
29
|
+
export declare function generateRpcType(ctx: Context, hasStreamingMethods: boolean): Code;
|
|
30
|
+
export declare function generateDataLoadersType(): Code;
|
|
31
|
+
export declare function generateDataLoaderOptionsType(): Code;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Context } from "./context";
|
|
2
|
+
import { Code } from "ts-poet";
|
|
3
|
+
export type StructFieldNames = {
|
|
4
|
+
nullValue: string;
|
|
5
|
+
numberValue: string;
|
|
6
|
+
stringValue: string;
|
|
7
|
+
boolValue: string;
|
|
8
|
+
structValue: string;
|
|
9
|
+
listValue: string;
|
|
10
|
+
};
|
|
11
|
+
/** Whether we need to generate `.wrap` and `.unwrap` methods for the given type. */
|
|
12
|
+
export declare function isWrapperType(fullProtoTypeName: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Converts ts-proto's idiomatic Struct/Value/ListValue representation to the proto messages.
|
|
15
|
+
*
|
|
16
|
+
* We do this deeply b/c NestJS does not invoke wrappers recursively.
|
|
17
|
+
*/
|
|
18
|
+
export declare function generateWrapDeep(ctx: Context, fullProtoTypeName: string, fieldNames: StructFieldNames): Code[];
|
|
19
|
+
/**
|
|
20
|
+
* Converts proto's Struct/Value?listValue messages to ts-proto's idiomatic representation.
|
|
21
|
+
*
|
|
22
|
+
* We do this deeply b/c NestJS does not invoke wrappers recursively.
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateUnwrapDeep(ctx: Context, fullProtoTypeName: string, fieldNames: StructFieldNames): Code[];
|
|
25
|
+
/**
|
|
26
|
+
* Converts ts-proto's idiomatic Struct/Value/ListValue representation to the proto messages.
|
|
27
|
+
*
|
|
28
|
+
* We do this shallow's b/c ts-proto's encode methods handle the recursion.
|
|
29
|
+
*/
|
|
30
|
+
export declare function generateWrapShallow(ctx: Context, fullProtoTypeName: string, fieldNames: StructFieldNames): Code[];
|
|
31
|
+
/**
|
|
32
|
+
* Converts proto's Struct/Value?listValue messages to ts-proto's idiomatic representation.
|
|
33
|
+
*
|
|
34
|
+
* We do this shallowly b/c ts-proto's decode methods handle recursion.
|
|
35
|
+
*/
|
|
36
|
+
export declare function generateUnwrapShallow(ctx: Context, fullProtoTypeName: string, fieldNames: StructFieldNames): Code[];
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DateOption, EnvOption, JsonTimestampOption, LongOption, OneofOption, Options, ServiceOption } from "./options";
|
package/build/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceOption = exports.OneofOption = exports.LongOption = exports.JsonTimestampOption = exports.EnvOption = exports.DateOption = void 0;
|
|
4
|
+
var options_1 = require("./options");
|
|
5
|
+
Object.defineProperty(exports, "DateOption", { enumerable: true, get: function () { return options_1.DateOption; } });
|
|
6
|
+
Object.defineProperty(exports, "EnvOption", { enumerable: true, get: function () { return options_1.EnvOption; } });
|
|
7
|
+
Object.defineProperty(exports, "JsonTimestampOption", { enumerable: true, get: function () { return options_1.JsonTimestampOption; } });
|
|
8
|
+
Object.defineProperty(exports, "LongOption", { enumerable: true, get: function () { return options_1.LongOption; } });
|
|
9
|
+
Object.defineProperty(exports, "OneofOption", { enumerable: true, get: function () { return options_1.OneofOption; } });
|
|
10
|
+
Object.defineProperty(exports, "ServiceOption", { enumerable: true, get: function () { return options_1.ServiceOption; } });
|
package/build/main.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Code } from "ts-poet";
|
|
2
|
+
import { ConditionalOutput } from "ts-poet/build/ConditionalOutput";
|
|
3
|
+
import { FileDescriptorProto } from "ts-proto-descriptors";
|
|
4
|
+
import { Context } from "./context";
|
|
5
|
+
import { Options } from "./options";
|
|
6
|
+
export declare function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [string, Code];
|
|
7
|
+
export type Utils = ReturnType<typeof makeDeepPartial> & ReturnType<typeof makeObjectIdMethods> & ReturnType<typeof makeTimestampMethods> & ReturnType<typeof makeByteUtils> & ReturnType<typeof makeLongUtils> & ReturnType<typeof makeComparisonUtils> & ReturnType<typeof makeNiceGrpcServerStreamingMethodResult> & ReturnType<typeof makeGrpcWebErrorClass> & ReturnType<typeof makeExtensionClass> & ReturnType<typeof makeAssertionUtils>;
|
|
8
|
+
/** These are runtime utility methods used by the generated code. */
|
|
9
|
+
export declare function makeUtils(options: Options): Utils;
|
|
10
|
+
declare function makeLongUtils(options: Options, bytes: ReturnType<typeof makeByteUtils>): {
|
|
11
|
+
numberToLong: ConditionalOutput;
|
|
12
|
+
longToNumber: ConditionalOutput;
|
|
13
|
+
longToString: ConditionalOutput;
|
|
14
|
+
longToBigint: ConditionalOutput;
|
|
15
|
+
Long: ConditionalOutput;
|
|
16
|
+
};
|
|
17
|
+
declare function makeByteUtils(options: Options): {
|
|
18
|
+
globalThis: ConditionalOutput;
|
|
19
|
+
bytesFromBase64: ConditionalOutput;
|
|
20
|
+
base64FromBytes: ConditionalOutput;
|
|
21
|
+
};
|
|
22
|
+
declare function makeDeepPartial(options: Options, longs: ReturnType<typeof makeLongUtils>): {
|
|
23
|
+
Builtin: ConditionalOutput;
|
|
24
|
+
DeepPartial: ConditionalOutput;
|
|
25
|
+
Exact: ConditionalOutput;
|
|
26
|
+
};
|
|
27
|
+
declare function makeObjectIdMethods(): {
|
|
28
|
+
fromJsonObjectId: ConditionalOutput;
|
|
29
|
+
fromProtoObjectId: ConditionalOutput;
|
|
30
|
+
toProtoObjectId: ConditionalOutput;
|
|
31
|
+
};
|
|
32
|
+
declare function makeTimestampMethods(options: Options, longs: ReturnType<typeof makeLongUtils>, bytes: ReturnType<typeof makeByteUtils>): {
|
|
33
|
+
toTimestamp: ConditionalOutput;
|
|
34
|
+
fromTimestamp: ConditionalOutput;
|
|
35
|
+
fromJsonTimestamp: ConditionalOutput;
|
|
36
|
+
};
|
|
37
|
+
declare function makeComparisonUtils(): {
|
|
38
|
+
isObject: ConditionalOutput;
|
|
39
|
+
isSet: ConditionalOutput;
|
|
40
|
+
};
|
|
41
|
+
declare function makeNiceGrpcServerStreamingMethodResult(options: Options): {
|
|
42
|
+
NiceGrpcServerStreamingMethodResult: ConditionalOutput;
|
|
43
|
+
};
|
|
44
|
+
declare function makeGrpcWebErrorClass(bytes: ReturnType<typeof makeByteUtils>): {
|
|
45
|
+
GrpcWebError: ConditionalOutput;
|
|
46
|
+
};
|
|
47
|
+
declare function makeExtensionClass(options: Options): {
|
|
48
|
+
Extension: ConditionalOutput;
|
|
49
|
+
};
|
|
50
|
+
declare function makeAssertionUtils(bytes: ReturnType<typeof makeByteUtils>): {
|
|
51
|
+
fail: ConditionalOutput;
|
|
52
|
+
};
|
|
53
|
+
export declare const contextTypeVar = "Context extends DataLoaders";
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ToStringOpts } from "ts-poet/build/Code";
|
|
2
|
+
export declare enum LongOption {
|
|
3
|
+
NUMBER = "number",
|
|
4
|
+
LONG = "long",
|
|
5
|
+
STRING = "string",
|
|
6
|
+
BIGINT = "bigint"
|
|
7
|
+
}
|
|
8
|
+
export declare enum DateOption {
|
|
9
|
+
DATE = "date",
|
|
10
|
+
STRING = "string",
|
|
11
|
+
STRING_NANO = "string-nano",
|
|
12
|
+
TIMESTAMP = "timestamp"
|
|
13
|
+
}
|
|
14
|
+
export declare enum JsonTimestampOption {
|
|
15
|
+
RFC3339 = "rfc3339",
|
|
16
|
+
RAW = "raw"
|
|
17
|
+
}
|
|
18
|
+
export declare enum EnvOption {
|
|
19
|
+
NODE = "node",
|
|
20
|
+
BROWSER = "browser",
|
|
21
|
+
BOTH = "both"
|
|
22
|
+
}
|
|
23
|
+
export declare enum OneofOption {
|
|
24
|
+
PROPERTIES = "properties",
|
|
25
|
+
UNIONS = "unions"
|
|
26
|
+
}
|
|
27
|
+
export declare enum ServiceOption {
|
|
28
|
+
GRPC = "grpc-js",
|
|
29
|
+
NICE_GRPC = "nice-grpc",
|
|
30
|
+
GENERIC = "generic-definitions",
|
|
31
|
+
DEFAULT = "default",
|
|
32
|
+
NONE = "none"
|
|
33
|
+
}
|
|
34
|
+
export type Options = {
|
|
35
|
+
context: boolean;
|
|
36
|
+
snakeToCamel: Array<"json" | "keys">;
|
|
37
|
+
forceLong: LongOption;
|
|
38
|
+
globalThisPolyfill: boolean;
|
|
39
|
+
useOptionals: boolean | "none" | "deprecatedOnly" | "messages" | "all";
|
|
40
|
+
emitDefaultValues: Array<"json-methods">;
|
|
41
|
+
useDate: DateOption;
|
|
42
|
+
useJsonTimestamp: JsonTimestampOption;
|
|
43
|
+
useMongoObjectId: boolean;
|
|
44
|
+
oneof: OneofOption;
|
|
45
|
+
esModuleInterop: boolean;
|
|
46
|
+
fileSuffix: string;
|
|
47
|
+
importSuffix: string;
|
|
48
|
+
outputEncodeMethods: true | false | "encode-only" | "decode-only" | "encode-no-creation";
|
|
49
|
+
outputJsonMethods: true | false | "to-only" | "from-only";
|
|
50
|
+
outputPartialMethods: boolean;
|
|
51
|
+
outputTypeAnnotations: boolean | "static-only" | "optional";
|
|
52
|
+
outputTypeRegistry: boolean;
|
|
53
|
+
stringEnums: boolean;
|
|
54
|
+
constEnums: boolean;
|
|
55
|
+
removeEnumPrefix: boolean;
|
|
56
|
+
enumsAsLiterals: boolean;
|
|
57
|
+
outputClientImpl: boolean | "grpc-web";
|
|
58
|
+
outputServices: ServiceOption[];
|
|
59
|
+
addGrpcMetadata: boolean;
|
|
60
|
+
metadataType: string | undefined;
|
|
61
|
+
addNestjsRestParameter: boolean;
|
|
62
|
+
returnObservable: boolean;
|
|
63
|
+
lowerCaseServiceMethods: boolean;
|
|
64
|
+
nestJs: boolean;
|
|
65
|
+
env: EnvOption;
|
|
66
|
+
unrecognizedEnum: boolean;
|
|
67
|
+
unrecognizedEnumName: string;
|
|
68
|
+
unrecognizedEnumValue: number;
|
|
69
|
+
exportCommonSymbols: boolean;
|
|
70
|
+
outputSchema: boolean;
|
|
71
|
+
onlyTypes: boolean;
|
|
72
|
+
emitImportedFiles: boolean;
|
|
73
|
+
useAbortSignal: boolean;
|
|
74
|
+
useExactTypes: boolean;
|
|
75
|
+
useAsyncIterable: boolean;
|
|
76
|
+
unknownFields: boolean;
|
|
77
|
+
usePrototypeForDefaults: boolean;
|
|
78
|
+
useJsonName: boolean;
|
|
79
|
+
useJsonWireFormat: boolean;
|
|
80
|
+
useNumericEnumForJson: boolean;
|
|
81
|
+
initializeFieldsAsUndefined: boolean;
|
|
82
|
+
useMapType: boolean;
|
|
83
|
+
useReadonlyTypes: boolean;
|
|
84
|
+
useSnakeTypeName: boolean;
|
|
85
|
+
outputExtensions: boolean;
|
|
86
|
+
outputIndex: boolean;
|
|
87
|
+
M: {
|
|
88
|
+
[from: string]: string;
|
|
89
|
+
};
|
|
90
|
+
rpcBeforeRequest: boolean;
|
|
91
|
+
rpcAfterResponse: boolean;
|
|
92
|
+
rpcErrorHandler: boolean;
|
|
93
|
+
comments: boolean;
|
|
94
|
+
disableProto2Optionals: boolean;
|
|
95
|
+
disableProto2DefaultValues: boolean;
|
|
96
|
+
useNullAsOptional: boolean;
|
|
97
|
+
};
|
|
98
|
+
export declare function defaultOptions(): Options;
|
|
99
|
+
export declare function optionsFromParameter(parameter: string | undefined): Options;
|
|
100
|
+
export declare function getTsPoetOpts(options: Options): ToStringOpts;
|
|
101
|
+
export declare function addTypeToMessages(options: Options): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FileDescriptorProto } from "ts-proto-descriptors";
|
|
2
|
+
import { Code } from "ts-poet";
|
|
3
|
+
import { Context } from "./context";
|
|
4
|
+
import SourceInfo from "./sourceInfo";
|
|
5
|
+
export declare function generateSchema(ctx: Context, fileDesc: FileDescriptorProto, sourceInfo: SourceInfo): Code[];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { FileDescriptorProto } from "ts-proto-descriptors";
|
|
2
|
+
/** This type is expecting a value from the Fields constant. */
|
|
3
|
+
export type FieldID = number;
|
|
4
|
+
/**
|
|
5
|
+
* The field values here represent the proto field IDs associated with the types
|
|
6
|
+
* (file,message,enum,service).
|
|
7
|
+
*
|
|
8
|
+
* For more information read the comments for SourceCodeInfo declared in
|
|
9
|
+
* google's 'descriptor.proto' file, see:
|
|
10
|
+
* https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto#L730
|
|
11
|
+
*/
|
|
12
|
+
export declare const Fields: {
|
|
13
|
+
file: {
|
|
14
|
+
syntax: number;
|
|
15
|
+
message_type: number;
|
|
16
|
+
enum_type: number;
|
|
17
|
+
service: number;
|
|
18
|
+
extension: number;
|
|
19
|
+
};
|
|
20
|
+
message: {
|
|
21
|
+
field: number;
|
|
22
|
+
nested_type: number;
|
|
23
|
+
enum_type: number;
|
|
24
|
+
oneof_decl: number;
|
|
25
|
+
};
|
|
26
|
+
enum: {
|
|
27
|
+
value: number;
|
|
28
|
+
};
|
|
29
|
+
service: {
|
|
30
|
+
method: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* This type is simply an interface on the SourceCodeInfo.Location message.
|
|
35
|
+
*/
|
|
36
|
+
export interface SourceDescription {
|
|
37
|
+
readonly span: number[];
|
|
38
|
+
readonly leadingComments: string;
|
|
39
|
+
readonly trailingComments: string;
|
|
40
|
+
readonly leadingDetachedComments: string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Mapping from a string of dotted notation `path` parts to efficiently
|
|
44
|
+
* lookup the related source information.
|
|
45
|
+
*/
|
|
46
|
+
export type SourceInfoMap = {
|
|
47
|
+
[key: string]: SourceDescription;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* This class provides direct lookup and navigation through the type
|
|
51
|
+
* system by the use of lookup/open to access the source info for types
|
|
52
|
+
* defined in a protocol buffer.
|
|
53
|
+
*/
|
|
54
|
+
export default class SourceInfo implements SourceDescription {
|
|
55
|
+
private readonly sourceCode;
|
|
56
|
+
private readonly selfDescription;
|
|
57
|
+
/** Returns an empty SourceInfo */
|
|
58
|
+
static empty(): SourceInfo;
|
|
59
|
+
/**
|
|
60
|
+
* Creates the SourceInfo from the FileDescriptorProto given to you
|
|
61
|
+
* by the protoc compiler. It indexes file.sourceCodeInfo by dotted
|
|
62
|
+
* path notation and returns the root SourceInfo.
|
|
63
|
+
*/
|
|
64
|
+
static fromDescriptor(file: FileDescriptorProto): SourceInfo;
|
|
65
|
+
private constructor();
|
|
66
|
+
/** Returns the code span [start line, start column, end line] */
|
|
67
|
+
get span(): number[];
|
|
68
|
+
/** Leading consecutive comment lines prior to the current element */
|
|
69
|
+
get leadingComments(): string;
|
|
70
|
+
/** Documentation is unclear about what exactly this is */
|
|
71
|
+
get trailingComments(): string;
|
|
72
|
+
/** Detached comments are those preceeding but separated by a blank non-comment line */
|
|
73
|
+
get leadingDetachedComments(): string[];
|
|
74
|
+
/** Return the source info for the field id and index specficied */
|
|
75
|
+
lookup(type: FieldID, index?: number): SourceDescription;
|
|
76
|
+
/** Returns a new SourceInfo class representing the field id and index specficied */
|
|
77
|
+
open(type: FieldID, index: number): SourceInfo;
|
|
78
|
+
}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { CodeGeneratorRequest, DescriptorProto, EnumDescriptorProto, FieldDescriptorProto, FieldDescriptorProto_Type, FileDescriptorProto, MessageOptions, MethodDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
|
|
2
|
+
import { Code, Import } from "ts-poet";
|
|
3
|
+
import { Options } from "./options";
|
|
4
|
+
import { Context } from "./context";
|
|
5
|
+
/** Based on https://github.com/dcodeIO/protobuf.js/blob/master/src/types.js#L37. */
|
|
6
|
+
export declare function basicWireType(type: FieldDescriptorProto_Type): number;
|
|
7
|
+
export declare function basicLongWireType(type: FieldDescriptorProto_Type): number | undefined;
|
|
8
|
+
/** Returns the type name without any repeated/required/etc. labels. */
|
|
9
|
+
export declare function basicTypeName(ctx: Context, field: FieldDescriptorProto, typeOptions?: {
|
|
10
|
+
keepValueType?: boolean;
|
|
11
|
+
}): Code;
|
|
12
|
+
/** Returns the Reader method for the primitive's read/write call. */
|
|
13
|
+
export declare function toReaderCall(field: FieldDescriptorProto): string;
|
|
14
|
+
export declare function packedType(type: FieldDescriptorProto_Type): number | undefined;
|
|
15
|
+
export declare function defaultValue(ctx: Context, field: FieldDescriptorProto): any;
|
|
16
|
+
/** Creates code that checks that the field is not the default value. Supports scalars and enums. */
|
|
17
|
+
export declare function notDefaultCheck(ctx: Context, field: FieldDescriptorProto, messageOptions: MessageOptions | undefined, place: string): Code;
|
|
18
|
+
/** A map of proto type name, e.g. `foo.Message.Inner`, to module/class name, e.g. `foo`, `Message_Inner`. */
|
|
19
|
+
export type TypeMap = Map<string, [string, string, DescriptorProto | EnumDescriptorProto]>;
|
|
20
|
+
/** Scans all of the proto files in `request` and builds a map of proto typeName -> TS module/name. */
|
|
21
|
+
export declare function createTypeMap(request: CodeGeneratorRequest, options: Options): TypeMap;
|
|
22
|
+
/** A "Scalar Value Type" as defined in https://developers.google.com/protocol-buffers/docs/proto3#scalar */
|
|
23
|
+
export declare function isScalar(field: FieldDescriptorProto): boolean;
|
|
24
|
+
export declare function isOptionalProperty(field: FieldDescriptorProto, messageOptions: MessageOptions | undefined, options: Options, isProto3Syntax: boolean): boolean;
|
|
25
|
+
/** This includes all scalars, enums and the [groups type](https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/DescriptorProtos.FieldDescriptorProto.Type.html#TYPE_GROUP) */
|
|
26
|
+
export declare function isPrimitive(field: FieldDescriptorProto): boolean;
|
|
27
|
+
export declare function isBytes(field: FieldDescriptorProto): boolean;
|
|
28
|
+
export declare function isMessage(field: FieldDescriptorProto): boolean;
|
|
29
|
+
export declare function isEnum(field: FieldDescriptorProto): boolean;
|
|
30
|
+
export declare function isWithinOneOf(field: FieldDescriptorProto): boolean;
|
|
31
|
+
export declare function isWithinOneOfThatShouldBeUnion(options: Options, field: FieldDescriptorProto): boolean;
|
|
32
|
+
export declare function isRepeated(field: FieldDescriptorProto): boolean;
|
|
33
|
+
export declare function isLong(field: FieldDescriptorProto): boolean;
|
|
34
|
+
export declare function isWholeNumber(field: FieldDescriptorProto): boolean;
|
|
35
|
+
export declare function isMapType(ctx: Context, messageDesc: DescriptorProto, field: FieldDescriptorProto): boolean;
|
|
36
|
+
export declare function isObjectId(field: FieldDescriptorProto): boolean;
|
|
37
|
+
export declare function isTimestamp(field: FieldDescriptorProto): boolean;
|
|
38
|
+
export declare function isValueType(ctx: Context, field: FieldDescriptorProto): boolean;
|
|
39
|
+
export declare function isAnyValueType(field: FieldDescriptorProto): boolean;
|
|
40
|
+
export declare function isAnyValueTypeName(typeName: string): boolean;
|
|
41
|
+
export declare function isBytesValueType(field: FieldDescriptorProto): boolean;
|
|
42
|
+
export declare function isFieldMaskType(field: FieldDescriptorProto): boolean;
|
|
43
|
+
export declare function isFieldMaskTypeName(typeName: string): boolean;
|
|
44
|
+
export declare function isListValueType(field: FieldDescriptorProto): boolean;
|
|
45
|
+
export declare function isListValueTypeName(typeName: string): boolean;
|
|
46
|
+
export declare function isStructType(field: FieldDescriptorProto): boolean;
|
|
47
|
+
export declare function isStructTypeName(typeName: string): boolean;
|
|
48
|
+
export declare function isLongValueType(field: FieldDescriptorProto): boolean;
|
|
49
|
+
export declare function isEmptyType(typeName: string): boolean;
|
|
50
|
+
export declare function valueTypeName(ctx: Context, typeName: string): Code | undefined;
|
|
51
|
+
export declare function wrapperTypeName(typeName: string): string | undefined;
|
|
52
|
+
/** Maps `.some_proto_namespace.Message` to a TypeName. */
|
|
53
|
+
export declare function messageToTypeName(ctx: Context, protoType: string, typeOptions?: {
|
|
54
|
+
keepValueType?: boolean;
|
|
55
|
+
repeated?: boolean;
|
|
56
|
+
}): Code;
|
|
57
|
+
export declare function getEnumMethod(ctx: Context, enumProtoType: string, methodSuffix: string): Import;
|
|
58
|
+
/** Return the TypeName for any field (primitive/message/etc.) as exposed in the interface. */
|
|
59
|
+
export declare function toTypeName(ctx: Context, messageDesc: DescriptorProto | undefined, field: FieldDescriptorProto, ensureOptional?: boolean): Code;
|
|
60
|
+
/**
|
|
61
|
+
* For a protobuf map field, if the generated code should use the javascript Map type.
|
|
62
|
+
*
|
|
63
|
+
* If the type of a protobuf map key corresponds to the Long type, we always use the Map type. This avoids generating
|
|
64
|
+
* invalid code such as below (using Long as key of a javascript object):
|
|
65
|
+
*
|
|
66
|
+
* export interface Foo {
|
|
67
|
+
* bar: { [key: Long]: Long }
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* See https://github.com/stephenh/ts-proto/issues/708 for more details.
|
|
71
|
+
*/
|
|
72
|
+
export declare function shouldGenerateJSMapType(ctx: Context, message: DescriptorProto, field: FieldDescriptorProto): boolean;
|
|
73
|
+
export declare function detectMapType(ctx: Context, messageDesc: DescriptorProto, fieldDesc: FieldDescriptorProto): {
|
|
74
|
+
messageDesc: DescriptorProto;
|
|
75
|
+
keyField: FieldDescriptorProto;
|
|
76
|
+
keyType: Code;
|
|
77
|
+
valueField: FieldDescriptorProto;
|
|
78
|
+
valueType: Code;
|
|
79
|
+
} | undefined;
|
|
80
|
+
export declare function rawRequestType(ctx: Context, methodDesc: MethodDescriptorProto, typeOptions?: {
|
|
81
|
+
keepValueType?: boolean;
|
|
82
|
+
repeated?: boolean;
|
|
83
|
+
}): Code;
|
|
84
|
+
export declare function observableType(ctx: Context, asType?: boolean): Code;
|
|
85
|
+
export declare function requestType(ctx: Context, methodDesc: MethodDescriptorProto, partial?: boolean): Code;
|
|
86
|
+
export declare function responseType(ctx: Context, methodDesc: MethodDescriptorProto, typeOptions?: {
|
|
87
|
+
keepValueType?: boolean;
|
|
88
|
+
repeated?: boolean;
|
|
89
|
+
}): Code;
|
|
90
|
+
export declare function responsePromise(ctx: Context, methodDesc: MethodDescriptorProto): Code;
|
|
91
|
+
export declare function responseObservable(ctx: Context, methodDesc: MethodDescriptorProto): Code;
|
|
92
|
+
export declare function responsePromiseOrObservable(ctx: Context, methodDesc: MethodDescriptorProto): Code;
|
|
93
|
+
export interface BatchMethod {
|
|
94
|
+
methodDesc: MethodDescriptorProto;
|
|
95
|
+
uniqueIdentifier: string;
|
|
96
|
+
singleMethodName: string;
|
|
97
|
+
inputFieldName: string;
|
|
98
|
+
inputType: Code;
|
|
99
|
+
outputFieldName: string;
|
|
100
|
+
outputType: Code;
|
|
101
|
+
mapType: boolean;
|
|
102
|
+
}
|
|
103
|
+
export declare function detectBatchMethod(ctx: Context, fileDesc: FileDescriptorProto, serviceDesc: ServiceDescriptorProto, methodDesc: MethodDescriptorProto): BatchMethod | undefined;
|
package/build/utils.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Code, Import } from "ts-poet";
|
|
4
|
+
import { CodeGeneratorRequest, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, MethodOptions } from "ts-proto-descriptors";
|
|
5
|
+
import ReadStream = NodeJS.ReadStream;
|
|
6
|
+
import { SourceDescription } from "./sourceInfo";
|
|
7
|
+
import { Options } from "./options";
|
|
8
|
+
export declare function protoFilesToGenerate(request: CodeGeneratorRequest): FileDescriptorProto[];
|
|
9
|
+
export declare function generateIndexFiles(files: FileDescriptorProto[], options: Options): [string, Code][];
|
|
10
|
+
export declare function readToBuffer(stream: ReadStream): Promise<Buffer>;
|
|
11
|
+
export declare function fail(message: string): never;
|
|
12
|
+
export declare function singular(name: string): string;
|
|
13
|
+
export declare function lowerFirst(name: string): string;
|
|
14
|
+
export declare function upperFirst(name: string): string;
|
|
15
|
+
/** Removes potentially harmful characters from comments and pushes it into chunks. */
|
|
16
|
+
export declare function maybeAddComment(options: Pick<Options, "comments">, desc: Partial<Pick<SourceDescription, "leadingComments" | "trailingComments">>, chunks: Code[], deprecated?: boolean, prefix?: string): void;
|
|
17
|
+
export declare function prefixDisableLinter(spec: string): string;
|
|
18
|
+
export declare function maybePrefixPackage(fileDesc: FileDescriptorProto, rest: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Asserts that an object is an instance of a certain class
|
|
21
|
+
* @param obj The object to check
|
|
22
|
+
* @param constructor The constructor of the class to check
|
|
23
|
+
*/
|
|
24
|
+
export declare function assertInstanceOf<T>(obj: unknown, constructor: {
|
|
25
|
+
new (...args: any[]): T;
|
|
26
|
+
}): asserts obj is T;
|
|
27
|
+
/**
|
|
28
|
+
* A MethodDescriptorProto subclass that adds formatted properties
|
|
29
|
+
*/
|
|
30
|
+
export declare class FormattedMethodDescriptor implements MethodDescriptorProto {
|
|
31
|
+
name: string;
|
|
32
|
+
inputType: string;
|
|
33
|
+
outputType: string;
|
|
34
|
+
options: MethodOptions | undefined;
|
|
35
|
+
clientStreaming: boolean;
|
|
36
|
+
serverStreaming: boolean;
|
|
37
|
+
private original;
|
|
38
|
+
private ctxOptions;
|
|
39
|
+
/**
|
|
40
|
+
* The name of this method with formatting applied according to the `Options` object passed to the constructor.
|
|
41
|
+
* Automatically updates to any changes to the `Options` or `name` of this object
|
|
42
|
+
*/
|
|
43
|
+
get formattedName(): string;
|
|
44
|
+
constructor(src: MethodDescriptorProto, options: Options);
|
|
45
|
+
/**
|
|
46
|
+
* Retrieve the source `MethodDescriptorProto` used to construct this object
|
|
47
|
+
* @returns The source `MethodDescriptorProto` used to construct this object
|
|
48
|
+
*/
|
|
49
|
+
getSource(): MethodDescriptorProto;
|
|
50
|
+
/**
|
|
51
|
+
* Applies formatting rules to a gRPC method name.
|
|
52
|
+
* @param methodName The original method name
|
|
53
|
+
* @param options The options object containing rules to apply
|
|
54
|
+
* @returns The formatted method name
|
|
55
|
+
*/
|
|
56
|
+
static formatName(methodName: string, options: Options): string;
|
|
57
|
+
}
|
|
58
|
+
export declare function getFieldJsonName(field: Pick<FieldDescriptorProto, "name" | "jsonName">, options: Pick<Options, "snakeToCamel" | "useJsonName">): string;
|
|
59
|
+
export declare function getFieldName(field: Pick<FieldDescriptorProto, "name" | "jsonName">, options: Pick<Options, "snakeToCamel" | "useJsonName">): string;
|
|
60
|
+
/** Returns `bar` or `"bar"` if `propertyName` isn't a safe property name. */
|
|
61
|
+
export declare function safeAccessor(propertyName: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Returns a snippet for reading an object's property, such as `foo.bar`, or `foo['bar']` if the property name contains unusual characters.
|
|
64
|
+
* For simplicity, we don't match the ECMA 5/6 rules for valid identifiers exactly, and return array syntax liberally.
|
|
65
|
+
* @param objectName
|
|
66
|
+
* @param propertyName
|
|
67
|
+
* @param optional
|
|
68
|
+
*/
|
|
69
|
+
export declare function getPropertyAccessor(objectName: string, propertyName: string, optional?: boolean): string;
|
|
70
|
+
export declare function impFile(options: Options, spec: string): Import;
|
|
71
|
+
export declare function impProto(options: Options, module: string, type: string): Import;
|
|
72
|
+
export declare function tryCatchBlock(tryBlock: Code | string, handleErrorBlock: Code | string): Code;
|
|
73
|
+
export declare function arrowFunction(params: string, body: Code | string, isOneLine?: boolean): Code;
|
|
74
|
+
export declare function nullOrUndefined(options: Pick<Options, "useNullAsOptional">, hasProto3Optional?: boolean): string;
|
|
75
|
+
export declare function maybeCheckIsNotNull(options: Pick<Options, "useNullAsOptional">, typeName: string, prefix?: string): string;
|
|
76
|
+
export declare function maybeCheckIsNull(options: Pick<Options, "useNullAsOptional">, typeName: string, prefix?: string): string;
|
|
77
|
+
export declare function withOrMaybeCheckIsNotNull(options: Pick<Options, "useNullAsOptional">, typeName: string): string;
|
|
78
|
+
export declare function withOrMaybeCheckIsNull(options: Pick<Options, "useNullAsOptional">, typeName: string): string;
|
|
79
|
+
export declare function withAndMaybeCheckIsNotNull(options: Pick<Options, "useNullAsOptional">, typeName: string): string;
|
|
80
|
+
export declare function withAndMaybeCheckIsNull(options: Pick<Options, "useNullAsOptional">, typeName: string): string;
|
package/build/visit.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DescriptorProto, EnumDescriptorProto, FileDescriptorProto, ServiceDescriptorProto } from "ts-proto-descriptors";
|
|
2
|
+
import SourceInfo from "./sourceInfo";
|
|
3
|
+
import { Options } from "./options";
|
|
4
|
+
type MessageVisitor = (fullName: string, desc: DescriptorProto, sourceInfo: SourceInfo, fullProtoTypeName: string) => void;
|
|
5
|
+
type EnumVisitor = (fullName: string, desc: EnumDescriptorProto, sourceInfo: SourceInfo, fullProtoTypeName: string) => void;
|
|
6
|
+
export declare function visit(proto: FileDescriptorProto | DescriptorProto, sourceInfo: SourceInfo, messageFn: MessageVisitor, options: Options, enumFn?: EnumVisitor, tsPrefix?: string, protoPrefix?: string): void;
|
|
7
|
+
export declare function visitServices(proto: FileDescriptorProto, sourceInfo: SourceInfo, serviceFn: (desc: ServiceDescriptorProto, sourceInfo: SourceInfo) => void): void;
|
|
8
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.172.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
7
7
|
"bin": {
|
|
8
8
|
"protoc-gen-ts_proto": "./protoc-gen-ts_proto"
|
|
9
9
|
},
|
|
10
|
+
"types": "build/index.d.ts",
|
|
10
11
|
"scripts": {
|
|
11
12
|
"build": "yarn tsc",
|
|
12
13
|
"build:test": "yarn proto2bin && yarn proto2pbjs && yarn bin2ts",
|