@dxos/codec-protobuf
Advanced tools
Comparing version 1.1.1 to 2.10.0
@@ -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 |
@@ -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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
166904
0
100
427
1
0
6
3
10
28
+ Addedassert@^2.0.0
+ Addedlodash.merge@^4.6.2
+ Addedassert@2.1.0(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedis-nan@1.3.2(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedobject-is@1.1.6(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedutil@0.12.5(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
Updatedprotobufjs@^6.9.0