4.1.4 • Published 10 months ago

@cogeco-web/schema v4.1.4

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
10 months ago

< Back to main

@cogeco-web/schemas

Library of Typescript schemas, data models and related types, interfaces

Installation

yarn add @cogeco-web/schemas

or

npm install @cogeco-web/schemas

Usage

Example

import { ProductCatalog } from '@cogeco-web/schemas'

const myCatalog: ProductCatalog = {
  id: {},
}

Adding a new type, interface, classe or util function

Here are the steps in order to add a new object to the library.

  1. Within /packages/schemas/src/, locate the folder (interfaces, models, utils, etc..) which corresponds to the type of object you want to create. If you don't find an existing folder that matches the type of object you want to create, make a new one (using camelCase).
  2. Create a new file inside the corresponding folder (interfaces, models, utils, etc..) with the name of your object. Use PascalCase to name your file. Example: interfaces/ExampleType.ts
  3. Put your code in the new file and make sure you export it with same name as the file you created. For Example:
interface ExampleType {
  title: string
}

export default ExampleType
  1. Adding a dependency library for your new component (OPTIONAL)
    If you need to install a dependency library for your new component, install it using the following script (via terminal, at the root fo the repo, NOT within the /packages/components folder)
    A - If it's a dev dependency

    npx lerna add --scope=@cogeco-web/schemas -D my-npm-library-name

    B - Otherwise

    npx lerna add --scope=@cogeco-web/schemas my-npm-library-name
  2. Open the ./src/index.ts file and then:

        - Add an import for your newly created object

import ExxampleType from './interfaces/ExampleType'

        - Add the object to the list of exported objects (Note: Please try to keep the exports organized alphabetically)

export {
  ...
  ExxampleType
  ...
}
  1. Now that you are done, run the follwing scripts (at the root fo the repo, NOT within the /packages/schema folder).
    This will update the definition files and create a new build, hence making your new component available to use within other packages of the library.
yarn install
yarn build
  1. Documentation — To be added

Reference

For reference, check the CatalogProduct

4.1.4

10 months ago