0.5.11 • Published 4 years ago

tyranid-sanitize v0.5.11

Weekly downloads
41
License
-
Repository
-
Last release
4 years ago

Tyranid Sanitize

tyranid-sanitize is a tool for obfuscating text fields on documents in your tyranid collections using simple schema annotations.

Schema Annotations

In order to mark fields to be sanitized, add the sanitize property to a field definition.

import { Tyr } from 'tyranid';

export const Blog = new Tyr.Collection({
  id: 'b00',
  name: 'blog',
  dbName: 'blogs',
  fields: {
    _id: { is: 'mongoid' },
    /**
     *  we want to obfuscate the name when the database
     *  is passed to `tyranid-sanitize`, so we mark the field
     *  with `sanitize: 'name'` to generate a random name string
     *  using faker.js.
     */
    name: { is: 'string', sanitize: 'name' },
    organizationId: { link: 'organization' }
  }
});

The sanitize (see the type definition here: ./src/sanitize.ts) property can be one of the following:

  • true: this will use the default sanitization (a random string of lorem ipsum)
  • lorem: a random sentence of lorem ipsum
  • name: a random name
  • email: a random email

Sanitizing a database

After marking properties for sanitization, use the sanitize function to create a cloned, sanitized version of the database.

import { Tyr } from 'tyranid';
import { sanitize } from 'tyranid-sanitize';

// ... after booting tyranid
await sanitize(Tyr);

Sanitization Options

The sanitize(tyr: Tyr, opts?: SanitizeOptions) function takes an optional options argument:

interface SanitizeOptions {
  /**
   * desired name of the output database
   */
  outDbName?: string;
  /**
   * number of documents to batch insert at a time
   */
  batchSize?: number;
  /**
   * verbose progress logging
   */
  verbose?: boolean;
  /**
   * sanitize each collection serially (defaults to concurrently)
   */
  serial?: boolean;
  /**
   * faker.js seed
   */
  seed?: number;
  /**
   * sanitize every string field automatically
   */
  autoSanitize?: boolean;
}
0.5.11

4 years ago

0.5.10

5 years ago

0.5.9

5 years ago

0.5.8

5 years ago

0.5.7

6 years ago

0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago