@bufbuild/protobuf
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -28,2 +28,4 @@ "use strict"; | ||
scalarDefaultValue: scalars_js_1.scalarDefaultValue, | ||
safeIdentifier: names_js_1.safeIdentifier, | ||
safeObjectProperty: names_js_1.safeObjectProperty, | ||
// prettier-ignore | ||
@@ -30,0 +32,0 @@ symbols: { |
@@ -17,3 +17,3 @@ "use strict"; | ||
exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0; | ||
// @generated by protoc-gen-es v1.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated by protoc-gen-es v1.2.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3) | ||
@@ -20,0 +20,0 @@ /* eslint-disable */ |
@@ -17,3 +17,3 @@ "use strict"; | ||
exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0; | ||
// @generated by protoc-gen-es v1.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated by protoc-gen-es v1.2.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3) | ||
@@ -20,0 +20,0 @@ /* eslint-disable */ |
@@ -16,3 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findEnumSharedPrefix = exports.fieldJsonName = exports.localOneofName = exports.localFieldName = exports.localName = void 0; | ||
exports.safeIdentifier = exports.safeObjectProperty = exports.findEnumSharedPrefix = exports.fieldJsonName = exports.localOneofName = exports.localFieldName = exports.localName = void 0; | ||
/** | ||
@@ -38,6 +38,8 @@ * Returns the name of a protobuf element in generated code. | ||
const name = desc.typeName.substring(offset).replace(/\./g, "_"); | ||
if (reservedIdent[name]) { | ||
return name + "$"; | ||
} | ||
return name; | ||
// For services, we only care about safe identifiers, not safe object properties, | ||
// but we have shipped v1 with a bug that respected object properties, and we | ||
// do not want to introduce a breaking change, so we continue to escape for | ||
// safe object properties. | ||
// See https://github.com/bufbuild/protobuf-es/pull/391 | ||
return (0, exports.safeObjectProperty)((0, exports.safeIdentifier)(name)); | ||
} | ||
@@ -50,6 +52,3 @@ case "enum_value": { | ||
const name = desc.name.substring(sharedPrefix.length); | ||
if (reservedObjectProperties[name]) { | ||
return name + "$"; | ||
} | ||
return name; | ||
return (0, exports.safeObjectProperty)(name); | ||
} | ||
@@ -62,6 +61,3 @@ case "rpc": { | ||
name = name[0].toLowerCase() + name.substring(1); | ||
if (reservedObjectProperties[name]) { | ||
return name + "$"; | ||
} | ||
return name; | ||
return (0, exports.safeObjectProperty)(name); | ||
} | ||
@@ -75,3 +71,3 @@ } | ||
function localFieldName(protoName, inOneof) { | ||
let name = protoCamelCase(protoName); | ||
const name = protoCamelCase(protoName); | ||
if (inOneof) { | ||
@@ -81,6 +77,3 @@ // oneof member names are not properties, but values of the `case` property. | ||
} | ||
if (reservedObjectProperties[name] || reservedMessageProperties[name]) { | ||
name = name + "$"; | ||
} | ||
return name; | ||
return (0, exports.safeObjectProperty)(safeMessageProperty(name)); | ||
} | ||
@@ -165,89 +158,127 @@ exports.localFieldName = localFieldName; | ||
} | ||
// Names that cannot be used for identifiers, such as class names, | ||
// but _can_ be used for object properties. | ||
const reservedIdent = { | ||
/** | ||
* Names that cannot be used for identifiers, such as class names, | ||
* but _can_ be used for object properties. | ||
*/ | ||
const reservedIdentifiers = new Set([ | ||
// ECMAScript 2015 keywords | ||
break: true, | ||
case: true, | ||
catch: true, | ||
class: true, | ||
const: true, | ||
continue: true, | ||
debugger: true, | ||
default: true, | ||
delete: true, | ||
do: true, | ||
else: true, | ||
export: true, | ||
extends: true, | ||
false: true, | ||
finally: true, | ||
for: true, | ||
function: true, | ||
if: true, | ||
import: true, | ||
in: true, | ||
instanceof: true, | ||
new: true, | ||
null: true, | ||
return: true, | ||
super: true, | ||
switch: true, | ||
this: true, | ||
throw: true, | ||
true: true, | ||
try: true, | ||
typeof: true, | ||
var: true, | ||
void: true, | ||
while: true, | ||
with: true, | ||
yield: true, | ||
"break", | ||
"case", | ||
"catch", | ||
"class", | ||
"const", | ||
"continue", | ||
"debugger", | ||
"default", | ||
"delete", | ||
"do", | ||
"else", | ||
"export", | ||
"extends", | ||
"false", | ||
"finally", | ||
"for", | ||
"function", | ||
"if", | ||
"import", | ||
"in", | ||
"instanceof", | ||
"new", | ||
"null", | ||
"return", | ||
"super", | ||
"switch", | ||
"this", | ||
"throw", | ||
"true", | ||
"try", | ||
"typeof", | ||
"var", | ||
"void", | ||
"while", | ||
"with", | ||
"yield", | ||
// ECMAScript 2015 future reserved keywords | ||
enum: true, | ||
implements: true, | ||
interface: true, | ||
let: true, | ||
package: true, | ||
private: true, | ||
protected: true, | ||
public: true, | ||
static: true, | ||
"enum", | ||
"implements", | ||
"interface", | ||
"let", | ||
"package", | ||
"private", | ||
"protected", | ||
"public", | ||
"static", | ||
// Class name cannot be 'Object' when targeting ES5 with module CommonJS | ||
Object: true, | ||
"Object", | ||
// TypeScript keywords that cannot be used for types (as opposed to variables) | ||
bigint: true, | ||
number: true, | ||
boolean: true, | ||
string: true, | ||
object: true, | ||
"bigint", | ||
"number", | ||
"boolean", | ||
"string", | ||
"object", | ||
// Identifiers reserved for the runtime, so we can generate legible code | ||
globalThis: true, | ||
Uint8Array: true, | ||
Partial: true, | ||
}; | ||
// Names that cannot be used for object properties because they are reserved | ||
// by built-in JavaScript properties. | ||
const reservedObjectProperties = { | ||
"globalThis", | ||
"Uint8Array", | ||
"Partial", | ||
]); | ||
/** | ||
* Names that cannot be used for object properties because they are reserved | ||
* by built-in JavaScript properties. | ||
*/ | ||
const reservedObjectProperties = new Set([ | ||
// names reserved by JavaScript | ||
constructor: true, | ||
toString: true, | ||
toJSON: true, | ||
valueOf: true, | ||
}; | ||
// Names that cannot be used for object properties because they are reserved | ||
// by the runtime. | ||
const reservedMessageProperties = { | ||
"constructor", | ||
"toString", | ||
"toJSON", | ||
"valueOf", | ||
]); | ||
/** | ||
* Names that cannot be used for object properties because they are reserved | ||
* by the runtime. | ||
*/ | ||
const reservedMessageProperties = new Set([ | ||
// names reserved by the runtime | ||
getType: true, | ||
clone: true, | ||
equals: true, | ||
fromBinary: true, | ||
fromJson: true, | ||
fromJsonString: true, | ||
toBinary: true, | ||
toJson: true, | ||
toJsonString: true, | ||
"getType", | ||
"clone", | ||
"equals", | ||
"fromBinary", | ||
"fromJson", | ||
"fromJsonString", | ||
"toBinary", | ||
"toJson", | ||
"toJsonString", | ||
// names reserved by the runtime for the future | ||
toObject: true, | ||
"toObject", | ||
]); | ||
const fallback = (name) => `${name}$`; | ||
/** | ||
* Will wrap names that are Object prototype properties or names reserved | ||
* for `Message`s. | ||
*/ | ||
const safeMessageProperty = (name) => { | ||
if (reservedMessageProperties.has(name)) { | ||
return fallback(name); | ||
} | ||
return name; | ||
}; | ||
/** | ||
* Names that cannot be used for object properties because they are reserved | ||
* by built-in JavaScript properties. | ||
*/ | ||
const safeObjectProperty = (name) => { | ||
if (reservedObjectProperties.has(name)) { | ||
return fallback(name); | ||
} | ||
return name; | ||
}; | ||
exports.safeObjectProperty = safeObjectProperty; | ||
/** | ||
* Names that can be used for identifiers or class properties | ||
*/ | ||
const safeIdentifier = (name) => { | ||
if (reservedIdentifiers.has(name)) { | ||
return fallback(name); | ||
} | ||
return name; | ||
}; | ||
exports.safeIdentifier = safeIdentifier; |
@@ -14,3 +14,3 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
// limitations under the License. | ||
import { localName } from "./private/names.js"; | ||
import { localName, safeIdentifier, safeObjectProperty, } from "./private/names.js"; | ||
import { getUnwrappedFieldType } from "./private/field-wrapper.js"; | ||
@@ -26,2 +26,4 @@ import { scalarDefaultValue } from "./private/scalars.js"; | ||
scalarDefaultValue, | ||
safeIdentifier, | ||
safeObjectProperty, | ||
// prettier-ignore | ||
@@ -28,0 +30,0 @@ symbols: { |
@@ -14,3 +14,3 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
// limitations under the License. | ||
// @generated by protoc-gen-es v1.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated by protoc-gen-es v1.2.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3) | ||
@@ -17,0 +17,0 @@ /* eslint-disable */ |
@@ -14,3 +14,3 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
// limitations under the License. | ||
// @generated by protoc-gen-es v1.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated by protoc-gen-es v1.2.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3) | ||
@@ -17,0 +17,0 @@ /* eslint-disable */ |
@@ -34,6 +34,8 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
const name = desc.typeName.substring(offset).replace(/\./g, "_"); | ||
if (reservedIdent[name]) { | ||
return name + "$"; | ||
} | ||
return name; | ||
// For services, we only care about safe identifiers, not safe object properties, | ||
// but we have shipped v1 with a bug that respected object properties, and we | ||
// do not want to introduce a breaking change, so we continue to escape for | ||
// safe object properties. | ||
// See https://github.com/bufbuild/protobuf-es/pull/391 | ||
return safeObjectProperty(safeIdentifier(name)); | ||
} | ||
@@ -46,6 +48,3 @@ case "enum_value": { | ||
const name = desc.name.substring(sharedPrefix.length); | ||
if (reservedObjectProperties[name]) { | ||
return name + "$"; | ||
} | ||
return name; | ||
return safeObjectProperty(name); | ||
} | ||
@@ -58,6 +57,3 @@ case "rpc": { | ||
name = name[0].toLowerCase() + name.substring(1); | ||
if (reservedObjectProperties[name]) { | ||
return name + "$"; | ||
} | ||
return name; | ||
return safeObjectProperty(name); | ||
} | ||
@@ -70,3 +66,3 @@ } | ||
export function localFieldName(protoName, inOneof) { | ||
let name = protoCamelCase(protoName); | ||
const name = protoCamelCase(protoName); | ||
if (inOneof) { | ||
@@ -76,6 +72,3 @@ // oneof member names are not properties, but values of the `case` property. | ||
} | ||
if (reservedObjectProperties[name] || reservedMessageProperties[name]) { | ||
name = name + "$"; | ||
} | ||
return name; | ||
return safeObjectProperty(safeMessageProperty(name)); | ||
} | ||
@@ -157,89 +150,125 @@ /** | ||
} | ||
// Names that cannot be used for identifiers, such as class names, | ||
// but _can_ be used for object properties. | ||
const reservedIdent = { | ||
/** | ||
* Names that cannot be used for identifiers, such as class names, | ||
* but _can_ be used for object properties. | ||
*/ | ||
const reservedIdentifiers = new Set([ | ||
// ECMAScript 2015 keywords | ||
break: true, | ||
case: true, | ||
catch: true, | ||
class: true, | ||
const: true, | ||
continue: true, | ||
debugger: true, | ||
default: true, | ||
delete: true, | ||
do: true, | ||
else: true, | ||
export: true, | ||
extends: true, | ||
false: true, | ||
finally: true, | ||
for: true, | ||
function: true, | ||
if: true, | ||
import: true, | ||
in: true, | ||
instanceof: true, | ||
new: true, | ||
null: true, | ||
return: true, | ||
super: true, | ||
switch: true, | ||
this: true, | ||
throw: true, | ||
true: true, | ||
try: true, | ||
typeof: true, | ||
var: true, | ||
void: true, | ||
while: true, | ||
with: true, | ||
yield: true, | ||
"break", | ||
"case", | ||
"catch", | ||
"class", | ||
"const", | ||
"continue", | ||
"debugger", | ||
"default", | ||
"delete", | ||
"do", | ||
"else", | ||
"export", | ||
"extends", | ||
"false", | ||
"finally", | ||
"for", | ||
"function", | ||
"if", | ||
"import", | ||
"in", | ||
"instanceof", | ||
"new", | ||
"null", | ||
"return", | ||
"super", | ||
"switch", | ||
"this", | ||
"throw", | ||
"true", | ||
"try", | ||
"typeof", | ||
"var", | ||
"void", | ||
"while", | ||
"with", | ||
"yield", | ||
// ECMAScript 2015 future reserved keywords | ||
enum: true, | ||
implements: true, | ||
interface: true, | ||
let: true, | ||
package: true, | ||
private: true, | ||
protected: true, | ||
public: true, | ||
static: true, | ||
"enum", | ||
"implements", | ||
"interface", | ||
"let", | ||
"package", | ||
"private", | ||
"protected", | ||
"public", | ||
"static", | ||
// Class name cannot be 'Object' when targeting ES5 with module CommonJS | ||
Object: true, | ||
"Object", | ||
// TypeScript keywords that cannot be used for types (as opposed to variables) | ||
bigint: true, | ||
number: true, | ||
boolean: true, | ||
string: true, | ||
object: true, | ||
"bigint", | ||
"number", | ||
"boolean", | ||
"string", | ||
"object", | ||
// Identifiers reserved for the runtime, so we can generate legible code | ||
globalThis: true, | ||
Uint8Array: true, | ||
Partial: true, | ||
}; | ||
// Names that cannot be used for object properties because they are reserved | ||
// by built-in JavaScript properties. | ||
const reservedObjectProperties = { | ||
"globalThis", | ||
"Uint8Array", | ||
"Partial", | ||
]); | ||
/** | ||
* Names that cannot be used for object properties because they are reserved | ||
* by built-in JavaScript properties. | ||
*/ | ||
const reservedObjectProperties = new Set([ | ||
// names reserved by JavaScript | ||
constructor: true, | ||
toString: true, | ||
toJSON: true, | ||
valueOf: true, | ||
}; | ||
// Names that cannot be used for object properties because they are reserved | ||
// by the runtime. | ||
const reservedMessageProperties = { | ||
"constructor", | ||
"toString", | ||
"toJSON", | ||
"valueOf", | ||
]); | ||
/** | ||
* Names that cannot be used for object properties because they are reserved | ||
* by the runtime. | ||
*/ | ||
const reservedMessageProperties = new Set([ | ||
// names reserved by the runtime | ||
getType: true, | ||
clone: true, | ||
equals: true, | ||
fromBinary: true, | ||
fromJson: true, | ||
fromJsonString: true, | ||
toBinary: true, | ||
toJson: true, | ||
toJsonString: true, | ||
"getType", | ||
"clone", | ||
"equals", | ||
"fromBinary", | ||
"fromJson", | ||
"fromJsonString", | ||
"toBinary", | ||
"toJson", | ||
"toJsonString", | ||
// names reserved by the runtime for the future | ||
toObject: true, | ||
"toObject", | ||
]); | ||
const fallback = (name) => `${name}$`; | ||
/** | ||
* Will wrap names that are Object prototype properties or names reserved | ||
* for `Message`s. | ||
*/ | ||
const safeMessageProperty = (name) => { | ||
if (reservedMessageProperties.has(name)) { | ||
return fallback(name); | ||
} | ||
return name; | ||
}; | ||
/** | ||
* Names that cannot be used for object properties because they are reserved | ||
* by built-in JavaScript properties. | ||
*/ | ||
export const safeObjectProperty = (name) => { | ||
if (reservedObjectProperties.has(name)) { | ||
return fallback(name); | ||
} | ||
return name; | ||
}; | ||
/** | ||
* Names that can be used for identifiers or class properties | ||
*/ | ||
export const safeIdentifier = (name) => { | ||
if (reservedIdentifiers.has(name)) { | ||
return fallback(name); | ||
} | ||
return name; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { localName } from "./private/names.js"; | ||
import { localName, safeIdentifier, safeObjectProperty } from "./private/names.js"; | ||
import { getUnwrappedFieldType } from "./private/field-wrapper.js"; | ||
@@ -13,2 +13,4 @@ import { scalarDefaultValue } from "./private/scalars.js"; | ||
readonly reifyWkt: typeof reifyWkt; | ||
readonly safeIdentifier: typeof safeIdentifier; | ||
readonly safeObjectProperty: typeof safeObjectProperty; | ||
} | ||
@@ -15,0 +17,0 @@ type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoInt64" | "ScalarType" | "MethodKind" | "MethodIdempotency" | "IMessageTypeRegistry"; |
@@ -34,2 +34,11 @@ import type { DescEnum, DescEnumValue, DescField, DescMessage, DescService } from "../descriptor-set.js"; | ||
declare function protoCamelCase(snakeCase: string): string; | ||
/** | ||
* Names that cannot be used for object properties because they are reserved | ||
* by built-in JavaScript properties. | ||
*/ | ||
export declare const safeObjectProperty: (name: string) => string; | ||
/** | ||
* Names that can be used for identifiers or class properties | ||
*/ | ||
export declare const safeIdentifier: (name: string) => string; | ||
export {}; |
{ | ||
"name": "@bufbuild/protobuf", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"license": "(Apache-2.0 AND BSD-3-Clause)", | ||
@@ -5,0 +5,0 @@ "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1026173
26043