
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@orchestrator/gen-io-ts
Advanced tools
Generate io-ts codecs for classes by decorating props
$ npm install --save @orchestrator/gen-io-ts
NOTE: Library uses globalThis
variable to get Reflect
object.
You can either provide it manually via provideReflect()
function
or make sure that Reflect
API is loaded globally (via polyfills).
If required - you may need to load globalThis
polyfill.
First decorate your properties that you want to validate:
// my-class.ts
import { Property } from '@orchestrator/gen-io-ts';
class MyClass {
@Property() // This will validate `prop` to be a string
prop: string;
internalProp: any;
}
Now generate codec type for your decorated class:
// main.ts
import { genIoType } from '@orchestrator/gen-io-ts';
import { MyClass } from './my-class.ts';
const myClassType = genIoType(MyClass);
// Then you can validate the type
myClassType.decode({ prop: 'ok' }); // This will produce Right({prop: 'ok'})
myClassType.decode({ prop: false }); // This will produce Left([...])
You can now report any validation errors as usual in io-ts:
import { ThrowReporter } from 'io-ts/lib/ThrowReporter';
ThrowReporter.report(myClassType.decode({...})); // This will throw errors
NOTE: By default every property is optional. To change it - see Required property section.
Every property is configured to be NOT required, which means you can assign
null/undefined
values and validation will not fail.
To change that set isRequired
option to true
:
import { Property } from '@orchestrator/gen-io-ts';
class MyClass {
@Property({ isRequired: true }) // Will now fail if `null/undefined` was set
prop: string;
}
Allows to override default inferred type with custom:
import { Property } from '@orchestrator/gen-io-ts';
class MyClass {
@Property({ type: typeOf(Boolean) }) // Will now allow only booleans instead of strings
prop: string;
}
Allows to override/adjust(refine) default type:
import * as t from 'io-ts';
import { Property } from '@orchestrator/gen-io-ts';
class MyClass {
@Property({
typeFactory: type => t.refine(type, str => str.length > 0, 'NotEmpty'),
}) // Will now allow only non empty strings
prop: string;
}
See: io-ts
Refinements for more usage info.
This project was generated with Angular CLI version 7.1.4.
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Run ng build
to build the project. The build artifacts will be stored in the dist/
directory. Use the --prod
flag for a production build.
Run ng test
to execute the unit tests via Karma.
Run ng e2e
to execute the end-to-end tests via Protractor.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.
FAQs
Generate io-ts codecs for classes by decorating props
The npm package @orchestrator/gen-io-ts receives a total of 2,840 weekly downloads. As such, @orchestrator/gen-io-ts popularity was classified as popular.
We found that @orchestrator/gen-io-ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.