Comparing version 6.0.23 to 6.0.24
@@ -713,6 +713,7 @@ const b4a = require('b4a') | ||
static async getUserData (core) { | ||
const viewName = await core.getUserData('autobase/view') | ||
const view = await core.getUserData('autobase/view') | ||
return { | ||
referrer: await core.getUserData('referrer'), | ||
view: viewName ? b4a.toString(viewName) : null | ||
view: (!view || view[0] !== 0) ? null : c.decode(messages.ViewRecord, view) | ||
} | ||
@@ -719,0 +720,0 @@ } |
@@ -9,2 +9,3 @@ const { EventEmitter } = require('events') | ||
const Signer = require('./signer') | ||
const { ViewRecord } = require('./messages') | ||
@@ -332,2 +333,3 @@ const { | ||
this.wakeupExtension = null | ||
this.migrated = null | ||
@@ -408,2 +410,4 @@ this.opts = opts | ||
if (swap) await prevOriginalCore.close() | ||
await this._ensureUserData(this.core, false) | ||
} | ||
@@ -488,3 +492,3 @@ | ||
await this._ensureUserData(this.originalCore) | ||
await this._ensureUserData(this.originalCore, false) | ||
@@ -498,5 +502,17 @@ this._updateCoreState() | ||
async _ensureUserData (core) { | ||
async _ensureUserData (core, force) { | ||
await core.setUserData('referrer', this.base.key) | ||
await core.setUserData('autobase/view', b4a.from(this.name)) | ||
let buf = await core.getUserData('autobase/view') | ||
if (buf && buf[0] !== 0) { // sniff for old record | ||
// old core, audit it real quick | ||
const corrections = await core.core.audit() | ||
if (corrections.blocks || corrections.tree) debugWarn('view', core.id, 'auto corrected itself', corrections) | ||
buf = null | ||
} | ||
const prev = !force && buf ? c.decode(ViewRecord, buf) : null | ||
if (prev && !this.migrated) this.migrated = prev.migrated | ||
await core.setUserData('autobase/view', c.encode(ViewRecord, { name: this.name, migrated: prev ? prev.migrated : this.migrated })) | ||
} | ||
@@ -773,6 +789,3 @@ | ||
async _migrateCurrentCore (next, length, indexers) { | ||
if (length === 0) { | ||
// can't sign zero length core, set userData as it won't be copied | ||
await this._ensureUserData(next) | ||
} else { | ||
if (length > 0) { | ||
const sourceLength = this.core.indexedLength | ||
@@ -795,2 +808,6 @@ | ||
// force update as we might have copied to old migrated pointer userdata | ||
this.migrated = this.core.key | ||
await this._ensureUserData(next, true) | ||
// todo: should core always be flushed to length? | ||
@@ -862,1 +879,5 @@ const batch = next.batch({ autoClose: false, session: true, checkout: length }) | ||
} | ||
function debugWarn (...msg) { // calls to this are ONLY allowed for soft assertions | ||
console.warn('[autobase]', ...msg) | ||
} |
@@ -101,2 +101,30 @@ const c = require('compact-encoding') | ||
const ViewRecord = { | ||
preencode (state, m) { | ||
c.uint.preencode(state, 0) // version | ||
c.string.preencode(state, m.name) | ||
c.uint.preencode(state, m.migrated ? 1 : 0) | ||
if (m.migrated) c.fixed32.preencode(state, m.migrated) | ||
}, | ||
encode (state, m) { | ||
c.uint.encode(state, 0) // version | ||
c.string.encode(state, m.name) | ||
c.uint.encode(state, m.migrated ? 1 : 0) | ||
if (m.migrated) c.fixed32.encode(state, m.migrated) | ||
}, | ||
decode (state) { | ||
const v = c.uint.decode(state) | ||
assert(v === 0, 'Unsupported version: ' + v) | ||
const name = c.string.decode(state) | ||
const flags = c.uint.decode(state) | ||
const migrated = (flags & 1) ? c.fixed32.decode(state) : null | ||
return { | ||
name, | ||
migrated | ||
} | ||
} | ||
} | ||
const Checkpoint = c.array({ | ||
@@ -427,2 +455,3 @@ preencode (state, idx) { | ||
BootRecord, | ||
ViewRecord, | ||
OplogMessage, | ||
@@ -429,0 +458,0 @@ Checkpoint, |
{ | ||
"name": "autobase", | ||
"version": "6.0.23", | ||
"version": "6.0.24", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
174406
4683