Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsinai committed Feb 16, 2023
2 parents e713cfa + c2d882a commit 690bb64
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 28 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Publish node-rdkafka

on:
release:
types: [created]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- name: Install node-gyp deps
run: sudo apt-get install -y autoconf make libtool automake
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
cache: "npm"
- run: npm ci
- run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Node.js CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
strategy:
matrix:
node: [16]
os: [ubuntu-22.04]
include:
- node: 16
os: macos-12
runs-on: ${{ matrix.os }}
steps:
- name: Install node-gyp deps
run: |
if [ "${{ matrix.os }}" == "ubuntu-22.04" ]; then
sudo apt-get install -y autoconf make libtool automake
else
brew install autoconf automake libtool
fi
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023-present, Port IO, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# jq-node-bindings

This is a library for Node.js that provides C bindings to the [jq](https://stedolan.github.io/jq/) library. It allows you to use jq to extract and manipulate data from JSON objects in Node.js.

## Installation

```
npm install @port-labs/jq-node-bindings
```

## Requirements

To use this library, you must have `node-gyp` installed on your system. and the following libraries

1. `node-gyp`
```
npm install -g node-gyp
```
2. XCode on Mac, gcc on unix
Mac
```
xcode-select --install
```
Yum
```
sudo yum install gcc g++
```
apt-get
```
sudo apt-get gcc g++
```
3. The following C\C++ toolchains autoconf make libtool automake
Homebrew
```
brew install autoconf make automake libtool
```
Yum
```
sudo apt-get install -y autoconf make libtool automake
```
apt-get
```
sudo apt-get install -y autoconf make libtool automake
```
## Usage
Here's an example of how to use the library:
```typescript
import { exec } from 'jq-node-bindings';
const json = { foo: 'bar' };
const input = '.foo';
const result = exec(json, input);
console.log(result); // outputs "bar"
```

The exec function takes two arguments: a JSON object and a jq input string. It returns the result of running the jq program on the JSON object. The result can be of any type supported by jq: object, array, string, number, boolean, or null.

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License
[MIT](https://choosealicense.com/licenses/mit/)
4 changes: 2 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"include_dirs": [
"<!(node -e \"require('nan')\")",
"<(module_root_dir)/",
"deps/jq/src"
"deps/jq"
],
'conditions': [
[
Expand All @@ -19,7 +19,7 @@
"-Wl,-rpath='$$ORIGIN/../deps'",
],
'cflags_cc': [
'-std=c++17 -fno-exceptions'
'-std=c++17'
],
'cflags_cc!': [
'-fno-rtti -fno-exceptions'
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# aclocal, autoconf, make, libtool, automake
# autoconf, make, libtool, automake
scriptdir=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)

pushd ./deps/jq &> /dev/null
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "jq-node-bindings",
"version": "v0.0.1",
"name": "@port-labs/jq-node-bindings",
"version": "v0.0.2",
"description": "Node.js bindings for JQ",
"jq-node-bindings": "0.0.1",
"jq-node-bindings": "0.0.2",
"main": "lib/index.js",
"scripts": {
"configure": "node-gyp configure",
"build": "node-gyp build",
"install": "node-gyp rebuild",
"prepack": "npm run test",
"test": "jest"
},
"keywords": [
Expand Down Expand Up @@ -44,4 +45,4 @@
"engines": {
"node": ">=6.0.0"
}
}
}
26 changes: 13 additions & 13 deletions reports/jest-port-api.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="jest tests" tests="15" failures="0" errors="0" time="0.453">
<testsuite name="jq" errors="0" failures="0" skipped="0" timestamp="2023-02-15T17:15:25" time="0.412" tests="15">
<testcase classname="jq should break" name="jq should break" time="0.004">
<testsuites name="jest tests" tests="15" failures="0" errors="0" time="0.234">
<testsuite name="jq" errors="0" failures="0" skipped="0" timestamp="2023-02-15T19:54:29" time="0.208" tests="15">
<testcase classname="jq should break" name="jq should break" time="0.002">
</testcase>
<testcase classname="jq should break for invalid input" name="jq should break for invalid input" time="0.002">
<testcase classname="jq should break for invalid input" name="jq should break for invalid input" time="0.001">
</testcase>
<testcase classname="jq should break for invalid input" name="jq should break for invalid input" time="0.002">
<testcase classname="jq should break for invalid input" name="jq should break for invalid input" time="0.001">
</testcase>
<testcase classname="jq should break for invalid input" name="jq should break for invalid input" time="0.002">
<testcase classname="jq should break for invalid input" name="jq should break for invalid input" time="0.001">
</testcase>
<testcase classname="jq string should work" name="jq string should work" time="0.001">
<testcase classname="jq string should work" name="jq string should work" time="0">
</testcase>
<testcase classname="jq number should work" name="jq number should work" time="0.001">
<testcase classname="jq number should work" name="jq number should work" time="0">
</testcase>
<testcase classname="jq should return null" name="jq should return null" time="0.001">
</testcase>
<testcase classname="jq should return array with object" name="jq should return array with object" time="0.001">
<testcase classname="jq should return array with object" name="jq should return array with object" time="0">
</testcase>
<testcase classname="jq should return an item of an array" name="jq should return an item of an array" time="0.003">
<testcase classname="jq should return an item of an array" name="jq should return an item of an array" time="0.001">
</testcase>
<testcase classname="jq should return array with objects" name="jq should return array with objects" time="0.001">
<testcase classname="jq should return array with objects" name="jq should return array with objects" time="0">
</testcase>
<testcase classname="jq should return boolean" name="jq should return boolean" time="0.001">
</testcase>
<testcase classname="jq should return object" name="jq should return object" time="0.001">
<testcase classname="jq should return object" name="jq should return object" time="0">
</testcase>
<testcase classname="jq should return recursed obj" name="jq should return recursed obj" time="0">
</testcase>
<testcase classname="jq should return recursed obj" name="jq should return recursed obj" time="0.001">
<testcase classname="jq should return recursed obj" name="jq should return recursed obj" time="0">
</testcase>
<testcase classname="jq should return null on invalid json" name="jq should return null on invalid json" time="0">
</testcase>
Expand Down
6 changes: 0 additions & 6 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ std::string FromV8String(v8::Local<v8::String> val) {
}

void Exec(const Nan::FunctionCallbackInfo<v8::Value>& info) {
try {
v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();

if (info.Length() < 2) {
Expand All @@ -164,11 +163,6 @@ void Exec(const Nan::FunctionCallbackInfo<v8::Value>& info) {
std::string filter = FromV8String(Nan::To<v8::String>(info[1]).ToLocalChecked());

jq_exec(json, filter, info);
} catch (const std::exception& ex) {
Nan::ThrowError(ex.what());
} catch (...) {
Nan::ThrowError("Unknown error occurred");
}
}

void Init(v8::Local<v8::Object> exports) {
Expand Down

0 comments on commit 690bb64

Please sign in to comment.