当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript version.vMax方法代码示例

本文整理汇总了TypeScript中@statecraft/core.version.vMax方法的典型用法代码示例。如果您正苦于以下问题:TypeScript version.vMax方法的具体用法?TypeScript version.vMax怎么用?TypeScript version.vMax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@statecraft/core.version的用法示例。


在下文中一共展示了version.vMax方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

 await Promise.all(Array.from(query.q).map(async k => {
   const result = await tn.get(k)
   if (result) {
     const [stamp, value] = result
     if (value != null) results.set(k, opts.noDocs ? 1 : value)
     maxVersion = maxVersion ? versionLib.vMax(maxVersion, stamp) : stamp
   }
 }))
开发者ID:josephg,项目名称:statecraft,代码行数:8,代码来源:fdb.ts

示例2: bakeRange

 results = q.map((range) => {
   const staticRange = (query.type === I.QueryType.Range) ? bakeRange(dbTxn, range) : (range as I.StaticRange)
   const docs = [] // A map might be nicer.
   for (const [k, bytes] of rangeContentIter(dbTxn, staticRange)) {
     const [lastMod, doc] = decode(bytes)
     maxVersion = versionLib.vMax(maxVersion, lastMod)
     docs.push([k, doc])
   }
   return docs
 })
开发者ID:josephg,项目名称:statecraft,代码行数:10,代码来源:lmdb.ts

示例3: rawGet

  const getKVResults = (dbTxn: lmdb.Txn, query: Iterable<I.Key>, opts: I.FetchOpts, resultsOut: Map<I.Key, Val>) => {
    let maxVersion = V_ZERO

    for (let k of query) {
      const [lastMod, doc] = rawGet(dbTxn, k)
      if (doc != null) resultsOut.set(k, opts.noDocs ? 1 : doc)
      // Note we update maxVersion even if the document is null.
      maxVersion = versionLib.vMax(maxVersion, lastMod)
    }

    return maxVersion
  }
开发者ID:josephg,项目名称:statecraft,代码行数:12,代码来源:lmdb.ts

示例4: while

  const getAllResults = (dbTxn: lmdb.Txn, opts: I.FetchOpts, resultsOut: Map<I.Key, Val>) => {
    let maxVersion = V_ZERO
    const cursor = new lmdb.Cursor(dbTxn, dbi)
    let k = cursor.goToRange('\x02') // positioned right after config key
    while (k != null) {
      const bytes = cursor.getCurrentBinaryUnsafe()
      const [lastMod, doc] = decode(bytes)
      if (doc != null) resultsOut.set(k as string, opts.noDocs ? 1 : doc)
      maxVersion = versionLib.vMax(maxVersion, lastMod)

      k = cursor.goToNext()
    }
    cursor.close()

    return maxVersion
  }
开发者ID:josephg,项目名称:statecraft,代码行数:16,代码来源:lmdb.ts

示例5: pack

    const vs = await rawDb.doTn(async rawTn => {
      // This could be way cleaner.
      const tn = rawTn.scopedTo(rawDb.withValueEncoding({
        pack() {throw Error('Cannot write')},
        unpack: unpackVersion
      }))

      switch (query.type) {
        case I.QueryType.KV: {
          results = new Map<I.Key, Val>()
          await Promise.all(Array.from(query.q).map(async k => {
            const result = await tn.get(k)
            if (result) {
              const [stamp, value] = result
              if (value != null) results.set(k, opts.noDocs ? 1 : value)
              maxVersion = maxVersion ? versionLib.vMax(maxVersion, stamp) : stamp
            }
          }))
          break
        }

        case I.QueryType.AllKV: {
          // TODO: Make this work with larger databases (>5mb). Currently
          // this is trying to fetch the whole db contents using a single
          // txn, which will cause problems if the database is nontrivial.

          // There's a few strategies we could implement here:
          //
          // - Lean on fdb's MVCC implementation and create a series of
          //   transactions at the same version
          // - Use a series of transactions at incrementing versions, then
          //   fetch all the operations in the range and run catchup on any
          //   old data that was returned
          // - Implement maxDocs and force the client to implement the 
          //   iterative retry logic

          // Whatever we do should also work on static ranges.

          const resultsList = await tn.getRangeAll(START_KEY, END_KEY)
          results = new Map<I.Key, Val>()
          for (const [kbuf, [stamp, value]] of resultsList) {
            results.set(kbuf.toString('utf8'), opts.noDocs ? 1 : value)
            maxVersion = maxVersion ? versionLib.vMax(maxVersion, stamp) : stamp
          }
          break
        }

        case I.QueryType.StaticRange: {
          // const q = query.q as I.RangeQuery
          results = await Promise.all(query.q.map(async ({low, high, reverse}) => {
            // This is so clean. Its almost like I designed statecraft with
            // foundationdb in mind... ;)
            return (await tn.getRangeAll(staticKStoFDBSel(low), staticKStoFDBSel(high), {reverse: reverse}))
              .map(([kbuf, [stamp, value]]) => {
                maxVersion = maxVersion ? versionLib.vMax(maxVersion, stamp) : stamp
                return [kbuf.toString('utf8'), opts.noDocs ? 1 : value] as [I.Key, Val]
              }) //.filter(([k, v]) => v != undefined)
          }))
          break
        }

        case I.QueryType.Range: {
          // There's a bunch of ways I could write this, but a bit of copy + pasta is the simplest.
          // bakedQuery = {type: 'static range', q:[]}
          const baked: I.StaticRangeQuery = []
          results = await Promise.all(query.q.map(async ({low, high, reverse, limit}, i) => {
            // console.log('range results', (await tn.getRangeAll(kStoFDBSel(low), kStoFDBSel(high), {reverse: reverse, limit: limit})).length)
            const vals = (await tn.getRangeAll(kStoFDBSel(low), kStoFDBSel(high), {reverse: reverse, limit: limit}))
              .map(([kbuf, [stamp, value]]) => {
                maxVersion = maxVersion ? versionLib.vMax(maxVersion, stamp) : stamp
                // console.log('arr entry', [kbuf.toString('utf8'), value])
                return [kbuf.toString('utf8'), opts.noDocs ? 1 : value] as [I.Key, Val]
              }) //.filter(([k, v]) => v != undefined)

            // Note: These aren't tested thoroughly yet. Probably a bit broken.
            baked[i] = vals.length ? {
              low: {k: reverse ? vals[vals.length-1][0] : vals[0][0], isAfter: !!reverse},
              high: {k: reverse ? vals[0][0] : vals[vals.length-1][0], isAfter: !reverse},
              reverse
            } : {
              low: {k: low.k, isAfter: low.isAfter},
              high: {k: low.k, isAfter: low.isAfter},
              reverse
            }

            // console.log('range ->', vals)
            return vals
          }))
          // console.log('range query ->', results)
          bakedQuery = {type: I.QueryType.StaticRange, q: baked}
          break
        }

        default: throw new err.UnsupportedTypeError(`${query.type} not supported by fdb store`)
      }

      return rawTn.getVersionstampPrefixedValue(VERSION_KEY)
    })
开发者ID:josephg,项目名称:statecraft,代码行数:98,代码来源:fdb.ts


注:本文中的@statecraft/core.version.vMax方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。