# typescript-schema

> A reflective type model for TypeScript applications

Latest version **0.7.8** (published 2015-10-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install typescript-schema
pnpm add typescript-schema
yarn add typescript-schema
bun add typescript-schema
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.8 |
| Published | 2015-10-20 |
| First published | 2015-06-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 49 |
| Author | Christy Haragan |
| Maintainers | christyharagan |
| Keywords | typescript, schema, json, types |

## Links

- npm: https://www.npmjs.com/package/typescript-schema
- Repository: https://github.com/christyharagan/ts-schema
- Homepage: https://github.com/christyharagan/ts-schema#readme
- Issues: https://github.com/christyharagan/ts-schema/issues
- npm.io page: https://npm.io/package/typescript-schema

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) 1.6.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.7.8 (latest) — 2015-10-20
- 0.7.7 — 2015-10-10
- 0.7.6 — 2015-10-08
- 0.7.5 — 2015-09-25
- 0.7.4 — 2015-09-25
- 0.7.3 — 2015-09-25
- 0.7.2 — 2015-09-23
- 0.7.1 — 2015-09-23
- 0.7.0 — 2015-09-23
- 0.6.1 — 2015-09-21
- 0.6.0 — 2015-09-18
- 0.5.0 — 2015-09-06
- 0.3.2 — 2015-07-16
- 0.3.1 — 2015-07-15
- 0.3.0 — 2015-07-08
- … 6 more at https://npm.io/package/typescript-schema/versions

## README

TypeScript Schema Library
===

Overview
--

A reflective type model for TypeScript applications. There are two primary models:

 * A raw model, which is a serialisable format (consider using [typescript-package](https://github.com/christyharagan/typescript-package) for the generation of this from a TypeScript package or project). References to types are stored as a {moduleName:string, name:string} object.
 * A fully resolved model, where all references are replaced with actual instances of that type. This is the model most useful for use.

A high level over-view of the modules in this library are:

 * rawConverter: converts raw models to resolved models.
 * model: contains the type meta-model, both for raw and resolved models
 * factories: used by rawConverter. Contains the code for creating resolved model elements
 * equals: contains equality functions for resolved models
 * typeCloser: elements with type-parameters (classes, interfaces, etc.) are treated as type-constructors. To create an actual type, use typeCloser with arguments for the parameters
 * typeUtils: some useful functions for dealing with types
 * serialiserParser: use this to create a more readable serialised form of a raw model (and for parsing that form)
 * filter: used to reduce raw models to complete sub-models based off specific elements (e.g.: filtered to a closed model for a particular module, or class)
 * toString: used to create a unique identifier for various resolved model elements
 * expressionToLiteral: used to convert a resolved expression model into a pure javascript equivalent
 * visitor: used to easily navigate a resolved model

Usage
--

Install:
```
npm install typescript-schema
```

Basic Usage:

```TypeScript
import * as s from 'typescript-schema'

let rawModules:s.Map<s.Module>

// Given a raw model, filter its contents to only contain types relevant to and referenced by some module
let filteredModules = s.filterRawModules(['moduleA'], rawModules)

// Given a raw model, convert to a resolved one:
let resolvedModules = s.convertRawModules(rawModules)

// Give a raw model, create a nice text format
let str = s.stringify(rawModules)
// And parse it back into a raw model
rawModules = s.parse(str)

let someInterfaceConstructor:s.InterfaceConstructor
let someTypeForT:s.Type
// Given a type constructor (e.g. interface A<T>), create a type
s.closeInterface(someInterfaceConstructor, [someTypeForT])

// Visit the elements in a model
s.modulesVisitor(resolveModules, {
  onModule: function(module){
    return <s.ModuleVisitor> {
      onClassConstructor: function(cc) {
        // etc
      }
    }
  }
})

// Get the unique id for an element
let id = s.interfaceConstructorToString(someInterfaceConstructor)

let decorator:s.Decorator

// For some expression (e.g. from a decorator)
let pureValue = s.expressionToLiteral(decorator.parameters[0])

let someOtherInterfaceConstructor

// Compare two entities
let isEqual = someInterfaceConstructor.equals(someOtherInterfaceConstructor)
```

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