Skip to content

Commit

Permalink
Node 14+ 💥💚; pbf -> protobufjs 💥; 4.0.0
Browse files Browse the repository at this point in the history
closes #2
closes #6
  • Loading branch information
derhuerst committed Jun 29, 2021
1 parent cf1b793 commit 71ac301
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ npm-debug.log
package-lock.json
shrinkwrap.yaml

gtfs-realtime.proto
index.js
schema.json
/gtfs-realtime.proto
/gtfs-realtime.schema.json
/gtfs-realtime.pbf.js
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: node_js
node_js:
- 'stable'
- 'lts/*'
- '8'
- '14'
script:
- npm run build
- npm test
5 changes: 3 additions & 2 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const data = {
}]
}

const buf = FeedMessage.encode(data)
FeedMessage.verify(data)
const buf = FeedMessage.encode(data).finish()
console.log(buf)

const parsedData = FeedMessage.decode(buf)
const parsedData = FeedMessage.fromObject(FeedMessage.decode(buf))
console.log(parsedData)
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

const {transit_realtime} = require('./gtfs-realtime.pbf.js')

module.exports = transit_realtime
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "gtfs-rt-bindings",
"description": "Parse and serialize GTFS Realtime.",
"version": "3.2.0",
"version": "4.0.0",
"main": "index.js",
"files": [
"index.js",
"schema.json",
"gtfs-realtime.proto",
"gtfs-realtime.schema.json",
"gtfs-realtime.pbf.js",
"example.js"
],
"keywords": [
Expand All @@ -24,21 +25,19 @@
"bugs": "https://github.com/derhuerst/gtfs-rt-bindings/issues",
"license": "ISC",
"engines": {
"node": ">=8"
"node": ">=14"
},
"dependencies": {
"protocol-buffers-encodings": "^1.1.0"
"protobufjs": "^6.11.2"
},
"devDependencies": {
"protobufjs": "^6.8.9",
"protocol-buffers": "^4.1.0",
"tap-min": "^2.0.0",
"tape": "^5.0.0"
},
"scripts": {
"download": "curl -L -s 'https://github.com/google/transit/raw/master/gtfs-realtime/proto/gtfs-realtime.proto' >gtfs-realtime.proto",
"compile": "protocol-buffers gtfs-realtime.proto -o index.js",
"schema": "pbjs gtfs-realtime.proto -t json >schema.json",
"compile": "pbjs gtfs-realtime.proto -t static-module -w commonjs --keep-case --force-number -o gtfs-realtime.pbf.js",
"schema": "pbjs gtfs-realtime.proto -t json -o gtfs-realtime.schema.json",
"build": "npm run download && npm run compile && npm run schema",
"test": "node test.js | tap-min",
"prepublishOnly": "npm run build && npm test"
Expand Down
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ const data = {
}


const buf = TripUpdate.encode(data)
TripUpdate.verify(data)
const buf = TripUpdate.encode(data).finish()
console.log(buf)
// <Buffer 0a 11 0a 06 74 72 69 70 2d 31 2a 07 72 6f 75 74 65 2d 31 12 06 08 03 12 02 08 1e>

const parsedData = TripUpdate.decode(buf)
const parsedData = TripUpdate.fromObject(TripUpdate.decode(buf))
console.log(parsedData)
```

Expand Down
7 changes: 4 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const test = require('tape')

const {FeedMessage} = require('.')
const schema = require('./schema.json')
const schema = require('./gtfs-realtime.schema.json')

const data = {
header: {
Expand All @@ -27,8 +27,9 @@ const data = {
}

test('round trip', (t) => {
const buf = FeedMessage.encode(data)
const parsed = FeedMessage.decode(buf)
FeedMessage.verify(data)
const buf = FeedMessage.encode(data).finish()
const parsed = FeedMessage.fromObject(FeedMessage.decode(buf))

// todo: find a tool for this
t.ok(parsed)
Expand Down

0 comments on commit 71ac301

Please sign in to comment.