@phosphor/datastore
Advanced tools
Comparing version 0.7.2 to 0.7.3
@@ -158,2 +158,8 @@ import { IIterable, IIterator } from '@phosphor/algorithm'; | ||
/** | ||
* Serialize the state of the datastore to a string. | ||
* | ||
* @returns The serialized state. | ||
*/ | ||
toString(): string; | ||
/** | ||
* Create a new datastore. | ||
@@ -233,2 +239,6 @@ * | ||
transactionIdFactory?: TransactionIdFactory; | ||
/** | ||
* Initialize the state to a previously serialized one. | ||
*/ | ||
restoreState?: string; | ||
} | ||
@@ -235,0 +245,0 @@ /** |
@@ -85,5 +85,16 @@ "use strict"; | ||
var tables = new collections_1.BPlusTree(Private.recordCmp); | ||
tables.assign(algorithm_1.map(schemas, function (s) { | ||
return table_1.Table.create(s, context); | ||
})); | ||
if (options.restoreState) { | ||
// If passed state to restore, pass the intital state to recreate each | ||
// table | ||
var state_1 = JSON.parse(options.restoreState); | ||
tables.assign(algorithm_1.map(schemas, function (s) { | ||
return table_1.Table.recreate(s, context, state_1[s.id] || []); | ||
})); | ||
} | ||
else { | ||
// Otherwise, simply create a new, empty table | ||
tables.assign(algorithm_1.map(schemas, function (s) { | ||
return table_1.Table.create(s, context); | ||
})); | ||
} | ||
return new Datastore(context, tables, options.broadcastHandler); | ||
@@ -313,2 +324,12 @@ }; | ||
/** | ||
* Serialize the state of the datastore to a string. | ||
* | ||
* @returns The serialized state. | ||
*/ | ||
Datastore.prototype.toString = function () { | ||
return JSON.stringify(algorithm_1.toObject(algorithm_1.map(this, function (table) { | ||
return [table.schema.id, algorithm_1.toArray(table)]; | ||
}))); | ||
}; | ||
/** | ||
* Apply a transaction to the datastore. | ||
@@ -315,0 +336,0 @@ * |
@@ -0,0 +0,0 @@ import { ReadonlyJSONValue } from '@phosphor/coreutils'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ReadonlyJSONValue } from '@phosphor/coreutils'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export * from './datastore'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ReadonlyJSONValue } from '@phosphor/coreutils'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ReadonlyJSONValue } from '@phosphor/coreutils'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Schema } from './schema'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -0,0 +0,0 @@ import { ReadonlyJSONValue } from '@phosphor/coreutils'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { AnyField } from './field'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -1,2 +0,2 @@ | ||
import { IIterable, IIterator } from '@phosphor/algorithm'; | ||
import { IIterable, IIterator, IterableOrArrayLike } from '@phosphor/algorithm'; | ||
import { Datastore } from './datastore'; | ||
@@ -24,2 +24,14 @@ import { Record } from './record'; | ||
* | ||
* Create a new datastore table with a previously exported state. | ||
* | ||
* @param schema - The schema for the table. | ||
* | ||
* @param context - The datastore context. | ||
* | ||
* @returns A new datastore table. | ||
*/ | ||
static recreate<U extends Schema>(schema: U, context: Datastore.Context, records: IterableOrArrayLike<Record<U>>): Table<U>; | ||
/** | ||
* @internal | ||
* | ||
* Apply a patch to a datastore table. | ||
@@ -26,0 +38,0 @@ * |
@@ -34,6 +34,9 @@ "use strict"; | ||
*/ | ||
function Table(schema, context) { | ||
function Table(schema, context, records) { | ||
this._records = new collections_1.BPlusTree(Private.recordCmp); | ||
this.schema = schema; | ||
this._context = context; | ||
if (records) { | ||
this._records.assign(records); | ||
} | ||
} | ||
@@ -57,2 +60,16 @@ /** | ||
* | ||
* Create a new datastore table with a previously exported state. | ||
* | ||
* @param schema - The schema for the table. | ||
* | ||
* @param context - The datastore context. | ||
* | ||
* @returns A new datastore table. | ||
*/ | ||
Table.recreate = function (schema, context, records) { | ||
return new Table(schema, context, records); | ||
}; | ||
/** | ||
* @internal | ||
* | ||
* Apply a patch to a datastore table. | ||
@@ -59,0 +76,0 @@ * |
@@ -0,0 +0,0 @@ import { Field } from './field'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "@phosphor/datastore", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "PhosphorJS - DataStore", | ||
@@ -55,3 +55,3 @@ "homepage": "https://github.com/phosphorjs/phosphor", | ||
}, | ||
"gitHead": "7fdcefb4740fbd459c4f25b3c0b8641f94614de0" | ||
"gitHead": "57aee96800e0df2d7502d5f0b7ed8cf6b502063c" | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4063
0
137785