Socket
Socket
Sign inDemoInstall

@dxos/codec-protobuf

Package Overview
Dependencies
Maintainers
9
Versions
2980
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dxos/codec-protobuf - npm Package Compare versions

Comparing version 1.1.1 to 2.10.0

dist/src/any.d.ts

10

dist/src/codec.d.ts

@@ -5,3 +5,3 @@ import protobufjs from 'protobufjs';

export declare class Schema<T> {
private readonly _typesRoot;
private _typesRoot;
static fromJson<T extends Record<string, any>>(schema: any, substitutions?: Substitutions): Schema<T>;

@@ -12,2 +12,6 @@ private readonly _mapping;

tryGetCodecForType(typeName: string): Codec;
/**
* Dynamically add new definitions to this schema.
*/
addJson(schema: any): void;
}

@@ -21,3 +25,7 @@ export declare class Codec<T = any> {

decode(data: Uint8Array): T;
/**
* Dynamically add new definitions to this codec. Mutates the underlying schema.
*/
addJson(schema: any): void;
}
//# sourceMappingURL=codec.d.ts.map

@@ -5,2 +5,21 @@ "use strict";

//
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -11,3 +30,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.Codec = exports.Schema = void 0;
const protobufjs_1 = __importDefault(require("protobufjs"));
const lodash_merge_1 = __importDefault(require("lodash.merge"));
const protobufjs_1 = __importStar(require("protobufjs"));
const mapping_1 = require("./mapping");

@@ -24,4 +44,5 @@ class Schema {

getCodecForType(typeName) {
if (typeof typeName !== 'string')
if (typeof typeName !== 'string') {
throw new TypeError('Expected `typeName` argument to be a string');
}
const type = this._typesRoot.lookupType(typeName);

@@ -31,7 +52,17 @@ return new Codec(type, this._mapping, this);

tryGetCodecForType(typeName) {
if (typeof typeName !== 'string')
if (typeof typeName !== 'string') {
throw new TypeError('Expected `typeName` argument to be a string');
}
const type = this._typesRoot.lookupType(typeName);
return new Codec(type, this._mapping, this);
}
/**
* Dynamically add new definitions to this schema.
*/
addJson(schema) {
if (!schema.nested) {
throw new Error('Invalid schema: missing nested object');
}
this._typesRoot = protobufjs_1.Root.fromJSON(lodash_merge_1.default(this._typesRoot.toJSON(), schema));
}
}

@@ -53,4 +84,10 @@ exports.Schema = Schema;

}
/**
* Dynamically add new definitions to this codec. Mutates the underlying schema.
*/
addJson(schema) {
this._schema.addJson(schema);
}
}
exports.Codec = Codec;
//# sourceMappingURL=codec.js.map
export * from './common';
export * from './codec';
export * from './any';
//# sourceMappingURL=index.d.ts.map

@@ -18,2 +18,3 @@ "use strict";

__exportStar(require("./codec"), exports);
__exportStar(require("./any"), exports);
//# sourceMappingURL=index.js.map

3

dist/src/mapping.js

@@ -28,4 +28,5 @@ "use strict";

for (const field of type.fieldsArray) {
if (!(field.name in obj))
if (!(field.name in obj)) {
continue;
}
res[field.name] = mapField(field, substitutions, obj[field.name], extraArgs);

@@ -32,0 +33,0 @@ }

{
"name": "@dxos/codec-protobuf",
"version": "1.1.1",
"version": "2.10.0",
"license": "MIT",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"license": "MIT",
"scripts": {
"build": "tsc",
"test": "echo No tests",
"lint": "eslint 'src/**/*.ts'"
},
"files": [

@@ -16,18 +11,38 @@ "dist",

],
"scripts": {
"build": "tsc && pnpm run lint && pnpm run test 2>&1 && true",
"test": "jest",
"lint": "eslint '{src,test}/**/*.ts'"
},
"eslintConfig": {
"extends": "plugin:@dxos/recomended"
},
"jest": {
"modulePathIgnorePatterns": [
"test/gen",
"dist"
],
"preset": "ts-jest/presets/default",
"testEnvironment": "node"
},
"dependencies": {
"assert": "^2.0.0",
"lodash.merge": "^4.6.2",
"protobufjs": "^6.9.0"
},
"devDependencies": {
"@dxos/eslint-plugin": "^1.0.5",
"eslint": "^7.10.0",
"@dxos/eslint-plugin": "~1.0.10",
"@types/assert": "^1.5.4",
"@types/jest": "^26.0.7",
"@types/lodash.merge": "~4.6.6",
"@types/node": "^14.0.9",
"eslint": "^7.7.0",
"jest": "^26.2.2",
"ts-jest": "^26.1.4",
"ts-node": "^9.0.0",
"typescript": "^4.0.2"
},
"dependencies": {
"protobufjs": "^6.10.1"
},
"eslintConfig": {
"extends": "plugin:@dxos/recomended"
},
"publishConfig": {
"access": "public"
},
"gitHead": "a15d0689f19e11e2ee2837c95b4094283f3d7293"
}
}

@@ -5,3 +5,4 @@ //

import protobufjs from 'protobufjs';
import merge from 'lodash.merge';
import protobufjs, { Root } from 'protobufjs';

@@ -20,3 +21,3 @@ import { Substitutions } from './common';

constructor (
private readonly _typesRoot: protobufjs.Root,
private _typesRoot: protobufjs.Root,
substitutions: Substitutions

@@ -28,3 +29,5 @@ ) {

getCodecForType<K extends keyof T & string> (typeName: K): Codec<T[K]> {
if (typeof typeName !== 'string') throw new TypeError('Expected `typeName` argument to be a string');
if (typeof typeName !== 'string') {
throw new TypeError('Expected `typeName` argument to be a string');
}
const type = this._typesRoot.lookupType(typeName);

@@ -35,6 +38,18 @@ return new Codec(type, this._mapping, this);

tryGetCodecForType (typeName: string): Codec {
if (typeof typeName !== 'string') throw new TypeError('Expected `typeName` argument to be a string');
if (typeof typeName !== 'string') {
throw new TypeError('Expected `typeName` argument to be a string');
}
const type = this._typesRoot.lookupType(typeName);
return new Codec(type, this._mapping, this);
}
/**
* Dynamically add new definitions to this schema.
*/
addJson (schema: any) {
if (!schema.nested) {
throw new Error('Invalid schema: missing nested object');
}
this._typesRoot = Root.fromJSON(merge(this._typesRoot.toJSON(), schema));
}
}

@@ -58,2 +73,9 @@

}
/**
* Dynamically add new definitions to this codec. Mutates the underlying schema.
*/
addJson (schema: any) {
this._schema.addJson(schema);
}
}

@@ -7,1 +7,2 @@ //

export * from './codec';
export * from './any';

@@ -33,3 +33,5 @@ //

for (const field of type.fieldsArray) {
if (!(field.name in obj)) continue;
if (!(field.name in obj)) {
continue;
}
res[field.name] = mapField(field, substitutions, obj[field.name], extraArgs);

@@ -36,0 +38,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc