0.10.0 • Published 2 years ago

thaumaturge v0.10.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Thaumaturge

npm CI

Thaumaturge is a fixtures and seeding library powered by io-ts.

Installation

Thaumaturge has peer dependencies on io-ts and fp-ts, so be sure to have those installed first.

The thaumaturge package should then be installed as a development dependency:

Yarn

yarn add -D thaumaturge

npm

npm install -D thaumaturge

Usage

import * as t from 'io-ts';
import { define, manifest } from 'thaumaturge';

const Movie = t.strict({
  title: t.string,
  year: t.number,
});

define(Movie, {
  sequences: {
    titles: new Sequence(n => `Movie ${n}` as const),
    years: new Sequence(n => 2022 - n),
  },
  manifest: ({ sequences }) => ({
    title: sequences.titles.next(),
    year: sequences.years.next(),
  }),
});

const movie = manifest(Movie);

console.log(movie);
// > { title: 'Movie 1', year: 2021 }

Entity Hierarchies

import * as t from 'io-ts';
import { define, manifest, Ref } from 'thaumaturge';

const Author = t.type({
  id: t.string,
  name: t.string,
});

const Book = t.type({
  id: t.string,
  authorId: t.string,
  title: t.string,
});

define(Author, {
  manifest: ({ uuid }) => ({
    id: uuid(),
    name: 'J. R. R. Tolkien',
  }),
});

define(Book, {
  manifest: ({ uuid }) => ({
    id: uuid(),
    authorId: Ref.to(Author).through(author => author.id),
    title: 'The Lord of the Rings',
  }),
});

const book = manifest(Book);

console.log(book);
// > {
//     id: '1ab4790a-9911-4e20-9006-b12e6b60dfe6',
//     authorId: 'c6a1f6e0-6845-4675-b570-87024446a371',
//     title: 'The Lord of the Rings'
//   }
0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.7.0

2 years ago

0.4.3

2 years ago

0.6.0

2 years ago

0.4.2

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago