Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

chore: remove protons, upgrade deps #26

Merged
merged 2 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
language: node_js
cache: npm

branches:
only:
- master
- /^release\/.*$/

stages:
- check
- test
- cov

node_js:
- '10'
- '12'
- 'lts/*'
- 'node'

os:
- linux
Expand Down
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"lint": "aegir lint",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser -t webworker",
"prepare": "aegir build --no-bundle",
"prepare": "npm run build",
"build": "run-s build:*",
"build:types": "aegir build --no-bundle",
"build:proto": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/record/record.js ./src/record/record.proto",
"build:proto-types": "pbts -o src/record/record.d.ts src/record/record.js",
"docs": "aegir docs",
"release": "aegir release",
"release-minor": "aegir release --type minor",
Expand All @@ -24,8 +28,7 @@
"IPFS"
],
"engines": {
"node": ">=6.0.0",
"npm": ">=3.0.0"
"node": ">=14.0.0"
},
"pre-push": [
"lint"
Expand All @@ -45,16 +48,17 @@
},
"types": "dist/src/index.d.ts",
"devDependencies": {
"aegir": "^30.3.0",
"aegir": "^33.0.0",
"libp2p-crypto": "^0.19.0",
"multibase": "^3.0.0",
"multibase": "^4.0.3",
"npm-run-all": "^4.1.5",
"peer-id": "^0.14.0"
},
"dependencies": {
"err-code": "^3.0.0",
"multihashes": "^3.0.1",
"multihashing-async": "^2.1.0",
"protons": "^2.0.0",
"multihashes": "^4.0.2",
"multihashing-async": "^2.1.2",
"protobufjs": "^6.10.2",
"uint8arrays": "^2.0.5"
},
"contributors": [
Expand Down
21 changes: 13 additions & 8 deletions src/record.js → src/record/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

// @ts-ignore
const protons = require('protons')
const pb = protons(require('./record.proto')).Record
const utils = require('./utils')
const {
Record: PBRecord
} = require('./record')
const utils = require('../utils')

/**
* @typedef {{ key: Uint8Array, value: Uint8Array, timeReceived: string }} ProtobufRecord
Expand All @@ -30,7 +30,7 @@ class Record {
}

serialize () {
return pb.encode(this.prepareSerialize())
return PBRecord.encode(this.prepareSerialize()).finish()
}

/**
Expand All @@ -50,14 +50,19 @@ class Record {
* @param {Uint8Array} raw
*/
static deserialize (raw) {
const dec = pb.decode(raw)
return Record.fromDeserialized(dec)
const message = PBRecord.decode(raw)
return Record.fromDeserialized(PBRecord.toObject(message, {
defaults: false,
arrays: true,
longs: Number,
objects: false
}))
}

/**
* Create a record from the raw object returned from the protobuf library.
*
* @param {ProtobufRecord} obj
* @param {{ [k: string]: any }} obj
*/
static fromDeserialized (obj) {
let recvtime
Expand Down
71 changes: 71 additions & 0 deletions src/record/record.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as $protobuf from "protobufjs";
/** Properties of a Record. */
export interface IRecord {

/** Record key */
key?: (Uint8Array|null);

/** Record value */
value?: (Uint8Array|null);

/** Record timeReceived */
timeReceived?: (string|null);
}

/** Represents a Record. */
export class Record implements IRecord {

/**
* Constructs a new Record.
* @param [p] Properties to set
*/
constructor(p?: IRecord);

/** Record key. */
public key: Uint8Array;

/** Record value. */
public value: Uint8Array;

/** Record timeReceived. */
public timeReceived: string;

/**
* Encodes the specified Record message. Does not implicitly {@link Record.verify|verify} messages.
* @param m Record message or plain object to encode
* @param [w] Writer to encode to
* @returns Writer
*/
public static encode(m: IRecord, w?: $protobuf.Writer): $protobuf.Writer;

/**
* Decodes a Record message from the specified reader or buffer.
* @param r Reader or buffer to decode from
* @param [l] Message length if known beforehand
* @returns Record
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Record;

/**
* Creates a Record message from a plain object. Also converts values to their respective internal types.
* @param d Plain object
* @returns Record
*/
public static fromObject(d: { [k: string]: any }): Record;

/**
* Creates a plain object from a Record message. Also converts values to other types if specified.
* @param m Record
* @param [o] Conversion options
* @returns Plain object
*/
public static toObject(m: Record, o?: $protobuf.IConversionOptions): { [k: string]: any };

/**
* Converts this Record to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
204 changes: 204 additions & 0 deletions src/record/record.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/*eslint-disable*/
"use strict";

var $protobuf = require("protobufjs/minimal");

// Common aliases
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;

// Exported root namespace
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});

$root.Record = (function() {

/**
* Properties of a Record.
* @exports IRecord
* @interface IRecord
* @property {Uint8Array|null} [key] Record key
* @property {Uint8Array|null} [value] Record value
* @property {string|null} [timeReceived] Record timeReceived
*/

/**
* Constructs a new Record.
* @exports Record
* @classdesc Represents a Record.
* @implements IRecord
* @constructor
* @param {IRecord=} [p] Properties to set
*/
function Record(p) {
if (p)
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
if (p[ks[i]] != null)
this[ks[i]] = p[ks[i]];
}

/**
* Record key.
* @member {Uint8Array} key
* @memberof Record
* @instance
*/
Record.prototype.key = $util.newBuffer([]);

/**
* Record value.
* @member {Uint8Array} value
* @memberof Record
* @instance
*/
Record.prototype.value = $util.newBuffer([]);

/**
* Record timeReceived.
* @member {string} timeReceived
* @memberof Record
* @instance
*/
Record.prototype.timeReceived = "";

/**
* Encodes the specified Record message. Does not implicitly {@link Record.verify|verify} messages.
* @function encode
* @memberof Record
* @static
* @param {IRecord} m Record message or plain object to encode
* @param {$protobuf.Writer} [w] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Record.encode = function encode(m, w) {
if (!w)
w = $Writer.create();
if (m.key != null && Object.hasOwnProperty.call(m, "key"))
w.uint32(10).bytes(m.key);
if (m.value != null && Object.hasOwnProperty.call(m, "value"))
w.uint32(18).bytes(m.value);
if (m.timeReceived != null && Object.hasOwnProperty.call(m, "timeReceived"))
w.uint32(42).string(m.timeReceived);
return w;
};

/**
* Decodes a Record message from the specified reader or buffer.
* @function decode
* @memberof Record
* @static
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
* @param {number} [l] Message length if known beforehand
* @returns {Record} Record
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Record.decode = function decode(r, l) {
if (!(r instanceof $Reader))
r = $Reader.create(r);
var c = l === undefined ? r.len : r.pos + l, m = new $root.Record();
while (r.pos < c) {
var t = r.uint32();
switch (t >>> 3) {
case 1:
m.key = r.bytes();
break;
case 2:
m.value = r.bytes();
break;
case 5:
m.timeReceived = r.string();
break;
default:
r.skipType(t & 7);
break;
}
}
return m;
};

/**
* Creates a Record message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof Record
* @static
* @param {Object.<string,*>} d Plain object
* @returns {Record} Record
*/
Record.fromObject = function fromObject(d) {
if (d instanceof $root.Record)
return d;
var m = new $root.Record();
if (d.key != null) {
if (typeof d.key === "string")
$util.base64.decode(d.key, m.key = $util.newBuffer($util.base64.length(d.key)), 0);
else if (d.key.length)
m.key = d.key;
}
if (d.value != null) {
if (typeof d.value === "string")
$util.base64.decode(d.value, m.value = $util.newBuffer($util.base64.length(d.value)), 0);
else if (d.value.length)
m.value = d.value;
}
if (d.timeReceived != null) {
m.timeReceived = String(d.timeReceived);
}
return m;
};

/**
* Creates a plain object from a Record message. Also converts values to other types if specified.
* @function toObject
* @memberof Record
* @static
* @param {Record} m Record
* @param {$protobuf.IConversionOptions} [o] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Record.toObject = function toObject(m, o) {
if (!o)
o = {};
var d = {};
if (o.defaults) {
if (o.bytes === String)
d.key = "";
else {
d.key = [];
if (o.bytes !== Array)
d.key = $util.newBuffer(d.key);
}
if (o.bytes === String)
d.value = "";
else {
d.value = [];
if (o.bytes !== Array)
d.value = $util.newBuffer(d.value);
}
d.timeReceived = "";
}
if (m.key != null && m.hasOwnProperty("key")) {
d.key = o.bytes === String ? $util.base64.encode(m.key, 0, m.key.length) : o.bytes === Array ? Array.prototype.slice.call(m.key) : m.key;
}
if (m.value != null && m.hasOwnProperty("value")) {
d.value = o.bytes === String ? $util.base64.encode(m.value, 0, m.value.length) : o.bytes === Array ? Array.prototype.slice.call(m.value) : m.value;
}
if (m.timeReceived != null && m.hasOwnProperty("timeReceived")) {
d.timeReceived = m.timeReceived;
}
return d;
};

/**
* Converts this Record to JSON.
* @function toJSON
* @memberof Record
* @instance
* @returns {Object.<string,*>} JSON object
*/
Record.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};

return Record;
})();

module.exports = $root;
Loading