Skip to content

Commit

Permalink
codegen(ts): Prepend @ts-nocheck on generated typescript files (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyp3rflow committed Feb 4, 2023
1 parent 4f08e9c commit f358b46
Show file tree
Hide file tree
Showing 59 changed files with 260 additions and 4 deletions.
1 change: 1 addition & 0 deletions codegen/ts/aot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default async function* aot({
yield [
module.filePath,
new StringReader([
"// @ts-nocheck\n",
importBufferToCode(module.importBuffer),
Array.from(module).map((fragment) => {
if (fragment instanceof Export) {
Expand Down
46 changes: 42 additions & 4 deletions compat/protoc/file-descriptor-set/pbkit2fds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
} from "../../../generated/messages/google/protobuf/(MethodOptions)/IdempotencyLevel.ts";
import { Type as CType } from "../../../generated/messages/google/protobuf/(FieldOptions)/CType.ts";
import { Type as JSType } from "../../../generated/messages/google/protobuf/(FieldOptions)/JSType.ts";
import { Type as OptionRetention } from "../../../generated/messages/google/protobuf/(FieldOptions)/OptionRetention.ts";
import { Type as OptionTargetType } from "../../../generated/messages/google/protobuf/(FieldOptions)/OptionTargetType.ts";

export interface ConvertSchemaToFileDescriptorSetConfig {
schema: Schema;
Expand Down Expand Up @@ -393,10 +395,8 @@ function getServicesFromFile(schema: Schema, file: File): ServiceWithName[] {
type OptionsBase = { uninterpretedOption: UninterpretedOption[] };
function optionsOrUndefined<T extends OptionsBase>(options: T): T | undefined {
const { uninterpretedOption, ...rest } = options;
const countOfOption = (
uninterpretedOption.length +
Object.values(rest).filter((x) => x !== undefined).length
);
const countOfOption = uninterpretedOption.length +
Object.values(rest).filter((x) => x !== undefined).length;
return countOfOption === 0 ? undefined : options;
}

Expand Down Expand Up @@ -500,6 +500,9 @@ function fieldDescriptorOptions(
unverifiedLazy: booleanOptionValue(options["unverified_lazy"]),
ctype: getCType(options["ctype"]),
jstype: getJSType(options["jstype"]),
debugRedact: booleanOptionValue(options["debug_redact"]),
retention: getOptionRetention(options["retention"]),
target: getOptionTargetType(options["target"]),
uninterpretedOption: [], // TODO
};
return result;
Expand All @@ -523,6 +526,37 @@ function fieldDescriptorOptions(
return undefined;
}
}
function getOptionRetention(
retention: OptionValue,
): OptionRetention | undefined {
switch (retention) {
case "RETENTION_UNKNOWN":
case "RETENTION_RUNTIME":
case "RETENTION_SOURCE":
return retention;
default:
return undefined;
}
}
function getOptionTargetType(
target: OptionValue,
): OptionTargetType | undefined {
switch (target) {
case "TARGET_TYPE_UNKNOWN":
case "TARGET_TYPE_FILE":
case "TARGET_TYPE_EXTENSION_RANGE":
case "TARGET_TYPE_MESSAGE":
case "TARGET_TYPE_FIELD":
case "TARGET_TYPE_ONEOF":
case "TARGET_TYPE_ENUM":
case "TARGET_TYPE_ENUM_ENTRY":
case "TARGET_TYPE_SERVICE":
case "TARGET_TYPE_METHOD":
return target;
default:
return undefined;
}
}
}

function enumDescriptorOptions(
Expand All @@ -532,6 +566,7 @@ function enumDescriptorOptions(
{
allowAlias: booleanOptionValue(options["allow_alias"]),
deprecated: booleanOptionValue(options["deprecated"]),
deprecatedLegacyJsonFieldConflicts: undefined,
uninterpretedOption: [], // TODO
};
return result;
Expand Down Expand Up @@ -559,6 +594,9 @@ function descriptorOptions(
),
deprecated: booleanOptionValue(options["deprecated"]),
mapEntry: booleanOptionValue(options["map_entry"]),
deprecatedLegacyJsonFieldConflicts: booleanOptionValue(
options["deprecated_legacy_json_field_conflicts"],
),
uninterpretedOption: [], // TODO
};
return result;
Expand Down
1 change: 1 addition & 0 deletions generated/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import * as messages from "./messages/index.ts";

export type {
Expand Down
1 change: 1 addition & 0 deletions generated/messages/google/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import * as protobuf from "./protobuf/index.ts";

export type {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
Type as ExtensionRangeOptions,
encodeJson as encodeJson_1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
tsValueToJsonValueFns,
jsonValueToTsValueFns,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// @ts-nocheck
export type { Type as ExtensionRange } from "./ExtensionRange.ts";
export type { Type as ReservedRange } from "./ReservedRange.ts";
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
tsValueToJsonValueFns,
jsonValueToTsValueFns,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// @ts-nocheck
export type { Type as EnumReservedRange } from "./EnumReservedRange.ts";
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
export declare namespace $.google.protobuf.FieldDescriptorProto {
export type Label =
| "UNSPECIFIED"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
export declare namespace $.google.protobuf.FieldDescriptorProto {
export type Type =
| "UNSPECIFIED"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// @ts-nocheck
export type { Type as Type } from "./Type.ts";
export type { Type as Label } from "./Label.ts";
1 change: 1 addition & 0 deletions generated/messages/google/protobuf/(FieldOptions)/CType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
export declare namespace $.google.protobuf.FieldOptions {
export type CType =
| "STRING"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
export declare namespace $.google.protobuf.FieldOptions {
export type JSType =
| "JS_NORMAL"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-nocheck
export declare namespace $.google.protobuf.FieldOptions {
export type OptionRetention =
| "RETENTION_UNKNOWN"
| "RETENTION_RUNTIME"
| "RETENTION_SOURCE";
}

export type Type = $.google.protobuf.FieldOptions.OptionRetention;

export const num2name = {
0: "RETENTION_UNKNOWN",
1: "RETENTION_RUNTIME",
2: "RETENTION_SOURCE",
} as const;

export const name2num = {
RETENTION_UNKNOWN: 0,
RETENTION_RUNTIME: 1,
RETENTION_SOURCE: 2,
} as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @ts-nocheck
export declare namespace $.google.protobuf.FieldOptions {
export type OptionTargetType =
| "TARGET_TYPE_UNKNOWN"
| "TARGET_TYPE_FILE"
| "TARGET_TYPE_EXTENSION_RANGE"
| "TARGET_TYPE_MESSAGE"
| "TARGET_TYPE_FIELD"
| "TARGET_TYPE_ONEOF"
| "TARGET_TYPE_ENUM"
| "TARGET_TYPE_ENUM_ENTRY"
| "TARGET_TYPE_SERVICE"
| "TARGET_TYPE_METHOD";
}

export type Type = $.google.protobuf.FieldOptions.OptionTargetType;

export const num2name = {
0: "TARGET_TYPE_UNKNOWN",
1: "TARGET_TYPE_FILE",
2: "TARGET_TYPE_EXTENSION_RANGE",
3: "TARGET_TYPE_MESSAGE",
4: "TARGET_TYPE_FIELD",
5: "TARGET_TYPE_ONEOF",
6: "TARGET_TYPE_ENUM",
7: "TARGET_TYPE_ENUM_ENTRY",
8: "TARGET_TYPE_SERVICE",
9: "TARGET_TYPE_METHOD",
} as const;

export const name2num = {
TARGET_TYPE_UNKNOWN: 0,
TARGET_TYPE_FILE: 1,
TARGET_TYPE_EXTENSION_RANGE: 2,
TARGET_TYPE_MESSAGE: 3,
TARGET_TYPE_FIELD: 4,
TARGET_TYPE_ONEOF: 5,
TARGET_TYPE_ENUM: 6,
TARGET_TYPE_ENUM_ENTRY: 7,
TARGET_TYPE_SERVICE: 8,
TARGET_TYPE_METHOD: 9,
} as const;
3 changes: 3 additions & 0 deletions generated/messages/google/protobuf/(FieldOptions)/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// @ts-nocheck
export type { Type as CType } from "./CType.ts";
export type { Type as JSType } from "./JSType.ts";
export type { Type as OptionRetention } from "./OptionRetention.ts";
export type { Type as OptionTargetType } from "./OptionTargetType.ts";
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
export declare namespace $.google.protobuf.FileOptions {
export type OptimizeMode =
| "UNSPECIFIED"
Expand Down
1 change: 1 addition & 0 deletions generated/messages/google/protobuf/(FileOptions)/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// @ts-nocheck
export type { Type as OptimizeMode } from "./OptimizeMode.ts";
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
export declare namespace $.google.protobuf.GeneratedCodeInfo.Annotation {
export type Semantic =
| "NONE"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// @ts-nocheck
export type { Type as Semantic } from "./Semantic.ts";
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
Type as Semantic,
name2num,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// @ts-nocheck
export type { Type as Annotation } from "./Annotation.ts";
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
export declare namespace $.google.protobuf.MethodOptions {
export type IdempotencyLevel =
| "IDEMPOTENCY_UNKNOWN"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// @ts-nocheck
export type { Type as IdempotencyLevel } from "./IdempotencyLevel.ts";
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
tsValueToJsonValueFns,
jsonValueToTsValueFns,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// @ts-nocheck
export type { Type as Location } from "./Location.ts";
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
tsValueToJsonValueFns,
jsonValueToTsValueFns,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// @ts-nocheck
export type { Type as NamePart } from "./NamePart.ts";
1 change: 1 addition & 0 deletions generated/messages/google/protobuf/DescriptorProto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
Type as FieldDescriptorProto,
encodeJson as encodeJson_1,
Expand Down
1 change: 1 addition & 0 deletions generated/messages/google/protobuf/EnumDescriptorProto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
Type as EnumValueDescriptorProto,
encodeJson as encodeJson_1,
Expand Down
19 changes: 19 additions & 0 deletions generated/messages/google/protobuf/EnumOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
Type as UninterpretedOption,
encodeJson as encodeJson_1,
Expand Down Expand Up @@ -28,6 +29,8 @@ export declare namespace $.google.protobuf {
export type EnumOptions = {
allowAlias?: boolean;
deprecated?: boolean;
/** @deprecated */
deprecatedLegacyJsonFieldConflicts?: boolean;
uninterpretedOption: UninterpretedOption[];
}
}
Expand All @@ -38,6 +41,7 @@ export function getDefaultValue(): $.google.protobuf.EnumOptions {
return {
allowAlias: undefined,
deprecated: undefined,
deprecatedLegacyJsonFieldConflicts: undefined,
uninterpretedOption: [],
};
}
Expand All @@ -53,6 +57,7 @@ export function encodeJson(value: $.google.protobuf.EnumOptions): unknown {
const result: any = {};
if (value.allowAlias !== undefined) result.allowAlias = tsValueToJsonValueFns.bool(value.allowAlias);
if (value.deprecated !== undefined) result.deprecated = tsValueToJsonValueFns.bool(value.deprecated);
if (value.deprecatedLegacyJsonFieldConflicts !== undefined) result.deprecatedLegacyJsonFieldConflicts = tsValueToJsonValueFns.bool(value.deprecatedLegacyJsonFieldConflicts);
result.uninterpretedOption = value.uninterpretedOption.map(value => encodeJson_1(value));
return result;
}
Expand All @@ -61,6 +66,7 @@ export function decodeJson(value: any): $.google.protobuf.EnumOptions {
const result = getDefaultValue();
if (value.allowAlias !== undefined) result.allowAlias = jsonValueToTsValueFns.bool(value.allowAlias);
if (value.deprecated !== undefined) result.deprecated = jsonValueToTsValueFns.bool(value.deprecated);
if (value.deprecatedLegacyJsonFieldConflicts !== undefined) result.deprecatedLegacyJsonFieldConflicts = jsonValueToTsValueFns.bool(value.deprecatedLegacyJsonFieldConflicts);
result.uninterpretedOption = value.uninterpretedOption?.map((value: any) => decodeJson_1(value)) ?? [];
return result;
}
Expand All @@ -79,6 +85,12 @@ export function encodeBinary(value: $.google.protobuf.EnumOptions): Uint8Array {
[3, tsValueToWireValueFns.bool(tsValue)],
);
}
if (value.deprecatedLegacyJsonFieldConflicts !== undefined) {
const tsValue = value.deprecatedLegacyJsonFieldConflicts;
result.push(
[6, tsValueToWireValueFns.bool(tsValue)],
);
}
for (const tsValue of value.uninterpretedOption) {
result.push(
[999, { type: WireType.LengthDelimited as const, value: encodeBinary_1(tsValue) }],
Expand All @@ -105,6 +117,13 @@ export function decodeBinary(binary: Uint8Array): $.google.protobuf.EnumOptions
if (value === undefined) break field;
result.deprecated = value;
}
field: {
const wireValue = wireFields.get(6);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.bool(wireValue);
if (value === undefined) break field;
result.deprecatedLegacyJsonFieldConflicts = value;
}
collection: {
const wireValues = wireMessage.filter(([fieldNumber]) => fieldNumber === 999).map(([, wireValue]) => wireValue);
const value = wireValues.map((wireValue) => wireValue.type === WireType.LengthDelimited ? decodeBinary_1(wireValue.value) : undefined).filter(x => x !== undefined);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
Type as EnumValueOptions,
encodeJson as encodeJson_1,
Expand Down
1 change: 1 addition & 0 deletions generated/messages/google/protobuf/EnumValueOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
Type as UninterpretedOption,
encodeJson as encodeJson_1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
Type as UninterpretedOption,
encodeJson as encodeJson_1,
Expand Down
1 change: 1 addition & 0 deletions generated/messages/google/protobuf/FieldDescriptorProto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
Type as Label,
name2num,
Expand Down

0 comments on commit f358b46

Please sign in to comment.