@protobuf-ts/runtime
Advanced tools
Comparing version 2.9.1 to 2.9.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MessageType = void 0; | ||
const message_type_contract_1 = require("./message-type-contract"); | ||
const reflection_info_1 = require("./reflection-info"); | ||
@@ -27,2 +28,3 @@ const reflection_type_check_1 = require("./reflection-type-check"); | ||
this.options = options !== null && options !== void 0 ? options : {}; | ||
this.messagePrototype = Object.defineProperty({}, message_type_contract_1.MESSAGE_TYPE, { value: this }); | ||
this.refTypeCheck = new reflection_type_check_1.ReflectionTypeCheck(this); | ||
@@ -29,0 +31,0 @@ this.refJsonReader = new reflection_json_reader_1.ReflectionJsonReader(this); |
@@ -11,4 +11,15 @@ "use strict"; | ||
function reflectionCreate(type) { | ||
const msg = {}; | ||
Object.defineProperty(msg, message_type_contract_1.MESSAGE_TYPE, { enumerable: false, value: type }); | ||
/** | ||
* This ternary can be removed in the next major version. | ||
* The `Object.create()` code path utilizes a new `messagePrototype` | ||
* property on the `IMessageType` which has this same `MESSAGE_TYPE` | ||
* non-enumerable property on it. Doing it this way means that we only | ||
* pay the cost of `Object.defineProperty()` once per `IMessageType` | ||
* class of once per "instance". The falsy code path is only provided | ||
* for backwards compatibility in cases where the runtime library is | ||
* updated without also updating the generated code. | ||
*/ | ||
const msg = type.messagePrototype | ||
? Object.create(type.messagePrototype) | ||
: Object.defineProperty({}, message_type_contract_1.MESSAGE_TYPE, { value: type }); | ||
for (let field of type.fields) { | ||
@@ -15,0 +26,0 @@ let name = field.localName; |
@@ -0,1 +1,2 @@ | ||
import { MESSAGE_TYPE } from "./message-type-contract"; | ||
import { normalizeFieldInfo } from "./reflection-info"; | ||
@@ -24,2 +25,3 @@ import { ReflectionTypeCheck } from "./reflection-type-check"; | ||
this.options = options !== null && options !== void 0 ? options : {}; | ||
this.messagePrototype = Object.defineProperty({}, MESSAGE_TYPE, { value: this }); | ||
this.refTypeCheck = new ReflectionTypeCheck(this); | ||
@@ -26,0 +28,0 @@ this.refJsonReader = new ReflectionJsonReader(this); |
@@ -8,4 +8,15 @@ import { reflectionScalarDefault } from "./reflection-scalar-default"; | ||
export function reflectionCreate(type) { | ||
const msg = {}; | ||
Object.defineProperty(msg, MESSAGE_TYPE, { enumerable: false, value: type }); | ||
/** | ||
* This ternary can be removed in the next major version. | ||
* The `Object.create()` code path utilizes a new `messagePrototype` | ||
* property on the `IMessageType` which has this same `MESSAGE_TYPE` | ||
* non-enumerable property on it. Doing it this way means that we only | ||
* pay the cost of `Object.defineProperty()` once per `IMessageType` | ||
* class of once per "instance". The falsy code path is only provided | ||
* for backwards compatibility in cases where the runtime library is | ||
* updated without also updating the generated code. | ||
*/ | ||
const msg = type.messagePrototype | ||
? Object.create(type.messagePrototype) | ||
: Object.defineProperty({}, MESSAGE_TYPE, { value: type }); | ||
for (let field of type.fields) { | ||
@@ -12,0 +23,0 @@ let name = field.localName; |
@@ -52,2 +52,7 @@ import type { FieldInfo, MessageInfo } from "./reflection-info"; | ||
/** | ||
* Contains the prototype for messages returned by create() which | ||
* includes the `MESSAGE_TYPE` symbol pointing back to `this`. | ||
*/ | ||
readonly messagePrototype?: Readonly<{}>; | ||
/** | ||
* Create a new message with default values. | ||
@@ -54,0 +59,0 @@ * |
@@ -38,2 +38,7 @@ import type { IMessageType, PartialMessage } from "./message-type-contract"; | ||
readonly options: JsonOptionsMap; | ||
/** | ||
* Contains the prototype for messages returned by create() which | ||
* includes the `MESSAGE_TYPE` symbol pointing back to `this`. | ||
*/ | ||
readonly messagePrototype: Readonly<{}> | undefined; | ||
protected readonly defaultCheckDepth = 16; | ||
@@ -40,0 +45,0 @@ protected readonly refTypeCheck: ReflectionTypeCheck; |
{ | ||
"name": "@protobuf-ts/runtime", | ||
"version": "2.9.1", | ||
"version": "2.9.2", | ||
"description": "Runtime library for code generated by the protoc plugin \"protobuf-ts\"", | ||
@@ -40,3 +40,3 @@ "license": "(Apache-2.0 AND BSD-3-Clause)", | ||
}, | ||
"gitHead": "15e71e2133631e00e13e570c191186b711377c9b" | ||
"gitHead": "96b4656be1904ff85f285dfe99455ab7bd5e8bc8" | ||
} |
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
348018
8799