How to use the rambdax.pipe function in rambdax

To help you get started, we’ve selected a few rambdax 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 Nozbe / WatermelonDB / src / adapters / sqlite / encodeInsert / index.js View on Github external
// @flow

import { pipe, join, keys, values, always, map } from 'rambdax'

import type Model from '../../../Model'
import type { SQLiteQuery } from '../index'

import encodeName from '../encodeName'

const columnNames = pipe(
  keys,
  map(encodeName),
  join(', '),
)

const valuePlaceholders = pipe(
  values,
  map(always('?')),
  join(', '),
)

export default function encodeInsert(model: Model): SQLiteQuery {
  const { _raw: raw, table } = model
  const sql = `insert into ${table} (${columnNames(raw)}) values (${valuePlaceholders(raw)})`
  const args = values(raw)
github Nozbe / WatermelonDB / src / adapters / lokijs / worker / encodeQuery / index.js View on Github external
const lengthEq = n =>
  pipe(
    length,
    identical(n),
  )

// Note: empty query returns `undefined` because
// Loki's Collection.count() works but count({}) doesn't
const concatRawQueries: (LokiRawQuery[]) => LokiRawQuery = (cond([
  [lengthEq(0), always(undefined)],
  [lengthEq(1), head],
  [T, objOf('$and')],
]): any)

const encodeConditions: (Where[] | On[]) => LokiRawQuery = pipe(
  conditions => map(encodeCondition, conditions),
  concatRawQueries,
)

const encodeMapKey: AssociationInfo => ColumnName = ifElse(
  propEq('type', 'belongs_to'),
  always(columnName('id')),
  prop('foreignKey'),
)

const encodeJoinKey: AssociationInfo => ColumnName = ifElse(
  propEq('type', 'belongs_to'),
  prop('key'),
  always(columnName('id')),
)
github Nozbe / WatermelonDB / src / adapters / sqlite / encodeInsert / index.js View on Github external
// @flow

import { pipe, join, keys, values, always, map } from 'rambdax'

import type Model from '../../../Model'
import type { SQLiteQuery } from '../index'

import encodeName from '../encodeName'

const columnNames = pipe(
  keys,
  map(encodeName),
  join(', '),
)

const valuePlaceholders = pipe(
  values,
  map(always('?')),
  join(', '),
)

export default function encodeInsert(model: Model): SQLiteQuery {
  const { _raw: raw, table } = model
  const sql = `insert into ${table} (${columnNames(raw)}) values (${valuePlaceholders(raw)})`
  const args = values(raw)

  return [sql, args]
}
github Nozbe / WatermelonDB / src / sync / impl / fetchLocal.js View on Github external
)

async function fetchLocalChangesForCollection(
  collection: Collection,
): Promise<[SyncTableChangeSet, T[]]> {
  const changedRecords = await collection.query(notSyncedQuery).fetch()
  const changeSet = {
    created: rawsForStatus('created', changedRecords),
    updated: rawsForStatus('updated', changedRecords),
    deleted: await collection.database.adapter.getDeletedRecords(collection.table),
  }
  return [changeSet, changedRecords]
}

const extractChanges = map(([changeSet]) => changeSet)
const extractAllAffectedRecords = pipe(
  values,
  map(([, records]) => records),
  unnest,
)

export default function fetchLocalChanges(db: Database): Promise {
  ensureActionsEnabled(db)
  return db.action(async () => {
    const changes = await promiseAllObject(
      map(
        fetchLocalChangesForCollection,
        // $FlowFixMe
        db.collections.map,
      ),
    )
    // TODO: deep-freeze changes object (in dev mode only) to detect mutations (user bug)
github Nozbe / WatermelonDB / src / adapters / lokijs / worker / encodeQuery / index.js View on Github external
const encodeAndOr: LokiKeyword => (And | Or) => LokiRawQuery = op =>
  pipe(
    prop('conditions'),
    map(encodeCondition),
    objOf(op),
  )
github Nozbe / WatermelonDB / src / adapters / lokijs / worker / encodeQuery / index.js View on Github external
const encodeOriginalConditions: (On[]) => Where[] = map(({ left, comparison }) => ({
  type: 'where',
  left,
  comparison,
}))

const encodeJoin: (AssociationArgs, On[]) => LokiJoin = ([table, associationInfo], conditions) => ({
  table,
  query: encodeConditions(conditions),
  originalConditions: encodeOriginalConditions(conditions),
  mapKey: encodeMapKey(associationInfo),
  joinKey: encodeJoinKey(associationInfo),
})

const groupByTable: (On[]) => On[][] = pipe(
  groupBy(prop('table')),
  values,
)

const zipAssociationsConditions: (AssociationArgs[], On[]) => [AssociationArgs, On[]][] = (
  associations,
  conditions,
) => zip(associations, groupByTable(conditions))

const encodeJoins: (AssociationArgs[], On[]) => LokiJoin[] = (associations, on) => {
  const conditions = zipAssociationsConditions(associations, on)
  return map(([association, _on]) => encodeJoin(association, _on), conditions)
}

export default function encodeQuery(query: SerializedQuery): LokiQuery {
  const {
github Nozbe / WatermelonDB / src / observation / encodeMatcher / index.js View on Github external
[typeEq('where'), encodeWhereDescription],
  ]): any)(where)

const encodeAnd: And => Matcher<*> = pipe(
  prop('conditions'),
  map(encodeWhere),
  allPass,
)

const encodeOr: Or => Matcher<*> = pipe(
  prop('conditions'),
  map(encodeWhere),
  anyPass,
)

const encodeConditions: (Where[]) => Matcher<*> = pipe(
  map(encodeWhere),
  allPass,
)

export default function encodeMatcher(query: QueryDescription): Matcher<element> {
  const { join, where } = query

  invariant(!join.length, `Queries with joins can't be encoded into a matcher`)

  return (encodeConditions(where): any)
}
</element>
github Nozbe / WatermelonDB / scripts / make.js View on Github external
/integrationTest/,
  /__mocks__/,
  /\.DS_Store/,
  /package\.json/,
]

const isNotIncludedInBuildPaths = value => !anymatch(DO_NOT_BUILD_PATHS, value)

const cleanFolder = dir => rimraf.sync(dir)

const takeFiles = pipe(
  prop('path'),
  both(endsWith('.js'), isNotIncludedInBuildPaths),
)

const takeModules = pipe(
  filter(takeFiles),
  map(prop('path')),
)

const removeSourcePath = replace(SOURCE_PATH, '')

const createModulePath = format => {
  const formatPathSegment = format === CJS_MODULES ? [] : [format]
  const modulePath = resolvePath(DIR_PATH, ...formatPathSegment)
  return replace(SOURCE_PATH, modulePath)
}

const createFolder = dir => mkdirp.sync(resolvePath(dir))

const babelTransform = (format, file) => {
  if (format === SRC_MODULES) {
github Nozbe / WatermelonDB / src / observation / encodeMatcher / index.js View on Github external
const typeEq = propEq('type')

const encodeWhere: Where =&gt; Matcher&lt;*&gt; = where =&gt;
  (cond([
    [typeEq('and'), encodeAnd],
    [typeEq('or'), encodeOr],
    [typeEq('where'), encodeWhereDescription],
  ]): any)(where)

const encodeAnd: And =&gt; Matcher&lt;*&gt; = pipe(
  prop('conditions'),
  map(encodeWhere),
  allPass,
)

const encodeOr: Or =&gt; Matcher&lt;*&gt; = pipe(
  prop('conditions'),
  map(encodeWhere),
  anyPass,
)

const encodeConditions: (Where[]) =&gt; Matcher&lt;*&gt; = pipe(
  map(encodeWhere),
  allPass,
)

export default function encodeMatcher(query: QueryDescription): Matcher<element> {
  const { join, where } = query

  invariant(!join.length, `Queries with joins can't be encoded into a matcher`)

  return (encodeConditions(where): any)</element>
github Nozbe / WatermelonDB / scripts / make.js View on Github external
const DO_NOT_BUILD_PATHS = [
  /__tests__/,
  /adapters\/__tests__/,
  /test\.js/,
  /integrationTest/,
  /__mocks__/,
  /\.DS_Store/,
  /package\.json/,
]

const isNotIncludedInBuildPaths = value => !anymatch(DO_NOT_BUILD_PATHS, value)

const cleanFolder = dir => rimraf.sync(dir)

const takeFiles = pipe(
  prop('path'),
  both(endsWith('.js'), isNotIncludedInBuildPaths),
)

const takeModules = pipe(
  filter(takeFiles),
  map(prop('path')),
)

const removeSourcePath = replace(SOURCE_PATH, '')

const createModulePath = format => {
  const formatPathSegment = format === CJS_MODULES ? [] : [format]
  const modulePath = resolvePath(DIR_PATH, ...formatPathSegment)
  return replace(SOURCE_PATH, modulePath)
}