Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions cda-client/.github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build, Test, and Publish

on:
workflow_dispatch:

permissions:
pages: write
id-token: write

jobs:
build-test-publish:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Generate and build API
run: npm run buildApi

- name: Install dependencies in tests directory
working-directory: tests
run: npm ci

- name: Link cwmjs dependency from src to tests
run: npm run link

- name: Run tests
working-directory: tests
run: npm run test --ci

- name: Publish to npm
if: success()
working-directory: cwmsjs
run: npm publish --provenance --access public

- name: Build docs
if: success()
run: npm run buildDocs

- name: Upload docs artifact
if: success()
uses: actions/upload-pages-artifact@v3
with:
path: ./cwmsjs/docs

deploy-docs:
needs: build-test-publish
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
5 changes: 5 additions & 0 deletions cda-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
wwwroot/*.js
node_modules
typings
cwmsjs/
cwms-swagger*.json
1 change: 1 addition & 0 deletions cda-client/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
70 changes: 70 additions & 0 deletions cda-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# CWMSjs

_CWMS Data API (CDA) client library created with OpenAPI generator in TypeScript for use with web browsers._

## Getting Started

- Install CWMSjs to your react project with:
`npm install cwmsjs`
(This will grab the latest)

- Import the API endpoint you wish to use:
- Avaiable endpoints are here (Classes ending in API): [Endpoints](https://hydrologicengineeringcenter.github.io/cwms-data-api-client-javascript/modules.html)
- At the top of your js/jsx/file type:
```javascript
import { TimeSeriesAPI } from "cwmsjs";
```
- Then initialize the TimeSeriesAPI with:
```javascript
const ts_api = new TimeSeriesAPI();
```
- Fetch time series data with:
```javascript
await ts_api
.getTimeSeries({
office: "SWT",
name: "KEYS.Elev.Inst.1Hour.0.Ccp-Rev",
})
.then((data) => {
console.log(data);
})
.catch((e) => {
console.log("My Error", e);
});
```

Documentation is available for both developers and new users:

- New Users : [Examples](https://hydrologicengineeringcenter.github.io/cwms-data-api-client-javascript/examples/)
- Advanced users : [Type Documentation / Developer Docs](https://hydrologicengineeringcenter.github.io/cwms-data-api-client-javascript/)

## API Adjustments
Some tweaks are made to the base cwms-data-api syntax during the build process to improve quality of life while working in JavaScript. Users should be aware of the following:

### camelCase
Most response object keys in CDA are written in snake-case. All response object keys have been converted to camelCase in order to play more nicely with javascript's object dot notation (`object.key`).

### "TimeSeries" standardization
Throughout CDA, "time series" is arbitrarily referred to in both a one-word ("timeseries") and two-word ("time series") format. During the cwmsjs build, all instances of "time series" for method names, types, etc. are standardized to the two-word form.

## Developers
### Versioning
In order to accommodate changes both to the generator and to CDA itself, cwmsjs is versioned in the following format:
`[generator SemVer]-[CDA schema version]`

The generator now uses the live OpenAPI `info.version` published by CDA. If that field is unavailable, it falls back to the current date.

### Publishing
Contributors with authorization can publish a new version of cwmsjs by manually running the "Build, Test, and Publish" GitHub Action.

The workflow will build an updated cwmsjs library using the current generator and national CDA instance OpenAPI spec. If all tests pass, the library will be published to npm and updated documentation will be deployed to GitHub Pages.

## Building CWMSjs from source

- Clone this repository
- Install dependencies with: `npm install`
- Optionally set `CWMS_SCHEMA_URL` if you need to build from a non-default CDA schema endpoint
- Run the generator with:
`npm run build`

All generated files (source, library, and docs) will be in `[repo]/cwmsjs`
7 changes: 7 additions & 0 deletions cda-client/openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "5.4.0"
}
}
Loading
Loading