本文整理汇总了TypeScript中@statecraft/core.version类的典型用法代码示例。如果您正苦于以下问题:TypeScript version类的具体用法?TypeScript version怎么用?TypeScript version使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了version类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
const opwatcher = async () => {
try {
// running++
// await new Promise(resolve => setTimeout(resolve, 1000))
if (v0 == null) throw new Error('Inconsistent state - version key missing')
// console.log('initial version', v0)
while (!closed) {
const watch = await rawDb.getAndWatch(VERSION_KEY)
const {value: version, promise} = watch
if (version != null && !v0.equals(version)) {
// TODO: Probably should chunk this?
const ops = await opDb.getRangeAll(
keySelector.firstGreaterThan(v0),
keySelector.firstGreaterThan(version!)
)
// console.log('version', v0, version, ops)
const txns: I.TxnWithMeta<Val>[] = []
for (let i = 0; i < ops.length; i++) {
const [version, v] = ops[i]
const [op, meta] = v
// console.log('v', v0, version)
assert(versionLib.vCmp(v0, version) < 0)
txns.push({
txn: new Map(op),
meta,
versions: [version],
})
}
// console.log('subgroup', v0, '->', version, ops)
subGroup.onOp(0, v0, txns)
v0 = version
}
// If the store was closed between the top of the loop and this point
// (async, remember!) then we explicitly close now. We need to cancel
// the watch immediately because otherwise the node event loop would
// be held open.
if (closed) { watch.cancel(); break }
else cancelWatch = watch.cancel.bind(watch)
// This promise should resolve to false when the watch was cancelled.
// TODO: Check what happens when the database connection is
// interrupted.
await promise
}
} catch (e) {
console.error('Unhandled error in FDB operation watch process', e.message, e.stack)
// Throw to the global exception handler, which will normally crash the process.
process.emit('uncaughtException', e)
}
// running--
}
示例2: bitHas
;(async () => {
const qt = store.storeInfo.capabilities.queryTypes
const q: I.Query = bitHas(qt, I.QueryType.AllKV) ? {type: I.QueryType.AllKV, q:true}
: bitHas(qt, I.QueryType.StaticRange) ? {type: I.QueryType.StaticRange, q: [{low: sel(''), high: sel('\xff')}]}
// : qt.has('static range') ? {type: 'static range', q: [{low: sel('mdraw/'), high: sel('mdraw/~')}]}
: {type: I.QueryType.Single, q:true}
const rtype = queryTypes[q.type].resultType
// I would love to just use subResults here, but
for await (const {raw, results, versions} of subResults(rtype.type!, store.subscribe(q))) {
// console.log('results', results)
state.data = rtype.type! === I.ResultType.Range
? new Map(results[0])
: results
// console.log('val', results, state.data, versions)
const v = version.vRangeTo(versions)
if (raw.replace) {
rtype.mapReplace<any, void>(raw.replace.with, (val, k) => {
pushOp(k, {v, replace: val})
})
}
raw.txns.forEach(({txn}) => {
rtype.mapTxn<any, void>(txn, (op, k) => {
pushOp(k, {v, op})
return null as any as I.Op<void> // It'd be better to have a forEach .. .eh.
})
})
state.versions = v
emitter.emit('render')
}
})()
示例3:
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
}
}))
示例4: 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
})
示例5: 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
}
示例6: 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
}
示例7: Error
const lmdbStore = <Val>(inner: I.Store<Val>, location: string): Promise<I.Store<Val>> => {
const env = new lmdb.Env()
// console.log('inner', inner)
if (inner.storeInfo.sources.length !== 1) {
// It would be trivial though.
throw new Error('LMDB store with multiple sources not implemented')
}
const source: I.Source = inner.storeInfo.sources[0]
// Check that the directory exists.
try { fs.mkdirSync(location) }
catch(e) { if (e.code !== 'EEXIST') throw e }
env.open({path: location, maxDbs: 2, noTls: true})
const dbi = env.openDbi({name: null, create: true})
// const configdb = env.openDbi({name: 'config', create: true})
// Note: I'm using 'native' Prozess version numbers, so the local store
// starts at version 0 and event 1 moves us to version 1.
let version: I.Version = new Uint8Array()
const setVersion = (txn: lmdb.Txn, v: I.Version) => {
version = v
txn.putBinary(dbi, VERSION_KEY, Buffer.from(version))
}
// Ok, first do catchup.
{
const txn = env.beginTxn()
const configBytes = txn.getBinary(dbi, CONFIG_KEY)
if (configBytes == null) {
// console.log('Database was created - no config!')
txn.putBinary(dbi, CONFIG_KEY, msgpack.encode({sc_ver: 1, source}))
setVersion(txn, new Uint8Array(8))
} else {
const {sc_ver, source:dbSource} = msgpack.decode(configBytes)
assert(sc_ver === 1, 'LDMB database was set up using invalid or old statecraft version.')
assert(dbSource === source, `LDMB database at ${location} is invalid. Delete and restart`)
version = new Uint8Array(txn.getBinary(dbi, VERSION_KEY))
}
txn.commit()
}
debug('Opened database at version', version)
const ready = resolvable()
// const ready = inner.start!([version])
// TODO: Generate these based on the opstore.
const capabilities = {
queryTypes: bitSet(I.QueryType.AllKV, I.QueryType.KV, I.QueryType.StaticRange, I.QueryType.Range),
mutationTypes: bitSet(I.ResultType.KV),
}
const decode = (bytes: Buffer | null): [Uint8Array, any] => {
if (bytes == null) return [V_ZERO, null]
else {
const [vBuf, data] = msgpack.decode(bytes)
return [new Uint8Array(vBuf), data]
}
}
const rawGet = (txn: lmdb.Txn, k: I.Key) => decode(txn.getBinaryUnsafe(dbi, k))
// TODO: Probably cleaner to write this as iterators? This is simpler / more
// understandable though.
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
}
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
}
const setCursor = (cursor: lmdb.Cursor, sel: I.StaticKeySelector) => {
let {k, isAfter} = sel
//.........这里部分代码省略.........