# dcs-schemas

> ```bash npm i @dcl/schemas ```

Latest version **5.0.2-168926-1** (published 2022-07-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install dcs-schemas
pnpm add dcs-schemas
yarn add dcs-schemas
bun add dcs-schemas
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.2-168926-1 |
| Published | 2022-07-18 |
| First published | 2022-07-17 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 271.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | redblow |

## Links

- npm: https://www.npmjs.com/package/dcs-schemas
- npm.io page: https://npm.io/package/dcs-schemas

## Dependencies (3)

- [ajv](https://npm.io/package/ajv.md) ^8.11.0
- [ajv-errors](https://npm.io/package/ajv-errors.md) ^3.0.0
- [ajv-keywords](https://npm.io/package/ajv-keywords.md) ^5.1.0

## Recent versions

- 5.0.2-168926-1 (latest) — 2022-07-18
- 3.8.0-168926-1 — 2022-07-18
- 5.0.3-168926-1 — 2022-07-18
- 5.3.0-168926-1 — 2022-07-18
- 4.9.0-168926-1 — 2022-07-18
- 1.1.1-168926-1 — 2022-07-17
- 3.9.0-168926-1 — 2022-07-17
- 4.14.0-168926-1 — 2022-07-17
- 4.13.0-168926-1 — 2022-07-17
- 4.6.0-168926-1 — 2022-07-17
- 4.2.0-168926-1 — 2022-07-17
- 5.4.0-168926-1 — 2022-07-17
- 5.4.1-deepspace-3 — 2022-07-17
- 5.4.1-deepspace-2 — 2022-07-17
- 5.4.1-deepspace-1 — 2022-07-17

## README

# common-schemas

```bash
npm i @dcl/schemas
```

### Design considerations

- The main entrypoint of the library export types only (and the helper functions to prevent lockin)
- Every type is also a namespace
- Type names are PascalCase
- Validators and schemas are camelCase

## Generating types, validators and schemas

We will export types that also act as values. We do that using the "namespaces" of typescript. That is, every type is also a JS object, including two properties: `schema` and `validate`. It can also be a const, but a namespace _sounds_ better.

```ts
// Declare type
export type MyType = {
  value: number;
};

// Declare namespace for the type
export namespace MyType {
  export const schema: Schema<MyType> = {
    type: "object",
    properties: {
      value: { type: number },
    },
    additionalProperties: false,
    required: ["value"],
  };

  export const validate = generateValidator<MyType>(schema);
}
```

In that sense, MyType can be both used as type `const a: MyType` and as object `MyType.validate(a)`.

Beware that `validate` has type `ValidateFunction<T>` which `ajv` creates automatically. When writing new
validations always try to implement it as an ajv validation, even if custom code is needed. See [here](https://ajv.js.org/keywords.html#define-keyword-with-code-generation-function).

In particular, don't fall in the trap of doing this:

```ts
const validator = generateValidator<MyType>(schema);
export const validate = (mt: MyType) =>
  validator.validate(mt) && otherValidations(mt);
```

By doing this, all the errors reported by the `validator.validate` function are lost and never returned
to the caller.

## Type ownership

Please add types and schemas of your domain into the `src/<team>` folder, also add your team to the [CODEOWNERS](.github/CODEOWNERS) repository to make sure nobody accidentally changes it without your team noticing it.

## Informing changes

Please notify about changes to the schemas to the teams by adding the whole team (i.e. `@decentraland/dapps`) as reviewers of the pull requests.

It is recommended that if you are a stakeholder of the interoperable parts of Decentraland, you are subscribed to this repository (wathing it in the button up right).

## Making changes

To make sure everybody is aware of changes in types, we have a process of api-extraction using https://api-extractor.com. It creates [a report file](report/schemas.api.md) that should be reviewed upon every change and committed as part of the PR.

To generate the file with your changes run `npm run refresh-api`.

In the CI, `npm run check-api` is executed to verify the generated file matches the exported types.

## Versions and publishing

Versions are handled manually using Github releases and semver.

Main branch is automatically published to the `@next` dist tag to test integrations before final releases happen.

---
_Source: https://npm.io/package/dcs-schemas · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
