How to use the rambdax.map 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 / sync / impl / fetchLocal.js View on Github external
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)
    return {
      // $FlowFixMe
      changes: extractChanges(changes),
      affectedRecords: extractAllAffectedRecords(changes),
    }
  }, 'sync-fetchLocalChanges')
}
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)
    return {
      // $FlowFixMe
github Nozbe / WatermelonDB / src / Schema / migrations / helpers.js View on Github external
// @flow

import { prop, pipe, map } from 'rambdax'
import { unnest } from '../../utils/fp'

import { type SchemaMigrations, type MigrationStep } from './index'
import { type SchemaVersion } from '../index'

const getAllSteps = pipe(
  map(prop('steps')),
  unnest,
)

export function stepsForMigration({
  migrations: schemaMigrations,
  fromVersion,
  toVersion,
}: $Exact<{
  migrations: SchemaMigrations,
  fromVersion: SchemaVersion,
  toVersion: SchemaVersion,
}>): ?(MigrationStep[]) {
  const { sortedMigrations, minVersion, maxVersion } = schemaMigrations

  // see if migrations in this range are available
  if (fromVersion < minVersion || toVersion > maxVersion) {
github Nozbe / WatermelonDB / src / adapters / sqlite / encodeUpdate / index.js View on Github external
// @flow

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

import type { TableName } from '../../../Schema'
import type { RawRecord } from '../../../RawRecord'
import type { SQL, SQLiteQuery, SQLiteArg } from '../index'

import encodeName from '../encodeName'

const encodeSetPlaceholders: RawRecord => SQL = pipe(
  keys,
  map(encodeName),
  map(key => `${key}=?`),
  join(', '),
)

const getArgs: RawRecord => SQLiteArg[] = raw =>
  pipe(
    values,
    append(raw.id), // for `where id is ?`
  )(raw)

export default function encodeUpdate(table: TableName, raw: RawRecord): SQLiteQuery {
  const sql = `update ${encodeName(table)} set ${encodeSetPlaceholders(raw)} where "id" is ?`
  const args = getArgs(raw)

  return [sql, args]
}
github Nozbe / WatermelonDB / scripts / make.js View on Github external
/\.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) {
    // no transform, just return source
    return fs.readFileSync(file)
github selfrefactor / useful-javascript-libraries / src / indexProve.js View on Github external
const allLinks = bookmarksContent
    .split('\n')
    .s(reject(includes('gist.')))
    .s(reject(includes('?tab')))
    .s(reject(includes('trending')))
    .s(filter(x => x.includes('github.com') || x.includes('npmjs')))

  const withCorrectLinks = await mapAsync(async x => {
    if (x.includes('github.com')) return x
    const url = await toGithubURL(x)

    return url
  }, allLinks)

  return withCorrectLinks.s(filter(Boolean)).s(
    map(x => {
      const replaced = replace(/(git:)|(ssh:)/, 'https:', x)

      return remove('git@', replaced)
    })
  )
}
github Nozbe / WatermelonDB / src / QueryDescription / index.js View on Github external
return {
    type: 'on',
    table,
    left: whereDescription.left,
    comparison: whereDescription.comparison,
  }
}

const syncStatusColumn = columnName('_status')
const getJoins: (Condition[]) => [On[], Where[]] = (partition(propEq('type', 'on')): any)
const whereNotDeleted = where(syncStatusColumn, notEq('deleted'))
const joinsWithoutDeleted = pipe(
  map(prop('table')),
  uniq,
  map(table => on(table, syncStatusColumn, notEq('deleted'))),
)

export function buildQueryDescription(conditions: Condition[]): QueryDescription {
  const [join, whereConditions] = getJoins(conditions)

  return { join, where: whereConditions }
}

export function queryWithoutDeleted(query: QueryDescription): QueryDescription {
  const { join, where: whereConditions } = query

  return {
    join: [...join, ...joinsWithoutDeleted(join)],
    where: [...whereConditions, whereNotDeleted],
  }
}
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 / observation / encodeMatcher / index.js View on Github external
return operator(left, right)
}

const typeEq = propEq('type')

const encodeWhere: Where => Matcher<*> = where =>
  (cond([
    [typeEq('and'), encodeAnd],
    [typeEq('or'), encodeOr],
    [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</element>
github Nozbe / WatermelonDB / src / adapters / lokijs / worker / encodeQuery / index.js View on Github external
const encodeJoins: (AssociationArgs[], On[]) => LokiJoin[] = (associations, on) => {
  const conditions = zipAssociationsConditions(associations, on)
  return map(([association, _on]) => encodeJoin(association, _on), conditions)
}