Skip to content

Commit

Permalink
Merge pull request #772 from eddie-atkinson/devel
Browse files Browse the repository at this point in the history
Migrate Validation to Typebox
  • Loading branch information
gadicc authored Aug 7, 2024
2 parents 42b48df + 6af931d commit ae257e6
Show file tree
Hide file tree
Showing 46 changed files with 4,565 additions and 13,547 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ jobs:
# Check for TypeScript errors
- run: yarn test:ts

# Check that schema is up-to-date
- run: scripts/schema-check.sh

- run: yarn prettier --check src tests tests-modules

# run tests!
Expand Down
16 changes: 5 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ work and submitting your PR.

All PRs should be submitted against the `devel` branch (github default).

**Changing TypeScript Interfaces**

Run `yarn generateSchema` after changing any interfaces, this will regenerate
the `schema.json` file which is used for run-time tests.

**Commit Messages**

Commit messages should follow the
Expand Down Expand Up @@ -134,12 +129,11 @@ TODO
Checklist:

1. Create it in `src/modules/myAmazingModule.ts`
1. Run `yarn generateSchema` (and on any future interface changes)
1. Test it in `src/modules/myAmazingModule.spec.ts`
1. Add it to `src/index-common.ts`
1. Docs in `docs/modules/myAmazingModule.md`
1. Link these docs in `README.md` and `docs/README.md`.
1. Commit all the above and any `tests/http/*` created in your tests.
2. Test it in `src/modules/myAmazingModule.spec.ts`
3. Add it to `src/index-common.ts`
4. Docs in `docs/modules/myAmazingModule.md`
5. Link these docs in `README.md` and `docs/README.md`.
6. Commit all the above and any `tests/http/*` created in your tests.

For a model example, see the
[recommendationsBySymbol PR](https://github.com/gadicc/node-yahoo-finance2/pull/28)
Expand Down
5 changes: 3 additions & 2 deletions docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,17 @@ receive back, we'll no longer throw a new error on new unknown keys.
This is important because Yahoo constantly add new fields, and this would
break all existing deployments.

You can revert to the old behaviour with:
You can revert to the old behaviour by passing the `_internalThrowOnAdditionalProperties` to the global configuration like so:

```js
yahooFinance._disallowAdditionalProps();
yahooFinance.setGlobalConfig({ validation: { _internalThrowOnAdditionalProperties: true} });
```

which is the default when `NODE_ENV==="test"`. This means that during our
development of the library itself, we make sure that we're testing against
all types.


<a name="help-fix"></a>
## Help Fix Validation Errors

Expand Down
15 changes: 3 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@
"scripts": {
"coverage": "yarn test --coverage",
"lint": "eslint . --ext .js,.ts",
"//schema": "ts-json-schema-generator -f tsconfig.json -p 'src/{modules/**/*.ts,lib/options.ts}' -t '*' | node bin/schema-tweak.js > schema.json",
"schema": "node --loader ts-node/esm scripts/schema.js > schema.json",
"timeseries": "node --loader ts-node/esm scripts/timeseries.js",
"build": "yarn run build:esm && yarn run build:cjs && yarn run build:post",
"build": "yarn run build:esm && yarn run build:cjs",
"build:esm": "tsc --module es2020 --target es2019 --outDir dist/esm",
"build:cjs": "tsc --module commonjs --target es2015 --outDir dist/cjs && sed 's/\"type\": \"module\",/\"type:\": \"commonjs\",/' dist/cjs/package.json > dist/cjs/package-changed.json && mv dist/cjs/package-changed.json dist/cjs/package.json",
"build:post": "scripts/json-transform.sh",
"generateSchema": "yarn schema",
"prepublishOnly": "yarn build && yarn generateSchema && yarn build:post",
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
"test:ts": "tsc --noEmit",
"test:esm": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js -c tests-modules/esm/jest.config.js tests-modules/esm/tests/*",
Expand All @@ -54,13 +49,11 @@
"test:build": "yarn test:modules"
},
"files": [
"dist",
"schema.json"
"dist"
],
"dependencies": {
"@sinclair/typebox": "^0.32.27",
"@types/tough-cookie": "^4.0.2",
"ajv": "8.10.0",
"ajv-formats": "2.1.1",
"node-fetch": "^2.6.1",
"tough-cookie": "^4.1.2",
"tough-cookie-file-store": "^2.0.3"
Expand All @@ -83,11 +76,9 @@
"globby": "13.2.2",
"jest": "29.7.0",
"jest-tobetype": "1.2.3",
"oas-schema-walker": "1.1.5",
"prettier": "2.8.8",
"semantic-release": "19.0.5",
"ts-jest": "29.1.2",
"ts-json-schema-generator": "1.5.0",
"ts-node": "10.9.2",
"typescript": "5.4.3"
}
Expand Down
Loading

0 comments on commit ae257e6

Please sign in to comment.