How to use the rulr/Record function in rulr

To help you get started, we’ve selected a few rulr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kube-js / kube-ts-server / src / presenter / commander / functions / dbSeed / functions / createUser / index.ts View on Github external
// tslint:disable:no-console
// tslint:disable:no-magic-numbers
import faker from 'faker';
import promptly from 'promptly';
import Record from 'rulr/Record';
import validateData from 'rulr/validateData';
import { v4 as uuid } from 'uuid';
import { VARCHAR_LENGTH } from '../../../../../../constants';
import hashPassword from '../../../../../../utils/helpers/auth/hashPassword';
import getUtcDate from '../../../../../../utils/helpers/date/getUtcDate';
import Email from '../../../../../../utils/validation/rules/Email';
import String from '../../../../../../utils/validation/rules/String';
import FactoryConfig from '../../../../presenterFactory/FactoryConfig';

const rules = Record({
  email: Email(),
  // FYI: intential just String validation on password,
  // allowing weak passwords for development
  password: String(0, VARCHAR_LENGTH),
});

export interface Options {
  readonly userType: string;
  readonly defaultEmail: string;
  readonly defaultPassword: string;
  readonly rolesIds: string[];
}

const createUser = (config: FactoryConfig) => async ({
  defaultEmail,
  defaultPassword,
github kube-js / kube-ts-server / src / presenter / express / utils / schemas / roles / updateItem / index.ts View on Github external
import Record from 'rulr/Record';
import { VARCHAR_LENGTH } from '../../../../../../constants';
import Optional from '../../../../../../utils/validation/rules/Optional';
import String from '../../../../../../utils/validation/rules/String';

import baseSchema from '../base/schema';

export const beforeUpdateSchema = {
  ...baseSchema,
  name: Optional(String(0, VARCHAR_LENGTH)),
};

const rules = Record(beforeUpdateSchema);

export default rules;
github kube-js / kube-ts-server / src / presenter / express / utils / schemas / roles / createItem / index.ts View on Github external
import Record from 'rulr/Record';
import baseSchema from '../base/schema';

export const beforeCreateSchema = {
  ...baseSchema,
};

const rules = Record(beforeCreateSchema);

export default rules;
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / autocompleteHandler / index.ts View on Github external
catchErrors(config, async (req, res) => {
    const name = config.appConfig.http.client.autocompleteQueryParam;

    const validationSchema = {
      [name]: String(0, SAFE_URL_LENGTH),
    };

    const rules = Record(validationSchema);
    const value = req.query[name];

    const payload: any = {[name]:value};

    validateData(rules)(payload);

    const response = await config.service.autocomplete({
      query: value
    });
       
    sendResponse({
      body: toSnake(response),
      req,
      res,
      status: OK,
    });
github kube-js / kube-ts-server / src / presenter / express / utils / schemas / auth / register / index.ts View on Github external
import Email from '../../../../../../utils/validation/rules/Email';
import Match from '../../../../../../utils/validation/rules/Match';
import Password from '../../../../../../utils/validation/rules/Password';
import String from '../../../../../../utils/validation/rules/String';
import { schema as baseSchema } from '../../users/createItem';

export const schema = {
  ...baseSchema,
  email: Intersection([String(0, VARCHAR_LENGTH), Email()]),
  password: Intersection([String(0, VARCHAR_LENGTH), Password()]),
  password_confirmation: Intersection([String(0, VARCHAR_LENGTH), Password()]),
};

const rules = Intersection([
  Object,
  Record(schema),
  Match('password', 'password_confirmation'),
]);

export default rules;
github kube-js / kube-ts-server / src / presenter / express / utils / schemas / auth / resetPassword / index.ts View on Github external
import Object from 'rulr/Object';
import Record from 'rulr/Record';
import { UUID_LENGTH, VARCHAR_LENGTH } from '../../../../../../constants';
import Match from '../../../../../../utils/validation/rules/Match';
import Password from '../../../../../../utils/validation/rules/Password';
import String from '../../../../../../utils/validation/rules/String';

export const schema = {
  password: Intersection([String(0, VARCHAR_LENGTH),Password()]),
  password_confirmation: Intersection([String(0, VARCHAR_LENGTH),Password()]),
  token: String(UUID_LENGTH, UUID_LENGTH),
};

const rules = Intersection([
  Object,
  Record(schema),
  Match('password', 'password_confirmation'),
]);

export default rules;
github kube-js / kube-ts-server / src / presenter / express / utils / schemas / roles / replaceItem / index.ts View on Github external
import Record from 'rulr/Record';
import baseSchema from '../base/schema';

export const beforeReplaceSchema = {
  ...baseSchema,
};

const rules = Record(beforeReplaceSchema);

export default rules;
github kube-js / kube-ts-server / src / presenter / express / utils / schemas / courses / createItem / index.ts View on Github external
import Record from 'rulr/Record';
import { VARCHAR_LENGTH } from '../../../../../../constants';
import String from '../../../../../../utils/validation/rules/String';
import baseSchema from '../base/schema';

export const beforeCreateSchema = {
  ...baseSchema,
  slug: String(0, VARCHAR_LENGTH),
  title: String(0, VARCHAR_LENGTH),
};

const rules = Record(beforeCreateSchema);

export default rules;
github kube-js / kube-ts-server / src / presenter / express / utils / schemas / users / createItem / index.ts View on Github external
import Intersection from 'rulr/Intersection';
import Record from 'rulr/Record';
import { VARCHAR_LENGTH } from '../../../../../../constants';
import Email from '../../../../../../utils/validation/rules/Email';
import Password from '../../../../../../utils/validation/rules/Password';
import String from '../../../../../../utils/validation/rules/String';
import baseSchema from '../base/schema';

export const schema = {
  ...baseSchema,
  email: Intersection([String(0, VARCHAR_LENGTH), Email()]),
  password: Intersection([String(0, VARCHAR_LENGTH), Password()]),
};

const rules = Record(schema);

export default rules;
github kube-js / kube-ts-server / src / presenter / express / utils / schemas / permissions / createItem / index.ts View on Github external
import Record from 'rulr/Record';
import baseSchema from '../base/schema';

export const beforeCreateSchema = {
  ...baseSchema,
};

const rules = Record(beforeCreateSchema);

export default rules;

rulr

Validation and unit conversion errors in TypeScript at compile-time. Started in 2016.

MIT
Latest version published 3 months ago

Package Health Score

69 / 100
Full package analysis