diff --git a/CHANGES.md b/CHANGES.md index 2023641..7fa6905 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,44 @@ # CHANGES +## Filter by object version (unreleased) + +- API addition: Allow supplying objects to `filter()` + +## Schema version (unreleased) + +- API change (breaking): Will delete unused indexes by default; set a new + property `clearUnusedIndexes` if not desired (when using `schema` or + `whole`-type `schema` objects within `schemas`) +- API addition: Support a `clearUnusedStores` option property to + conditionally avoid deleting old stores (when using `schema` or + `whole`-type `schema` objects within `schemas`). +- API addition: Support a `schemas` object. Its keys are the schema versions + and its values are--if `schemaType` is `"mixed"` (the default, unless + `schema` is used, in which case, it will be treated as `"whole"`)--arrays + containing an object whose single key is the schema type for that version + (either `"idb-schema"`, `"merge"`, or `"whole"`) and whose values are + `schema` objects whose structure differs depending on the schema type. + If `schemaType` is not `"mixed"` (`"whole"`, `"idb-schema"`, or `"merge"`), + each `schemas` key will be a schema version and its value a single + "schema object" (or, in the case of `"idb-schema"`, the function that + will be passed the `IdbSchema` instance). Where an object is expected, + one may also use a function which resolves to a valid object. +- API addition: Support `moveFrom` and `copyFrom` for moving/copying a store + wholesale to another new store. +- API addition: Support a `schemaBuilder` callback which accepts an + [idb-schema](http://github.com/treojs/idb-schema) object for incremental, + versioned schema building and whose `addCallback` method will be + passed an enhanced `upgradeneeded` event object that will be passed a + `Server` object as its second argument for making db.js-style queries + (e.g., to modify store content). This option differs from `schemas` used + with `idb-schema` in that it adds the versions as well as stores and + indexes programmatically. Addresses issues #84/#109 +- API addition: If there is an upgrade problem, one can use a `retry` method + on the error event object +- Fix: Add Promise rejection for `update()`. +- Documentation: Update `version` to take `schemaBuilder` into account + (and document `schemaBuilder`). + ## Unreleased - Breaking change: Change `db.cmp()` to return a `Promise` to deliver @@ -10,7 +49,8 @@ - Deprecated: on `schema.indexes`, in place of the index `key` property, `keyPath` should be used. - API fix: Disallow `map` on itself (only one will be used anyways); -- API addition: Add Server aliases, `put` and `delete`. +- API addition: Add Server aliases, `put` and `delete` (or `del`) and `db.del` + as a `db.delete` alias. - API change: Allow `desc`, `distinct`, `filter`, `keys`, `map`, `modify` on `limit`; - API change: Allow `limit` on `distinct`, `desc`, `keys`; @@ -18,7 +58,7 @@ - API change: Allow `add`/`update` items to be of any value including `undefined` or `null` - API change: Allow Mongoifying of `add`/`update`/`remove` keys -- API change: Disallow key in `count()` if null; +- API change: Disallow key in `count()` if `null`; - Cross-browser support: Auto-wrap user-supplied `Server.error()` and `Server.addEventListener('error', ...)` handlers with `preventDefault` so as to avoid hard `ConstraintError` aborts in Firefox. @@ -26,7 +66,7 @@ `onupgradeneeded` errors will not become reported in Firefox (though it will occur regardless) - Cross-browser support (minor): wrap `delete` `onblocked` event's - `newVersion` (=null) with `Proxy` but avoid using using `Proxy` + `newVersion` (=`null`) with `Proxy` but avoid using using `Proxy` if not present for sake of PhantomJS or older browsers (Firefox); could not wrap `oldVersion`, however. - Fix: Ensure there is a promise rejection for a bad schema callback, diff --git a/Gruntfile.js b/Gruntfile.js index fd4704d..6f1711e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -76,7 +76,7 @@ module.exports = function (grunt) { }, eslint: { - target: ['src/db.js', 'src/test-worker.js'] + target: ['src/db.js', 'src/test-worker.js', 'src/idb-import'] }, babel: { @@ -86,7 +86,8 @@ module.exports = function (grunt) { dist: { files: { 'dist/db.js': 'src/db.js', - 'tests/test-worker.js': 'src/test-worker.js' + 'tests/test-worker.js': 'src/test-worker.js', + 'dist/idb-import.js': 'src/idb-import.js' } } }, @@ -101,6 +102,11 @@ module.exports = function (grunt) { standalone: 'db' } } + }, + dest: { + files: { + 'dist/idb-import.js': 'dist/idb-import.js' + } } }, @@ -117,6 +123,14 @@ module.exports = function (grunt) { 'dist/db.min.js': ['dist/db.js'] } }, + idbImport: { + options: { + sourceMapIn: 'dist/idb-import.js.map' // input sourcemap from a previous compilation + }, + files: { + 'dist/idb-import.min.js': ['dist/idb-import.js'] + } + }, testworker: { options: { sourceMapIn: 'tests/test-worker.js.map' // input sourcemap from a previous compilation diff --git a/README.md b/README.md index dc119db..17aab1b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ db.open({ version: 1, schema: { people: { + // Optionally add parameters for creating the object store key: {keyPath: 'id', autoIncrement: true}, // Optionally add indexes indexes: { @@ -53,25 +54,84 @@ Note that `open()` takes an options object with the following properties: - *version* - The current version of the database to open. Should be an integer. You can start with `1`. You must increase the `version` if updating the schema or otherwise the `schema` property will have no effect. +If the `schemaBuilder` property is used, `version` (if present) cannot be +greater than the highest version built by `schemaBuilder`. - *server* - The name of this server. Any subsequent attempt to open a server with this name (and with the current version) will reuse the already opened connection (unless it has been closed). - *schema* - Expects an object, or, if a function is supplied, a schema -object should be returned). A schema object optionally has store names as +object should be returned). A `schema` object optionally has store names as keys (these stores will be auto-created if not yet added and modified -otherwise). The values of these schema objects should be objects, optionally +otherwise). The values of these store objects should be objects, optionally with the property "key" and/or "indexes". The "key" property, if present, should contain valid [createObjectStore](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/createObjectStore) -parameters (`keyPath` or `autoIncrement`). The "indexes" property should +parameters (`keyPath` or `autoIncrement`)--or one may express `keyPath` and +`autoIncrement` directly inside the store object. The "indexes" property should contain an object whose keys are the desired index keys and whose values are objects which can include the optional parameters and values available to [createIndex](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex) (`unique`, `multiEntry`, and, for Firefox-only, `locale`). Note that the `keyPath` of the index will be set to the supplied index key, or if present, a `keyPath` property on the provided parameter object. Note also that when a schema is supplied for a new version, any object stores not present on -the schema object will be deleted. +the schema object will be deleted unless `clearUnusedStores` is set to `false` +(the latter may be necessary if you may be sharing the domain with applications +building their own stores) and any unused indexes will also be removed unless +`clearUnusedIndexes` is set to `false`. One may also add a `moveFrom` or +`copyFrom` property to the store object to point to the name of a preexisting +store which one wishes to rename or copy. + +- *schemas* - `schemas` is keyed by schema version and its values are--if +`schemaType` is `"mixed"` (the default, unless `schema` is used, in which +case, its default type will be `"whole"`)--arrays containing an object whose +single key is the schema type for that version (either `"idb-schema"`, +`"merge"`, or `"whole"`) and whose values are `schema` objects whose structure +differs depending on the schema type. If `schemaType` is not `"mixed"` +(`"whole"`, `"idb-schema"`, or `"merge"`), each `schemas` key will be a schema +version and its value a single "schema object" (or, in the case of +`"idb-schema"`, the function that will be passed the `IdbSchema` instance), +with no need to indicate type on an object. Where an object or array is +expected, one may also use a function which resolves to a valid object or +array. So, if the user was last on version 2 and now it is version 4, they will +first be brought to version 3 and then 4, while, if they are already on version +4, no further upgrading will occur but the connection will open. See the +section on "schema types" for more details on the behavior of the different +schema types. + +- *schemaType* - Determines how `schemas` will be interpreted. Possible values +are `"whole"`, `"power"`, `"merge"`, or `"mixed"`. The default is `"mixed"`. +See the discussion under `schemas`. Note that if `schema` is used, it will +behave as `"whole"`. + +- *schemaBuilder* - While the use of `schema` works more simply by deleting +whatever stores existed before which no longer exist in `schema` and creating +those which do not yet exist, `schemaBuilder` is a callback which will be +passed an [idb-schema](https://github.com/treojs/idb-schema) +object which allows (as with the plural `schemas` property) for specifying +an incremental path to upgrading a schema (as could be required if your +users might have already opened say version 1 of your database and you +have already made two upgrades to have a version 3 but the changes you have +for version 2 must first be applied). Besides precise control of versioning +(via `version()`) and, as with `schema`, the creating or deleting stores +and indexes (via `addStore`, `delStore`, `getStore` (then `addIndex`, and +`delIndex`)), `schemaBuilder` also offers `stores` for introspection on the +existing stores and, more importantly, `addCallback` which is passed the +`upgradeneeded` event and can be used for making queries such as modifying +store values. See the [idb-schema](https://github.com/treojs/idb-schema) +documentation for full details. + +Note that the event object which is passed as the first argument to +`addCallback` is the underlying IndexedDB event, but in `db.js`, we call +these callbacks with a second argument which is the db.js `Server` object, +allowing for db.js-style queries during the `upgradeneeded` event as +desired (e.g., +`.addCallback(function (e, server) {server.query(table).all().modify(...)});`) +with the exception that `close` is disallowed as this should not occur within +the `upgradeneeded` event. Note, however, that due to limitations with Promises +and the nature of the IndexedDB specification with regard to this event, +you may need to avoid use of Promises within these callbacks (though you can +run `addCallback` multiple times). A connection is intended to be persisted, and you can perform multiple operations while it's kept open. @@ -90,7 +150,10 @@ db.open({ // ... }).catch(function (err) { if (err.type === 'blocked') { - oldConnection.close(); + oldConnection.close(); // `versionchange` handlers set up for earlier + // versions (e.g., in other tabs) should have + // ideally anticipated this need already (see + // comment at end of this sample). return err.resume; } // Handle other errors here @@ -106,6 +169,170 @@ db.open({ Check out the `/tests/specs` folder for more examples. +## Schema types + +Schemas can be expressed as one of the following types: `"whole"`, +`"idb-schema"`, `"merge"`, or `"mixed"`. + +If `schema` is used, the default will be `"whole"`. + +If `schemas` is used, the default will be `"mixed"`, but this can +be overridden with the `schemaType` property. + +### "whole" type schemas + +The `whole` type merge (the default for `schema`, but not for `schemas`) +is to delete all unreferenced stores or indexes, creating anew those +stores or indexes which did not exist previously, recreating those +stores or indexes with differences). Unless the options `clearUnusedStores` +or `clearUnusedIndexes` are set to `false`, unused stores and indexes +will also be deleted. + +The advantage of this approach is that each "version" will give a clear +snapshot of all stores and indexes currently in use at the time. The +disadvantage is the same--namely, that it may end up being bulkier than +the other types which only indicate differences from the previous version. + +The following will add a version 1 of the schema with a `person` store, +and add a version 2 of the schema, containing a `people` +store which begins with the data contained in the `person` store (though +deleting the `person` store after migrated), but overriding the `keyPath` +and `autoIncrement` information with its own and adding two indexes. +The store `addresses` will be preserved since it is re-expressed in version 2, +but `oldStore` will be removed since it is not re-expressed. + +```js +schemaType: 'whole', +schemas: { + 1: { + oldStore: {}, + person: {}, + addresses: {}, + phoneNumbers: {} + }, + 2: { + addresses: {}, + phoneNumbers: {}, + people: { + moveFrom: 'person', + // Optionally add parameters for creating the object store + keyPath: 'id', + autoIncrement: true, + // Optionally add indexes + indexes: { + firstName: {}, + answer: {unique: true} + } + } + } +} +``` + +### "merge" type schemas + +The `merge` type schema allows one to exclusively indicate changes between +versions without needing to redundantly indicate stores or indexes added +from previous versions. + +`merge` type schemas behave similarly to [JSON Merge Patch](https://tools.ietf.org/html/rfc7396) +in allowing one to re-express those parts of the JSON structure that one +wishes to change, but with the enhancement that instead of overriding `null` +for deletions (and preventing it from being used as a value), the NUL string +`"\0"` will indicate deletions (if one wishes to add a value which actually +begins with NUL, one should supply an extra NUL character at the beginning +of the string). + +One could use the `merge` type to implement the example shown under the `whole` +type section in the following manner: + +```js +schemaType: 'merge', +schemas: { + 1: { + oldStore: {}, + person: {}, + addresses: {}, + phoneNumbers: {} + }, + 2: { + oldStore: '\0', + people: { + moveFrom: 'person', + // Optionally add parameters for creating the object store + keyPath: 'id', + autoIncrement: true, + // Optionally add indexes + indexes: { + firstName: {}, + answer: {unique: true} + } + } + } +} +``` + +### "idb-schema" type schemas + +This type of schema allows for sophisticated programmatic changes +by use of `idb-schema`'s '`addEarlyCallback` and `addCallback` and +other methods. One could use the `idb-schema` type to implement the +example shown under the `whole` type section in the following manner: + +```js +schemaType: 'idb-schema', +schemas: { + 1: function (idbschema) { + idbschema.addStore('oldStore').addStore('person').addStore('addresses').addStore('phoneNumbers'); + }, + 2: function (idbschema) { + idbschema.delStore('oldStore').renameStore('person', 'people', {keyPath: 'id', autoIncrement: true}) + .addIndex('firstName', 'firstName') + .addIndex('answer', 'answer', {unique: true}); + } +} +``` + +(Note that using the `schemaBuilder` function would behave similarly, except +that the versions would also need to be built programmatically (via calls to +`version()`).) + +### "mixed" type schemas + +The `mixed` type is the default type for `schemas` (but not for `schema`). It +adds a little verbosity but allows you to combine any of the types across and +even within a version. + +One could use the `mixed` type to implement the example shown under +the `whole` type section in such as the following manner: + +```js +schemas: { + 1: [ + {'whole': { + addresses: {}, + phoneNumbers: {} + }}, + {'idb-schema': function (idbschema) { + idbschema.addStore('oldStore').addStore('person'); + }} + ], + 2: [{'merge': { + oldStore: '\0', + people: { + moveFrom: 'person', + // Optionally add parameters for creating the object store + keyPath: 'id', + autoIncrement: true, + // Optionally add indexes + indexes: { + firstName: {}, + answer: {unique: true} + } + } + }}] +} +``` + ## General server/store methods Note that by default the methods below (not including `close`, @@ -267,6 +494,17 @@ server.people.query() }); ``` +###### Filter with object + +```js +server.people.query() + .filter({firstName: 'Aaron', lastName: 'Powell'}) + .execute() + .then(function (results) { + // do something with the results + }); +``` + ###### Filter with function ```js @@ -293,7 +531,7 @@ server.people }); ``` -##### Querying with ranges +##### Querying with ranges/keys All ranges supported by `IDBKeyRange` can be used (`only`, `bound`, `lowerBound`, `upperBound`). @@ -336,7 +574,6 @@ your store with an array `keyPath` (and optionally with an index `keyPath`). ```js - // The definition: schema: { people: { @@ -353,10 +590,11 @@ schema: { } } -// ...elsewhere... +// ...elsewhere to add the data... +s.people.add({lastName: 'Zamir', firstName: 'Brett'}); -// The query: -s.test.query('name') +// Then later, the query: +s.people.query('name') .only(['Zamir', 'Brett']) .execute() .then(function (results) { @@ -364,6 +602,36 @@ s.test.query('name') }); ``` +Nested (dot-separated) key paths (with optional index) +may also be queried: + +```js +// The definition: +schema: { + people: { + key: { + keyPath: 'person.name.lastName' + }, + indexes: { + personName: { + keyPath: 'person.name.lastName' + } + } + } +} + +// ...elsewhere to add the data... +s.people.add({person: {name: {lastName: 'Zamir', firstName: 'Brett'}}}); + +// Then later, the query: +s.people.query('personName') + .only('Zamir') + .execute() + .then(function (results) { + // do something with the results + }); +``` + ##### Limiting cursor range Unlike key ranges which filter by the range of present values, @@ -518,7 +786,8 @@ server.profiles.query('name') `modify` changes will be seen by any `map` functions. `modify` can be used after: `all`, `filter`, ranges (`range`, `only`, -`bound`, `upperBound`, and `lowerBound`), `desc`, `distinct`, and `map`. +`bound`, `upperBound`, and `lowerBound`), `desc`, `distinct`, `limit`, +and `map`. ## Other server methods @@ -602,6 +871,8 @@ db.delete(dbName).catch(function (err) { See the documentation on `open` for more on such recovery from blocking connections. +`del` is also available as an alias of `delete`. + ## Comparing two keys Returns `1` if the first key is greater than the second, `-1` if the first diff --git a/dist/db.js b/dist/db.js index 607dad5..2ec85a8 100644 --- a/dist/db.js +++ b/dist/db.js @@ -5,27 +5,36 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = [ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +var _idbImport = require('./idb-import'); + +var _idbImport2 = _interopRequireDefault(_idbImport); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } (function (local) { 'use strict'; - var IDBKeyRange = local.IDBKeyRange || local.webkitIDBKeyRange; - var transactionModes = { - readonly: 'readonly', - readwrite: 'readwrite' - }; var hasOwn = Object.prototype.hasOwnProperty; - var defaultMapper = function defaultMapper(x) { - return x; - }; var indexedDB = local.indexedDB || local.webkitIndexedDB || local.mozIndexedDB || local.oIndexedDB || local.msIndexedDB || local.shimIndexedDB || function () { throw new Error('IndexedDB required'); }(); + var IDBKeyRange = local.IDBKeyRange || local.webkitIDBKeyRange; - var dbCache = {}; + var defaultMapper = function defaultMapper(x) { + return x; + }; var serverEvents = ['abort', 'error', 'versionchange']; + var transactionModes = { + readonly: 'readonly', + readwrite: 'readwrite' + }; + + var dbCache = {}; function isObject(item) { return item && (typeof item === 'undefined' ? 'undefined' : _typeof(item)) === 'object'; @@ -90,13 +99,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr var runQuery = function runQuery(type, args, cursorType, direction, limitRange, filters, mapper) { return new Promise(function (resolve, reject) { - var keyRange = void 0; - try { - keyRange = type ? IDBKeyRange[type].apply(IDBKeyRange, _toConsumableArray(args)) : null; - } catch (e) { - reject(e); - return; - } + var keyRange = type ? IDBKeyRange[type].apply(IDBKeyRange, _toConsumableArray(args)) : null; // May throw filters = filters || []; limitRange = limitRange || null; @@ -154,44 +157,36 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr var result = 'value' in cursor ? cursor.value : cursor.key; try { + // We must manually catch for this promise as we are within an async event function filters.forEach(function (filter) { - if (typeof filter[0] === 'function') { - matchFilter = matchFilter && filter[0](result); + var propObj = filter[0]; + if (typeof propObj === 'function') { + matchFilter = matchFilter && propObj(result); // May throw with filter on non-object } else { - matchFilter = matchFilter && result[filter[0]] === filter[1]; - } + if (!propObj || (typeof propObj === 'undefined' ? 'undefined' : _typeof(propObj)) !== 'object') { + propObj = _defineProperty({}, propObj, filter[1]); + } + Object.keys(propObj).forEach(function (prop) { + matchFilter = matchFilter && result[prop] === propObj[prop]; // May throw with error in filter function + }); + } }); + + if (matchFilter) { + counter++; + // If we're doing a modify, run it now + if (modifyObj) { + result = modifyRecord(result); // May throw + cursor.update(result); // May throw as `result` should only be a "structured clone"-able object + } + results.push(mapper(result)); // May throw + } } catch (err) { - // Could be filter on non-object or error in filter function reject(err); return { v: void 0 }; } - - if (matchFilter) { - counter++; - // If we're doing a modify, run it now - if (modifyObj) { - try { - result = modifyRecord(result); - cursor.update(result); // `result` should only be a "structured clone"-able object - } catch (err) { - reject(err); - return { - v: void 0 - }; - } - } - try { - results.push(mapper(result)); - } catch (err) { - reject(err); - return { - v: void 0 - }; - } - } cursor.continue(); }(); @@ -221,23 +216,12 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr var count = function count() { direction = null; cursorType = 'count'; - - return { - execute: execute - }; + return { execute: execute }; }; var keys = function keys() { cursorType = 'openKeyCursor'; - - return { - desc: desc, - distinct: distinct, - execute: execute, - filter: filter, - limit: limit, - map: map - }; + return { desc: desc, distinct: distinct, execute: execute, filter: filter, limit: limit, map: map }; }; var limit = function limit(start, end) { @@ -245,94 +229,35 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr error = limitRange.some(function (val) { return typeof val !== 'number'; }) ? new Error('limit() arguments must be numeric') : error; - - return { - desc: desc, - distinct: distinct, - filter: filter, - keys: keys, - execute: execute, - map: map, - modify: modify - }; + return { desc: desc, distinct: distinct, filter: filter, keys: keys, execute: execute, map: map, modify: modify }; }; var filter = function filter(prop, val) { filters.push([prop, val]); - - return { - desc: desc, - distinct: distinct, - execute: execute, - filter: filter, - keys: keys, - limit: limit, - map: map, - modify: modify - }; + return { desc: desc, distinct: distinct, execute: execute, filter: filter, keys: keys, limit: limit, map: map, modify: modify }; }; var desc = function desc() { direction = 'prev'; - - return { - distinct: distinct, - execute: execute, - filter: filter, - keys: keys, - limit: limit, - map: map, - modify: modify - }; + return { distinct: distinct, execute: execute, filter: filter, keys: keys, limit: limit, map: map, modify: modify }; }; var distinct = function distinct() { unique = true; - return { - count: count, - desc: desc, - execute: execute, - filter: filter, - keys: keys, - limit: limit, - map: map, - modify: modify - }; + return { count: count, desc: desc, execute: execute, filter: filter, keys: keys, limit: limit, map: map, modify: modify }; }; var modify = function modify(update) { modifyObj = update && (typeof update === 'undefined' ? 'undefined' : _typeof(update)) === 'object' ? update : null; - return { - execute: execute - }; + return { execute: execute }; }; var map = function map(fn) { mapper = fn; - - return { - count: count, - desc: desc, - distinct: distinct, - execute: execute, - filter: filter, - keys: keys, - limit: limit, - modify: modify - }; + return { count: count, desc: desc, distinct: distinct, execute: execute, filter: filter, keys: keys, limit: limit, modify: modify }; }; - return { - count: count, - desc: desc, - distinct: distinct, - execute: execute, - filter: filter, - keys: keys, - limit: limit, - map: map, - modify: modify - }; + return { count: count, desc: desc, distinct: distinct, execute: execute, filter: filter, keys: keys, limit: limit, map: map, modify: modify }; }; ['only', 'bound', 'upperBound', 'lowerBound'].forEach(function (name) { @@ -362,6 +287,23 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr }; }; + var setupTransactionAndStore = function setupTransactionAndStore(db, table, records, resolve, reject, readonly) { + var transaction = db.transaction(table, readonly ? transactionModes.readonly : transactionModes.readwrite); + transaction.onerror = function (e) { + // prevent throwing aborting (hard) + // https://bugzilla.mozilla.org/show_bug.cgi?id=872873 + e.preventDefault(); + reject(e); + }; + transaction.onabort = function (e) { + return reject(e); + }; + transaction.oncomplete = function () { + return resolve(records); + }; + return transaction.objectStore(table); + }; + var Server = function Server(db, name, version, noServerMethods) { var _this2 = this; @@ -394,21 +336,8 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr return records.concat(aip); }, []); - var transaction = db.transaction(table, transactionModes.readwrite); - transaction.onerror = function (e) { - // prevent throwing a ConstraintError and aborting (hard) - // https://bugzilla.mozilla.org/show_bug.cgi?id=872873 - e.preventDefault(); - reject(e); - }; - transaction.onabort = function (e) { - return reject(e); - }; - transaction.oncomplete = function () { - return resolve(records); - }; + var store = setupTransactionAndStore(db, table, records, resolve, reject); - var store = transaction.objectStore(table); records.some(function (record) { var req = void 0, key = void 0; @@ -416,25 +345,15 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr key = record.key; record = record.item; if (key != null) { - try { - key = mongoifyKey(key); - } catch (e) { - reject(e); - return true; - } + key = mongoifyKey(key); // May throw } } - try { - // Safe to add since in readwrite - if (key != null) { - req = store.add(record, key); - } else { - req = store.add(record); - } - } catch (e) { - reject(e); - return true; + // Safe to add since in readwrite, but may still throw + if (key != null) { + req = store.add(record, key); + } else { + req = store.add(record); } req.onsuccess = function (e) { @@ -473,21 +392,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr return records.concat(aip); }, []); - var transaction = db.transaction(table, transactionModes.readwrite); - transaction.onerror = function (e) { - // prevent throwing aborting (hard) - // https://bugzilla.mozilla.org/show_bug.cgi?id=872873 - e.preventDefault(); - reject(e); - }; - transaction.onabort = function (e) { - return reject(e); - }; - transaction.oncomplete = function () { - return resolve(records); - }; - - var store = transaction.objectStore(table); + var store = setupTransactionAndStore(db, table, records, resolve, reject); records.some(function (record) { var req = void 0, @@ -496,24 +401,14 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr key = record.key; record = record.item; if (key != null) { - try { - key = mongoifyKey(key); - } catch (e) { - reject(e); - return true; - } + key = mongoifyKey(key); // May throw } } - try { - // These can throw DataError, e.g., if function passed in - if (key != null) { - req = store.put(record, key); - } else { - req = store.put(record); - } - } catch (err) { - reject(err); - return true; + // These can throw DataError, e.g., if function passed in + if (key != null) { + req = store.put(record, key); + } else { + req = store.put(record); } req.onsuccess = function (e) { @@ -547,37 +442,15 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr reject(new Error('Database has been closed')); return; } - try { - key = mongoifyKey(key); - } catch (e) { - reject(e); - return; - } + key = mongoifyKey(key); // May throw - var transaction = db.transaction(table, transactionModes.readwrite); - transaction.onerror = function (e) { - // prevent throwing and aborting (hard) - // https://bugzilla.mozilla.org/show_bug.cgi?id=872873 - e.preventDefault(); - reject(e); - }; - transaction.onabort = function (e) { - return reject(e); - }; - transaction.oncomplete = function () { - return resolve(key); - }; + var store = setupTransactionAndStore(db, table, key, resolve, reject); - var store = transaction.objectStore(table); - try { - store.delete(key); - } catch (err) { - reject(err); - } + store.delete(key); // May throw }); }; - this.delete = function () { + this.del = this.delete = function () { return this.remove.apply(this, arguments); }; @@ -587,18 +460,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr reject(new Error('Database has been closed')); return; } - var transaction = db.transaction(table, transactionModes.readwrite); - transaction.onerror = function (e) { - return reject(e); - }; - transaction.onabort = function (e) { - return reject(e); - }; - transaction.oncomplete = function () { - return resolve(); - }; - - var store = transaction.objectStore(table); + var store = setupTransactionAndStore(db, table, undefined, resolve, reject); store.clear(); }); }; @@ -609,9 +471,9 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr reject(new Error('Database has been closed')); return; } - db.close(); closed = true; delete dbCache[name][version]; + db.close(); resolve(); }); }; @@ -622,32 +484,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr reject(new Error('Database has been closed')); return; } - try { - key = mongoifyKey(key); - } catch (e) { - reject(e); - return; - } - - var transaction = db.transaction(table); - transaction.onerror = function (e) { - // prevent throwing and aborting (hard) - // https://bugzilla.mozilla.org/show_bug.cgi?id=872873 - e.preventDefault(); - reject(e); - }; - transaction.onabort = function (e) { - return reject(e); - }; + key = mongoifyKey(key); // May throw - var store = transaction.objectStore(table); + var store = setupTransactionAndStore(db, table, undefined, resolve, reject, true); - var req = void 0; - try { - req = store.get(key); - } catch (err) { - reject(err); - } + var req = store.get(key); req.onsuccess = function (e) { return resolve(e.target.result); }; @@ -660,31 +501,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr reject(new Error('Database has been closed')); return; } - try { - key = mongoifyKey(key); - } catch (e) { - reject(e); - return; - } + key = mongoifyKey(key); // May throw - var transaction = db.transaction(table); - transaction.onerror = function (e) { - // prevent throwing and aborting (hard) - // https://bugzilla.mozilla.org/show_bug.cgi?id=872873 - e.preventDefault(); - reject(e); - }; - transaction.onabort = function (e) { - return reject(e); - }; + var store = setupTransactionAndStore(db, table, undefined, resolve, reject, true); - var store = transaction.objectStore(table); - var req = void 0; - try { - req = key == null ? store.count() : store.count(key); - } catch (err) { - reject(err); - } + var req = key == null ? store.count() : store.count(key); // May throw req.onsuccess = function (e) { return resolve(e.target.result); }; @@ -697,7 +518,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr } if (eventName === 'error') { db.addEventListener(eventName, function (e) { - e.preventDefault(); // Needed by Firefox to prevent hard abort with ConstraintError + e.preventDefault(); // Needed to prevent hard abort with ConstraintError handler(e); }); return; @@ -724,7 +545,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr } var err = void 0; - [].some.call(db.objectStoreNames, function (storeName) { + Array.from(db.objectStoreNames).some(function (storeName) { if (_this2[storeName]) { err = new Error('The store name, "' + storeName + '", which you have attempted to load, conflicts with db.js method names."'); _this2.close(); @@ -747,172 +568,128 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr return err; }; - var createSchema = function createSchema(e, request, schema, db, server, version) { - if (!schema || schema.length === 0) { - return; - } - - for (var i = 0; i < db.objectStoreNames.length; i++) { - var name = db.objectStoreNames[i]; - if (!hasOwn.call(schema, name)) { - // Errors for which we are not concerned and why: - // `InvalidStateError` - We are in the upgrade transaction. - // `TransactionInactiveError` (as by the upgrade having already - // completed or somehow aborting) - since we've just started and - // should be without risk in this loop - // `NotFoundError` - since we are iterating the dynamically updated - // `objectStoreNames` - db.deleteObjectStore(name); - } - } - - var ret = void 0; - Object.keys(schema).some(function (tableName) { - var table = schema[tableName]; - var store = void 0; - if (db.objectStoreNames.contains(tableName)) { - store = request.transaction.objectStore(tableName); // Shouldn't throw - } else { - // Errors for which we are not concerned and why: - // `InvalidStateError` - We are in the upgrade transaction. - // `ConstraintError` - We are just starting (and probably never too large anyways) for a key generator. - // `ConstraintError` - The above condition should prevent the name already existing. - // - // Possible errors: - // `TransactionInactiveError` - if the upgrade had already aborted, - // e.g., from a previous `QuotaExceededError` which is supposed to nevertheless return - // the store but then abort the transaction. - // `SyntaxError` - if an invalid `table.key.keyPath` is supplied. - // `InvalidAccessError` - if `table.key.autoIncrement` is `true` and `table.key.keyPath` is an - // empty string or any sequence (empty or otherwise). - try { - store = db.createObjectStore(tableName, table.key); - } catch (err) { - ret = err; - return true; - } - } - - Object.keys(table.indexes || {}).some(function (indexKey) { - try { - store.index(indexKey); - } catch (err) { - var index = table.indexes[indexKey]; - index = index && (typeof index === 'undefined' ? 'undefined' : _typeof(index)) === 'object' ? index : {}; - // Errors for which we are not concerned and why: - // `InvalidStateError` - We are in the upgrade transaction and store found above should not have already been deleted. - // `ConstraintError` - We have already tried getting the index, so it shouldn't already exist - // - // Possible errors: - // `TransactionInactiveError` - if the upgrade had already aborted, - // e.g., from a previous `QuotaExceededError` which is supposed to nevertheless return - // the index object but then abort the transaction. - // `SyntaxError` - If the `keyPath` (second argument) is an invalid key path - // `InvalidAccessError` - If `multiEntry` on `index` is `true` and - // `keyPath` (second argument) is a sequence - try { - store.createIndex(indexKey, index.keyPath || index.key || indexKey, index); - } catch (err2) { - ret = err2; - return true; - } - } - }); - }); - return ret; - }; - - var _open = function _open(e, server, version, noServerMethods) { - var db = e.target.result; + var _open = function _open(db, server, version, noServerMethods) { dbCache[server][version] = db; - var s = new Server(db, server, version, noServerMethods); - return s instanceof Error ? Promise.reject(s) : Promise.resolve(s); + return new Server(db, server, version, noServerMethods); }; var db = { version: '0.15.0', open: function open(options) { var server = options.server; + var noServerMethods = options.noServerMethods; + var clearUnusedStores = options.clearUnusedStores !== false; + var clearUnusedIndexes = options.clearUnusedIndexes !== false; var version = options.version || 1; var schema = options.schema; - var noServerMethods = options.noServerMethods; - + var schemas = options.schemas; + var schemaType = options.schemaType || (schema ? 'whole' : 'mixed'); if (!dbCache[server]) { dbCache[server] = {}; } + var openDb = function openDb(db) { + var s = _open(db, server, version, noServerMethods); + if (s instanceof Error) { + throw s; + } + return s; + }; + return new Promise(function (resolve, reject) { if (dbCache[server][version]) { - _open({ - target: { - result: dbCache[server][version] - } - }, server, version, noServerMethods).then(resolve, reject); - } else { - var _ret2 = function () { - if (typeof schema === 'function') { - try { - schema = schema(); - } catch (e) { - reject(e); - return { - v: void 0 - }; - } - } - var request = indexedDB.open(server, version); - - request.onsuccess = function (e) { - return _open(e, server, version, noServerMethods).then(resolve, reject); - }; - request.onerror = function (e) { - // Prevent default for `BadVersion` and `AbortError` errors, etc. - // These are not necessarily reported in console in Chrome but present; see - // https://bugzilla.mozilla.org/show_bug.cgi?id=872873 - // http://stackoverflow.com/questions/36225779/aborterror-within-indexeddb-upgradeneeded-event/36266502 - e.preventDefault(); - reject(e); - }; - request.onupgradeneeded = function (e) { - var err = createSchema(e, request, schema, e.target.result, server, version); - if (err) { - reject(err); + var s = _open(dbCache[server][version], server, version, noServerMethods); + if (s instanceof Error) { + reject(s); + return; + } + resolve(s); + return; + } + var idbimport = new _idbImport2.default(); + var p = Promise.resolve(); + if (schema || schemas || options.schemaBuilder) { + (function () { + var _addCallback = idbimport.addCallback; + idbimport.addCallback = function (cb) { + function newCb(db) { + var s = _open(db, server, version, noServerMethods); + if (s instanceof Error) { + throw s; + } + return cb(db, s); } + return _addCallback.call(idbimport, newCb); }; - request.onblocked = function (e) { - var resume = new Promise(function (res, rej) { - // We overwrite handlers rather than make a new - // open() since the original request is still - // open and its onsuccess will still fire if - // the user unblocks by closing the blocking - // connection - request.onsuccess = function (ev) { - _open(ev, server, version, noServerMethods).then(res, rej); - }; - request.onerror = function (e) { - return rej(e); - }; - }); - e.resume = resume; - reject(e); - }; - }(); - if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") return _ret2.v; + p = p.then(function () { + if (options.schemaBuilder) { + return options.schemaBuilder(idbimport); + } + }).then(function () { + if (schema) { + switch (schemaType) { + case 'mixed':case 'idb-schema':case 'merge':case 'whole': + { + schemas = _defineProperty({}, version, schema); + break; + } + } + } + if (schemas) { + idbimport.createVersionedSchema(schemas, schemaType, clearUnusedStores, clearUnusedIndexes); + } + var idbschemaVersion = idbimport.version(); + if (options.version && idbschemaVersion < version) { + throw new Error('Your highest schema building (IDBSchema) version (' + idbschemaVersion + ') ' + 'must not be less than your designated version (' + version + ').'); + } + if (!options.version && idbschemaVersion > version) { + version = idbschemaVersion; + } + }); + })(); } + + p.then(function () { + return idbimport.open(server, version); + }).catch(function (err) { + if (err.resume) { + err.resume = err.resume.then(openDb); + } + if (err.retry) { + (function () { + var _retry = err.retry; + err.retry = function () { + _retry.call(err).then(openDb); + }; + })(); + } + throw err; + }).then(openDb).then(resolve).catch(function (e) { + reject(e); + }); }); }, + del: function del(dbName) { + return this.delete(dbName); + }, delete: function _delete(dbName) { return new Promise(function (resolve, reject) { var request = indexedDB.deleteDatabase(dbName); // Does not throw request.onsuccess = function (e) { - return resolve(e); + // The following is needed currently by PhantomJS (though we cannot polyfill `oldVersion`): https://github.com/ariya/phantomjs/issues/14141 + if (!('newVersion' in e)) { + e.newVersion = null; + } + resolve(e); }; request.onerror = function (e) { - return reject(e); - }; // No errors currently + // No errors currently + e.preventDefault(); + reject(e); + }; request.onblocked = function (e) { // The following addresses part of https://bugzilla.mozilla.org/show_bug.cgi?id=1220279 e = e.newVersion === null || typeof Proxy === 'undefined' ? e : new Proxy(e, { get: function get(target, name) { @@ -937,7 +714,8 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr res(ev); }; request.onerror = function (e) { - return rej(e); + e.preventDefault(); + rej(e); }; }); e.resume = resume; @@ -948,11 +726,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr cmp: function cmp(param1, param2) { return new Promise(function (resolve, reject) { - try { - resolve(indexedDB.cmp(param1, param2)); - } catch (e) { - reject(e); - } + resolve(indexedDB.cmp(param1, param2)); // May throw }); } }; @@ -969,5 +743,7839 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr })(self); +},{"./idb-import":2}],2:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _idbSchema = require('idb-schema'); + +var _idbSchema2 = _interopRequireDefault(_idbSchema); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +/* +# Notes + +1. Could use/adapt [jtlt](https://github.com/brettz9/jtlt/) for changing JSON data + +# Possible to-dos + +1. Support data within adapted JSON Merge Patch +1. Allow JSON Schema to be specified during import (and export): https://github.com/aaronpowell/db.js/issues/181 +1. JSON format above database level to allow for deleting or moving/copying of whole databases +1. `copyFrom`/`moveFrom` for indexes +*/ + +self._babelPolyfill = false; // Need by Phantom in avoiding duplicate babel polyfill error + + +var stringify = JSON.stringify; +var hasOwn = function hasOwn(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +}; +var compareStringified = function compareStringified(a, b) { + return stringify(a) === stringify(b); +}; + +var IdbImport = function (_IdbSchema) { + _inherits(IdbImport, _IdbSchema); + + function IdbImport() { + _classCallCheck(this, IdbImport); + + return _possibleConstructorReturn(this, Object.getPrototypeOf(IdbImport).call(this)); + } + + _createClass(IdbImport, [{ + key: '_setup', + value: function _setup(schema, cb, mergePatch) { + var _this2 = this; + + var isNUL = schema === '\0'; + if (!schema || (typeof schema === 'undefined' ? 'undefined' : _typeof(schema)) !== 'object' && !(mergePatch && isNUL)) { + throw new Error('Bad schema object'); + } + this.addEarlyCallback(function (e) { + var db = e.target.result; + var transaction = e.target.transaction; + if (mergePatch && isNUL) { + _this2._deleteAllUnused(db, transaction, {}, true); + return; + } + return cb(e, db, transaction); + }); + } + }, { + key: '_deleteIndexes', + value: function _deleteIndexes(transaction, storeName, exceptionIndexes) { + var _this3 = this; + + var store = transaction.objectStore(storeName); // Shouldn't throw + Array.from(store.indexNames).forEach(function (indexName) { + if (!exceptionIndexes || !hasOwn(exceptionIndexes, indexName)) { + _this3.delIndex(indexName); + } + }); + } + }, { + key: '_deleteAllUnused', + value: function _deleteAllUnused(db, transaction, schema, clearUnusedStores, clearUnusedIndexes) { + var _this4 = this; + + if (clearUnusedStores || clearUnusedIndexes) { + Array.from(db.objectStoreNames).forEach(function (storeName) { + if (clearUnusedStores && !hasOwn(schema, storeName)) { + // Errors for which we are not concerned and why: + // `InvalidStateError` - We are in the upgrade transaction. + // `TransactionInactiveError` (as by the upgrade having already + // completed or somehow aborting) - since we've just started and + // should be without risk in this loop + // `NotFoundError` - since we are iterating the dynamically updated + // `objectStoreNames` + // this._versions[version].dropStores.push({name: storeName}); + // Avoid deleting if going to delete in a move/copy + if (!Object.keys(schema).some(function (key) { + return [schema[key].moveFrom, schema[key].copyFrom].includes(storeName); + })) { + _this4.delStore(storeName); // Shouldn't throw // Keep this and delete previous line if this PR is accepted: https://github.com/treojs/idb-schema/pull/14 + } + } else if (clearUnusedIndexes) { + _this4._deleteIndexes(transaction, storeName, schema[storeName].indexes); + } + }); + } + } + }, { + key: '_createStoreIfNotSame', + value: function _createStoreIfNotSame(db, transaction, schema, storeName, mergePatch) { + var newStore = schema[storeName]; + var store = void 0; + var storeParams = {}; + function setCanonicalProps(storeProp) { + var canonicalPropValue = void 0; + if (hasOwn(newStore, 'key')) { + // Support old approach of db.js + canonicalPropValue = newStore.key[storeProp]; + } else if (hasOwn(newStore, storeProp)) { + canonicalPropValue = newStore[storeProp]; + } else { + canonicalPropValue = storeProp === 'keyPath' ? null : false; + } + if (mergePatch && typeof canonicalPropValue === 'string') { + if (canonicalPropValue === '\0') { + canonicalPropValue = storeProp === 'keyPath' ? null : false; + } else { + canonicalPropValue = canonicalPropValue.replace(/^\0/, ''); // Remove escape if present + } + } + storeParams[storeProp] = canonicalPropValue; + } + var copyFrom = newStore.copyFrom; + var moveFrom = newStore.moveFrom; + try { + ['keyPath', 'autoIncrement'].forEach(setCanonicalProps); + if (!db.objectStoreNames.contains(storeName)) { + throw new Error('goto catch to build store'); + } + store = transaction.objectStore(storeName); // Shouldn't throw + this.getStore(store); + if (!['keyPath', 'autoIncrement'].every(function (storeProp) { + return compareStringified(storeParams[storeProp], store[storeProp]); + })) { + // Avoid deleting if going to delete in a move/copy + if (!copyFrom && !moveFrom) this.delStore(storeName); + throw new Error('goto catch to build store'); + } + } catch (err) { + if (err.message !== 'goto catch to build store') { + throw err; + } + if (copyFrom) { + this.copyStore(copyFrom, storeName, storeParams); // May throw + } else if (moveFrom) { + this.renameStore(moveFrom, storeName, storeParams); // May throw + } else { + // Errors for which we are not concerned and why: + // `InvalidStateError` - We are in the upgrade transaction. + // `ConstraintError` - We are just starting (and probably never too large anyways) for a key generator. + // `ConstraintError` - The above condition should prevent the name already existing. + // + // Possible errors: + // `TransactionInactiveError` - if the upgrade had already aborted, + // e.g., from a previous `QuotaExceededError` which is supposed to nevertheless return + // the store but then abort the transaction. + // `SyntaxError` - if an invalid `storeParams.keyPath` is supplied. + // `InvalidAccessError` - if `storeParams.autoIncrement` is `true` and `storeParams.keyPath` is an + // empty string or any sequence (empty or otherwise). + this.addStore(storeName, storeParams); // May throw + } + } + return [store, newStore]; + } + }, { + key: '_createIndex', + value: function _createIndex(store, indexes, indexName, mergePatch) { + var _this5 = this; + + var newIndex = indexes[indexName]; + var indexParams = {}; + function setCanonicalProps(indexProp) { + var canonicalPropValue = void 0; + if (hasOwn(newIndex, indexProp)) { + canonicalPropValue = newIndex[indexProp]; + } else { + canonicalPropValue = indexProp === 'keyPath' ? null : false; + } + if (mergePatch && typeof canonicalPropValue === 'string') { + if (canonicalPropValue === '\0') { + canonicalPropValue = indexProp === 'keyPath' ? null : false; + } else { + canonicalPropValue = canonicalPropValue.replace(/^\0/, ''); // Remove escape if present + } + } + indexParams[indexProp] = canonicalPropValue; + } + try { + (function () { + ['keyPath', 'unique', 'multiEntry', 'locale'].forEach(setCanonicalProps); + if (!store || !store.indexNames.contains(indexName)) { + throw new Error('goto catch to build index'); + } + var oldIndex = store.index(indexName); + if (!['keyPath', 'unique', 'multiEntry', 'locale'].every(function (indexProp) { + return compareStringified(indexParams[indexProp], oldIndex[indexProp]); + })) { + _this5.delIndex(indexName); + throw new Error('goto catch to build index'); + } + })(); + } catch (err) { + if (err.message !== 'goto catch to build index') { + throw err; + } + // Errors for which we are not concerned and why: + // `InvalidStateError` - We are in the upgrade transaction and store found above should not have already been deleted. + // `ConstraintError` - We have already tried getting the index, so it shouldn't already exist + // + // Possible errors: + // `TransactionInactiveError` - if the upgrade had already aborted, + // e.g., from a previous `QuotaExceededError` which is supposed to nevertheless return + // the index object but then abort the transaction. + // `SyntaxError` - If the `keyPath` (second argument) is an invalid key path + // `InvalidAccessError` - If `multiEntry` on `index` is `true` and + // `keyPath` (second argument) is a sequence + this.addIndex(indexName, indexParams.keyPath !== null ? indexParams.keyPath : indexName, indexParams); + } + } + }, { + key: 'createIdbSchemaPatchSchema', + value: function createIdbSchemaPatchSchema(schema) { + schema(this); // May throw + } + // Modified JSON Merge Patch type schemas: https://github.com/json-schema-org/json-schema-spec/issues/15#issuecomment-211142145 + + }, { + key: 'createMergePatchSchema', + value: function createMergePatchSchema(schema) { + var _this6 = this; + + this._setup(schema, function (e, db, transaction) { + Object.keys(schema).forEach(function (storeName) { + var schemaObj = schema[storeName]; + var isNUL = schemaObj === '\0'; + if (isNUL) { + _this6.delStore(storeName); + return; + } + if (!schemaObj || (typeof schemaObj === 'undefined' ? 'undefined' : _typeof(schemaObj)) !== 'object') { + throw new Error('Invalid merge patch schema object (type: ' + (typeof schemaObj === 'undefined' ? 'undefined' : _typeof(schemaObj)) + '): ' + schemaObj); + } + + var _createStoreIfNotSame2 = _this6._createStoreIfNotSame(db, transaction, schema, storeName, true); + + var _createStoreIfNotSame3 = _slicedToArray(_createStoreIfNotSame2, 1); + + var store = _createStoreIfNotSame3[0]; + + if (hasOwn(schemaObj, 'indexes')) { + var _ret2 = function () { + var indexes = schemaObj.indexes; + var isNUL = indexes === '\0'; + if (isNUL) { + _this6._deleteIndexes(transaction, storeName); + return { + v: void 0 + }; + } + if (!indexes || (typeof indexes === 'undefined' ? 'undefined' : _typeof(indexes)) !== 'object') { + throw new Error('Invalid merge patch indexes object (type: ' + (typeof indexes === 'undefined' ? 'undefined' : _typeof(indexes)) + '): ' + indexes); + } + Object.keys(indexes).forEach(function (indexName) { + var indexObj = indexes[indexName]; + var isNUL = indexObj === '\0'; + if (isNUL) { + _this6.delIndex(indexName); + return; + } + if (!indexObj || (typeof indexObj === 'undefined' ? 'undefined' : _typeof(indexObj)) !== 'object') { + throw new Error('Invalid merge patch index object (type: ' + (typeof indexObj === 'undefined' ? 'undefined' : _typeof(indexObj)) + '): ' + indexObj); + } + _this6._createIndex(store, indexes, indexName, true); + }); + }(); + + if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") return _ret2.v; + } + }); + }); + } + }, { + key: 'createWholePatchSchema', + value: function createWholePatchSchema(schema) { + var _this7 = this; + + var clearUnusedStores = arguments.length <= 1 || arguments[1] === undefined ? true : arguments[1]; + var clearUnusedIndexes = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2]; + + this._setup(schema, function (e, db, transaction) { + _this7._deleteAllUnused(db, transaction, schema, clearUnusedStores, clearUnusedIndexes); + + Object.keys(schema).forEach(function (storeName) { + var _createStoreIfNotSame4 = _this7._createStoreIfNotSame(db, transaction, schema, storeName); + + var _createStoreIfNotSame5 = _slicedToArray(_createStoreIfNotSame4, 2); + + var store = _createStoreIfNotSame5[0]; + var newStore = _createStoreIfNotSame5[1]; + + var indexes = newStore.indexes; + Object.keys(indexes || {}).forEach(function (indexName) { + _this7._createIndex(store, indexes, indexName); + }); + }); + }); + } + }, { + key: 'createVersionedSchema', + value: function createVersionedSchema(schemas, schemaType, clearUnusedStores, clearUnusedIndexes) { + var _this8 = this; + + var createPatches = function createPatches(schemaObj, schemaType) { + switch (schemaType) { + case 'mixed': + { + schemaObj.forEach(function (mixedObj) { + var schemaType = Object.keys(mixedObj)[0]; + var schema = mixedObj[schemaType]; + if (schemaType !== 'idb-schema' && schema === 'function') { + schema = schema(_this8); // May throw + } + // These could immediately throw with a bad version + switch (schemaType) { + case 'idb-schema': + { + // Function called above + _this8.createIdbSchemaPatchSchema(schema); + break; + } + case 'merge': + { + _this8.createMergePatchSchema(schema); + break; + } + case 'whole': + { + _this8.createWholePatchSchema(schema, clearUnusedStores, clearUnusedIndexes); + break; + } + case 'mixed': + { + createPatches(schema, schemaType); + break; + } + default: + throw new Error('Unrecognized schema type'); + } + }); + break; + } + case 'merge': + { + _this8.createMergePatchSchema(schemaObj); + break; + } + case 'idb-schema': + { + _this8.createIdbSchemaPatchSchema(schemaObj); + break; + } + case 'whole': + { + _this8.createWholePatchSchema(schemaObj, clearUnusedStores, clearUnusedIndexes); + break; + } + } + }; + Object.keys(schemas || {}).sort().forEach(function (schemaVersion) { + var version = parseInt(schemaVersion, 10); + var schemaObj = schemas[version]; + if (schemaType !== 'idb-schema' && typeof schemaObj === 'function') { + schemaObj = schemaObj(_this8); // May throw + } + _this8.version(version); + createPatches(schemaObj, schemaType, version); + }); + } + }]); + + return IdbImport; +}(_idbSchema2.default); + +exports.default = IdbImport; + + +},{"idb-schema":288}],3:[function(require,module,exports){ +(function (global){ +/* eslint max-len: 0 */ + +"use strict"; + +var _Object$defineProperty = require("babel-runtime/core-js/object/define-property")["default"]; + +require("core-js/shim"); + +require("babel-regenerator-runtime"); + +// Should be removed in the next major release: + +require("core-js/fn/regexp/escape"); + +if (global._babelPolyfill) { + throw new Error("only one instance of babel-polyfill is allowed"); +} +global._babelPolyfill = true; + +function define(O, key, value) { + O[key] || _Object$defineProperty(O, key, { + writable: true, + configurable: true, + value: value + }); +} + +define(String.prototype, "padLeft", "".padStart); +define(String.prototype, "padRight", "".padEnd); + +"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(function (key) { + [][key] && define(Array, key, Function.call.bind([][key])); +}); +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"babel-regenerator-runtime":283,"babel-runtime/core-js/object/define-property":284,"core-js/fn/regexp/escape":4,"core-js/shim":282}],4:[function(require,module,exports){ +require('../../modules/core.regexp.escape'); +module.exports = require('../../modules/_core').RegExp.escape; +},{"../../modules/_core":24,"../../modules/core.regexp.escape":116}],5:[function(require,module,exports){ +module.exports = function(it){ + if(typeof it != 'function')throw TypeError(it + ' is not a function!'); + return it; +}; +},{}],6:[function(require,module,exports){ +var cof = require('./_cof'); +module.exports = function(it, msg){ + if(typeof it != 'number' && cof(it) != 'Number')throw TypeError(msg); + return +it; +}; +},{"./_cof":19}],7:[function(require,module,exports){ +// 22.1.3.31 Array.prototype[@@unscopables] +var UNSCOPABLES = require('./_wks')('unscopables') + , ArrayProto = Array.prototype; +if(ArrayProto[UNSCOPABLES] == undefined)require('./_hide')(ArrayProto, UNSCOPABLES, {}); +module.exports = function(key){ + ArrayProto[UNSCOPABLES][key] = true; +}; +},{"./_hide":39,"./_wks":113}],8:[function(require,module,exports){ +module.exports = function(it, Constructor, name, forbiddenField){ + if(!(it instanceof Constructor) || (forbiddenField !== undefined && forbiddenField in it)){ + throw TypeError(name + ': incorrect invocation!'); + } return it; +}; +},{}],9:[function(require,module,exports){ +var isObject = require('./_is-object'); +module.exports = function(it){ + if(!isObject(it))throw TypeError(it + ' is not an object!'); + return it; +}; +},{"./_is-object":48}],10:[function(require,module,exports){ +// 22.1.3.3 Array.prototype.copyWithin(target, start, end = this.length) +'use strict'; +var toObject = require('./_to-object') + , toIndex = require('./_to-index') + , toLength = require('./_to-length'); + +module.exports = [].copyWithin || function copyWithin(target/*= 0*/, start/*= 0, end = @length*/){ + var O = toObject(this) + , len = toLength(O.length) + , to = toIndex(target, len) + , from = toIndex(start, len) + , end = arguments.length > 2 ? arguments[2] : undefined + , count = Math.min((end === undefined ? len : toIndex(end, len)) - from, len - to) + , inc = 1; + if(from < to && to < from + count){ + inc = -1; + from += count - 1; + to += count - 1; + } + while(count-- > 0){ + if(from in O)O[to] = O[from]; + else delete O[to]; + to += inc; + from += inc; + } return O; +}; +},{"./_to-index":103,"./_to-length":106,"./_to-object":107}],11:[function(require,module,exports){ +// 22.1.3.6 Array.prototype.fill(value, start = 0, end = this.length) +'use strict'; +var toObject = require('./_to-object') + , toIndex = require('./_to-index') + , toLength = require('./_to-length'); +module.exports = function fill(value /*, start = 0, end = @length */){ + var O = toObject(this) + , length = toLength(O.length) + , aLen = arguments.length + , index = toIndex(aLen > 1 ? arguments[1] : undefined, length) + , end = aLen > 2 ? arguments[2] : undefined + , endPos = end === undefined ? length : toIndex(end, length); + while(endPos > index)O[index++] = value; + return O; +}; +},{"./_to-index":103,"./_to-length":106,"./_to-object":107}],12:[function(require,module,exports){ +var forOf = require('./_for-of'); + +module.exports = function(iter, ITERATOR){ + var result = []; + forOf(iter, false, result.push, result, ITERATOR); + return result; +}; + +},{"./_for-of":36}],13:[function(require,module,exports){ +// false -> Array#indexOf +// true -> Array#includes +var toIObject = require('./_to-iobject') + , toLength = require('./_to-length') + , toIndex = require('./_to-index'); +module.exports = function(IS_INCLUDES){ + return function($this, el, fromIndex){ + var O = toIObject($this) + , length = toLength(O.length) + , index = toIndex(fromIndex, length) + , value; + // Array#includes uses SameValueZero equality algorithm + if(IS_INCLUDES && el != el)while(length > index){ + value = O[index++]; + if(value != value)return true; + // Array#toIndex ignores holes, Array#includes - not + } else for(;length > index; index++)if(IS_INCLUDES || index in O){ + if(O[index] === el)return IS_INCLUDES || index; + } return !IS_INCLUDES && -1; + }; +}; +},{"./_to-index":103,"./_to-iobject":105,"./_to-length":106}],14:[function(require,module,exports){ +// 0 -> Array#forEach +// 1 -> Array#map +// 2 -> Array#filter +// 3 -> Array#some +// 4 -> Array#every +// 5 -> Array#find +// 6 -> Array#findIndex +var ctx = require('./_ctx') + , IObject = require('./_iobject') + , toObject = require('./_to-object') + , toLength = require('./_to-length') + , asc = require('./_array-species-create'); +module.exports = function(TYPE, $create){ + var IS_MAP = TYPE == 1 + , IS_FILTER = TYPE == 2 + , IS_SOME = TYPE == 3 + , IS_EVERY = TYPE == 4 + , IS_FIND_INDEX = TYPE == 6 + , NO_HOLES = TYPE == 5 || IS_FIND_INDEX + , create = $create || asc; + return function($this, callbackfn, that){ + var O = toObject($this) + , self = IObject(O) + , f = ctx(callbackfn, that, 3) + , length = toLength(self.length) + , index = 0 + , result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined + , val, res; + for(;length > index; index++)if(NO_HOLES || index in self){ + val = self[index]; + res = f(val, index, O); + if(TYPE){ + if(IS_MAP)result[index] = res; // map + else if(res)switch(TYPE){ + case 3: return true; // some + case 5: return val; // find + case 6: return index; // findIndex + case 2: result.push(val); // filter + } else if(IS_EVERY)return false; // every + } + } + return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result; + }; +}; +},{"./_array-species-create":16,"./_ctx":25,"./_iobject":44,"./_to-length":106,"./_to-object":107}],15:[function(require,module,exports){ +var aFunction = require('./_a-function') + , toObject = require('./_to-object') + , IObject = require('./_iobject') + , toLength = require('./_to-length'); + +module.exports = function(that, callbackfn, aLen, memo, isRight){ + aFunction(callbackfn); + var O = toObject(that) + , self = IObject(O) + , length = toLength(O.length) + , index = isRight ? length - 1 : 0 + , i = isRight ? -1 : 1; + if(aLen < 2)for(;;){ + if(index in self){ + memo = self[index]; + index += i; + break; + } + index += i; + if(isRight ? index < 0 : length <= index){ + throw TypeError('Reduce of empty array with no initial value'); + } + } + for(;isRight ? index >= 0 : length > index; index += i)if(index in self){ + memo = callbackfn(memo, self[index], index, O); + } + return memo; +}; +},{"./_a-function":5,"./_iobject":44,"./_to-length":106,"./_to-object":107}],16:[function(require,module,exports){ +// 9.4.2.3 ArraySpeciesCreate(originalArray, length) +var isObject = require('./_is-object') + , isArray = require('./_is-array') + , SPECIES = require('./_wks')('species'); +module.exports = function(original, length){ + var C; + if(isArray(original)){ + C = original.constructor; + // cross-realm fallback + if(typeof C == 'function' && (C === Array || isArray(C.prototype)))C = undefined; + if(isObject(C)){ + C = C[SPECIES]; + if(C === null)C = undefined; + } + } return new (C === undefined ? Array : C)(length); +}; +},{"./_is-array":46,"./_is-object":48,"./_wks":113}],17:[function(require,module,exports){ +'use strict'; +var aFunction = require('./_a-function') + , isObject = require('./_is-object') + , invoke = require('./_invoke') + , arraySlice = [].slice + , factories = {}; + +var construct = function(F, len, args){ + if(!(len in factories)){ + for(var n = [], i = 0; i < len; i++)n[i] = 'a[' + i + ']'; + factories[len] = Function('F,a', 'return new F(' + n.join(',') + ')'); + } return factories[len](F, args); +}; + +module.exports = Function.bind || function bind(that /*, args... */){ + var fn = aFunction(this) + , partArgs = arraySlice.call(arguments, 1); + var bound = function(/* args... */){ + var args = partArgs.concat(arraySlice.call(arguments)); + return this instanceof bound ? construct(fn, args.length, args) : invoke(fn, args, that); + }; + if(isObject(fn.prototype))bound.prototype = fn.prototype; + return bound; +}; +},{"./_a-function":5,"./_invoke":43,"./_is-object":48}],18:[function(require,module,exports){ +// getting tag from 19.1.3.6 Object.prototype.toString() +var cof = require('./_cof') + , TAG = require('./_wks')('toStringTag') + // ES3 wrong here + , ARG = cof(function(){ return arguments; }()) == 'Arguments'; + +// fallback for IE11 Script Access Denied error +var tryGet = function(it, key){ + try { + return it[key]; + } catch(e){ /* empty */ } +}; + +module.exports = function(it){ + var O, T, B; + return it === undefined ? 'Undefined' : it === null ? 'Null' + // @@toStringTag case + : typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T + // builtinTag case + : ARG ? cof(O) + // ES3 arguments fallback + : (B = cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B; +}; +},{"./_cof":19,"./_wks":113}],19:[function(require,module,exports){ +var toString = {}.toString; + +module.exports = function(it){ + return toString.call(it).slice(8, -1); +}; +},{}],20:[function(require,module,exports){ +'use strict'; +var dP = require('./_object-dp').f + , create = require('./_object-create') + , hide = require('./_hide') + , redefineAll = require('./_redefine-all') + , ctx = require('./_ctx') + , anInstance = require('./_an-instance') + , defined = require('./_defined') + , forOf = require('./_for-of') + , $iterDefine = require('./_iter-define') + , step = require('./_iter-step') + , setSpecies = require('./_set-species') + , DESCRIPTORS = require('./_descriptors') + , fastKey = require('./_meta').fastKey + , SIZE = DESCRIPTORS ? '_s' : 'size'; + +var getEntry = function(that, key){ + // fast case + var index = fastKey(key), entry; + if(index !== 'F')return that._i[index]; + // frozen object case + for(entry = that._f; entry; entry = entry.n){ + if(entry.k == key)return entry; + } +}; + +module.exports = { + getConstructor: function(wrapper, NAME, IS_MAP, ADDER){ + var C = wrapper(function(that, iterable){ + anInstance(that, C, NAME, '_i'); + that._i = create(null); // index + that._f = undefined; // first entry + that._l = undefined; // last entry + that[SIZE] = 0; // size + if(iterable != undefined)forOf(iterable, IS_MAP, that[ADDER], that); + }); + redefineAll(C.prototype, { + // 23.1.3.1 Map.prototype.clear() + // 23.2.3.2 Set.prototype.clear() + clear: function clear(){ + for(var that = this, data = that._i, entry = that._f; entry; entry = entry.n){ + entry.r = true; + if(entry.p)entry.p = entry.p.n = undefined; + delete data[entry.i]; + } + that._f = that._l = undefined; + that[SIZE] = 0; + }, + // 23.1.3.3 Map.prototype.delete(key) + // 23.2.3.4 Set.prototype.delete(value) + 'delete': function(key){ + var that = this + , entry = getEntry(that, key); + if(entry){ + var next = entry.n + , prev = entry.p; + delete that._i[entry.i]; + entry.r = true; + if(prev)prev.n = next; + if(next)next.p = prev; + if(that._f == entry)that._f = next; + if(that._l == entry)that._l = prev; + that[SIZE]--; + } return !!entry; + }, + // 23.2.3.6 Set.prototype.forEach(callbackfn, thisArg = undefined) + // 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined) + forEach: function forEach(callbackfn /*, that = undefined */){ + anInstance(this, C, 'forEach'); + var f = ctx(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3) + , entry; + while(entry = entry ? entry.n : this._f){ + f(entry.v, entry.k, this); + // revert to the last existing entry + while(entry && entry.r)entry = entry.p; + } + }, + // 23.1.3.7 Map.prototype.has(key) + // 23.2.3.7 Set.prototype.has(value) + has: function has(key){ + return !!getEntry(this, key); + } + }); + if(DESCRIPTORS)dP(C.prototype, 'size', { + get: function(){ + return defined(this[SIZE]); + } + }); + return C; + }, + def: function(that, key, value){ + var entry = getEntry(that, key) + , prev, index; + // change existing entry + if(entry){ + entry.v = value; + // create new entry + } else { + that._l = entry = { + i: index = fastKey(key, true), // <- index + k: key, // <- key + v: value, // <- value + p: prev = that._l, // <- previous entry + n: undefined, // <- next entry + r: false // <- removed + }; + if(!that._f)that._f = entry; + if(prev)prev.n = entry; + that[SIZE]++; + // add to index + if(index !== 'F')that._i[index] = entry; + } return that; + }, + getEntry: getEntry, + setStrong: function(C, NAME, IS_MAP){ + // add .keys, .values, .entries, [@@iterator] + // 23.1.3.4, 23.1.3.8, 23.1.3.11, 23.1.3.12, 23.2.3.5, 23.2.3.8, 23.2.3.10, 23.2.3.11 + $iterDefine(C, NAME, function(iterated, kind){ + this._t = iterated; // target + this._k = kind; // kind + this._l = undefined; // previous + }, function(){ + var that = this + , kind = that._k + , entry = that._l; + // revert to the last existing entry + while(entry && entry.r)entry = entry.p; + // get next entry + if(!that._t || !(that._l = entry = entry ? entry.n : that._t._f)){ + // or finish the iteration + that._t = undefined; + return step(1); + } + // return step by kind + if(kind == 'keys' )return step(0, entry.k); + if(kind == 'values')return step(0, entry.v); + return step(0, [entry.k, entry.v]); + }, IS_MAP ? 'entries' : 'values' , !IS_MAP, true); + + // add [@@species], 23.1.2.2, 23.2.2.2 + setSpecies(NAME); + } +}; +},{"./_an-instance":8,"./_ctx":25,"./_defined":26,"./_descriptors":27,"./_for-of":36,"./_hide":39,"./_iter-define":52,"./_iter-step":54,"./_meta":61,"./_object-create":65,"./_object-dp":66,"./_redefine-all":84,"./_set-species":89}],21:[function(require,module,exports){ +// https://github.com/DavidBruant/Map-Set.prototype.toJSON +var classof = require('./_classof') + , from = require('./_array-from-iterable'); +module.exports = function(NAME){ + return function toJSON(){ + if(classof(this) != NAME)throw TypeError(NAME + "#toJSON isn't generic"); + return from(this); + }; +}; +},{"./_array-from-iterable":12,"./_classof":18}],22:[function(require,module,exports){ +'use strict'; +var redefineAll = require('./_redefine-all') + , getWeak = require('./_meta').getWeak + , anObject = require('./_an-object') + , isObject = require('./_is-object') + , anInstance = require('./_an-instance') + , forOf = require('./_for-of') + , createArrayMethod = require('./_array-methods') + , $has = require('./_has') + , arrayFind = createArrayMethod(5) + , arrayFindIndex = createArrayMethod(6) + , id = 0; + +// fallback for uncaught frozen keys +var uncaughtFrozenStore = function(that){ + return that._l || (that._l = new UncaughtFrozenStore); +}; +var UncaughtFrozenStore = function(){ + this.a = []; +}; +var findUncaughtFrozen = function(store, key){ + return arrayFind(store.a, function(it){ + return it[0] === key; + }); +}; +UncaughtFrozenStore.prototype = { + get: function(key){ + var entry = findUncaughtFrozen(this, key); + if(entry)return entry[1]; + }, + has: function(key){ + return !!findUncaughtFrozen(this, key); + }, + set: function(key, value){ + var entry = findUncaughtFrozen(this, key); + if(entry)entry[1] = value; + else this.a.push([key, value]); + }, + 'delete': function(key){ + var index = arrayFindIndex(this.a, function(it){ + return it[0] === key; + }); + if(~index)this.a.splice(index, 1); + return !!~index; + } +}; + +module.exports = { + getConstructor: function(wrapper, NAME, IS_MAP, ADDER){ + var C = wrapper(function(that, iterable){ + anInstance(that, C, NAME, '_i'); + that._i = id++; // collection id + that._l = undefined; // leak store for uncaught frozen objects + if(iterable != undefined)forOf(iterable, IS_MAP, that[ADDER], that); + }); + redefineAll(C.prototype, { + // 23.3.3.2 WeakMap.prototype.delete(key) + // 23.4.3.3 WeakSet.prototype.delete(value) + 'delete': function(key){ + if(!isObject(key))return false; + var data = getWeak(key); + if(data === true)return uncaughtFrozenStore(this)['delete'](key); + return data && $has(data, this._i) && delete data[this._i]; + }, + // 23.3.3.4 WeakMap.prototype.has(key) + // 23.4.3.4 WeakSet.prototype.has(value) + has: function has(key){ + if(!isObject(key))return false; + var data = getWeak(key); + if(data === true)return uncaughtFrozenStore(this).has(key); + return data && $has(data, this._i); + } + }); + return C; + }, + def: function(that, key, value){ + var data = getWeak(anObject(key), true); + if(data === true)uncaughtFrozenStore(that).set(key, value); + else data[that._i] = value; + return that; + }, + ufstore: uncaughtFrozenStore +}; +},{"./_an-instance":8,"./_an-object":9,"./_array-methods":14,"./_for-of":36,"./_has":38,"./_is-object":48,"./_meta":61,"./_redefine-all":84}],23:[function(require,module,exports){ +'use strict'; +var global = require('./_global') + , $export = require('./_export') + , redefine = require('./_redefine') + , redefineAll = require('./_redefine-all') + , meta = require('./_meta') + , forOf = require('./_for-of') + , anInstance = require('./_an-instance') + , isObject = require('./_is-object') + , fails = require('./_fails') + , $iterDetect = require('./_iter-detect') + , setToStringTag = require('./_set-to-string-tag') + , inheritIfRequired = require('./_inherit-if-required'); + +module.exports = function(NAME, wrapper, methods, common, IS_MAP, IS_WEAK){ + var Base = global[NAME] + , C = Base + , ADDER = IS_MAP ? 'set' : 'add' + , proto = C && C.prototype + , O = {}; + var fixMethod = function(KEY){ + var fn = proto[KEY]; + redefine(proto, KEY, + KEY == 'delete' ? function(a){ + return IS_WEAK && !isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'has' ? function has(a){ + return IS_WEAK && !isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'get' ? function get(a){ + return IS_WEAK && !isObject(a) ? undefined : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'add' ? function add(a){ fn.call(this, a === 0 ? 0 : a); return this; } + : function set(a, b){ fn.call(this, a === 0 ? 0 : a, b); return this; } + ); + }; + if(typeof C != 'function' || !(IS_WEAK || proto.forEach && !fails(function(){ + new C().entries().next(); + }))){ + // create collection constructor + C = common.getConstructor(wrapper, NAME, IS_MAP, ADDER); + redefineAll(C.prototype, methods); + meta.NEED = true; + } else { + var instance = new C + // early implementations not supports chaining + , HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) != instance + // V8 ~ Chromium 40- weak-collections throws on primitives, but should return false + , THROWS_ON_PRIMITIVES = fails(function(){ instance.has(1); }) + // most early implementations doesn't supports iterables, most modern - not close it correctly + , ACCEPT_ITERABLES = $iterDetect(function(iter){ new C(iter); }) // eslint-disable-line no-new + // for early implementations -0 and +0 not the same + , BUGGY_ZERO = !IS_WEAK && fails(function(){ + // V8 ~ Chromium 42- fails only with 5+ elements + var $instance = new C() + , index = 5; + while(index--)$instance[ADDER](index, index); + return !$instance.has(-0); + }); + if(!ACCEPT_ITERABLES){ + C = wrapper(function(target, iterable){ + anInstance(target, C, NAME); + var that = inheritIfRequired(new Base, target, C); + if(iterable != undefined)forOf(iterable, IS_MAP, that[ADDER], that); + return that; + }); + C.prototype = proto; + proto.constructor = C; + } + if(THROWS_ON_PRIMITIVES || BUGGY_ZERO){ + fixMethod('delete'); + fixMethod('has'); + IS_MAP && fixMethod('get'); + } + if(BUGGY_ZERO || HASNT_CHAINING)fixMethod(ADDER); + // weak collections should not contains .clear method + if(IS_WEAK && proto.clear)delete proto.clear; + } + + setToStringTag(C, NAME); + + O[NAME] = C; + $export($export.G + $export.W + $export.F * (C != Base), O); + + if(!IS_WEAK)common.setStrong(C, NAME, IS_MAP); + + return C; +}; +},{"./_an-instance":8,"./_export":31,"./_fails":33,"./_for-of":36,"./_global":37,"./_inherit-if-required":42,"./_is-object":48,"./_iter-detect":53,"./_meta":61,"./_redefine":85,"./_redefine-all":84,"./_set-to-string-tag":90}],24:[function(require,module,exports){ +var core = module.exports = {version: '2.1.5'}; +if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef +},{}],25:[function(require,module,exports){ +// optional / simple context binding +var aFunction = require('./_a-function'); +module.exports = function(fn, that, length){ + aFunction(fn); + if(that === undefined)return fn; + switch(length){ + case 1: return function(a){ + return fn.call(that, a); + }; + case 2: return function(a, b){ + return fn.call(that, a, b); + }; + case 3: return function(a, b, c){ + return fn.call(that, a, b, c); + }; + } + return function(/* ...args */){ + return fn.apply(that, arguments); + }; +}; +},{"./_a-function":5}],26:[function(require,module,exports){ +// 7.2.1 RequireObjectCoercible(argument) +module.exports = function(it){ + if(it == undefined)throw TypeError("Can't call method on " + it); + return it; +}; +},{}],27:[function(require,module,exports){ +// Thank's IE8 for his funny defineProperty +module.exports = !require('./_fails')(function(){ + return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7; +}); +},{"./_fails":33}],28:[function(require,module,exports){ +var isObject = require('./_is-object') + , document = require('./_global').document + // in old IE typeof document.createElement is 'object' + , is = isObject(document) && isObject(document.createElement); +module.exports = function(it){ + return is ? document.createElement(it) : {}; +}; +},{"./_global":37,"./_is-object":48}],29:[function(require,module,exports){ +// IE 8- don't enum bug keys +module.exports = ( + 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' +).split(','); +},{}],30:[function(require,module,exports){ +// all enumerable object keys, includes symbols +var getKeys = require('./_object-keys') + , gOPS = require('./_object-gops') + , pIE = require('./_object-pie'); +module.exports = function(it){ + var result = getKeys(it) + , getSymbols = gOPS.f; + if(getSymbols){ + var symbols = getSymbols(it) + , isEnum = pIE.f + , i = 0 + , key; + while(symbols.length > i)if(isEnum.call(it, key = symbols[i++]))result.push(key); + } return result; +}; +},{"./_object-gops":71,"./_object-keys":74,"./_object-pie":75}],31:[function(require,module,exports){ +var global = require('./_global') + , core = require('./_core') + , hide = require('./_hide') + , redefine = require('./_redefine') + , ctx = require('./_ctx') + , PROTOTYPE = 'prototype'; + +var $export = function(type, name, source){ + var IS_FORCED = type & $export.F + , IS_GLOBAL = type & $export.G + , IS_STATIC = type & $export.S + , IS_PROTO = type & $export.P + , IS_BIND = type & $export.B + , target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE] + , exports = IS_GLOBAL ? core : core[name] || (core[name] = {}) + , expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {}) + , key, own, out, exp; + if(IS_GLOBAL)source = name; + for(key in source){ + // contains in native + own = !IS_FORCED && target && target[key] !== undefined; + // export native or passed + out = (own ? target : source)[key]; + // bind timers to global for call from export context + exp = IS_BIND && own ? ctx(out, global) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; + // extend global + if(target)redefine(target, key, out, type & $export.U); + // export + if(exports[key] != out)hide(exports, key, exp); + if(IS_PROTO && expProto[key] != out)expProto[key] = out; + } +}; +global.core = core; +// type bitmap +$export.F = 1; // forced +$export.G = 2; // global +$export.S = 4; // static +$export.P = 8; // proto +$export.B = 16; // bind +$export.W = 32; // wrap +$export.U = 64; // safe +$export.R = 128; // real proto method for `library` +module.exports = $export; +},{"./_core":24,"./_ctx":25,"./_global":37,"./_hide":39,"./_redefine":85}],32:[function(require,module,exports){ +var MATCH = require('./_wks')('match'); +module.exports = function(KEY){ + var re = /./; + try { + '/./'[KEY](re); + } catch(e){ + try { + re[MATCH] = false; + return !'/./'[KEY](re); + } catch(f){ /* empty */ } + } return true; +}; +},{"./_wks":113}],33:[function(require,module,exports){ +module.exports = function(exec){ + try { + return !!exec(); + } catch(e){ + return true; + } +}; +},{}],34:[function(require,module,exports){ +'use strict'; +var hide = require('./_hide') + , redefine = require('./_redefine') + , fails = require('./_fails') + , defined = require('./_defined') + , wks = require('./_wks'); + +module.exports = function(KEY, length, exec){ + var SYMBOL = wks(KEY) + , fns = exec(defined, SYMBOL, ''[KEY]) + , strfn = fns[0] + , rxfn = fns[1]; + if(fails(function(){ + var O = {}; + O[SYMBOL] = function(){ return 7; }; + return ''[KEY](O) != 7; + })){ + redefine(String.prototype, KEY, strfn); + hide(RegExp.prototype, SYMBOL, length == 2 + // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue) + // 21.2.5.11 RegExp.prototype[@@split](string, limit) + ? function(string, arg){ return rxfn.call(string, this, arg); } + // 21.2.5.6 RegExp.prototype[@@match](string) + // 21.2.5.9 RegExp.prototype[@@search](string) + : function(string){ return rxfn.call(string, this); } + ); + } +}; +},{"./_defined":26,"./_fails":33,"./_hide":39,"./_redefine":85,"./_wks":113}],35:[function(require,module,exports){ +'use strict'; +// 21.2.5.3 get RegExp.prototype.flags +var anObject = require('./_an-object'); +module.exports = function(){ + var that = anObject(this) + , result = ''; + if(that.global) result += 'g'; + if(that.ignoreCase) result += 'i'; + if(that.multiline) result += 'm'; + if(that.unicode) result += 'u'; + if(that.sticky) result += 'y'; + return result; +}; +},{"./_an-object":9}],36:[function(require,module,exports){ +var ctx = require('./_ctx') + , call = require('./_iter-call') + , isArrayIter = require('./_is-array-iter') + , anObject = require('./_an-object') + , toLength = require('./_to-length') + , getIterFn = require('./core.get-iterator-method'); +module.exports = function(iterable, entries, fn, that, ITERATOR){ + var iterFn = ITERATOR ? function(){ return iterable; } : getIterFn(iterable) + , f = ctx(fn, that, entries ? 2 : 1) + , index = 0 + , length, step, iterator; + if(typeof iterFn != 'function')throw TypeError(iterable + ' is not iterable!'); + // fast case for arrays with default iterator + if(isArrayIter(iterFn))for(length = toLength(iterable.length); length > index; index++){ + entries ? f(anObject(step = iterable[index])[0], step[1]) : f(iterable[index]); + } else for(iterator = iterFn.call(iterable); !(step = iterator.next()).done; ){ + call(iterator, f, step.value, entries); + } +}; +},{"./_an-object":9,"./_ctx":25,"./_is-array-iter":45,"./_iter-call":50,"./_to-length":106,"./core.get-iterator-method":114}],37:[function(require,module,exports){ +// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 +var global = module.exports = typeof window != 'undefined' && window.Math == Math + ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); +if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef +},{}],38:[function(require,module,exports){ +var hasOwnProperty = {}.hasOwnProperty; +module.exports = function(it, key){ + return hasOwnProperty.call(it, key); +}; +},{}],39:[function(require,module,exports){ +var dP = require('./_object-dp') + , createDesc = require('./_property-desc'); +module.exports = require('./_descriptors') ? function(object, key, value){ + return dP.f(object, key, createDesc(1, value)); +} : function(object, key, value){ + object[key] = value; + return object; +}; +},{"./_descriptors":27,"./_object-dp":66,"./_property-desc":83}],40:[function(require,module,exports){ +module.exports = require('./_global').document && document.documentElement; +},{"./_global":37}],41:[function(require,module,exports){ +module.exports = !require('./_descriptors') && !require('./_fails')(function(){ + return Object.defineProperty(require('./_dom-create')('div'), 'a', {get: function(){ return 7; }}).a != 7; +}); +},{"./_descriptors":27,"./_dom-create":28,"./_fails":33}],42:[function(require,module,exports){ +var isObject = require('./_is-object') + , setPrototypeOf = require('./_set-proto').set; +module.exports = function(that, target, C){ + var P, S = target.constructor; + if(S !== C && typeof S == 'function' && (P = S.prototype) !== C.prototype && isObject(P) && setPrototypeOf){ + setPrototypeOf(that, P); + } return that; +}; +},{"./_is-object":48,"./_set-proto":88}],43:[function(require,module,exports){ +// fast apply, http://jsperf.lnkit.com/fast-apply/5 +module.exports = function(fn, args, that){ + var un = that === undefined; + switch(args.length){ + case 0: return un ? fn() + : fn.call(that); + case 1: return un ? fn(args[0]) + : fn.call(that, args[0]); + case 2: return un ? fn(args[0], args[1]) + : fn.call(that, args[0], args[1]); + case 3: return un ? fn(args[0], args[1], args[2]) + : fn.call(that, args[0], args[1], args[2]); + case 4: return un ? fn(args[0], args[1], args[2], args[3]) + : fn.call(that, args[0], args[1], args[2], args[3]); + } return fn.apply(that, args); +}; +},{}],44:[function(require,module,exports){ +// fallback for non-array-like ES3 and non-enumerable old V8 strings +var cof = require('./_cof'); +module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){ + return cof(it) == 'String' ? it.split('') : Object(it); +}; +},{"./_cof":19}],45:[function(require,module,exports){ +// check on default Array iterator +var Iterators = require('./_iterators') + , ITERATOR = require('./_wks')('iterator') + , ArrayProto = Array.prototype; + +module.exports = function(it){ + return it !== undefined && (Iterators.Array === it || ArrayProto[ITERATOR] === it); +}; +},{"./_iterators":55,"./_wks":113}],46:[function(require,module,exports){ +// 7.2.2 IsArray(argument) +var cof = require('./_cof'); +module.exports = Array.isArray || function isArray(arg){ + return cof(arg) == 'Array'; +}; +},{"./_cof":19}],47:[function(require,module,exports){ +// 20.1.2.3 Number.isInteger(number) +var isObject = require('./_is-object') + , floor = Math.floor; +module.exports = function isInteger(it){ + return !isObject(it) && isFinite(it) && floor(it) === it; +}; +},{"./_is-object":48}],48:[function(require,module,exports){ +module.exports = function(it){ + return typeof it === 'object' ? it !== null : typeof it === 'function'; +}; +},{}],49:[function(require,module,exports){ +// 7.2.8 IsRegExp(argument) +var isObject = require('./_is-object') + , cof = require('./_cof') + , MATCH = require('./_wks')('match'); +module.exports = function(it){ + var isRegExp; + return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : cof(it) == 'RegExp'); +}; +},{"./_cof":19,"./_is-object":48,"./_wks":113}],50:[function(require,module,exports){ +// call something on iterator step with safe closing on error +var anObject = require('./_an-object'); +module.exports = function(iterator, fn, value, entries){ + try { + return entries ? fn(anObject(value)[0], value[1]) : fn(value); + // 7.4.6 IteratorClose(iterator, completion) + } catch(e){ + var ret = iterator['return']; + if(ret !== undefined)anObject(ret.call(iterator)); + throw e; + } +}; +},{"./_an-object":9}],51:[function(require,module,exports){ +'use strict'; +var create = require('./_object-create') + , descriptor = require('./_property-desc') + , setToStringTag = require('./_set-to-string-tag') + , IteratorPrototype = {}; + +// 25.1.2.1.1 %IteratorPrototype%[@@iterator]() +require('./_hide')(IteratorPrototype, require('./_wks')('iterator'), function(){ return this; }); + +module.exports = function(Constructor, NAME, next){ + Constructor.prototype = create(IteratorPrototype, {next: descriptor(1, next)}); + setToStringTag(Constructor, NAME + ' Iterator'); +}; +},{"./_hide":39,"./_object-create":65,"./_property-desc":83,"./_set-to-string-tag":90,"./_wks":113}],52:[function(require,module,exports){ +'use strict'; +var LIBRARY = require('./_library') + , $export = require('./_export') + , redefine = require('./_redefine') + , hide = require('./_hide') + , has = require('./_has') + , Iterators = require('./_iterators') + , $iterCreate = require('./_iter-create') + , setToStringTag = require('./_set-to-string-tag') + , getPrototypeOf = require('./_object-gpo') + , ITERATOR = require('./_wks')('iterator') + , BUGGY = !([].keys && 'next' in [].keys()) // Safari has buggy iterators w/o `next` + , FF_ITERATOR = '@@iterator' + , KEYS = 'keys' + , VALUES = 'values'; + +var returnThis = function(){ return this; }; + +module.exports = function(Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED){ + $iterCreate(Constructor, NAME, next); + var getMethod = function(kind){ + if(!BUGGY && kind in proto)return proto[kind]; + switch(kind){ + case KEYS: return function keys(){ return new Constructor(this, kind); }; + case VALUES: return function values(){ return new Constructor(this, kind); }; + } return function entries(){ return new Constructor(this, kind); }; + }; + var TAG = NAME + ' Iterator' + , DEF_VALUES = DEFAULT == VALUES + , VALUES_BUG = false + , proto = Base.prototype + , $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT] + , $default = $native || getMethod(DEFAULT) + , $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined + , $anyNative = NAME == 'Array' ? proto.entries || $native : $native + , methods, key, IteratorPrototype; + // Fix native + if($anyNative){ + IteratorPrototype = getPrototypeOf($anyNative.call(new Base)); + if(IteratorPrototype !== Object.prototype){ + // Set @@toStringTag to native iterators + setToStringTag(IteratorPrototype, TAG, true); + // fix for some old engines + if(!LIBRARY && !has(IteratorPrototype, ITERATOR))hide(IteratorPrototype, ITERATOR, returnThis); + } + } + // fix Array#{values, @@iterator}.name in V8 / FF + if(DEF_VALUES && $native && $native.name !== VALUES){ + VALUES_BUG = true; + $default = function values(){ return $native.call(this); }; + } + // Define iterator + if((!LIBRARY || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])){ + hide(proto, ITERATOR, $default); + } + // Plug for library + Iterators[NAME] = $default; + Iterators[TAG] = returnThis; + if(DEFAULT){ + methods = { + values: DEF_VALUES ? $default : getMethod(VALUES), + keys: IS_SET ? $default : getMethod(KEYS), + entries: $entries + }; + if(FORCED)for(key in methods){ + if(!(key in proto))redefine(proto, key, methods[key]); + } else $export($export.P + $export.F * (BUGGY || VALUES_BUG), NAME, methods); + } + return methods; +}; +},{"./_export":31,"./_has":38,"./_hide":39,"./_iter-create":51,"./_iterators":55,"./_library":57,"./_object-gpo":72,"./_redefine":85,"./_set-to-string-tag":90,"./_wks":113}],53:[function(require,module,exports){ +var ITERATOR = require('./_wks')('iterator') + , SAFE_CLOSING = false; + +try { + var riter = [7][ITERATOR](); + riter['return'] = function(){ SAFE_CLOSING = true; }; + Array.from(riter, function(){ throw 2; }); +} catch(e){ /* empty */ } + +module.exports = function(exec, skipClosing){ + if(!skipClosing && !SAFE_CLOSING)return false; + var safe = false; + try { + var arr = [7] + , iter = arr[ITERATOR](); + iter.next = function(){ safe = true; }; + arr[ITERATOR] = function(){ return iter; }; + exec(arr); + } catch(e){ /* empty */ } + return safe; +}; +},{"./_wks":113}],54:[function(require,module,exports){ +module.exports = function(done, value){ + return {value: value, done: !!done}; +}; +},{}],55:[function(require,module,exports){ +module.exports = {}; +},{}],56:[function(require,module,exports){ +var getKeys = require('./_object-keys') + , toIObject = require('./_to-iobject'); +module.exports = function(object, el){ + var O = toIObject(object) + , keys = getKeys(O) + , length = keys.length + , index = 0 + , key; + while(length > index)if(O[key = keys[index++]] === el)return key; +}; +},{"./_object-keys":74,"./_to-iobject":105}],57:[function(require,module,exports){ +module.exports = false; +},{}],58:[function(require,module,exports){ +// 20.2.2.14 Math.expm1(x) +module.exports = Math.expm1 || function expm1(x){ + return (x = +x) == 0 ? x : x > -1e-6 && x < 1e-6 ? x + x * x / 2 : Math.exp(x) - 1; +}; +},{}],59:[function(require,module,exports){ +// 20.2.2.20 Math.log1p(x) +module.exports = Math.log1p || function log1p(x){ + return (x = +x) > -1e-8 && x < 1e-8 ? x - x * x / 2 : Math.log(1 + x); +}; +},{}],60:[function(require,module,exports){ +// 20.2.2.28 Math.sign(x) +module.exports = Math.sign || function sign(x){ + return (x = +x) == 0 || x != x ? x : x < 0 ? -1 : 1; +}; +},{}],61:[function(require,module,exports){ +var META = require('./_uid')('meta') + , isObject = require('./_is-object') + , has = require('./_has') + , setDesc = require('./_object-dp').f + , id = 0; +var isExtensible = Object.isExtensible || function(){ + return true; +}; +var FREEZE = !require('./_fails')(function(){ + return isExtensible(Object.preventExtensions({})); +}); +var setMeta = function(it){ + setDesc(it, META, {value: { + i: 'O' + ++id, // object ID + w: {} // weak collections IDs + }}); +}; +var fastKey = function(it, create){ + // return primitive with prefix + if(!isObject(it))return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it; + if(!has(it, META)){ + // can't set metadata to uncaught frozen object + if(!isExtensible(it))return 'F'; + // not necessary to add metadata + if(!create)return 'E'; + // add missing metadata + setMeta(it); + // return object ID + } return it[META].i; +}; +var getWeak = function(it, create){ + if(!has(it, META)){ + // can't set metadata to uncaught frozen object + if(!isExtensible(it))return true; + // not necessary to add metadata + if(!create)return false; + // add missing metadata + setMeta(it); + // return hash weak collections IDs + } return it[META].w; +}; +// add metadata on freeze-family methods calling +var onFreeze = function(it){ + if(FREEZE && meta.NEED && isExtensible(it) && !has(it, META))setMeta(it); + return it; +}; +var meta = module.exports = { + KEY: META, + NEED: false, + fastKey: fastKey, + getWeak: getWeak, + onFreeze: onFreeze +}; +},{"./_fails":33,"./_has":38,"./_is-object":48,"./_object-dp":66,"./_uid":112}],62:[function(require,module,exports){ +var Map = require('./es6.map') + , $export = require('./_export') + , shared = require('./_shared')('metadata') + , store = shared.store || (shared.store = new (require('./es6.weak-map'))); + +var getOrCreateMetadataMap = function(target, targetKey, create){ + var targetMetadata = store.get(target); + if(!targetMetadata){ + if(!create)return undefined; + store.set(target, targetMetadata = new Map); + } + var keyMetadata = targetMetadata.get(targetKey); + if(!keyMetadata){ + if(!create)return undefined; + targetMetadata.set(targetKey, keyMetadata = new Map); + } return keyMetadata; +}; +var ordinaryHasOwnMetadata = function(MetadataKey, O, P){ + var metadataMap = getOrCreateMetadataMap(O, P, false); + return metadataMap === undefined ? false : metadataMap.has(MetadataKey); +}; +var ordinaryGetOwnMetadata = function(MetadataKey, O, P){ + var metadataMap = getOrCreateMetadataMap(O, P, false); + return metadataMap === undefined ? undefined : metadataMap.get(MetadataKey); +}; +var ordinaryDefineOwnMetadata = function(MetadataKey, MetadataValue, O, P){ + getOrCreateMetadataMap(O, P, true).set(MetadataKey, MetadataValue); +}; +var ordinaryOwnMetadataKeys = function(target, targetKey){ + var metadataMap = getOrCreateMetadataMap(target, targetKey, false) + , keys = []; + if(metadataMap)metadataMap.forEach(function(_, key){ keys.push(key); }); + return keys; +}; +var toMetaKey = function(it){ + return it === undefined || typeof it == 'symbol' ? it : String(it); +}; +var exp = function(O){ + $export($export.S, 'Reflect', O); +}; + +module.exports = { + store: store, + map: getOrCreateMetadataMap, + has: ordinaryHasOwnMetadata, + get: ordinaryGetOwnMetadata, + set: ordinaryDefineOwnMetadata, + keys: ordinaryOwnMetadataKeys, + key: toMetaKey, + exp: exp +}; +},{"./_export":31,"./_shared":92,"./es6.map":145,"./es6.weak-map":251}],63:[function(require,module,exports){ +var global = require('./_global') + , macrotask = require('./_task').set + , Observer = global.MutationObserver || global.WebKitMutationObserver + , process = global.process + , Promise = global.Promise + , isNode = require('./_cof')(process) == 'process' + , head, last, notify; + +var flush = function(){ + var parent, fn; + if(isNode && (parent = process.domain))parent.exit(); + while(head){ + fn = head.fn; + fn(); // <- currently we use it only for Promise - try / catch not required + head = head.next; + } last = undefined; + if(parent)parent.enter(); +}; + +// Node.js +if(isNode){ + notify = function(){ + process.nextTick(flush); + }; +// browsers with MutationObserver +} else if(Observer){ + var toggle = true + , node = document.createTextNode(''); + new Observer(flush).observe(node, {characterData: true}); // eslint-disable-line no-new + notify = function(){ + node.data = toggle = !toggle; + }; +// environments with maybe non-completely correct, but existent Promise +} else if(Promise && Promise.resolve){ + notify = function(){ + Promise.resolve().then(flush); + }; +// for other environments - macrotask based on: +// - setImmediate +// - MessageChannel +// - window.postMessag +// - onreadystatechange +// - setTimeout +} else { + notify = function(){ + // strange IE + webpack dev server bug - use .call(global) + macrotask.call(global, flush); + }; +} + +module.exports = function(fn){ + var task = {fn: fn, next: undefined}; + if(last)last.next = task; + if(!head){ + head = task; + notify(); + } last = task; +}; +},{"./_cof":19,"./_global":37,"./_task":102}],64:[function(require,module,exports){ +'use strict'; +// 19.1.2.1 Object.assign(target, source, ...) +var getKeys = require('./_object-keys') + , gOPS = require('./_object-gops') + , pIE = require('./_object-pie') + , toObject = require('./_to-object') + , IObject = require('./_iobject') + , $assign = Object.assign; + +// should work with symbols and should have deterministic property order (V8 bug) +module.exports = !$assign || require('./_fails')(function(){ + var A = {} + , B = {} + , S = Symbol() + , K = 'abcdefghijklmnopqrst'; + A[S] = 7; + K.split('').forEach(function(k){ B[k] = k; }); + return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K; +}) ? function assign(target, source){ // eslint-disable-line no-unused-vars + var T = toObject(target) + , aLen = arguments.length + , index = 1 + , getSymbols = gOPS.f + , isEnum = pIE.f; + while(aLen > index){ + var S = IObject(arguments[index++]) + , keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S) + , length = keys.length + , j = 0 + , key; + while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key]; + } return T; +} : $assign; +},{"./_fails":33,"./_iobject":44,"./_object-gops":71,"./_object-keys":74,"./_object-pie":75,"./_to-object":107}],65:[function(require,module,exports){ +// 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties]) +var anObject = require('./_an-object') + , dPs = require('./_object-dps') + , enumBugKeys = require('./_enum-bug-keys') + , IE_PROTO = require('./_shared-key')('IE_PROTO') + , Empty = function(){ /* empty */ } + , PROTOTYPE = 'prototype'; + +// Create object with fake `null` prototype: use iframe Object with cleared prototype +var createDict = function(){ + // Thrash, waste and sodomy: IE GC bug + var iframe = require('./_dom-create')('iframe') + , i = enumBugKeys.length + , gt = '>' + , iframeDocument; + iframe.style.display = 'none'; + require('./_html').appendChild(iframe); + iframe.src = 'javascript:'; // eslint-disable-line no-script-url + // createDict = iframe.contentWindow.Object; + // html.removeChild(iframe); + iframeDocument = iframe.contentWindow.document; + iframeDocument.open(); + iframeDocument.write('