How to use the runtypes.Function function in runtypes

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

github citycide / trilogy / src / types.ts View on Github external
})

export const ColumnKind = t.Union(t.String, t.Function).withConstraint(value => {
  const type = isFunction(value) ? value.name : String(value)
  return type.toLowerCase() in ColumnTypes
}, { name: 'ColumnKind' })

export const ColumnDescriptor = t.Partial({
  defaultTo: t.Unknown,
  index: t.String,
  notNullable: t.Boolean,
  nullable: t.Boolean,
  primary: t.Boolean,
  unique: t.Boolean,
  type: ColumnKind,
  get: t.Function,
  set: t.Function
})

export type Index = t.Static<typeof Index>
export type Order = t.Static<typeof OrderClause>
export type Group = t.Static<typeof GroupClause>

export type TrilogyOptions = t.Static<typeof TrilogyOptions>
export type ModelOptions = t.Static<typeof ModelOptions>
export type AggregateOptions = t.Static<typeof AggregateOptions>
export type CreateOptions = t.Static<typeof CreateOptions>
export type UpdateOptions = t.Static<typeof UpdateOptions>
export type FindOptions = t.Static<typeof FindOptions>
export type ColumnKind = t.Static<typeof ColumnKind>
export type ColumnDescriptor = t.Static<typeof ColumnDescriptor>
github citycide / trilogy / src / types.ts View on Github external
raw: t.Boolean
})

export const FindOptions = t.Partial({
  limit: t.Number,
  order: OrderClause,
  random: t.Boolean,
  raw: t.Boolean,
  skip: t.Number
})

export const UpdateOptions = t.Partial({
  raw: t.Boolean
})

export const ColumnKind = t.Union(t.String, t.Function).withConstraint(value => {
  const type = isFunction(value) ? value.name : String(value)
  return type.toLowerCase() in ColumnTypes
}, { name: 'ColumnKind' })

export const ColumnDescriptor = t.Partial({
  defaultTo: t.Unknown,
  index: t.String,
  notNullable: t.Boolean,
  nullable: t.Boolean,
  primary: t.Boolean,
  unique: t.Boolean,
  type: ColumnKind,
  get: t.Function,
  set: t.Function
})
github citycide / trilogy / src / types.ts View on Github external
export const ColumnKind = t.Union(t.String, t.Function).withConstraint(value => {
  const type = isFunction(value) ? value.name : String(value)
  return type.toLowerCase() in ColumnTypes
}, { name: 'ColumnKind' })

export const ColumnDescriptor = t.Partial({
  defaultTo: t.Unknown,
  index: t.String,
  notNullable: t.Boolean,
  nullable: t.Boolean,
  primary: t.Boolean,
  unique: t.Boolean,
  type: ColumnKind,
  get: t.Function,
  set: t.Function
})

export type Index = t.Static<typeof Index>
export type Order = t.Static<typeof OrderClause>
export type Group = t.Static<typeof GroupClause>

export type TrilogyOptions = t.Static<typeof TrilogyOptions>
export type ModelOptions = t.Static<typeof ModelOptions>
export type AggregateOptions = t.Static<typeof AggregateOptions>
export type CreateOptions = t.Static<typeof CreateOptions>
export type UpdateOptions = t.Static<typeof UpdateOptions>
export type FindOptions = t.Static<typeof FindOptions>
export type ColumnKind = t.Static<typeof ColumnKind>
export type ColumnDescriptor = t.Static<typeof ColumnDescriptor>

export type SchemaRaw <D = LooseObject> = {