@protobuf-ts/runtime
Advanced tools
Comparing version 2.0.0-alpha.22 to 2.0.0-alpha.23
@@ -31,2 +31,3 @@ "use strict"; | ||
* Skip one element on the wire and return the skipped data. | ||
* Supports WireType.StartGroup since v2.0.0-alpha.23. | ||
*/ | ||
@@ -37,2 +38,7 @@ skip(wireType) { | ||
switch (wireType) { | ||
case binary_format_contract_1.WireType.Varint: | ||
while (this.buf[this.pos++] & 0x80) { | ||
// ignore | ||
} | ||
break; | ||
case binary_format_contract_1.WireType.Bit64: | ||
@@ -47,7 +53,12 @@ this.pos += 4; | ||
break; | ||
case binary_format_contract_1.WireType.Varint: | ||
while (this.buf[this.pos++] & 0x80) { | ||
// ignore | ||
case binary_format_contract_1.WireType.StartGroup: | ||
// From descriptor.proto: Group type is deprecated, not supported in proto3. | ||
// But we must still be able to parse and treat as unknown. | ||
let t; | ||
while ((t = this.tag()[1]) !== binary_format_contract_1.WireType.EndGroup) { | ||
this.skip(t); | ||
} | ||
break; | ||
default: | ||
throw new Error("cant skip wire type " + wireType); | ||
} | ||
@@ -54,0 +65,0 @@ this.assertBounds(); |
@@ -21,6 +21,7 @@ "use strict"; | ||
class MessageType { | ||
constructor(name, fields) { | ||
constructor(name, fields, options) { | ||
this.defaultCheckDepth = 16; | ||
this.typeName = name; | ||
this.fields = fields.map(reflection_info_1.normalizeFieldInfo); | ||
this.options = options !== null && options !== void 0 ? options : {}; | ||
this.refTypeCheck = new reflection_type_check_1.ReflectionTypeCheck(this); | ||
@@ -27,0 +28,0 @@ this.refJsonReader = new reflection_json_reader_1.ReflectionJsonReader(this); |
@@ -18,4 +18,6 @@ "use strict"; | ||
prepare() { | ||
var _a; | ||
if (!this.fieldNoToField) { | ||
this.fieldNoToField = new Map(this.info.fields.map(field => [field.no, field])); | ||
const fieldsInput = (_a = this.info.fields) !== null && _a !== void 0 ? _a : []; | ||
this.fieldNoToField = new Map(fieldsInput.map(field => [field.no, field])); | ||
} | ||
@@ -22,0 +24,0 @@ } |
@@ -19,3 +19,4 @@ "use strict"; | ||
if (!this.fields) { | ||
this.fields = this.info.fields.concat().sort((a, b) => a.no - b.no); | ||
const fieldsInput = this.info.fields ? this.info.fields.concat() : []; | ||
this.fields = fieldsInput.sort((a, b) => a.no - b.no); | ||
} | ||
@@ -22,0 +23,0 @@ } |
@@ -20,5 +20,7 @@ "use strict"; | ||
prepare() { | ||
var _a; | ||
if (this.fMap === undefined) { | ||
this.fMap = {}; | ||
for (const field of this.info.fields) { | ||
const fieldsInput = (_a = this.info.fields) !== null && _a !== void 0 ? _a : []; | ||
for (const field of fieldsInput) { | ||
this.fMap[field.name] = field; | ||
@@ -25,0 +27,0 @@ this.fMap[field.jsonName] = field; |
@@ -16,3 +16,4 @@ "use strict"; | ||
constructor(info) { | ||
this.info = info; | ||
var _a; | ||
this.fields = (_a = info.fields) !== null && _a !== void 0 ? _a : []; | ||
} | ||
@@ -24,3 +25,3 @@ /** | ||
const json = {}, source = message; | ||
for (const field of this.info.fields.filter(f => !f.oneof)) { | ||
for (const field of this.fields.filter(f => !f.oneof)) { | ||
let jsonValue = this.field(field, source[field.localName], options); | ||
@@ -31,3 +32,3 @@ if (jsonValue !== undefined) | ||
// flatten all oneof`s | ||
for (const field of this.info.fields) { | ||
for (const field of this.fields) { | ||
if (!field.oneof) | ||
@@ -34,0 +35,0 @@ continue; |
@@ -9,3 +9,4 @@ "use strict"; | ||
constructor(info) { | ||
this.info = info; | ||
var _a; | ||
this.fields = (_a = info.fields) !== null && _a !== void 0 ? _a : []; | ||
} | ||
@@ -16,3 +17,3 @@ prepare() { | ||
const req = [], known = [], oneofs = []; | ||
for (let field of this.info.fields) { | ||
for (let field of this.fields) { | ||
if (field.oneof) { | ||
@@ -92,3 +93,3 @@ if (!oneofs.includes(field.oneof)) { | ||
continue; | ||
const field = this.info.fields.find(f => f.localName === group.oneofKind); | ||
const field = this.fields.find(f => f.localName === group.oneofKind); | ||
if (!field) | ||
@@ -100,3 +101,3 @@ return false; // we found no field, but have a kind, something is wrong | ||
// check types | ||
for (const field of this.info.fields) { | ||
for (const field of this.fields) { | ||
if (field.oneof !== undefined) | ||
@@ -103,0 +104,0 @@ continue; |
@@ -28,2 +28,3 @@ import { WireType } from "./binary-format-contract"; | ||
* Skip one element on the wire and return the skipped data. | ||
* Supports WireType.StartGroup since v2.0.0-alpha.23. | ||
*/ | ||
@@ -34,2 +35,7 @@ skip(wireType) { | ||
switch (wireType) { | ||
case WireType.Varint: | ||
while (this.buf[this.pos++] & 0x80) { | ||
// ignore | ||
} | ||
break; | ||
case WireType.Bit64: | ||
@@ -44,7 +50,12 @@ this.pos += 4; | ||
break; | ||
case WireType.Varint: | ||
while (this.buf[this.pos++] & 0x80) { | ||
// ignore | ||
case WireType.StartGroup: | ||
// From descriptor.proto: Group type is deprecated, not supported in proto3. | ||
// But we must still be able to parse and treat as unknown. | ||
let t; | ||
while ((t = this.tag()[1]) !== WireType.EndGroup) { | ||
this.skip(t); | ||
} | ||
break; | ||
default: | ||
throw new Error("cant skip wire type " + wireType); | ||
} | ||
@@ -51,0 +62,0 @@ this.assertBounds(); |
@@ -18,6 +18,7 @@ import { normalizeFieldInfo } from "./reflection-info"; | ||
export class MessageType { | ||
constructor(name, fields) { | ||
constructor(name, fields, options) { | ||
this.defaultCheckDepth = 16; | ||
this.typeName = name; | ||
this.fields = fields.map(normalizeFieldInfo); | ||
this.options = options !== null && options !== void 0 ? options : {}; | ||
this.refTypeCheck = new ReflectionTypeCheck(this); | ||
@@ -24,0 +25,0 @@ this.refJsonReader = new ReflectionJsonReader(this); |
@@ -15,4 +15,6 @@ import { UnknownFieldHandler, WireType } from "./binary-format-contract"; | ||
prepare() { | ||
var _a; | ||
if (!this.fieldNoToField) { | ||
this.fieldNoToField = new Map(this.info.fields.map(field => [field.no, field])); | ||
const fieldsInput = (_a = this.info.fields) !== null && _a !== void 0 ? _a : []; | ||
this.fieldNoToField = new Map(fieldsInput.map(field => [field.no, field])); | ||
} | ||
@@ -19,0 +21,0 @@ } |
@@ -16,3 +16,4 @@ import { UnknownFieldHandler, WireType } from "./binary-format-contract"; | ||
if (!this.fields) { | ||
this.fields = this.info.fields.concat().sort((a, b) => a.no - b.no); | ||
const fieldsInput = this.info.fields ? this.info.fields.concat() : []; | ||
this.fields = fieldsInput.sort((a, b) => a.no - b.no); | ||
} | ||
@@ -19,0 +20,0 @@ } |
@@ -17,5 +17,7 @@ import { isJsonObject, typeofJsonValue } from "./json-typings"; | ||
prepare() { | ||
var _a; | ||
if (this.fMap === undefined) { | ||
this.fMap = {}; | ||
for (const field of this.info.fields) { | ||
const fieldsInput = (_a = this.info.fields) !== null && _a !== void 0 ? _a : []; | ||
for (const field of fieldsInput) { | ||
this.fMap[field.name] = field; | ||
@@ -22,0 +24,0 @@ this.fMap[field.jsonName] = field; |
@@ -13,3 +13,4 @@ import { base64encode } from "./base64"; | ||
constructor(info) { | ||
this.info = info; | ||
var _a; | ||
this.fields = (_a = info.fields) !== null && _a !== void 0 ? _a : []; | ||
} | ||
@@ -21,3 +22,3 @@ /** | ||
const json = {}, source = message; | ||
for (const field of this.info.fields.filter(f => !f.oneof)) { | ||
for (const field of this.fields.filter(f => !f.oneof)) { | ||
let jsonValue = this.field(field, source[field.localName], options); | ||
@@ -28,3 +29,3 @@ if (jsonValue !== undefined) | ||
// flatten all oneof`s | ||
for (const field of this.info.fields) { | ||
for (const field of this.fields) { | ||
if (!field.oneof) | ||
@@ -31,0 +32,0 @@ continue; |
@@ -6,3 +6,4 @@ import { LongType, ScalarType } from "./reflection-info"; | ||
constructor(info) { | ||
this.info = info; | ||
var _a; | ||
this.fields = (_a = info.fields) !== null && _a !== void 0 ? _a : []; | ||
} | ||
@@ -13,3 +14,3 @@ prepare() { | ||
const req = [], known = [], oneofs = []; | ||
for (let field of this.info.fields) { | ||
for (let field of this.fields) { | ||
if (field.oneof) { | ||
@@ -89,3 +90,3 @@ if (!oneofs.includes(field.oneof)) { | ||
continue; | ||
const field = this.info.fields.find(f => f.localName === group.oneofKind); | ||
const field = this.fields.find(f => f.localName === group.oneofKind); | ||
if (!field) | ||
@@ -97,3 +98,3 @@ return false; // we found no field, but have a kind, something is wrong | ||
// check types | ||
for (const field of this.info.fields) { | ||
for (const field of this.fields) { | ||
if (field.oneof !== undefined) | ||
@@ -100,0 +101,0 @@ continue; |
@@ -22,2 +22,3 @@ import type { IBinaryReader } from "./binary-format-contract"; | ||
* Skip one element on the wire and return the skipped data. | ||
* Supports WireType.StartGroup since v2.0.0-alpha.23. | ||
*/ | ||
@@ -24,0 +25,0 @@ skip(wireType: WireType): Uint8Array; |
@@ -1,2 +0,2 @@ | ||
import type { FieldInfo } from "./reflection-info"; | ||
import type { FieldInfo, MessageInfo } from "./reflection-info"; | ||
import type { BinaryReadOptions, BinaryWriteOptions, IBinaryReader, IBinaryWriter } from "./binary-format-contract"; | ||
@@ -22,3 +22,3 @@ import type { JsonValue } from "./json-typings"; | ||
*/ | ||
export interface IMessageType<T extends object> { | ||
export interface IMessageType<T extends object> extends MessageInfo { | ||
/** | ||
@@ -40,2 +40,8 @@ * The protobuf type name of the message, including package and | ||
/** | ||
* Contains custom message options from the .proto source in JSON format. | ||
*/ | ||
readonly options: { | ||
[extensionName: string]: JsonValue; | ||
}; | ||
/** | ||
* Create a new message with default values. | ||
@@ -42,0 +48,0 @@ * |
@@ -34,2 +34,6 @@ import type { IMessageType, PartialMessage } from "./message-type-contract"; | ||
readonly fields: readonly FieldInfo[]; | ||
/** | ||
* Contains custom service options from the .proto source in JSON format. | ||
*/ | ||
readonly options: JsonOptionsMap; | ||
protected readonly defaultCheckDepth = 16; | ||
@@ -41,3 +45,3 @@ protected readonly refTypeCheck: ReflectionTypeCheck; | ||
protected readonly refBinWriter: ReflectionBinaryWriter; | ||
constructor(name: string, fields: readonly PartialFieldInfo[]); | ||
constructor(name: string, fields: readonly PartialFieldInfo[], options?: JsonOptionsMap); | ||
/** | ||
@@ -149,1 +153,5 @@ * Create a new message with default values. | ||
} | ||
declare type JsonOptionsMap = { | ||
[extensionName: string]: JsonValue; | ||
}; | ||
export {}; |
import type { BinaryReadOptions, IBinaryReader } from "./binary-format-contract"; | ||
import type { FieldInfo, MessageInfo } from "./reflection-info"; | ||
import type { FieldInfo, PartialMessageInfo } from "./reflection-info"; | ||
import { LongType, ScalarType } from "./reflection-info"; | ||
@@ -11,5 +11,5 @@ import type { UnknownMap, UnknownScalar } from "./unknown-types"; | ||
export declare class ReflectionBinaryReader { | ||
protected readonly info: MessageInfo; | ||
private readonly info; | ||
protected fieldNoToField?: ReadonlyMap<number, FieldInfo>; | ||
constructor(info: MessageInfo); | ||
constructor(info: PartialMessageInfo); | ||
protected prepare(): void; | ||
@@ -16,0 +16,0 @@ /** |
import type { BinaryWriteOptions, IBinaryWriter } from "./binary-format-contract"; | ||
import { WireType } from "./binary-format-contract"; | ||
import type { FieldInfo, MessageInfo } from "./reflection-info"; | ||
import { ScalarType } from "./reflection-info"; | ||
import type { FieldInfo } from "./reflection-info"; | ||
import { PartialMessageInfo, ScalarType } from "./reflection-info"; | ||
import type { IMessageType } from "./message-type-contract"; | ||
@@ -12,5 +12,5 @@ /** | ||
export declare class ReflectionBinaryWriter { | ||
protected readonly info: MessageInfo; | ||
private readonly info; | ||
protected fields?: readonly FieldInfo[]; | ||
constructor(info: MessageInfo); | ||
constructor(info: PartialMessageInfo); | ||
protected prepare(): void; | ||
@@ -17,0 +17,0 @@ /** |
@@ -77,4 +77,18 @@ import type { IMessageType } from "./message-type-contract"; | ||
readonly fields: readonly FieldInfo[]; | ||
/** | ||
* Contains custom message options from the .proto source in JSON format. | ||
*/ | ||
readonly options: { | ||
[extensionName: string]: JsonValue; | ||
}; | ||
} | ||
/** | ||
* Version of `MessageInfo` that allows the following properties | ||
* to be omitted: | ||
* - "fields": omitting means the message has no fields | ||
* - "options": omitting means the message has no options | ||
*/ | ||
export declare type PartialMessageInfo = PartialPartial<MessageInfo, "fields" | "options">; | ||
declare type PartialPartial<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>; | ||
/** | ||
* Describes a field of a protobuf message for runtime | ||
@@ -81,0 +95,0 @@ * reflection. We distinguish between the following |
import type { JsonObject, JsonValue } from "./json-typings"; | ||
import type { JsonReadOptions } from "./json-format-contract"; | ||
import type { EnumInfo, MessageInfo } from "./reflection-info"; | ||
import { LongType, ScalarType } from "./reflection-info"; | ||
import type { EnumInfo } from "./reflection-info"; | ||
import { LongType, PartialMessageInfo, ScalarType } from "./reflection-info"; | ||
import type { UnknownEnum, UnknownScalar } from "./unknown-types"; | ||
@@ -12,3 +12,3 @@ /** | ||
export declare class ReflectionJsonReader { | ||
protected readonly info: MessageInfo; | ||
private readonly info; | ||
/** | ||
@@ -20,3 +20,3 @@ * JSON key to field. | ||
private fMap?; | ||
constructor(info: MessageInfo); | ||
constructor(info: PartialMessageInfo); | ||
protected prepare(): void; | ||
@@ -23,0 +23,0 @@ assert(condition: any, fieldName: string, jsonValue: JsonValue): asserts condition; |
import type { JsonValue } from "./json-typings"; | ||
import type { JsonWriteOptions } from "./json-format-contract"; | ||
import type { EnumInfo, FieldInfo, MessageInfo } from "./reflection-info"; | ||
import type { EnumInfo, FieldInfo, PartialMessageInfo } from "./reflection-info"; | ||
import { ScalarType } from "./reflection-info"; | ||
@@ -13,4 +13,4 @@ import type { IMessageType } from "./message-type-contract"; | ||
export declare class ReflectionJsonWriter { | ||
protected readonly info: MessageInfo; | ||
constructor(info: MessageInfo); | ||
private readonly fields; | ||
constructor(info: PartialMessageInfo); | ||
/** | ||
@@ -17,0 +17,0 @@ * Converts the message to a JSON object, based on the field descriptors. |
@@ -1,6 +0,6 @@ | ||
import type { MessageInfo } from "./reflection-info"; | ||
import type { PartialMessageInfo } from "./reflection-info"; | ||
export declare class ReflectionTypeCheck { | ||
private readonly info; | ||
private readonly fields; | ||
private data; | ||
constructor(info: MessageInfo); | ||
constructor(info: PartialMessageInfo); | ||
private prepare; | ||
@@ -7,0 +7,0 @@ /** |
{ | ||
"name": "@protobuf-ts/runtime", | ||
"version": "2.0.0-alpha.22", | ||
"version": "2.0.0-alpha.23", | ||
"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": "3745b1961d71d7619aebd2711521aafcc0e38988" | ||
"gitHead": "1a7a6300765d240eaf3c52b71e00bb3bc9578c6c" | ||
} |
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
326747
8298