Skip to content

Commit

Permalink
fix: make types more strict
Browse files Browse the repository at this point in the history
BREAKING CHANGE: bigint is used for all Int64/UInt64 fields now.  Type defs have also changed slightly.
  • Loading branch information
jedwards1211 committed Aug 17, 2021
1 parent de51e1d commit 78dc139
Show file tree
Hide file tree
Showing 13 changed files with 9,457 additions and 35 deletions.
71 changes: 49 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
# typescript-library-skeleton
# @jcoreio/sparkplug-payload

[![CircleCI](https://circleci.com/gh/jedwards1211/typescript-library-skeleton.svg?style=svg)](https://circleci.com/gh/jedwards1211/typescript-library-skeleton)
[![Coverage Status](https://codecov.io/gh/jedwards1211/typescript-library-skeleton/branch/master/graph/badge.svg)](https://codecov.io/gh/jedwards1211/typescript-library-skeleton)
[![CircleCI](https://circleci.com/gh/jcoreio/sparkplug-payload.svg?style=svg)](https://circleci.com/gh/jcoreio/sparkplug-payload)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![npm version](https://badge.fury.io/js/typescript-library-skeleton.svg)](https://badge.fury.io/js/typescript-library-skeleton)
[![npm version](https://badge.fury.io/js/%40jcoreio%2Fsparkplug-payload.svg)](https://badge.fury.io/js/%40jcoreio%2Fsparkplug-payload)

This is my personal skeleton for creating an typescript library npm package. You are welcome to use it.
A library that provides tools for encoding and decoding payload objects using
the Sparkplug Google Protocol Buffer Schema described in the Sparkplug
Specification from Cirrus Link Solutions.

## Quick start
https://s3.amazonaws.com/cirrus-link-com/Sparkplug+Topic+Namespace+and+State+ManagementV2.1+Apendix++Payload+B+format.pdf

**Not a drop-in replacement for the original `sparkplug-payload` package; require paths have changed.**

## Installation

```sh
npx 0-60 clone https://github.com/jedwards1211/typescript-library-skeleton.git
npm install --save @jcoreio/sparkplug-payload
```

## Tools used

- babel 7
- typescript
- mocha
- chai
- istanbul
- nyc
- eslint
- prettier
- husky
- semantic-release
- renovate
- Circle CI
- Codecov.io
### Encoding a payload

Here is a code example of encoding a payload:

```javascript
var sparkplug = require('sparkplug-payload/spBv1.0'),
payload = {
timestamp: new Date().getTime(),
metrics: [
{
name: 'intMetric',
value: 1,
type: 'Int32',
},
],
},
encoded = sparkplug.encodePayload(payload)
```

### Decoding a payload

Here is a code example of decoding an encoded payload:

```javascript
var decoded = sparkplug.decodePayload(encoded)
```

## License

Copyright (c) 2017 Cirrus Link Solutions

All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

Contributors: Cirrus Link Solutions, JCore Systems
104 changes: 104 additions & 0 deletions flow-typed/npm/long_v4.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// flow-typed signature: 7d695f62b25d736b51c93b05bb31ffd8
// flow-typed version: cc44a27e8f/long_v4.x.x/flow_>=v0.104.x

declare module 'long' {
declare class Long {
constructor(low: number, high: number, unsigned?: boolean): Long;

// Fields
low: number;
high: number;
unsigned: boolean;

// Methods
toNumber(): number;
add(addend: Long | number | string): Long;
and(other: Long | number | string): Long;
compare(other: Long | number | string): number;
comp(other: Long | number | string): number;
divide(divisor: Long | number | string): Long;
div(divisor: Long | number | string): Long;
equals(other: Long | number | string): boolean;
eq(other: Long | number | string): boolean;
getHighBits(): number;
getHighBitsUnsigned(): number;
getLowBits(): number;
getLowBitsUnsigned(): number;
getNumBitsAbs(): number;
greaterThan(other: Long | number | string): boolean;
gt(other: Long | number | string): boolean;
greaterThanOrEqual(other: Long | number | string): boolean;
gte(other: Long | number | string): boolean;
ge(other: Long | number | string): boolean;
isEven(): boolean;
isNegative(): boolean;
isOdd(): boolean;
isPositive(): boolean;
isZero(): boolean;
eqz(): boolean;
lessThan(other: Long | number | string): boolean;
lt(other: Long | number | string): boolean;
lessThanOrEqual(other: Long | number | string): boolean;
lte(other: Long | number | string): boolean;
le(other: Long | number | string): boolean;
modulo(divisor: Long | number | string): Long;
mod(divisor: Long | number | string): Long;
rem(divisor: Long | number | string): Long;
multiply(multiplier: Long | number | string): Long;
mul(multiplier: Long | number | string): Long;
negate(): Long;
neg(): Long;
not(): Long;
notEquals(other: Long | number | string): boolean;
neq(other: Long | number | string): boolean;
ne(other: Long | number | string): boolean;
or(other: Long | number | string): Long;
shiftLeft(numBits: Long | number | string): Long;
shl(numBits: Long | number | string): Long;
shiftRight(numBits: Long | number | string): Long;
shr(numBits: Long | number | string): Long;
shiftRightUnsigned(numBits: Long | number | string): Long;
shru(numBits: Long | number | string): Long;
shr_u(numBits: Long | number | string): Long;
subtract(subtrahend: Long | number | string): Long;
sub(subtrahend: Long | number | string): Long;
toBytes(le?: boolean): number[];
toBytesLE(): number[];
toBytesBE(): number[];
toInt(): number;
toNumber(): number;
toSigned(): Long;
// TODO: fix this. Uncommenting will break spreading for some reason... (e.g. {...new Long(1)})
// toString(radix?: number): string;
toUnsigned(): Long;
xor(other: Long | number | string): Long;

// Constants
static ZERO: Long;
static ONE: Long;
static NEG_ONE: Long;
static UZERO: Long;
static UONE: Long;
static MAX_VALUE: Long;
static MIN_VALUE: Long;
static MAX_UNSIGNED_VALUE: Long;

// Static methods
static isLong(obj: mixed): boolean;
static fromBits(
lowBits: number,
highBits: number,
unsigned?: boolean
): Long;
static fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long;
static fromBytesLE(bytes: number[], unsigned?: boolean): Long;
static fromBytesBE(bytes: number[], unsigned?: boolean): Long;
static fromInt(value: number, unsigned?: boolean): Long;
static fromNumber(value: number, unsigned?: boolean): Long;
static fromString(str: string, unsigned?: boolean, radix?: number): Long;
static fromString(str: string, radix: number): Long;
static fromValue(val: mixed, unsigned?: boolean): Long;
}

declare module.exports: typeof Long
}
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "typescript-library-skeleton",
"name": "@jcoreio/sparkplug-payload",
"version": "0.0.0-development",
"description": "my personal ES2015 library project skeleton",
"main": "index.js",
Expand All @@ -14,7 +14,7 @@
"clean": "rimraf es lib $(cd src; ls) *.js *.d.ts *.js.flow",
"build": "npm run clean && npm run build:types && npm run build:js",
"build:types": "tsc -p tsconfig.build.json && tsc -p tsconfig.build.json --outDir es && copy 'src/**/*.js.flow' . && copy 'src/**/*.js.flow' es",
"build:js": "babel src --out-dir es --extensions \".ts\" --source-maps inline && cross-env BABEL_ENV=es5 babel src --out-dir . --extensions \".ts\"",
"build:js": "cross-env BABEL_ENV=es5 babel src --ignore 'src/**/*.proto.d.ts' --out-dir . --extensions \".ts\" && copy 'src/**/*.proto.js' .",
"test": "cross-env NODE_ENV=test BABEL_ENV=es5 mocha $npm_package_config_mocha && cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=lcov --reporter=text mocha $npm_package_config_mocha",
"test:watch": "cross-env NODE_ENV=test BABEL_ENV=test mocha $npm_package_config_mocha --watch",
"test:debug": "cross-env NODE_ENV=test BABEL_ENV=test mocha --inspect-brk $npm_package_config_mocha",
Expand Down Expand Up @@ -68,17 +68,17 @@
},
"repository": {
"type": "git",
"url": "https://github.com/jedwards1211/typescript-library-skeleton.git"
"url": "https://github.com/jcoreio/sparkplug-payload.git"
},
"keywords": [
"typescript"
],
"author": "Andy Edwards",
"license": "MIT",
"bugs": {
"url": "https://github.com/jedwards1211/typescript-library-skeleton/issues"
"url": "https://github.com/jcoreio/sparkplug-payload/issues"
},
"homepage": "https://github.com/jedwards1211/typescript-library-skeleton#readme",
"homepage": "https://github.com/jcoreio/sparkplug-payload#readme",
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
Expand All @@ -99,6 +99,7 @@
"@jedwards1211/eslint-config": "^2.0.2",
"@jedwards1211/eslint-config-typescript": "^2.0.2",
"@types/chai": "^4.2.14",
"@types/long": "^4.0.1",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.22",
"@typescript-eslint/eslint-plugin": "^4.14.1",
Expand All @@ -124,6 +125,8 @@
"typescript": "^4.1.3"
},
"dependencies": {
"@babel/runtime": "^7.12.5"
"@babel/runtime": "^7.12.5",
"long": "^4.0.0",
"protobufjs": "^6.11.2"
}
}
Empty file removed src/index.js.flow
Empty file.
Empty file removed src/index.ts
Empty file.
Loading

0 comments on commit 78dc139

Please sign in to comment.