@mattnucc/gribberish 0.28.2 → 0.28.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +55 -54
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,87 +1,88 @@
1
- # `@napi-rs/package-template`
1
+ # @mattnucc/gribberish
2
2
 
3
- ![https://github.com/napi-rs/package-template/actions](https://github.com/napi-rs/package-template/workflows/CI/badge.svg)
3
+ ![CI](https://github.com/mpiannucci/gribberish/actions/workflows/js.yml/badge.svg)
4
4
 
5
- > Template project for writing node packages with napi-rs.
5
+ Node.js bindings for [gribberish](https://crates.io/crates/gribberish), a Rust GRIB2 reader.
6
6
 
7
- # Usage
7
+ This package is a **reader only**. Loading GRIB2 bytes from local files, object stores, or network sources is intentionally left to your application.
8
8
 
9
- 1. Click **Use this template**.
10
- 2. **Clone** your project.
11
- 3. Run `yarn install` to install dependencies.
12
- 4. Run `yarn napi rename -n [@your-scope/package-name] -b [binary-name]` command under the project folder to rename your package.
13
-
14
- ## Install this test package
9
+ ## Install
15
10
 
16
11
  ```bash
17
- yarn add @napi-rs/package-template
12
+ yarn add @mattnucc/gribberish
18
13
  ```
19
14
 
20
- ## Ability
21
-
22
- ### Build
23
-
24
- After `yarn build/npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
25
-
26
- ### Test
15
+ or
27
16
 
28
- With [ava](https://github.com/avajs/ava), run `yarn test/npm run test` to testing native addon. You can also switch to another testing framework if you want.
17
+ ```bash
18
+ npm install @mattnucc/gribberish
19
+ ```
29
20
 
30
- ### CI
21
+ ## Usage
31
22
 
32
- With GitHub Actions, each commit and pull request will be built and tested automatically in [`node@20`, `@node22`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms.
23
+ Read the first message in a GRIB2 file:
33
24
 
34
- ### Release
25
+ ```ts
26
+ import { readFileSync } from 'node:fs'
27
+ import { GribMessageFactory } from '@mattnucc/gribberish'
35
28
 
36
- Release native package is very difficult in old days. Native packages may ask developers who use it to install `build toolchain` like `gcc/llvm`, `node-gyp` or something more.
29
+ const data = readFileSync('sample.grib2')
30
+ const factory = GribMessageFactory.fromBuffer(data)
31
+ const first = factory.getMessage(factory.availableMessages[0])
37
32
 
38
- With `GitHub actions`, we can easily prebuild a `binary` for major platforms. And with `N-API`, we should never be afraid of **ABI Compatible**.
33
+ console.log(first.varName, first.gridShape.rows, first.gridShape.cols)
34
+ ```
39
35
 
40
- The other problem is how to deliver prebuild `binary` to users. Downloading it in `postinstall` script is a common way that most packages do it right now. The problem with this solution is it introduced many other packages to download binary that has not been used by `runtime codes`. The other problem is some users may not easily download the binary from `GitHub/CDN` if they are behind a private network (But in most cases, they have a private NPM mirror).
36
+ Common entry points:
41
37
 
42
- In this package, we choose a better way to solve this problem. We release different `npm packages` for different platforms. And add it to `optionalDependencies` before releasing the `Major` package to npm.
38
+ - `parseMessagesFromBuffer(buffer)` to parse all messages.
39
+ - `GribMessage.parseFromBuffer(buffer, offset)` to parse one message at a known offset.
40
+ - `GribMessageFactory.fromBuffer` to scan and fetch messages by key.
41
+ - `GribMessageMetadataFactory.fromBuffer` for metadata-first access.
43
42
 
44
- `NPM` will choose which native package should download from `registry` automatically. You can see [npm](./npm) dir for details. And you can also run `yarn add @napi-rs/package-template` to see how it works.
43
+ ## WebAssembly targets
45
44
 
46
- ## Develop requirements
45
+ WebAssembly packages are optional, so install with a wasm target selector instead of adding the package explicitly.
47
46
 
48
- - Install the latest `Rust`
49
- - Install `Node.js@10+` which fully supported `Node-API`
50
- - Install `yarn@1.x`
47
+ - npm (v10.2+):
51
48
 
52
- ## Test in local
49
+ ```bash
50
+ npm install --cpu=wasm32 @mattnucc/gribberish
51
+ ```
53
52
 
54
- - yarn
55
- - yarn build
56
- - yarn test
53
+ - yarn v4:
57
54
 
58
- And you will see:
55
+ ```yaml
56
+ # .yarnrc.yml
57
+ supportedArchitectures:
58
+ cpu:
59
+ - current
60
+ - wasm32
61
+ ```
59
62
 
60
- ```bash
61
- $ ava --verbose
63
+ Then run `yarn install`.
62
64
 
63
- sync function from native code
64
- ✔ sleep function from native code (201ms)
65
-
65
+ In Node, set `NAPI_RS_FORCE_WASI=1` (or `NAPI_RS_FORCE_WASI=error`) if you want to force the WASM runtime path.
66
66
 
67
- 2 tests passed
68
- ✨ Done in 1.12s.
69
- ```
67
+ ## Build and test
70
68
 
71
- ## Release package
69
+ - `yarn install`
70
+ - `yarn build`
71
+ - `yarn test`
72
72
 
73
- Ensure you have set your **NPM_TOKEN** in the `GitHub` project setting.
73
+ ## Requirements
74
74
 
75
- In `Settings -> Secrets`, add **NPM_TOKEN** into it.
75
+ - Rust toolchain
76
+ - Node.js (CI validates on 20/22; release jobs run on 24)
77
+ - Yarn 4.x (`packageManager: yarn@4.12.0`)
76
78
 
77
- When you want to release the package:
79
+ ## Release workflow
78
80
 
79
- ```bash
80
- npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
81
+ The `js` workflow publishes artifacts from GitHub Actions when you push a version tag.
81
82
 
82
- git push
83
- ```
83
+ 1. `npm version [major | minor | patch | ...]`
84
+ 2. `git push --follow-tags`
84
85
 
85
- GitHub actions will do the rest job for you.
86
+ Make sure `NPM_TOKEN` is set in repository secrets.
86
87
 
87
- > WARN: Don't run `npm publish` manually.
88
+ > Do not run `npm publish` manually.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mattnucc/gribberish",
3
- "version": "0.28.2",
3
+ "version": "0.28.4",
4
4
  "description": "JavaScript bindings for gribberish, a GRIB2 parsing library",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -106,10 +106,10 @@
106
106
  },
107
107
  "packageManager": "yarn@4.12.0",
108
108
  "optionalDependencies": {
109
- "@mattnucc/gribberish-win32-x64-msvc": "0.28.2",
110
- "@mattnucc/gribberish-darwin-x64": "0.28.2",
111
- "@mattnucc/gribberish-linux-x64-gnu": "0.28.2",
112
- "@mattnucc/gribberish-darwin-arm64": "0.28.2",
113
- "@mattnucc/gribberish-wasm32-wasi": "0.28.2"
109
+ "@mattnucc/gribberish-win32-x64-msvc": "0.28.4",
110
+ "@mattnucc/gribberish-darwin-x64": "0.28.4",
111
+ "@mattnucc/gribberish-linux-x64-gnu": "0.28.4",
112
+ "@mattnucc/gribberish-darwin-arm64": "0.28.4",
113
+ "@mattnucc/gribberish-wasm32-wasi": "0.28.4"
114
114
  }
115
115
  }