occc v1.0.4
OCCC
Obtain care config connector
occc - is a package that allows you to create JSONSchemaType using TypeScript interfaces, and validate them in your application, philosophy is:
- Type some config interface and generate schema
- create validate function and export it
- build and publish
- ✨enjoy ✨
Tech
OCCC uses a number of open source projects to work properly:
- ajv - Ajv generates code to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization!
- ts-json-schema-generator - awesome TSinterfaces-based schema-generator
Installation
OCCC requires Node.js v10+ to run.
npm iFor developmnet link occc to your project
cd ~/projects/occc # go into the package directory
npm link # creates global link
cd ~/projects/MyAwasomeProject # go into some other package directory.
npm link occc # link-install the packageNote that the link should be to the package name, not the directory name for that package.
Development
First:
cd src/programs/index.tsand declare some type
export declare type MyAwasomeEnvConfig = {
foo: string;
};go to programs and create dir
cd src/programs
mkdir MyAwasomeEnvConfigNote name of directory should be eaqual to your interface.
in generator.ts initialize a generateSchemaByTypeName function
generateSchemaByTypeName('MyAwasomeEnvConfig')Second: generate a JSON schema
npm generatein your MyAwasomeEnvConfig directory should appear a schema.json file.
Next to this file create index.ts with following code :
import ajvInstance from '../../ajv-instance';
import * as jsonSchema from './schema.json';
export default ajvInstance.compile(jsonSchema);this code will create ValidateFunction
Third:
in src/index.ts import and export your ValidateFunction
Usage
In your project:
create .env with following code:
REACT_APP_JCP=/config/jsonConfig.jsonand past some config in that path with .json extansion for example:
{
"providerService": {
"baseUrl": "https://provider.obtaincare.site"
}
}init your app with following code:
import initConfig, { adminToolValidator } from "occc";
initConfig(adminToolValidator).then(() =>
ReactDOM.render(<App />, document.getElementById("root"))
);License
MIT
Free Software, Hell Yeah!
