1.0.4 • Published 4 years ago

occc v1.0.4

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
4 years ago

OCCC

Obtain care config connector

N|Solid

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 i

For 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 package

Note that the link should be to the package name, not the directory name for that package.

Development

First:

cd src/programs/index.ts

and declare some type

export declare type MyAwasomeEnvConfig = {
  foo: string;
};

go to programs and create dir

cd src/programs 
mkdir MyAwasomeEnvConfig

Note name of directory should be eaqual to your interface.

in generator.ts initialize a generateSchemaByTypeName function

generateSchemaByTypeName('MyAwasomeEnvConfig')

Second: generate a JSON schema

npm generate

in 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.json

and 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!

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago