Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static create(options: Datastore.IOptions): Datastore {
let {schemas} = options;
// Throws an error for invalid schemas:
Private.validateSchemas(schemas);
let context = {
inTransaction: false,
transactionId: '',
version: 0,
storeId: options.id,
change: {},
patch: {},
};
let tables = new BPlusTree>(Private.recordCmp);
if (options.restoreState) {
// If passed state to restore, pass the intital state to recreate each
// table
let state = JSON.parse(options.restoreState);
tables.assign(map(schemas, s => {
return Table.recreate(s, context, state[s.id] || []);
}));
} else {
// Otherwise, simply create a new, empty table
tables.assign(map(schemas, s => {
return Table.create(s, context);
}));
}
return new Datastore(context, tables, options.adapter);
}
export
function setExceptionHandler(handler: ExceptionHandler): ExceptionHandler {
let old = exceptionHandler;
exceptionHandler = handler;
return old;
}
/**
* A type alias for a posted message pair.
*/
type PostedMessage = { handler: IMessageHandler | null, msg: Message | null };
/**
* The queue of posted message pairs.
*/
const messageQueue = new LinkedList();
/**
* A mapping of handler to array of installed message hooks.
*/
const messageHooks = new WeakMap>();
/**
* A set of message hook arrays which are pending cleanup.
*/
const dirtySet = new Set>();
/**
* The message loop exception handler.
*/
let exceptionHandler: ExceptionHandler = (err: Error) => {
console.error(err);
* Construct a new datastore table.
*
* @param schema - The schema for the table.
*
* @param context - The datastore context.
*/
private constructor(schema: S, context: Datastore.Context, records?: IterableOrArrayLike>) {
this.schema = schema;
this._context = context;
if (records) {
this._records.assign(records);
}
}
private _context: Datastore.Context;
private _records = new BPlusTree>(Private.recordCmp);
}
/**
* The namespace for the `Table` class statics.
*/
export
namespace Table {
/**
* A type alias for the table update type.
*/
export
type Update<s> = {
readonly [recordId: string]: Record.Update<s>;
};
</s></s>