Skip to content

Commit 78dc139

Browse files
committed
fix: make types more strict
BREAKING CHANGE: bigint is used for all Int64/UInt64 fields now. Type defs have also changed slightly.
1 parent de51e1d commit 78dc139

File tree

13 files changed

+9457
-35
lines changed

13 files changed

+9457
-35
lines changed

README.md

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,58 @@
1-
# typescript-library-skeleton
1+
# @jcoreio/sparkplug-payload
22

3-
[![CircleCI](https://circleci.com/gh/jedwards1211/typescript-library-skeleton.svg?style=svg)](https://circleci.com/gh/jedwards1211/typescript-library-skeleton)
4-
[![Coverage Status](https://codecov.io/gh/jedwards1211/typescript-library-skeleton/branch/master/graph/badge.svg)](https://codecov.io/gh/jedwards1211/typescript-library-skeleton)
3+
[![CircleCI](https://circleci.com/gh/jcoreio/sparkplug-payload.svg?style=svg)](https://circleci.com/gh/jcoreio/sparkplug-payload)
54
[![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)
65
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
7-
[![npm version](https://badge.fury.io/js/typescript-library-skeleton.svg)](https://badge.fury.io/js/typescript-library-skeleton)
6+
[![npm version](https://badge.fury.io/js/%40jcoreio%2Fsparkplug-payload.svg)](https://badge.fury.io/js/%40jcoreio%2Fsparkplug-payload)
87

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

11-
## Quick start
12+
https://s3.amazonaws.com/cirrus-link-com/Sparkplug+Topic+Namespace+and+State+ManagementV2.1+Apendix++Payload+B+format.pdf
13+
14+
**Not a drop-in replacement for the original `sparkplug-payload` package; require paths have changed.**
15+
16+
## Installation
1217

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

17-
## Tools used
18-
19-
- babel 7
20-
- typescript
21-
- mocha
22-
- chai
23-
- istanbul
24-
- nyc
25-
- eslint
26-
- prettier
27-
- husky
28-
- semantic-release
29-
- renovate
30-
- Circle CI
31-
- Codecov.io
22+
### Encoding a payload
23+
24+
Here is a code example of encoding a payload:
25+
26+
```javascript
27+
var sparkplug = require('sparkplug-payload/spBv1.0'),
28+
payload = {
29+
timestamp: new Date().getTime(),
30+
metrics: [
31+
{
32+
name: 'intMetric',
33+
value: 1,
34+
type: 'Int32',
35+
},
36+
],
37+
},
38+
encoded = sparkplug.encodePayload(payload)
39+
```
40+
41+
### Decoding a payload
42+
43+
Here is a code example of decoding an encoded payload:
44+
45+
```javascript
46+
var decoded = sparkplug.decodePayload(encoded)
47+
```
48+
49+
## License
50+
51+
Copyright (c) 2017 Cirrus Link Solutions
52+
53+
All rights reserved. This program and the accompanying materials
54+
are made available under the terms of the Eclipse Public License v1.0
55+
which accompanies this distribution, and is available at
56+
http://www.eclipse.org/legal/epl-v10.html
57+
58+
Contributors: Cirrus Link Solutions, JCore Systems

flow-typed/npm/long_v4.x.x.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// flow-typed signature: 7d695f62b25d736b51c93b05bb31ffd8
2+
// flow-typed version: cc44a27e8f/long_v4.x.x/flow_>=v0.104.x
3+
4+
declare module 'long' {
5+
declare class Long {
6+
constructor(low: number, high: number, unsigned?: boolean): Long;
7+
8+
// Fields
9+
low: number;
10+
high: number;
11+
unsigned: boolean;
12+
13+
// Methods
14+
toNumber(): number;
15+
add(addend: Long | number | string): Long;
16+
and(other: Long | number | string): Long;
17+
compare(other: Long | number | string): number;
18+
comp(other: Long | number | string): number;
19+
divide(divisor: Long | number | string): Long;
20+
div(divisor: Long | number | string): Long;
21+
equals(other: Long | number | string): boolean;
22+
eq(other: Long | number | string): boolean;
23+
getHighBits(): number;
24+
getHighBitsUnsigned(): number;
25+
getLowBits(): number;
26+
getLowBitsUnsigned(): number;
27+
getNumBitsAbs(): number;
28+
greaterThan(other: Long | number | string): boolean;
29+
gt(other: Long | number | string): boolean;
30+
greaterThanOrEqual(other: Long | number | string): boolean;
31+
gte(other: Long | number | string): boolean;
32+
ge(other: Long | number | string): boolean;
33+
isEven(): boolean;
34+
isNegative(): boolean;
35+
isOdd(): boolean;
36+
isPositive(): boolean;
37+
isZero(): boolean;
38+
eqz(): boolean;
39+
lessThan(other: Long | number | string): boolean;
40+
lt(other: Long | number | string): boolean;
41+
lessThanOrEqual(other: Long | number | string): boolean;
42+
lte(other: Long | number | string): boolean;
43+
le(other: Long | number | string): boolean;
44+
modulo(divisor: Long | number | string): Long;
45+
mod(divisor: Long | number | string): Long;
46+
rem(divisor: Long | number | string): Long;
47+
multiply(multiplier: Long | number | string): Long;
48+
mul(multiplier: Long | number | string): Long;
49+
negate(): Long;
50+
neg(): Long;
51+
not(): Long;
52+
notEquals(other: Long | number | string): boolean;
53+
neq(other: Long | number | string): boolean;
54+
ne(other: Long | number | string): boolean;
55+
or(other: Long | number | string): Long;
56+
shiftLeft(numBits: Long | number | string): Long;
57+
shl(numBits: Long | number | string): Long;
58+
shiftRight(numBits: Long | number | string): Long;
59+
shr(numBits: Long | number | string): Long;
60+
shiftRightUnsigned(numBits: Long | number | string): Long;
61+
shru(numBits: Long | number | string): Long;
62+
shr_u(numBits: Long | number | string): Long;
63+
subtract(subtrahend: Long | number | string): Long;
64+
sub(subtrahend: Long | number | string): Long;
65+
toBytes(le?: boolean): number[];
66+
toBytesLE(): number[];
67+
toBytesBE(): number[];
68+
toInt(): number;
69+
toNumber(): number;
70+
toSigned(): Long;
71+
// TODO: fix this. Uncommenting will break spreading for some reason... (e.g. {...new Long(1)})
72+
// toString(radix?: number): string;
73+
toUnsigned(): Long;
74+
xor(other: Long | number | string): Long;
75+
76+
// Constants
77+
static ZERO: Long;
78+
static ONE: Long;
79+
static NEG_ONE: Long;
80+
static UZERO: Long;
81+
static UONE: Long;
82+
static MAX_VALUE: Long;
83+
static MIN_VALUE: Long;
84+
static MAX_UNSIGNED_VALUE: Long;
85+
86+
// Static methods
87+
static isLong(obj: mixed): boolean;
88+
static fromBits(
89+
lowBits: number,
90+
highBits: number,
91+
unsigned?: boolean
92+
): Long;
93+
static fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long;
94+
static fromBytesLE(bytes: number[], unsigned?: boolean): Long;
95+
static fromBytesBE(bytes: number[], unsigned?: boolean): Long;
96+
static fromInt(value: number, unsigned?: boolean): Long;
97+
static fromNumber(value: number, unsigned?: boolean): Long;
98+
static fromString(str: string, unsigned?: boolean, radix?: number): Long;
99+
static fromString(str: string, radix: number): Long;
100+
static fromValue(val: mixed, unsigned?: boolean): Long;
101+
}
102+
103+
declare module.exports: typeof Long
104+
}

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "typescript-library-skeleton",
2+
"name": "@jcoreio/sparkplug-payload",
33
"version": "0.0.0-development",
44
"description": "my personal ES2015 library project skeleton",
55
"main": "index.js",
@@ -14,7 +14,7 @@
1414
"clean": "rimraf es lib $(cd src; ls) *.js *.d.ts *.js.flow",
1515
"build": "npm run clean && npm run build:types && npm run build:js",
1616
"build:types": "tsc -p tsconfig.build.json && tsc -p tsconfig.build.json --outDir es && copy 'src/**/*.js.flow' . && copy 'src/**/*.js.flow' es",
17-
"build:js": "babel src --out-dir es --extensions \".ts\" --source-maps inline && cross-env BABEL_ENV=es5 babel src --out-dir . --extensions \".ts\"",
17+
"build:js": "cross-env BABEL_ENV=es5 babel src --ignore 'src/**/*.proto.d.ts' --out-dir . --extensions \".ts\" && copy 'src/**/*.proto.js' .",
1818
"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",
1919
"test:watch": "cross-env NODE_ENV=test BABEL_ENV=test mocha $npm_package_config_mocha --watch",
2020
"test:debug": "cross-env NODE_ENV=test BABEL_ENV=test mocha --inspect-brk $npm_package_config_mocha",
@@ -68,17 +68,17 @@
6868
},
6969
"repository": {
7070
"type": "git",
71-
"url": "https://github.com/jedwards1211/typescript-library-skeleton.git"
71+
"url": "https://github.com/jcoreio/sparkplug-payload.git"
7272
},
7373
"keywords": [
7474
"typescript"
7575
],
7676
"author": "Andy Edwards",
7777
"license": "MIT",
7878
"bugs": {
79-
"url": "https://github.com/jedwards1211/typescript-library-skeleton/issues"
79+
"url": "https://github.com/jcoreio/sparkplug-payload/issues"
8080
},
81-
"homepage": "https://github.com/jedwards1211/typescript-library-skeleton#readme",
81+
"homepage": "https://github.com/jcoreio/sparkplug-payload#readme",
8282
"devDependencies": {
8383
"@babel/cli": "^7.12.10",
8484
"@babel/core": "^7.12.10",
@@ -99,6 +99,7 @@
9999
"@jedwards1211/eslint-config": "^2.0.2",
100100
"@jedwards1211/eslint-config-typescript": "^2.0.2",
101101
"@types/chai": "^4.2.14",
102+
"@types/long": "^4.0.1",
102103
"@types/mocha": "^8.2.0",
103104
"@types/node": "^14.14.22",
104105
"@typescript-eslint/eslint-plugin": "^4.14.1",
@@ -124,6 +125,8 @@
124125
"typescript": "^4.1.3"
125126
},
126127
"dependencies": {
127-
"@babel/runtime": "^7.12.5"
128+
"@babel/runtime": "^7.12.5",
129+
"long": "^4.0.0",
130+
"protobufjs": "^6.11.2"
128131
}
129132
}

src/index.js.flow

Whitespace-only changes.

src/index.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)