diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 00000000000..c5626c297d2 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,32 @@ +# Save as .codeclimate.yml (note leading .) in project root directory +languages: + JavaScript: true + +exclude_paths: + - "tests/*" + - "generators/*" + - "blueprints/*" + - "bin/*" + - "lib/*" + - "node-tests/*" + +version: "2" # required to adjust maintainability checks +checks: + argument-count: + config: + threshold: 4 + complex-logic: + config: + threshold: 4 + file-lines: + enabled: false # we should re-enable this and slowly reduce to ~750 over time + method-complexity: + enabled: false # we should re-enable this and slowly reduce to ~10 over time + method-count: + config: + threshold: 50 + method-lines: + config: + threshold: 100 + identical-code: + enabled: false # we should re-enable this once we no longer have a separate build step for RecordData diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..219985c2289 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +[*.hbs] +insert_final_newline = false + +[*.{diff,md}] +trim_trailing_whitespace = false diff --git a/.ember-cli b/.ember-cli new file mode 100644 index 00000000000..ee64cfed2a8 --- /dev/null +++ b/.ember-cli @@ -0,0 +1,9 @@ +{ + /** + Ember CLI sends analytics information by default. The data is completely + anonymous, but there are times when you might want to disable this behavior. + + Setting `disableAnalytics` to true will prevent any data from being sent. + */ + "disableAnalytics": false +} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000000..5bdf749fccd --- /dev/null +++ b/.eslintignore @@ -0,0 +1,7 @@ +tmp +dist +node-tests/fixtures/ +blueprints/*/mocha-files/ +blueprints/*/qunit-files/ +blueprints/*/files/ +blueprints/*/native-files/ diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000000..e8cb3d64082 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,108 @@ +module.exports = { + root: true, + parserOptions: { + ecmaVersion: 2017, + sourceType: 'module', + }, + parser: 'babel-eslint', + extends: ['eslint:recommended', 'prettier'], + plugins: ['prettier'], + rules: { + 'prettier/prettier': 'error', + + 'no-unused-vars': ['error', { + 'args': 'none', + }], + + // from JSHint + 'no-cond-assign': ['error', 'except-parens'], + 'eqeqeq': 'error', + 'no-eval': 'error', + 'new-cap': ['error', { + 'capIsNew': false, + }], + 'no-caller': 'error', + 'no-irregular-whitespace': 'error', + 'no-undef': 'error', + 'no-eq-null': 'error', + }, + overrides: [ + // node files + { + files: [ + 'ember-cli-build.js', + 'index.js', + 'testem.js', + 'lib/**/*.js', + 'blueprints/*/index.js', + 'blueprints/*.js', + 'config/**/*.js', + 'tests/dummy/config/**/*.js', + 'node-tests/**', + 'bin/**', + ], + excludedFiles: [ + 'addon/**', + 'addon-test-support/**', + 'app/**', + 'tests/dummy/app/**' + ], + parserOptions: { + sourceType: 'script', + ecmaVersion: 2015 + }, + env: { + browser: false, + node: true, + es6: true, + }, + plugins: ['node'], + rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, { + // add your custom rules and overrides for node files here + }) + }, + + // browser files + { + files: [ + 'addon/**', + 'app/**', + 'tests/**', + ], + excludedFiles: [ + 'tests/dummy/config/**' + ], + env: { + browser: true, + node: false, + }, + globals: { + heimdall: true, + Map: false, + WeakMap: true, + } + }, + + // browser tests + { + files: [ + 'tests/**' + ], + + rules: { + 'no-console': 0 + } + }, + + // node tests + { + files: [ + 'node-tests/**' + ], + + env: { + mocha: true, + } + } + ], +}; diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000000..4cc61ebc863 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,38 @@ +# Thank you for opening this issue! + +Hopefully, this issue template will help you provide us with enough information to assist in resolving the issue. + +If you haven't already browsed recent issues (or less recent issues if this is for a past release), please do + so first to see if your issue already has a ticket created for it. It is usually best to first ask about the + issue you are observing in the `#ember-data` channel on [Discord](https://discord.gg/zT3asNS), doing so may + help you discover existing issues or provide a clearer reproduction. + +### Reproduction + +Please provide one of the following: + +- a PR linking to this issue with a failing test showing the issue +- a [Twiddle](https://ember-twiddle.com/) with a simplified reproduction and instructions for how to + observe the unexpected result. +- a github repository with a simplified reproduction and instructions for how to observe the unexpected result + +### Description + +Describe the issue in a few sentences, include both the *expected* result and the observed *unexpected* result. +If a previous version of `ember-data` worked as `expected`, which was the most recent version that worked? + +### Versions + +Run the following command and paste the output below: `npm ls ember-source && npm ls ember-cli && npm ls ember-data`. + +```cli +[Replace this line with the output] +``` + +*P.S. If any of the packages show more than one installed version, that may be the root cause of the issue!* + +-------------------------------------------------------------- + +Thanks again! + +The `ember-data` Team <3 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000000..39271b7c656 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,3 @@ +// ... please delete this default text after reading + +If this is your first PR to `ember-data`, you may want to read our [Contributor Guide](https://github.com/emberjs/data/blob/master/CONTRIBUTING.md). diff --git a/.gitignore b/.gitignore index dda4bf08f01..3f82369c2b6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,11 +3,16 @@ bundle tmp/ tests/source/ dist/ +*.iml +yarn-error.log + +benchmarks/results/*.json .DS_Store .project .github-upload-token +*.swp tests/ember-data-tests.js *gem @@ -16,3 +21,10 @@ docs/build/ docs/node_modules/ node_modules/ +bower_components/ +.metadata_never_index +npm-debug.log + +/DEBUG + +.vscode/ \ No newline at end of file diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 5e4b72c7e3b..00000000000 --- a/.jshintrc +++ /dev/null @@ -1,64 +0,0 @@ -{ - "predef": [ - "console", - "requireModule", - "Ember", - "DS", - "Handlebars", - "Metamorph", - "ember_assert", - "ember_warn", - "ember_deprecate", - "ember_deprecateFunc", - "require", - "setupStore", - "createStore", - "equal", - "asyncEqual", - "notEqual", - "asyncTest", - "test", - "raises", - "deepEqual", - "start", - "stop", - "ok", - "strictEqual", - "module", - "expect", - "minispade", - "async", - "invokeAsync", - "jQuery", - "expectAssertion", - "expectDeprecation" - - ], - - "node" : false, - "es3" : true, - "browser" : true, - - "boss" : true, - "curly": false, - "debug": false, - "devel": false, - "eqeqeq": true, - "evil": true, - "forin": false, - "immed": false, - "laxbreak": false, - "newcap": true, - "noarg": true, - "noempty": false, - "nonew": false, - "nomen": false, - "onevar": false, - "plusplus": false, - "regexp": false, - "undef": true, - "sub": true, - "strict": false, - "white": false, - "eqnull": true -} diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000000..a032d9a0a41 --- /dev/null +++ b/.npmignore @@ -0,0 +1,35 @@ +/bower_components +/config/ember-try.js +/node-tests +/tests +/tmp +/bin +/docs +/.node_modules.ember-try +/notes + +# Ignore all assets except /dist/docs folder +/dist/assets/ +/dist/crossdomain.xml +/dist/index.html +/dist/robots.txt + +**/.gitkeep +.appveyor.yml +.bowerrc +.editorconfig +.ember-cli +.gitignore +.eslintrc.js +.watchmanconfig +.travis.yml +bower.json +ember-cli-build.js +testem.js +yarn.lock + +*.gem +*.gemspec +**/*.rb +node-tests/ +lib/version-replace.js diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000000..43c97e719a5 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000000..978b4d511ea --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + singleQuote: true, + trailingComma: 'es5', + printWidth: 100, +}; diff --git a/.travis.yml b/.travis.yml index ff7ac4908b6..942538b69c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,138 @@ --- -rvm: -- 1.9.3 +language: node_js +sudo: false +dist: trusty +node_js: + - "10" + +addons: + chrome: stable + firefox: latest + +cache: + yarn: true + +branches: + only: + - master + - beta + - release + # release and LTS branches + - /^(release|lts)-.*/ + # npm version tags + - /^v\d+\.\d+\.\d+/ + +stages: + - test + - additional tests + - ember version tests + - name: external partner tests + if: NOT (branch ~= /^(release|lts).*/) + - name: deploy + if: type = push AND (branch IN (master, beta, release) OR tag IS present) + +jobs: + fail_fast: true + + include: + # runs tests with current locked deps and linting + - stage: test + name: "Linting" + if: NOT (branch ~= /^(release|lts).*/) + script: + - ./bin/lint-features + - yarn lint:js + - name: "Basic Tests" + script: yarn test + + - stage: additional tests + name: "Optional Features" + if: NOT (branch ~= /^(release|lts).*/) + install: yarn install + script: yarn test:optional-features + + - name: "Floating Dependencies" + install: yarn install --no-lockfile --non-interactive + script: yarn test + + - name: "Production" + install: yarn install + script: yarn test:production + + - name: "Max Transpilation" + install: yarn install + env: TARGET_IE11=true + script: yarn test + + - name: "Node Tests" + install: yarn install + script: yarn test:node + + # runs tests against each supported Ember version + - stage: ember version tests + name: "Ember LTS 2.18" + env: EMBER_TRY_SCENARIO=ember-lts-2.18 + - name: "Ember LTS 3.4" + env: EMBER_TRY_SCENARIO=ember-lts-3.4 + - name: "Ember Release" + if: NOT (branch ~= /^(release|lts).*/) + env: EMBER_TRY_SCENARIO=ember-release + - name: "Ember Beta" + if: NOT (branch ~= /^(release|lts).*/) + env: EMBER_TRY_SCENARIO=ember-beta + - name: "Ember Canary" + if: NOT (branch ~= /^(release|lts).*/) + env: EMBER_TRY_SCENARIO=ember-canary + + # runs tests against various open-source projects for early-warning regression analysis + # We typically have 4 concurrent jobs, these jobs below are ordered to optimize total completion time + # By running longer jobs first, we allow the shorter jobs to complete within the same time block in parallel + - stage: external partner tests + name: "Ilios Frontend" # ~30min job + script: yarn test-external:ilios-frontend + - name: "Travis Web" # ~10min job + script: yarn test-external:travis-web + - name: "Ember Data Storefront" # ~5min job + script: yarn test-external:storefront + - name: "Ember Data Factory Guy" # ~5min job + script: yarn test-external:factory-guy + - name: "Ember Observer" # ~5min job + script: yarn test-external:ember-observer + - name: "Ember Resource Metadata" # ~4.25min job + script: yarn test-external:ember-resource-metadata + - name: "Ember Data Relationship Tracker" # ~4.25min job + script: yarn test-external:ember-data-relationship-tracker + - name: "Ember Data Model Fragments" # ~3.5min job + script: yarn test-external:model-fragments + - name: "emberaddons.com" # ~3.5min job + script: yarn test-external:emberaddons.com + - name: "Ember Data Change Tracker" # ~3.5min job + script: yarn test-external:ember-data-change-tracker + - name: "ember-m3" # ~3.5min job + script: yarn test-external:ember-m3 + + - stage: deploy + name: "Publish" + install: yarn install + script: + - node_modules/.bin/ember try:reset + - yarn build:production + + +before_install: + - curl -o- -L https://yarnpkg.com/install.sh | bash + - export PATH=$HOME/.yarn/bin:$PATH + install: -- "bin/cached-npm install" -- "bin/cached-bundle install --deployment" -- sudo apt-get update && sudo apt-get install git -script: bundle exec rake test[all] -after_success: bundle exec rake publish_build + - yarn install + - yarn add global bower + +script: + - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup + env: global: + - BROCCOLI_ENV="production" - S3_BUILD_CACHE_BUCKET=emberjs-build-cache - S3_BUCKET_NAME=builds.emberjs.com - secure: ! 'S+DIdzEPvqQenk1cFq5UjbkoEKDY4j3E/g+Wlz798xxyTkrKQZxoazLXng8I @@ -21,3 +145,5 @@ env: UvaE/CbWMxO/6FszR02gJHaF+YyfU5WAS0ahFFLHuC1twMtQPxi+nScjKZEs kLwKiKgRNhindV3WvbUcoiIrmrgBMCiBRRd4eyVBlhbZ8RTo1Ig=' + + - secure: "hJZXijsot2wMiMsxbDImH+nB5v77a7O7lQ7bicOQEQxmnTtXSvqfa4X4vQ/d4o7NNYYYHUuOpyILgRV+arqI6UOi7XEVGka/7M5q58R5exS6bk0cY0jnpUhUVW/8mpKEUgcVeE6mIDWaR090l3uaT2JhU/WSLkzbj45e38HaF/4=" diff --git a/.watchmanconfig b/.watchmanconfig new file mode 100644 index 00000000000..e7834e3e4f3 --- /dev/null +++ b/.watchmanconfig @@ -0,0 +1,3 @@ +{ + "ignore_dirs": ["tmp", "dist"] +} diff --git a/.yarn/releases/yarn-1.13.0.js b/.yarn/releases/yarn-1.13.0.js new file mode 100755 index 00000000000..4a4cb0d3de9 --- /dev/null +++ b/.yarn/releases/yarn-1.13.0.js @@ -0,0 +1,136098 @@ +#!/usr/bin/env node +module.exports = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 520); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports) { + +module.exports = require("path"); + +/***/ }), +/* 1 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony export (immutable) */ __webpack_exports__["a"] = __extends; +/* unused harmony export __assign */ +/* unused harmony export __rest */ +/* unused harmony export __decorate */ +/* unused harmony export __param */ +/* unused harmony export __metadata */ +/* unused harmony export __awaiter */ +/* unused harmony export __generator */ +/* unused harmony export __exportStar */ +/* unused harmony export __values */ +/* unused harmony export __read */ +/* unused harmony export __spread */ +/* unused harmony export __await */ +/* unused harmony export __asyncGenerator */ +/* unused harmony export __asyncDelegator */ +/* unused harmony export __asyncValues */ +/* unused harmony export __makeTemplateObject */ +/* unused harmony export __importStar */ +/* unused harmony export __importDefault */ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ +/* global Reflect, Promise */ + +var extendStatics = function(d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); +}; + +function __extends(d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +} + +var __assign = function() { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + } + return __assign.apply(this, arguments); +} + +function __rest(s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) + t[p[i]] = s[p[i]]; + return t; +} + +function __decorate(decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +} + +function __param(paramIndex, decorator) { + return function (target, key) { decorator(target, key, paramIndex); } +} + +function __metadata(metadataKey, metadataValue) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); +} + +function __awaiter(thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +} + +function __generator(thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +} + +function __exportStar(m, exports) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} + +function __values(o) { + var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; + if (m) return m.call(o); + return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; +} + +function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +} + +function __spread() { + for (var ar = [], i = 0; i < arguments.length; i++) + ar = ar.concat(__read(arguments[i])); + return ar; +} + +function __await(v) { + return this instanceof __await ? (this.v = v, this) : new __await(v); +} + +function __asyncGenerator(thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +} + +function __asyncDelegator(o) { + var i, p; + return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; + function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } +} + +function __asyncValues(o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], i; + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); + function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } + function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } +} + +function __makeTemplateObject(cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; + +function __importStar(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result.default = mod; + return result; +} + +function __importDefault(mod) { + return (mod && mod.__esModule) ? mod : { default: mod }; +} + + +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +exports.__esModule = true; + +var _promise = __webpack_require__(216); + +var _promise2 = _interopRequireDefault(_promise); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = function (fn) { + return function () { + var gen = fn.apply(this, arguments); + return new _promise2.default(function (resolve, reject) { + function step(key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + + if (info.done) { + resolve(value); + } else { + return _promise2.default.resolve(value).then(function (value) { + step("next", value); + }, function (err) { + step("throw", err); + }); + } + } + + return step("next"); + }); + }; +}; + +/***/ }), +/* 3 */ +/***/ (function(module, exports) { + +module.exports = require("util"); + +/***/ }), +/* 4 */ +/***/ (function(module, exports) { + +module.exports = require("fs"); + +/***/ }), +/* 5 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.getFirstSuitableFolder = exports.readFirstAvailableStream = exports.makeTempDir = exports.hardlinksWork = exports.writeFilePreservingEol = exports.getFileSizeOnDisk = exports.walk = exports.symlink = exports.find = exports.readJsonAndFile = exports.readJson = exports.readFileAny = exports.hardlinkBulk = exports.copyBulk = exports.unlink = exports.glob = exports.link = exports.chmod = exports.lstat = exports.exists = exports.mkdirp = exports.stat = exports.access = exports.rename = exports.readdir = exports.realpath = exports.readlink = exports.writeFile = exports.open = exports.readFileBuffer = exports.lockQueue = exports.constants = undefined; + +var _asyncToGenerator2; + +function _load_asyncToGenerator() { + return _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(2)); +} + +let buildActionsForCopy = (() => { + var _ref = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (queue, events, possibleExtraneous, reporter) { + + // + let build = (() => { + var _ref5 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (data) { + const src = data.src, + dest = data.dest, + type = data.type; + + const onFresh = data.onFresh || noop; + const onDone = data.onDone || noop; + + // TODO https://github.com/yarnpkg/yarn/issues/3751 + // related to bundled dependencies handling + if (files.has(dest.toLowerCase())) { + reporter.verbose(`The case-insensitive file ${dest} shouldn't be copied twice in one bulk copy`); + } else { + files.add(dest.toLowerCase()); + } + + if (type === 'symlink') { + yield mkdirp((_path || _load_path()).default.dirname(dest)); + onFresh(); + actions.symlink.push({ + dest, + linkname: src + }); + onDone(); + return; + } + + if (events.ignoreBasenames.indexOf((_path || _load_path()).default.basename(src)) >= 0) { + // ignored file + return; + } + + const srcStat = yield lstat(src); + let srcFiles; + + if (srcStat.isDirectory()) { + srcFiles = yield readdir(src); + } + + let destStat; + try { + // try accessing the destination + destStat = yield lstat(dest); + } catch (e) { + // proceed if destination doesn't exist, otherwise error + if (e.code !== 'ENOENT') { + throw e; + } + } + + // if destination exists + if (destStat) { + const bothSymlinks = srcStat.isSymbolicLink() && destStat.isSymbolicLink(); + const bothFolders = srcStat.isDirectory() && destStat.isDirectory(); + const bothFiles = srcStat.isFile() && destStat.isFile(); + + // EINVAL access errors sometimes happen which shouldn't because node shouldn't be giving + // us modes that aren't valid. investigate this, it's generally safe to proceed. + + /* if (srcStat.mode !== destStat.mode) { + try { + await access(dest, srcStat.mode); + } catch (err) {} + } */ + + if (bothFiles && artifactFiles.has(dest)) { + // this file gets changed during build, likely by a custom install script. Don't bother checking it. + onDone(); + reporter.verbose(reporter.lang('verboseFileSkipArtifact', src)); + return; + } + + if (bothFiles && srcStat.size === destStat.size && (0, (_fsNormalized || _load_fsNormalized()).fileDatesEqual)(srcStat.mtime, destStat.mtime)) { + // we can safely assume this is the same file + onDone(); + reporter.verbose(reporter.lang('verboseFileSkip', src, dest, srcStat.size, +srcStat.mtime)); + return; + } + + if (bothSymlinks) { + const srcReallink = yield readlink(src); + if (srcReallink === (yield readlink(dest))) { + // if both symlinks are the same then we can continue on + onDone(); + reporter.verbose(reporter.lang('verboseFileSkipSymlink', src, dest, srcReallink)); + return; + } + } + + if (bothFolders) { + // mark files that aren't in this folder as possibly extraneous + const destFiles = yield readdir(dest); + invariant(srcFiles, 'src files not initialised'); + + for (var _iterator4 = destFiles, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { + var _ref6; + + if (_isArray4) { + if (_i4 >= _iterator4.length) break; + _ref6 = _iterator4[_i4++]; + } else { + _i4 = _iterator4.next(); + if (_i4.done) break; + _ref6 = _i4.value; + } + + const file = _ref6; + + if (srcFiles.indexOf(file) < 0) { + const loc = (_path || _load_path()).default.join(dest, file); + possibleExtraneous.add(loc); + + if ((yield lstat(loc)).isDirectory()) { + for (var _iterator5 = yield readdir(loc), _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { + var _ref7; + + if (_isArray5) { + if (_i5 >= _iterator5.length) break; + _ref7 = _iterator5[_i5++]; + } else { + _i5 = _iterator5.next(); + if (_i5.done) break; + _ref7 = _i5.value; + } + + const file = _ref7; + + possibleExtraneous.add((_path || _load_path()).default.join(loc, file)); + } + } + } + } + } + } + + if (destStat && destStat.isSymbolicLink()) { + yield (0, (_fsNormalized || _load_fsNormalized()).unlink)(dest); + destStat = null; + } + + if (srcStat.isSymbolicLink()) { + onFresh(); + const linkname = yield readlink(src); + actions.symlink.push({ + dest, + linkname + }); + onDone(); + } else if (srcStat.isDirectory()) { + if (!destStat) { + reporter.verbose(reporter.lang('verboseFileFolder', dest)); + yield mkdirp(dest); + } + + const destParts = dest.split((_path || _load_path()).default.sep); + while (destParts.length) { + files.add(destParts.join((_path || _load_path()).default.sep).toLowerCase()); + destParts.pop(); + } + + // push all files to queue + invariant(srcFiles, 'src files not initialised'); + let remaining = srcFiles.length; + if (!remaining) { + onDone(); + } + for (var _iterator6 = srcFiles, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { + var _ref8; + + if (_isArray6) { + if (_i6 >= _iterator6.length) break; + _ref8 = _iterator6[_i6++]; + } else { + _i6 = _iterator6.next(); + if (_i6.done) break; + _ref8 = _i6.value; + } + + const file = _ref8; + + queue.push({ + dest: (_path || _load_path()).default.join(dest, file), + onFresh, + onDone: function (_onDone) { + function onDone() { + return _onDone.apply(this, arguments); + } + + onDone.toString = function () { + return _onDone.toString(); + }; + + return onDone; + }(function () { + if (--remaining === 0) { + onDone(); + } + }), + src: (_path || _load_path()).default.join(src, file) + }); + } + } else if (srcStat.isFile()) { + onFresh(); + actions.file.push({ + src, + dest, + atime: srcStat.atime, + mtime: srcStat.mtime, + mode: srcStat.mode + }); + onDone(); + } else { + throw new Error(`unsure how to copy this: ${src}`); + } + }); + + return function build(_x5) { + return _ref5.apply(this, arguments); + }; + })(); + + const artifactFiles = new Set(events.artifactFiles || []); + const files = new Set(); + + // initialise events + for (var _iterator = queue, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref2; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref2 = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref2 = _i.value; + } + + const item = _ref2; + + const onDone = item.onDone; + item.onDone = function () { + events.onProgress(item.dest); + if (onDone) { + onDone(); + } + }; + } + events.onStart(queue.length); + + // start building actions + const actions = { + file: [], + symlink: [], + link: [] + }; + + // custom concurrency logic as we're always executing stacks of CONCURRENT_QUEUE_ITEMS queue items + // at a time due to the requirement to push items onto the queue + while (queue.length) { + const items = queue.splice(0, CONCURRENT_QUEUE_ITEMS); + yield Promise.all(items.map(build)); + } + + // simulate the existence of some files to prevent considering them extraneous + for (var _iterator2 = artifactFiles, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref3; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref3 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref3 = _i2.value; + } + + const file = _ref3; + + if (possibleExtraneous.has(file)) { + reporter.verbose(reporter.lang('verboseFilePhantomExtraneous', file)); + possibleExtraneous.delete(file); + } + } + + for (var _iterator3 = possibleExtraneous, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { + var _ref4; + + if (_isArray3) { + if (_i3 >= _iterator3.length) break; + _ref4 = _iterator3[_i3++]; + } else { + _i3 = _iterator3.next(); + if (_i3.done) break; + _ref4 = _i3.value; + } + + const loc = _ref4; + + if (files.has(loc.toLowerCase())) { + possibleExtraneous.delete(loc); + } + } + + return actions; + }); + + return function buildActionsForCopy(_x, _x2, _x3, _x4) { + return _ref.apply(this, arguments); + }; +})(); + +let buildActionsForHardlink = (() => { + var _ref9 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (queue, events, possibleExtraneous, reporter) { + + // + let build = (() => { + var _ref13 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (data) { + const src = data.src, + dest = data.dest; + + const onFresh = data.onFresh || noop; + const onDone = data.onDone || noop; + if (files.has(dest.toLowerCase())) { + // Fixes issue https://github.com/yarnpkg/yarn/issues/2734 + // When bulk hardlinking we have A -> B structure that we want to hardlink to A1 -> B1, + // package-linker passes that modules A1 and B1 need to be hardlinked, + // the recursive linking algorithm of A1 ends up scheduling files in B1 to be linked twice which will case + // an exception. + onDone(); + return; + } + files.add(dest.toLowerCase()); + + if (events.ignoreBasenames.indexOf((_path || _load_path()).default.basename(src)) >= 0) { + // ignored file + return; + } + + const srcStat = yield lstat(src); + let srcFiles; + + if (srcStat.isDirectory()) { + srcFiles = yield readdir(src); + } + + const destExists = yield exists(dest); + if (destExists) { + const destStat = yield lstat(dest); + + const bothSymlinks = srcStat.isSymbolicLink() && destStat.isSymbolicLink(); + const bothFolders = srcStat.isDirectory() && destStat.isDirectory(); + const bothFiles = srcStat.isFile() && destStat.isFile(); + + if (srcStat.mode !== destStat.mode) { + try { + yield access(dest, srcStat.mode); + } catch (err) { + // EINVAL access errors sometimes happen which shouldn't because node shouldn't be giving + // us modes that aren't valid. investigate this, it's generally safe to proceed. + reporter.verbose(err); + } + } + + if (bothFiles && artifactFiles.has(dest)) { + // this file gets changed during build, likely by a custom install script. Don't bother checking it. + onDone(); + reporter.verbose(reporter.lang('verboseFileSkipArtifact', src)); + return; + } + + // correct hardlink + if (bothFiles && srcStat.ino !== null && srcStat.ino === destStat.ino) { + onDone(); + reporter.verbose(reporter.lang('verboseFileSkip', src, dest, srcStat.ino)); + return; + } + + if (bothSymlinks) { + const srcReallink = yield readlink(src); + if (srcReallink === (yield readlink(dest))) { + // if both symlinks are the same then we can continue on + onDone(); + reporter.verbose(reporter.lang('verboseFileSkipSymlink', src, dest, srcReallink)); + return; + } + } + + if (bothFolders) { + // mark files that aren't in this folder as possibly extraneous + const destFiles = yield readdir(dest); + invariant(srcFiles, 'src files not initialised'); + + for (var _iterator10 = destFiles, _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) { + var _ref14; + + if (_isArray10) { + if (_i10 >= _iterator10.length) break; + _ref14 = _iterator10[_i10++]; + } else { + _i10 = _iterator10.next(); + if (_i10.done) break; + _ref14 = _i10.value; + } + + const file = _ref14; + + if (srcFiles.indexOf(file) < 0) { + const loc = (_path || _load_path()).default.join(dest, file); + possibleExtraneous.add(loc); + + if ((yield lstat(loc)).isDirectory()) { + for (var _iterator11 = yield readdir(loc), _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) { + var _ref15; + + if (_isArray11) { + if (_i11 >= _iterator11.length) break; + _ref15 = _iterator11[_i11++]; + } else { + _i11 = _iterator11.next(); + if (_i11.done) break; + _ref15 = _i11.value; + } + + const file = _ref15; + + possibleExtraneous.add((_path || _load_path()).default.join(loc, file)); + } + } + } + } + } + } + + if (srcStat.isSymbolicLink()) { + onFresh(); + const linkname = yield readlink(src); + actions.symlink.push({ + dest, + linkname + }); + onDone(); + } else if (srcStat.isDirectory()) { + reporter.verbose(reporter.lang('verboseFileFolder', dest)); + yield mkdirp(dest); + + const destParts = dest.split((_path || _load_path()).default.sep); + while (destParts.length) { + files.add(destParts.join((_path || _load_path()).default.sep).toLowerCase()); + destParts.pop(); + } + + // push all files to queue + invariant(srcFiles, 'src files not initialised'); + let remaining = srcFiles.length; + if (!remaining) { + onDone(); + } + for (var _iterator12 = srcFiles, _isArray12 = Array.isArray(_iterator12), _i12 = 0, _iterator12 = _isArray12 ? _iterator12 : _iterator12[Symbol.iterator]();;) { + var _ref16; + + if (_isArray12) { + if (_i12 >= _iterator12.length) break; + _ref16 = _iterator12[_i12++]; + } else { + _i12 = _iterator12.next(); + if (_i12.done) break; + _ref16 = _i12.value; + } + + const file = _ref16; + + queue.push({ + onFresh, + src: (_path || _load_path()).default.join(src, file), + dest: (_path || _load_path()).default.join(dest, file), + onDone: function (_onDone2) { + function onDone() { + return _onDone2.apply(this, arguments); + } + + onDone.toString = function () { + return _onDone2.toString(); + }; + + return onDone; + }(function () { + if (--remaining === 0) { + onDone(); + } + }) + }); + } + } else if (srcStat.isFile()) { + onFresh(); + actions.link.push({ + src, + dest, + removeDest: destExists + }); + onDone(); + } else { + throw new Error(`unsure how to copy this: ${src}`); + } + }); + + return function build(_x10) { + return _ref13.apply(this, arguments); + }; + })(); + + const artifactFiles = new Set(events.artifactFiles || []); + const files = new Set(); + + // initialise events + for (var _iterator7 = queue, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { + var _ref10; + + if (_isArray7) { + if (_i7 >= _iterator7.length) break; + _ref10 = _iterator7[_i7++]; + } else { + _i7 = _iterator7.next(); + if (_i7.done) break; + _ref10 = _i7.value; + } + + const item = _ref10; + + const onDone = item.onDone || noop; + item.onDone = function () { + events.onProgress(item.dest); + onDone(); + }; + } + events.onStart(queue.length); + + // start building actions + const actions = { + file: [], + symlink: [], + link: [] + }; + + // custom concurrency logic as we're always executing stacks of CONCURRENT_QUEUE_ITEMS queue items + // at a time due to the requirement to push items onto the queue + while (queue.length) { + const items = queue.splice(0, CONCURRENT_QUEUE_ITEMS); + yield Promise.all(items.map(build)); + } + + // simulate the existence of some files to prevent considering them extraneous + for (var _iterator8 = artifactFiles, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { + var _ref11; + + if (_isArray8) { + if (_i8 >= _iterator8.length) break; + _ref11 = _iterator8[_i8++]; + } else { + _i8 = _iterator8.next(); + if (_i8.done) break; + _ref11 = _i8.value; + } + + const file = _ref11; + + if (possibleExtraneous.has(file)) { + reporter.verbose(reporter.lang('verboseFilePhantomExtraneous', file)); + possibleExtraneous.delete(file); + } + } + + for (var _iterator9 = possibleExtraneous, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { + var _ref12; + + if (_isArray9) { + if (_i9 >= _iterator9.length) break; + _ref12 = _iterator9[_i9++]; + } else { + _i9 = _iterator9.next(); + if (_i9.done) break; + _ref12 = _i9.value; + } + + const loc = _ref12; + + if (files.has(loc.toLowerCase())) { + possibleExtraneous.delete(loc); + } + } + + return actions; + }); + + return function buildActionsForHardlink(_x6, _x7, _x8, _x9) { + return _ref9.apply(this, arguments); + }; +})(); + +let copyBulk = exports.copyBulk = (() => { + var _ref17 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (queue, reporter, _events) { + const events = { + onStart: _events && _events.onStart || noop, + onProgress: _events && _events.onProgress || noop, + possibleExtraneous: _events ? _events.possibleExtraneous : new Set(), + ignoreBasenames: _events && _events.ignoreBasenames || [], + artifactFiles: _events && _events.artifactFiles || [] + }; + + const actions = yield buildActionsForCopy(queue, events, events.possibleExtraneous, reporter); + events.onStart(actions.file.length + actions.symlink.length + actions.link.length); + + const fileActions = actions.file; + + const currentlyWriting = new Map(); + + yield (_promise || _load_promise()).queue(fileActions, (() => { + var _ref18 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (data) { + let writePromise; + while (writePromise = currentlyWriting.get(data.dest)) { + yield writePromise; + } + + reporter.verbose(reporter.lang('verboseFileCopy', data.src, data.dest)); + const copier = (0, (_fsNormalized || _load_fsNormalized()).copyFile)(data, function () { + return currentlyWriting.delete(data.dest); + }); + currentlyWriting.set(data.dest, copier); + events.onProgress(data.dest); + return copier; + }); + + return function (_x14) { + return _ref18.apply(this, arguments); + }; + })(), CONCURRENT_QUEUE_ITEMS); + + // we need to copy symlinks last as they could reference files we were copying + const symlinkActions = actions.symlink; + yield (_promise || _load_promise()).queue(symlinkActions, function (data) { + const linkname = (_path || _load_path()).default.resolve((_path || _load_path()).default.dirname(data.dest), data.linkname); + reporter.verbose(reporter.lang('verboseFileSymlink', data.dest, linkname)); + return symlink(linkname, data.dest); + }); + }); + + return function copyBulk(_x11, _x12, _x13) { + return _ref17.apply(this, arguments); + }; +})(); + +let hardlinkBulk = exports.hardlinkBulk = (() => { + var _ref19 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (queue, reporter, _events) { + const events = { + onStart: _events && _events.onStart || noop, + onProgress: _events && _events.onProgress || noop, + possibleExtraneous: _events ? _events.possibleExtraneous : new Set(), + artifactFiles: _events && _events.artifactFiles || [], + ignoreBasenames: [] + }; + + const actions = yield buildActionsForHardlink(queue, events, events.possibleExtraneous, reporter); + events.onStart(actions.file.length + actions.symlink.length + actions.link.length); + + const fileActions = actions.link; + + yield (_promise || _load_promise()).queue(fileActions, (() => { + var _ref20 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (data) { + reporter.verbose(reporter.lang('verboseFileLink', data.src, data.dest)); + if (data.removeDest) { + yield (0, (_fsNormalized || _load_fsNormalized()).unlink)(data.dest); + } + yield link(data.src, data.dest); + }); + + return function (_x18) { + return _ref20.apply(this, arguments); + }; + })(), CONCURRENT_QUEUE_ITEMS); + + // we need to copy symlinks last as they could reference files we were copying + const symlinkActions = actions.symlink; + yield (_promise || _load_promise()).queue(symlinkActions, function (data) { + const linkname = (_path || _load_path()).default.resolve((_path || _load_path()).default.dirname(data.dest), data.linkname); + reporter.verbose(reporter.lang('verboseFileSymlink', data.dest, linkname)); + return symlink(linkname, data.dest); + }); + }); + + return function hardlinkBulk(_x15, _x16, _x17) { + return _ref19.apply(this, arguments); + }; +})(); + +let readFileAny = exports.readFileAny = (() => { + var _ref21 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (files) { + for (var _iterator13 = files, _isArray13 = Array.isArray(_iterator13), _i13 = 0, _iterator13 = _isArray13 ? _iterator13 : _iterator13[Symbol.iterator]();;) { + var _ref22; + + if (_isArray13) { + if (_i13 >= _iterator13.length) break; + _ref22 = _iterator13[_i13++]; + } else { + _i13 = _iterator13.next(); + if (_i13.done) break; + _ref22 = _i13.value; + } + + const file = _ref22; + + if (yield exists(file)) { + return readFile(file); + } + } + return null; + }); + + return function readFileAny(_x19) { + return _ref21.apply(this, arguments); + }; +})(); + +let readJson = exports.readJson = (() => { + var _ref23 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (loc) { + return (yield readJsonAndFile(loc)).object; + }); + + return function readJson(_x20) { + return _ref23.apply(this, arguments); + }; +})(); + +let readJsonAndFile = exports.readJsonAndFile = (() => { + var _ref24 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (loc) { + const file = yield readFile(loc); + try { + return { + object: (0, (_map || _load_map()).default)(JSON.parse(stripBOM(file))), + content: file + }; + } catch (err) { + err.message = `${loc}: ${err.message}`; + throw err; + } + }); + + return function readJsonAndFile(_x21) { + return _ref24.apply(this, arguments); + }; +})(); + +let find = exports.find = (() => { + var _ref25 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (filename, dir) { + const parts = dir.split((_path || _load_path()).default.sep); + + while (parts.length) { + const loc = parts.concat(filename).join((_path || _load_path()).default.sep); + + if (yield exists(loc)) { + return loc; + } else { + parts.pop(); + } + } + + return false; + }); + + return function find(_x22, _x23) { + return _ref25.apply(this, arguments); + }; +})(); + +let symlink = exports.symlink = (() => { + var _ref26 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (src, dest) { + if (process.platform !== 'win32') { + // use relative paths otherwise which will be retained if the directory is moved + src = (_path || _load_path()).default.relative((_path || _load_path()).default.dirname(dest), src); + // When path.relative returns an empty string for the current directory, we should instead use + // '.', which is a valid fs.symlink target. + src = src || '.'; + } + + try { + const stats = yield lstat(dest); + if (stats.isSymbolicLink()) { + const resolved = dest; + if (resolved === src) { + return; + } + } + } catch (err) { + if (err.code !== 'ENOENT') { + throw err; + } + } + + // We use rimraf for unlink which never throws an ENOENT on missing target + yield (0, (_fsNormalized || _load_fsNormalized()).unlink)(dest); + + if (process.platform === 'win32') { + // use directory junctions if possible on win32, this requires absolute paths + yield fsSymlink(src, dest, 'junction'); + } else { + yield fsSymlink(src, dest); + } + }); + + return function symlink(_x24, _x25) { + return _ref26.apply(this, arguments); + }; +})(); + +let walk = exports.walk = (() => { + var _ref27 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (dir, relativeDir, ignoreBasenames = new Set()) { + let files = []; + + let filenames = yield readdir(dir); + if (ignoreBasenames.size) { + filenames = filenames.filter(function (name) { + return !ignoreBasenames.has(name); + }); + } + + for (var _iterator14 = filenames, _isArray14 = Array.isArray(_iterator14), _i14 = 0, _iterator14 = _isArray14 ? _iterator14 : _iterator14[Symbol.iterator]();;) { + var _ref28; + + if (_isArray14) { + if (_i14 >= _iterator14.length) break; + _ref28 = _iterator14[_i14++]; + } else { + _i14 = _iterator14.next(); + if (_i14.done) break; + _ref28 = _i14.value; + } + + const name = _ref28; + + const relative = relativeDir ? (_path || _load_path()).default.join(relativeDir, name) : name; + const loc = (_path || _load_path()).default.join(dir, name); + const stat = yield lstat(loc); + + files.push({ + relative, + basename: name, + absolute: loc, + mtime: +stat.mtime + }); + + if (stat.isDirectory()) { + files = files.concat((yield walk(loc, relative, ignoreBasenames))); + } + } + + return files; + }); + + return function walk(_x26, _x27) { + return _ref27.apply(this, arguments); + }; +})(); + +let getFileSizeOnDisk = exports.getFileSizeOnDisk = (() => { + var _ref29 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (loc) { + const stat = yield lstat(loc); + const size = stat.size, + blockSize = stat.blksize; + + + return Math.ceil(size / blockSize) * blockSize; + }); + + return function getFileSizeOnDisk(_x28) { + return _ref29.apply(this, arguments); + }; +})(); + +let getEolFromFile = (() => { + var _ref30 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (path) { + if (!(yield exists(path))) { + return undefined; + } + + const buffer = yield readFileBuffer(path); + + for (let i = 0; i < buffer.length; ++i) { + if (buffer[i] === cr) { + return '\r\n'; + } + if (buffer[i] === lf) { + return '\n'; + } + } + return undefined; + }); + + return function getEolFromFile(_x29) { + return _ref30.apply(this, arguments); + }; +})(); + +let writeFilePreservingEol = exports.writeFilePreservingEol = (() => { + var _ref31 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (path, data) { + const eol = (yield getEolFromFile(path)) || (_os || _load_os()).default.EOL; + if (eol !== '\n') { + data = data.replace(/\n/g, eol); + } + yield writeFile(path, data); + }); + + return function writeFilePreservingEol(_x30, _x31) { + return _ref31.apply(this, arguments); + }; +})(); + +let hardlinksWork = exports.hardlinksWork = (() => { + var _ref32 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (dir) { + const filename = 'test-file' + Math.random(); + const file = (_path || _load_path()).default.join(dir, filename); + const fileLink = (_path || _load_path()).default.join(dir, filename + '-link'); + try { + yield writeFile(file, 'test'); + yield link(file, fileLink); + } catch (err) { + return false; + } finally { + yield (0, (_fsNormalized || _load_fsNormalized()).unlink)(file); + yield (0, (_fsNormalized || _load_fsNormalized()).unlink)(fileLink); + } + return true; + }); + + return function hardlinksWork(_x32) { + return _ref32.apply(this, arguments); + }; +})(); + +// not a strict polyfill for Node's fs.mkdtemp + + +let makeTempDir = exports.makeTempDir = (() => { + var _ref33 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (prefix) { + const dir = (_path || _load_path()).default.join((_os || _load_os()).default.tmpdir(), `yarn-${prefix || ''}-${Date.now()}-${Math.random()}`); + yield (0, (_fsNormalized || _load_fsNormalized()).unlink)(dir); + yield mkdirp(dir); + return dir; + }); + + return function makeTempDir(_x33) { + return _ref33.apply(this, arguments); + }; +})(); + +let readFirstAvailableStream = exports.readFirstAvailableStream = (() => { + var _ref34 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (paths) { + for (var _iterator15 = paths, _isArray15 = Array.isArray(_iterator15), _i15 = 0, _iterator15 = _isArray15 ? _iterator15 : _iterator15[Symbol.iterator]();;) { + var _ref35; + + if (_isArray15) { + if (_i15 >= _iterator15.length) break; + _ref35 = _iterator15[_i15++]; + } else { + _i15 = _iterator15.next(); + if (_i15.done) break; + _ref35 = _i15.value; + } + + const path = _ref35; + + try { + const fd = yield open(path, 'r'); + return (_fs || _load_fs()).default.createReadStream(path, { fd }); + } catch (err) { + // Try the next one + } + } + return null; + }); + + return function readFirstAvailableStream(_x34) { + return _ref34.apply(this, arguments); + }; +})(); + +let getFirstSuitableFolder = exports.getFirstSuitableFolder = (() => { + var _ref36 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (paths, mode = constants.W_OK | constants.X_OK) { + const result = { + skipped: [], + folder: null + }; + + for (var _iterator16 = paths, _isArray16 = Array.isArray(_iterator16), _i16 = 0, _iterator16 = _isArray16 ? _iterator16 : _iterator16[Symbol.iterator]();;) { + var _ref37; + + if (_isArray16) { + if (_i16 >= _iterator16.length) break; + _ref37 = _iterator16[_i16++]; + } else { + _i16 = _iterator16.next(); + if (_i16.done) break; + _ref37 = _i16.value; + } + + const folder = _ref37; + + try { + yield mkdirp(folder); + yield access(folder, mode); + + result.folder = folder; + + return result; + } catch (error) { + result.skipped.push({ + error, + folder + }); + } + } + return result; + }); + + return function getFirstSuitableFolder(_x35) { + return _ref36.apply(this, arguments); + }; +})(); + +exports.copy = copy; +exports.readFile = readFile; +exports.readFileRaw = readFileRaw; +exports.normalizeOS = normalizeOS; + +var _fs; + +function _load_fs() { + return _fs = _interopRequireDefault(__webpack_require__(4)); +} + +var _glob; + +function _load_glob() { + return _glob = _interopRequireDefault(__webpack_require__(93)); +} + +var _os; + +function _load_os() { + return _os = _interopRequireDefault(__webpack_require__(46)); +} + +var _path; + +function _load_path() { + return _path = _interopRequireDefault(__webpack_require__(0)); +} + +var _blockingQueue; + +function _load_blockingQueue() { + return _blockingQueue = _interopRequireDefault(__webpack_require__(103)); +} + +var _promise; + +function _load_promise() { + return _promise = _interopRequireWildcard(__webpack_require__(47)); +} + +var _promise2; + +function _load_promise2() { + return _promise2 = __webpack_require__(47); +} + +var _map; + +function _load_map() { + return _map = _interopRequireDefault(__webpack_require__(28)); +} + +var _fsNormalized; + +function _load_fsNormalized() { + return _fsNormalized = __webpack_require__(207); +} + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +const constants = exports.constants = typeof (_fs || _load_fs()).default.constants !== 'undefined' ? (_fs || _load_fs()).default.constants : { + R_OK: (_fs || _load_fs()).default.R_OK, + W_OK: (_fs || _load_fs()).default.W_OK, + X_OK: (_fs || _load_fs()).default.X_OK +}; + +const lockQueue = exports.lockQueue = new (_blockingQueue || _load_blockingQueue()).default('fs lock'); + +const readFileBuffer = exports.readFileBuffer = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.readFile); +const open = exports.open = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.open); +const writeFile = exports.writeFile = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.writeFile); +const readlink = exports.readlink = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.readlink); +const realpath = exports.realpath = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.realpath); +const readdir = exports.readdir = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.readdir); +const rename = exports.rename = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.rename); +const access = exports.access = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.access); +const stat = exports.stat = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.stat); +const mkdirp = exports.mkdirp = (0, (_promise2 || _load_promise2()).promisify)(__webpack_require__(136)); +const exists = exports.exists = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.exists, true); +const lstat = exports.lstat = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.lstat); +const chmod = exports.chmod = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.chmod); +const link = exports.link = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.link); +const glob = exports.glob = (0, (_promise2 || _load_promise2()).promisify)((_glob || _load_glob()).default); +exports.unlink = (_fsNormalized || _load_fsNormalized()).unlink; + +// fs.copyFile uses the native file copying instructions on the system, performing much better +// than any JS-based solution and consumes fewer resources. Repeated testing to fine tune the +// concurrency level revealed 128 as the sweet spot on a quad-core, 16 CPU Intel system with SSD. + +const CONCURRENT_QUEUE_ITEMS = (_fs || _load_fs()).default.copyFile ? 128 : 4; + +const fsSymlink = (0, (_promise2 || _load_promise2()).promisify)((_fs || _load_fs()).default.symlink); +const invariant = __webpack_require__(8); +const stripBOM = __webpack_require__(151); + +const noop = () => {}; + +function copy(src, dest, reporter) { + return copyBulk([{ src, dest }], reporter); +} + +function _readFile(loc, encoding) { + return new Promise((resolve, reject) => { + (_fs || _load_fs()).default.readFile(loc, encoding, function (err, content) { + if (err) { + reject(err); + } else { + resolve(content); + } + }); + }); +} + +function readFile(loc) { + return _readFile(loc, 'utf8').then(normalizeOS); +} + +function readFileRaw(loc) { + return _readFile(loc, 'binary'); +} + +function normalizeOS(body) { + return body.replace(/\r\n/g, '\n'); +} + +const cr = '\r'.charCodeAt(0); +const lf = '\n'.charCodeAt(0); + +/***/ }), +/* 6 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Subscriber; }); +/* unused harmony export SafeSubscriber */ +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tslib__ = __webpack_require__(1); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_isFunction__ = __webpack_require__(145); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Observer__ = __webpack_require__(392); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__Subscription__ = __webpack_require__(24); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__internal_symbol_rxSubscriber__ = __webpack_require__(289); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__config__ = __webpack_require__(176); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__util_hostReportError__ = __webpack_require__(291); +/** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */ + + + + + + + +var Subscriber = /*@__PURE__*/ (function (_super) { + __WEBPACK_IMPORTED_MODULE_0_tslib__["a" /* __extends */](Subscriber, _super); + function Subscriber(destinationOrNext, error, complete) { + var _this = _super.call(this) || this; + _this.syncErrorValue = null; + _this.syncErrorThrown = false; + _this.syncErrorThrowable = false; + _this.isStopped = false; + _this._parentSubscription = null; + switch (arguments.length) { + case 0: + _this.destination = __WEBPACK_IMPORTED_MODULE_2__Observer__["a" /* empty */]; + break; + case 1: + if (!destinationOrNext) { + _this.destination = __WEBPACK_IMPORTED_MODULE_2__Observer__["a" /* empty */]; + break; + } + if (typeof destinationOrNext === 'object') { + if (destinationOrNext instanceof Subscriber) { + _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; + _this.destination = destinationOrNext; + destinationOrNext.add(_this); + } + else { + _this.syncErrorThrowable = true; + _this.destination = new SafeSubscriber(_this, destinationOrNext); + } + break; + } + default: + _this.syncErrorThrowable = true; + _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete); + break; + } + return _this; + } + Subscriber.prototype[__WEBPACK_IMPORTED_MODULE_4__internal_symbol_rxSubscriber__["a" /* rxSubscriber */]] = function () { return this; }; + Subscriber.create = function (next, error, complete) { + var subscriber = new Subscriber(next, error, complete); + subscriber.syncErrorThrowable = false; + return subscriber; + }; + Subscriber.prototype.next = function (value) { + if (!this.isStopped) { + this._next(value); + } + }; + Subscriber.prototype.error = function (err) { + if (!this.isStopped) { + this.isStopped = true; + this._error(err); + } + }; + Subscriber.prototype.complete = function () { + if (!this.isStopped) { + this.isStopped = true; + this._complete(); + } + }; + Subscriber.prototype.unsubscribe = function () { + if (this.closed) { + return; + } + this.isStopped = true; + _super.prototype.unsubscribe.call(this); + }; + Subscriber.prototype._next = function (value) { + this.destination.next(value); + }; + Subscriber.prototype._error = function (err) { + this.destination.error(err); + this.unsubscribe(); + }; + Subscriber.prototype._complete = function () { + this.destination.complete(); + this.unsubscribe(); + }; + Subscriber.prototype._unsubscribeAndRecycle = function () { + var _a = this, _parent = _a._parent, _parents = _a._parents; + this._parent = null; + this._parents = null; + this.unsubscribe(); + this.closed = false; + this.isStopped = false; + this._parent = _parent; + this._parents = _parents; + this._parentSubscription = null; + return this; + }; + return Subscriber; +}(__WEBPACK_IMPORTED_MODULE_3__Subscription__["a" /* Subscription */])); + +var SafeSubscriber = /*@__PURE__*/ (function (_super) { + __WEBPACK_IMPORTED_MODULE_0_tslib__["a" /* __extends */](SafeSubscriber, _super); + function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) { + var _this = _super.call(this) || this; + _this._parentSubscriber = _parentSubscriber; + var next; + var context = _this; + if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__util_isFunction__["a" /* isFunction */])(observerOrNext)) { + next = observerOrNext; + } + else if (observerOrNext) { + next = observerOrNext.next; + error = observerOrNext.error; + complete = observerOrNext.complete; + if (observerOrNext !== __WEBPACK_IMPORTED_MODULE_2__Observer__["a" /* empty */]) { + context = Object.create(observerOrNext); + if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__util_isFunction__["a" /* isFunction */])(context.unsubscribe)) { + _this.add(context.unsubscribe.bind(context)); + } + context.unsubscribe = _this.unsubscribe.bind(_this); + } + } + _this._context = context; + _this._next = next; + _this._error = error; + _this._complete = complete; + return _this; + } + SafeSubscriber.prototype.next = function (value) { + if (!this.isStopped && this._next) { + var _parentSubscriber = this._parentSubscriber; + if (!__WEBPACK_IMPORTED_MODULE_5__config__["a" /* config */].useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { + this.__tryOrUnsub(this._next, value); + } + else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) { + this.unsubscribe(); + } + } + }; + SafeSubscriber.prototype.error = function (err) { + if (!this.isStopped) { + var _parentSubscriber = this._parentSubscriber; + var useDeprecatedSynchronousErrorHandling = __WEBPACK_IMPORTED_MODULE_5__config__["a" /* config */].useDeprecatedSynchronousErrorHandling; + if (this._error) { + if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { + this.__tryOrUnsub(this._error, err); + this.unsubscribe(); + } + else { + this.__tryOrSetError(_parentSubscriber, this._error, err); + this.unsubscribe(); + } + } + else if (!_parentSubscriber.syncErrorThrowable) { + this.unsubscribe(); + if (useDeprecatedSynchronousErrorHandling) { + throw err; + } + __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_6__util_hostReportError__["a" /* hostReportError */])(err); + } + else { + if (useDeprecatedSynchronousErrorHandling) { + _parentSubscriber.syncErrorValue = err; + _parentSubscriber.syncErrorThrown = true; + } + else { + __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_6__util_hostReportError__["a" /* hostReportError */])(err); + } + this.unsubscribe(); + } + } + }; + SafeSubscriber.prototype.complete = function () { + var _this = this; + if (!this.isStopped) { + var _parentSubscriber = this._parentSubscriber; + if (this._complete) { + var wrappedComplete = function () { return _this._complete.call(_this._context); }; + if (!__WEBPACK_IMPORTED_MODULE_5__config__["a" /* config */].useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { + this.__tryOrUnsub(wrappedComplete); + this.unsubscribe(); + } + else { + this.__tryOrSetError(_parentSubscriber, wrappedComplete); + this.unsubscribe(); + } + } + else { + this.unsubscribe(); + } + } + }; + SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) { + try { + fn.call(this._context, value); + } + catch (err) { + this.unsubscribe(); + if (__WEBPACK_IMPORTED_MODULE_5__config__["a" /* config */].useDeprecatedSynchronousErrorHandling) { + throw err; + } + else { + __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_6__util_hostReportError__["a" /* hostReportError */])(err); + } + } + }; + SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) { + if (!__WEBPACK_IMPORTED_MODULE_5__config__["a" /* config */].useDeprecatedSynchronousErrorHandling) { + throw new Error('bad call'); + } + try { + fn.call(this._context, value); + } + catch (err) { + if (__WEBPACK_IMPORTED_MODULE_5__config__["a" /* config */].useDeprecatedSynchronousErrorHandling) { + parent.syncErrorValue = err; + parent.syncErrorThrown = true; + return true; + } + else { + __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_6__util_hostReportError__["a" /* hostReportError */])(err); + return true; + } + } + return false; + }; + SafeSubscriber.prototype._unsubscribe = function () { + var _parentSubscriber = this._parentSubscriber; + this._context = null; + this._parentSubscriber = null; + _parentSubscriber.unsubscribe(); + }; + return SafeSubscriber; +}(Subscriber)); + +//# sourceMappingURL=Subscriber.js.map + + +/***/ }), +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +class MessageError extends Error { + constructor(msg, code) { + super(msg); + this.code = code; + } + +} + +exports.MessageError = MessageError; +class ProcessSpawnError extends MessageError { + constructor(msg, code, process) { + super(msg, code); + this.process = process; + } + +} + +exports.ProcessSpawnError = ProcessSpawnError; +class SecurityError extends MessageError {} + +exports.SecurityError = SecurityError; +class ProcessTermError extends MessageError {} + +exports.ProcessTermError = ProcessTermError; +class ResponseError extends Error { + constructor(msg, responseCode) { + super(msg); + this.responseCode = responseCode; + } + +} + +exports.ResponseError = ResponseError; +class OneTimePasswordError extends Error {} +exports.OneTimePasswordError = OneTimePasswordError; + +/***/ }), +/* 8 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + + + +/** + * Use invariant() to assert state which your program assumes to be true. + * + * Provide sprintf-style format (only %s is supported) and arguments + * to provide information about what broke and what you were + * expecting. + * + * The invariant message will be stripped in production, but the invariant + * will remain to ensure logic does not differ in production. + */ + +var NODE_ENV = process.env.NODE_ENV; + +var invariant = function(condition, format, a, b, c, d, e, f) { + if (NODE_ENV !== 'production') { + if (format === undefined) { + throw new Error('invariant requires an error message argument'); + } + } + + if (!condition) { + var error; + if (format === undefined) { + error = new Error( + 'Minified exception occurred; use the non-minified dev environment ' + + 'for the full error message and additional helpful warnings.' + ); + } else { + var args = [a, b, c, d, e, f]; + var argIndex = 0; + error = new Error( + format.replace(/%s/g, function() { return args[argIndex++]; }) + ); + error.name = 'Invariant Violation'; + } + + error.framesToPop = 1; // we don't care about invariant's own frame + throw error; + } +}; + +module.exports = invariant; + + +/***/ }), +/* 9 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.getPathKey = getPathKey; +const os = __webpack_require__(46); +const path = __webpack_require__(0); +const userHome = __webpack_require__(61).default; + +var _require = __webpack_require__(214); + +const getCacheDir = _require.getCacheDir, + getConfigDir = _require.getConfigDir, + getDataDir = _require.getDataDir; + +const isWebpackBundle = __webpack_require__(268); + +const DEPENDENCY_TYPES = exports.DEPENDENCY_TYPES = ['devDependencies', 'dependencies', 'optionalDependencies', 'peerDependencies']; +const OWNED_DEPENDENCY_TYPES = exports.OWNED_DEPENDENCY_TYPES = ['devDependencies', 'dependencies', 'optionalDependencies']; + +const RESOLUTIONS = exports.RESOLUTIONS = 'resolutions'; +const MANIFEST_FIELDS = exports.MANIFEST_FIELDS = [RESOLUTIONS, ...DEPENDENCY_TYPES]; + +const SUPPORTED_NODE_VERSIONS = exports.SUPPORTED_NODE_VERSIONS = '^4.8.0 || ^5.7.0 || ^6.2.2 || >=8.0.0'; + +const YARN_REGISTRY = exports.YARN_REGISTRY = 'https://registry.yarnpkg.com'; +const NPM_REGISTRY_RE = exports.NPM_REGISTRY_RE = /https?:\/\/registry\.npmjs\.org/g; + +const YARN_DOCS = exports.YARN_DOCS = 'https://yarnpkg.com/en/docs/cli/'; +const YARN_INSTALLER_SH = exports.YARN_INSTALLER_SH = 'https://yarnpkg.com/install.sh'; +const YARN_INSTALLER_MSI = exports.YARN_INSTALLER_MSI = 'https://yarnpkg.com/latest.msi'; + +const SELF_UPDATE_VERSION_URL = exports.SELF_UPDATE_VERSION_URL = 'https://yarnpkg.com/latest-version'; + +// cache version, bump whenever we make backwards incompatible changes +const CACHE_VERSION = exports.CACHE_VERSION = 4; + +// lockfile version, bump whenever we make backwards incompatible changes +const LOCKFILE_VERSION = exports.LOCKFILE_VERSION = 1; + +// max amount of network requests to perform concurrently +const NETWORK_CONCURRENCY = exports.NETWORK_CONCURRENCY = 8; + +// HTTP timeout used when downloading packages +const NETWORK_TIMEOUT = exports.NETWORK_TIMEOUT = 30 * 1000; // in milliseconds + +// max amount of child processes to execute concurrently +const CHILD_CONCURRENCY = exports.CHILD_CONCURRENCY = 5; + +const REQUIRED_PACKAGE_KEYS = exports.REQUIRED_PACKAGE_KEYS = ['name', 'version', '_uid']; + +function getPreferredCacheDirectories() { + const preferredCacheDirectories = [getCacheDir()]; + + if (process.getuid) { + // $FlowFixMe: process.getuid exists, dammit + preferredCacheDirectories.push(path.join(os.tmpdir(), `.yarn-cache-${process.getuid()}`)); + } + + preferredCacheDirectories.push(path.join(os.tmpdir(), `.yarn-cache`)); + + return preferredCacheDirectories; +} + +const PREFERRED_MODULE_CACHE_DIRECTORIES = exports.PREFERRED_MODULE_CACHE_DIRECTORIES = getPreferredCacheDirectories(); +const CONFIG_DIRECTORY = exports.CONFIG_DIRECTORY = getConfigDir(); +const DATA_DIRECTORY = exports.DATA_DIRECTORY = getDataDir(); +const LINK_REGISTRY_DIRECTORY = exports.LINK_REGISTRY_DIRECTORY = path.join(DATA_DIRECTORY, 'link'); +const GLOBAL_MODULE_DIRECTORY = exports.GLOBAL_MODULE_DIRECTORY = path.join(DATA_DIRECTORY, 'global'); + +const NODE_BIN_PATH = exports.NODE_BIN_PATH = process.execPath; +const YARN_BIN_PATH = exports.YARN_BIN_PATH = getYarnBinPath(); + +// Webpack needs to be configured with node.__dirname/__filename = false +function getYarnBinPath() { + if (isWebpackBundle) { + return __filename; + } else { + return path.join(__dirname, '..', 'bin', 'yarn.js'); + } +} + +const NODE_MODULES_FOLDER = exports.NODE_MODULES_FOLDER = 'node_modules'; +const NODE_PACKAGE_JSON = exports.NODE_PACKAGE_JSON = 'package.json'; + +const PNP_FILENAME = exports.PNP_FILENAME = '.pnp.js'; + +const POSIX_GLOBAL_PREFIX = exports.POSIX_GLOBAL_PREFIX = `${process.env.DESTDIR || ''}/usr/local`; +const FALLBACK_GLOBAL_PREFIX = exports.FALLBACK_GLOBAL_PREFIX = path.join(userHome, '.yarn'); + +const META_FOLDER = exports.META_FOLDER = '.yarn-meta'; +const INTEGRITY_FILENAME = exports.INTEGRITY_FILENAME = '.yarn-integrity'; +const LOCKFILE_FILENAME = exports.LOCKFILE_FILENAME = 'yarn.lock'; +const METADATA_FILENAME = exports.METADATA_FILENAME = '.yarn-metadata.json'; +const TARBALL_FILENAME = exports.TARBALL_FILENAME = '.yarn-tarball.tgz'; +const CLEAN_FILENAME = exports.CLEAN_FILENAME = '.yarnclean'; + +const NPM_LOCK_FILENAME = exports.NPM_LOCK_FILENAME = 'package-lock.json'; +const NPM_SHRINKWRAP_FILENAME = exports.NPM_SHRINKWRAP_FILENAME = 'npm-shrinkwrap.json'; + +const DEFAULT_INDENT = exports.DEFAULT_INDENT = ' '; +const SINGLE_INSTANCE_PORT = exports.SINGLE_INSTANCE_PORT = 31997; +const SINGLE_INSTANCE_FILENAME = exports.SINGLE_INSTANCE_FILENAME = '.yarn-single-instance'; + +const ENV_PATH_KEY = exports.ENV_PATH_KEY = getPathKey(process.platform, process.env); + +function getPathKey(platform, env) { + let pathKey = 'PATH'; + + // windows calls its path "Path" usually, but this is not guaranteed. + if (platform === 'win32') { + pathKey = 'Path'; + + for (const key in env) { + if (key.toLowerCase() === 'path') { + pathKey = key; + } + } + } + + return pathKey; +} + +const VERSION_COLOR_SCHEME = exports.VERSION_COLOR_SCHEME = { + major: 'red', + premajor: 'red', + minor: 'yellow', + preminor: 'yellow', + patch: 'green', + prepatch: 'green', + prerelease: 'red', + unchanged: 'white', + unknown: 'red' +}; + +/***/ }), +/* 10 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Observable; }); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__util_canReportError__ = __webpack_require__(290); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_toSubscriber__ = __webpack_require__(902); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__internal_symbol_observable__ = __webpack_require__(109); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_pipe__ = __webpack_require__(292); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__config__ = __webpack_require__(176); +/** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_internal_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */ + + + + + +var Observable = /*@__PURE__*/ (function () { + function Observable(subscribe) { + this._isScalar = false; + if (subscribe) { + this._subscribe = subscribe; + } + } + Observable.prototype.lift = function (operator) { + var observable = new Observable(); + observable.source = this; + observable.operator = operator; + return observable; + }; + Observable.prototype.subscribe = function (observerOrNext, error, complete) { + var operator = this.operator; + var sink = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__util_toSubscriber__["a" /* toSubscriber */])(observerOrNext, error, complete); + if (operator) { + operator.call(sink, this.source); + } + else { + sink.add(this.source || (__WEBPACK_IMPORTED_MODULE_4__config__["a" /* config */].useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ? + this._subscribe(sink) : + this._trySubscribe(sink)); + } + if (__WEBPACK_IMPORTED_MODULE_4__config__["a" /* config */].useDeprecatedSynchronousErrorHandling) { + if (sink.syncErrorThrowable) { + sink.syncErrorThrowable = false; + if (sink.syncErrorThrown) { + throw sink.syncErrorValue; + } + } + } + return sink; + }; + Observable.prototype._trySubscribe = function (sink) { + try { + return this._subscribe(sink); + } + catch (err) { + if (__WEBPACK_IMPORTED_MODULE_4__config__["a" /* config */].useDeprecatedSynchronousErrorHandling) { + sink.syncErrorThrown = true; + sink.syncErrorValue = err; + } + if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__util_canReportError__["a" /* canReportError */])(sink)) { + sink.error(err); + } + else { + console.warn(err); + } + } + }; + Observable.prototype.forEach = function (next, promiseCtor) { + var _this = this; + promiseCtor = getPromiseCtor(promiseCtor); + return new promiseCtor(function (resolve, reject) { + var subscription; + subscription = _this.subscribe(function (value) { + try { + next(value); + } + catch (err) { + reject(err); + if (subscription) { + subscription.unsubscribe(); + } + } + }, reject, resolve); + }); + }; + Observable.prototype._subscribe = function (subscriber) { + var source = this.source; + return source && source.subscribe(subscriber); + }; + Observable.prototype[__WEBPACK_IMPORTED_MODULE_2__internal_symbol_observable__["a" /* observable */]] = function () { + return this; + }; + Observable.prototype.pipe = function () { + var operations = []; + for (var _i = 0; _i < arguments.length; _i++) { + operations[_i] = arguments[_i]; + } + if (operations.length === 0) { + return this; + } + return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__util_pipe__["b" /* pipeFromArray */])(operations)(this); + }; + Observable.prototype.toPromise = function (promiseCtor) { + var _this = this; + promiseCtor = getPromiseCtor(promiseCtor); + return new promiseCtor(function (resolve, reject) { + var value; + _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); }); + }); + }; + Observable.create = function (subscribe) { + return new Observable(subscribe); + }; + return Observable; +}()); + +function getPromiseCtor(promiseCtor) { + if (!promiseCtor) { + promiseCtor = __WEBPACK_IMPORTED_MODULE_4__config__["a" /* config */].Promise || Promise; + } + if (!promiseCtor) { + throw new Error('no Promise impl found'); + } + return promiseCtor; +} +//# sourceMappingURL=Observable.js.map + + +/***/ }), +/* 11 */ +/***/ (function(module, exports) { + +module.exports = require("crypto"); + +/***/ }), +/* 12 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return OuterSubscriber; }); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tslib__ = __webpack_require__(1); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Subscriber__ = __webpack_require__(6); +/** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */ + + +var OuterSubscriber = /*@__PURE__*/ (function (_super) { + __WEBPACK_IMPORTED_MODULE_0_tslib__["a" /* __extends */](OuterSubscriber, _super); + function OuterSubscriber() { + return _super !== null && _super.apply(this, arguments) || this; + } + OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { + this.destination.next(innerValue); + }; + OuterSubscriber.prototype.notifyError = function (error, innerSub) { + this.destination.error(error); + }; + OuterSubscriber.prototype.notifyComplete = function (innerSub) { + this.destination.complete(); + }; + return OuterSubscriber; +}(__WEBPACK_IMPORTED_MODULE_1__Subscriber__["a" /* Subscriber */])); + +//# sourceMappingURL=OuterSubscriber.js.map + + +/***/ }), +/* 13 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony export (immutable) */ __webpack_exports__["a"] = subscribeToResult; +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__InnerSubscriber__ = __webpack_require__(77); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__subscribeTo__ = __webpack_require__(418); +/** PURE_IMPORTS_START _InnerSubscriber,_subscribeTo PURE_IMPORTS_END */ + + +function subscribeToResult(outerSubscriber, result, outerValue, outerIndex, destination) { + if (destination === void 0) { + destination = new __WEBPACK_IMPORTED_MODULE_0__InnerSubscriber__["a" /* InnerSubscriber */](outerSubscriber, outerValue, outerIndex); + } + if (destination.closed) { + return; + } + return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__subscribeTo__["a" /* subscribeTo */])(result)(destination); +} +//# sourceMappingURL=subscribeToResult.js.map + + +/***/ }), +/* 14 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +/* eslint-disable node/no-deprecated-api */ + + + +var buffer = __webpack_require__(80) +var Buffer = buffer.Buffer + +var safer = {} + +var key + +for (key in buffer) { + if (!buffer.hasOwnProperty(key)) continue + if (key === 'SlowBuffer' || key === 'Buffer') continue + safer[key] = buffer[key] +} + +var Safer = safer.Buffer = {} +for (key in Buffer) { + if (!Buffer.hasOwnProperty(key)) continue + if (key === 'allocUnsafe' || key === 'allocUnsafeSlow') continue + Safer[key] = Buffer[key] +} + +safer.Buffer.prototype = Buffer.prototype + +if (!Safer.from || Safer.from === Uint8Array.from) { + Safer.from = function (value, encodingOrOffset, length) { + if (typeof value === 'number') { + throw new TypeError('The "value" argument must not be of type number. Received type ' + typeof value) + } + if (value && typeof value.length === 'undefined') { + throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + typeof value) + } + return Buffer(value, encodingOrOffset, length) + } +} + +if (!Safer.alloc) { + Safer.alloc = function (size, fill, encoding) { + if (typeof size !== 'number') { + throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size) + } + if (size < 0 || size >= 2 * (1 << 30)) { + throw new RangeError('The value "' + size + '" is invalid for option "size"') + } + var buf = Buffer(size) + if (!fill || fill.length === 0) { + buf.fill(0) + } else if (typeof encoding === 'string') { + buf.fill(fill, encoding) + } else { + buf.fill(fill) + } + return buf + } +} + +if (!safer.kStringMaxLength) { + try { + safer.kStringMaxLength = process.binding('buffer').kStringMaxLength + } catch (e) { + // we can't determine kStringMaxLength in environments where process.binding + // is unsupported, so let's not set it + } +} + +if (!safer.constants) { + safer.constants = { + MAX_LENGTH: safer.kMaxLength + } + if (safer.kStringMaxLength) { + safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength + } +} + +module.exports = safer + + +/***/ }), +/* 15 */ +/***/ (function(module, exports, __webpack_require__) { + +// Copyright (c) 2012, Mark Cavage. All rights reserved. +// Copyright 2015 Joyent, Inc. + +var assert = __webpack_require__(27); +var Stream = __webpack_require__(22).Stream; +var util = __webpack_require__(3); + + +///--- Globals + +/* JSSTYLED */ +var UUID_REGEXP = /^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/; + + +///--- Internal + +function _capitalize(str) { + return (str.charAt(0).toUpperCase() + str.slice(1)); +} + +function _toss(name, expected, oper, arg, actual) { + throw new assert.AssertionError({ + message: util.format('%s (%s) is required', name, expected), + actual: (actual === undefined) ? typeof (arg) : actual(arg), + expected: expected, + operator: oper || '===', + stackStartFunction: _toss.caller + }); +} + +function _getClass(arg) { + return (Object.prototype.toString.call(arg).slice(8, -1)); +} + +function noop() { + // Why even bother with asserts? +} + + +///--- Exports + +var types = { + bool: { + check: function (arg) { return typeof (arg) === 'boolean'; } + }, + func: { + check: function (arg) { return typeof (arg) === 'function'; } + }, + string: { + check: function (arg) { return typeof (arg) === 'string'; } + }, + object: { + check: function (arg) { + return typeof (arg) === 'object' && arg !== null; + } + }, + number: { + check: function (arg) { + return typeof (arg) === 'number' && !isNaN(arg); + } + }, + finite: { + check: function (arg) { + return typeof (arg) === 'number' && !isNaN(arg) && isFinite(arg); + } + }, + buffer: { + check: function (arg) { return Buffer.isBuffer(arg); }, + operator: 'Buffer.isBuffer' + }, + array: { + check: function (arg) { return Array.isArray(arg); }, + operator: 'Array.isArray' + }, + stream: { + check: function (arg) { return arg instanceof Stream; }, + operator: 'instanceof', + actual: _getClass + }, + date: { + check: function (arg) { return arg instanceof Date; }, + operator: 'instanceof', + actual: _getClass + }, + regexp: { + check: function (arg) { return arg instanceof RegExp; }, + operator: 'instanceof', + actual: _getClass + }, + uuid: { + check: function (arg) { + return typeof (arg) === 'string' && UUID_REGEXP.test(arg); + }, + operator: 'isUUID' + } +}; + +function _setExports(ndebug) { + var keys = Object.keys(types); + var out; + + /* re-export standard assert */ + if (process.env.NODE_NDEBUG) { + out = noop; + } else { + out = function (arg, msg) { + if (!arg) { + _toss(msg, 'true', arg); + } + }; + } + + /* standard checks */ + keys.forEach(function (k) { + if (ndebug) { + out[k] = noop; + return; + } + var type = types[k]; + out[k] = function (arg, msg) { + if (!type.check(arg)) { + _toss(msg, k, type.operator, arg, type.actual); + } + }; + }); + + /* optional checks */ + keys.forEach(function (k) { + var name = 'optional' + _capitalize(k); + if (ndebug) { + out[name] = noop; + return; + } + var type = types[k]; + out[name] = function (arg, msg) { + if (arg === undefined || arg === null) { + return; + } + if (!type.check(arg)) { + _toss(msg, k, type.operator, arg, type.actual); + } + }; + }); + + /* arrayOf checks */ + keys.forEach(function (k) { + var name = 'arrayOf' + _capitalize(k); + if (ndebug) { + out[name] = noop; + return; + } + var type = types[k]; + var expected = '[' + k + ']'; + out[name] = function (arg, msg) { + if (!Array.isArray(arg)) { + _toss(msg, expected, type.operator, arg, type.actual); + } + var i; + for (i = 0; i < arg.length; i++) { + if (!type.check(arg[i])) { + _toss(msg, expected, type.operator, arg, type.actual); + } + } + }; + }); + + /* optionalArrayOf checks */ + keys.forEach(function (k) { + var name = 'optionalArrayOf' + _capitalize(k); + if (ndebug) { + out[name] = noop; + return; + } + var type = types[k]; + var expected = '[' + k + ']'; + out[name] = function (arg, msg) { + if (arg === undefined || arg === null) { + return; + } + if (!Array.isArray(arg)) { + _toss(msg, expected, type.operator, arg, type.actual); + } + var i; + for (i = 0; i < arg.length; i++) { + if (!type.check(arg[i])) { + _toss(msg, expected, type.operator, arg, type.actual); + } + } + }; + }); + + /* re-export built-in assertions */ + Object.keys(assert).forEach(function (k) { + if (k === 'AssertionError') { + out[k] = assert[k]; + return; + } + if (ndebug) { + out[k] = noop; + return; + } + out[k] = assert[k]; + }); + + /* export ourselves (for unit tests _only_) */ + out._setExports = _setExports; + + return out; +} + +module.exports = _setExports(process.env.NODE_NDEBUG); + + +/***/ }), +/* 16 */ +/***/ (function(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 + // eslint-disable-next-line no-new-func + : Function('return this')(); +if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef + + +/***/ }), +/* 17 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.sortAlpha = sortAlpha; +exports.sortOptionsByFlags = sortOptionsByFlags; +exports.entries = entries; +exports.removePrefix = removePrefix; +exports.removeSuffix = removeSuffix; +exports.addSuffix = addSuffix; +exports.hyphenate = hyphenate; +exports.camelCase = camelCase; +exports.compareSortedArrays = compareSortedArrays; +exports.sleep = sleep; +const _camelCase = __webpack_require__(219); + +function sortAlpha(a, b) { + // sort alphabetically in a deterministic way + const shortLen = Math.min(a.length, b.length); + for (let i = 0; i < shortLen; i++) { + const aChar = a.charCodeAt(i); + const bChar = b.charCodeAt(i); + if (aChar !== bChar) { + return aChar - bChar; + } + } + return a.length - b.length; +} + +function sortOptionsByFlags(a, b) { + const aOpt = a.flags.replace(/-/g, ''); + const bOpt = b.flags.replace(/-/g, ''); + return sortAlpha(aOpt, bOpt); +} + +function entries(obj) { + const entries = []; + if (obj) { + for (const key in obj) { + entries.push([key, obj[key]]); + } + } + return entries; +} + +function removePrefix(pattern, prefix) { + if (pattern.startsWith(prefix)) { + pattern = pattern.slice(prefix.length); + } + + return pattern; +} + +function removeSuffix(pattern, suffix) { + if (pattern.endsWith(suffix)) { + return pattern.slice(0, -suffix.length); + } + + return pattern; +} + +function addSuffix(pattern, suffix) { + if (!pattern.endsWith(suffix)) { + return pattern + suffix; + } + + return pattern; +} + +function hyphenate(str) { + return str.replace(/[A-Z]/g, match => { + return '-' + match.charAt(0).toLowerCase(); + }); +} + +function camelCase(str) { + if (/[A-Z]/.test(str)) { + return null; + } else { + return _camelCase(str); + } +} + +function compareSortedArrays(array1, array2) { + if (array1.length !== array2.length) { + return false; + } + for (let i = 0, len = array1.length; i < len; i++) { + if (array1[i] !== array2[i]) { + return false; + } + } + return true; +} + +function sleep(ms) { + return new Promise(resolve => { + setTimeout(resolve, ms); + }); +} + +/***/ }), +/* 18 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.stringify = exports.parse = undefined; + +var _asyncToGenerator2; + +function _load_asyncToGenerator() { + return _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(2)); +} + +var _parse; + +function _load_parse() { + return _parse = __webpack_require__(98); +} + +Object.defineProperty(exports, 'parse', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_parse || _load_parse()).default; + } +}); + +var _stringify; + +function _load_stringify() { + return _stringify = __webpack_require__(190); +} + +Object.defineProperty(exports, 'stringify', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_stringify || _load_stringify()).default; + } +}); +exports.implodeEntry = implodeEntry; +exports.explodeEntry = explodeEntry; + +var _misc; + +function _load_misc() { + return _misc = __webpack_require__(17); +} + +var _normalizePattern; + +function _load_normalizePattern() { + return _normalizePattern = __webpack_require__(36); +} + +var _parse2; + +function _load_parse2() { + return _parse2 = _interopRequireDefault(__webpack_require__(98)); +} + +var _constants; + +function _load_constants() { + return _constants = __webpack_require__(9); +} + +var _fs; + +function _load_fs() { + return _fs = _interopRequireWildcard(__webpack_require__(5)); +} + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +const invariant = __webpack_require__(8); + +const path = __webpack_require__(0); +const ssri = __webpack_require__(71); + +function getName(pattern) { + return (0, (_normalizePattern || _load_normalizePattern()).normalizePattern)(pattern).name; +} + +function blankObjectUndefined(obj) { + return obj && Object.keys(obj).length ? obj : undefined; +} + +function keyForRemote(remote) { + return remote.resolved || (remote.reference && remote.hash ? `${remote.reference}#${remote.hash}` : null); +} + +function serializeIntegrity(integrity) { + // We need this because `Integrity.toString()` does not use sorting to ensure a stable string output + // See https://git.io/vx2Hy + return integrity.toString().split(' ').sort().join(' '); +} + +function implodeEntry(pattern, obj) { + const inferredName = getName(pattern); + const integrity = obj.integrity ? serializeIntegrity(obj.integrity) : ''; + const imploded = { + name: inferredName === obj.name ? undefined : obj.name, + version: obj.version, + uid: obj.uid === obj.version ? undefined : obj.uid, + resolved: obj.resolved, + registry: obj.registry === 'npm' ? undefined : obj.registry, + dependencies: blankObjectUndefined(obj.dependencies), + optionalDependencies: blankObjectUndefined(obj.optionalDependencies), + permissions: blankObjectUndefined(obj.permissions), + prebuiltVariants: blankObjectUndefined(obj.prebuiltVariants) + }; + if (integrity) { + imploded.integrity = integrity; + } + return imploded; +} + +function explodeEntry(pattern, obj) { + obj.optionalDependencies = obj.optionalDependencies || {}; + obj.dependencies = obj.dependencies || {}; + obj.uid = obj.uid || obj.version; + obj.permissions = obj.permissions || {}; + obj.registry = obj.registry || 'npm'; + obj.name = obj.name || getName(pattern); + const integrity = obj.integrity; + if (integrity && integrity.isIntegrity) { + obj.integrity = ssri.parse(integrity); + } + return obj; +} + +class Lockfile { + constructor({ cache, source, parseResultType } = {}) { + this.source = source || ''; + this.cache = cache; + this.parseResultType = parseResultType; + } + + // source string if the `cache` was parsed + + + // if true, we're parsing an old yarn file and need to update integrity fields + hasEntriesExistWithoutIntegrity() { + if (!this.cache) { + return false; + } + + for (const key in this.cache) { + // $FlowFixMe - `this.cache` is clearly defined at this point + if (!/^.*@(file:|http)/.test(key) && this.cache[key] && !this.cache[key].integrity) { + return true; + } + } + + return false; + } + + static fromDirectory(dir, reporter) { + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + // read the manifest in this directory + const lockfileLoc = path.join(dir, (_constants || _load_constants()).LOCKFILE_FILENAME); + + let lockfile; + let rawLockfile = ''; + let parseResult; + + if (yield (_fs || _load_fs()).exists(lockfileLoc)) { + rawLockfile = yield (_fs || _load_fs()).readFile(lockfileLoc); + parseResult = (0, (_parse2 || _load_parse2()).default)(rawLockfile, lockfileLoc); + + if (reporter) { + if (parseResult.type === 'merge') { + reporter.info(reporter.lang('lockfileMerged')); + } else if (parseResult.type === 'conflict') { + reporter.warn(reporter.lang('lockfileConflict')); + } + } + + lockfile = parseResult.object; + } else if (reporter) { + reporter.info(reporter.lang('noLockfileFound')); + } + + return new Lockfile({ cache: lockfile, source: rawLockfile, parseResultType: parseResult && parseResult.type }); + })(); + } + + getLocked(pattern) { + const cache = this.cache; + if (!cache) { + return undefined; + } + + const shrunk = pattern in cache && cache[pattern]; + + if (typeof shrunk === 'string') { + return this.getLocked(shrunk); + } else if (shrunk) { + explodeEntry(pattern, shrunk); + return shrunk; + } + + return undefined; + } + + removePattern(pattern) { + const cache = this.cache; + if (!cache) { + return; + } + delete cache[pattern]; + } + + getLockfile(patterns) { + const lockfile = {}; + const seen = new Map(); + + // order by name so that lockfile manifest is assigned to the first dependency with this manifest + // the others that have the same remoteKey will just refer to the first + // ordering allows for consistency in lockfile when it is serialized + const sortedPatternsKeys = Object.keys(patterns).sort((_misc || _load_misc()).sortAlpha); + + for (var _iterator = sortedPatternsKeys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + const pattern = _ref; + + const pkg = patterns[pattern]; + const remote = pkg._remote, + ref = pkg._reference; + + invariant(ref, 'Package is missing a reference'); + invariant(remote, 'Package is missing a remote'); + + const remoteKey = keyForRemote(remote); + const seenPattern = remoteKey && seen.get(remoteKey); + if (seenPattern) { + // no point in duplicating it + lockfile[pattern] = seenPattern; + + // if we're relying on our name being inferred and two of the patterns have + // different inferred names then we need to set it + if (!seenPattern.name && getName(pattern) !== pkg.name) { + seenPattern.name = pkg.name; + } + continue; + } + const obj = implodeEntry(pattern, { + name: pkg.name, + version: pkg.version, + uid: pkg._uid, + resolved: remote.resolved, + integrity: remote.integrity, + registry: remote.registry, + dependencies: pkg.dependencies, + peerDependencies: pkg.peerDependencies, + optionalDependencies: pkg.optionalDependencies, + permissions: ref.permissions, + prebuiltVariants: pkg.prebuiltVariants + }); + + lockfile[pattern] = obj; + + if (remoteKey) { + seen.set(remoteKey, obj); + } + } + + return lockfile; + } +} +exports.default = Lockfile; + +/***/ }), +/* 19 */ +/***/ (function(module, exports, __webpack_require__) { + +var store = __webpack_require__(126)('wks'); +var uid = __webpack_require__(130); +var Symbol = __webpack_require__(16).Symbol; +var USE_SYMBOL = typeof Symbol == 'function'; + +var $exports = module.exports = function (name) { + return store[name] || (store[name] = + USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : uid)('Symbol.' + name)); +}; + +$exports.store = store; + + +/***/ }), +/* 20 */ +/***/ (function(module, exports) { + +exports = module.exports = SemVer; + +// The debug function is excluded entirely from the minified version. +/* nomin */ var debug; +/* nomin */ if (typeof process === 'object' && + /* nomin */ process.env && + /* nomin */ process.env.NODE_DEBUG && + /* nomin */ /\bsemver\b/i.test(process.env.NODE_DEBUG)) + /* nomin */ debug = function() { + /* nomin */ var args = Array.prototype.slice.call(arguments, 0); + /* nomin */ args.unshift('SEMVER'); + /* nomin */ console.log.apply(console, args); + /* nomin */ }; +/* nomin */ else + /* nomin */ debug = function() {}; + +// Note: this is the semver.org version of the spec that it implements +// Not necessarily the package version of this code. +exports.SEMVER_SPEC_VERSION = '2.0.0'; + +var MAX_LENGTH = 256; +var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; + +// Max safe segment length for coercion. +var MAX_SAFE_COMPONENT_LENGTH = 16; + +// The actual regexps go on exports.re +var re = exports.re = []; +var src = exports.src = []; +var R = 0; + +// The following Regular Expressions can be used for tokenizing, +// validating, and parsing SemVer version strings. + +// ## Numeric Identifier +// A single `0`, or a non-zero digit followed by zero or more digits. + +var NUMERICIDENTIFIER = R++; +src[NUMERICIDENTIFIER] = '0|[1-9]\\d*'; +var NUMERICIDENTIFIERLOOSE = R++; +src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; + + +// ## Non-numeric Identifier +// Zero or more digits, followed by a letter or hyphen, and then zero or +// more letters, digits, or hyphens. + +var NONNUMERICIDENTIFIER = R++; +src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; + + +// ## Main Version +// Three dot-separated numeric identifiers. + +var MAINVERSION = R++; +src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + + '(' + src[NUMERICIDENTIFIER] + ')\\.' + + '(' + src[NUMERICIDENTIFIER] + ')'; + +var MAINVERSIONLOOSE = R++; +src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; + +// ## Pre-release Version Identifier +// A numeric identifier, or a non-numeric identifier. + +var PRERELEASEIDENTIFIER = R++; +src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + + '|' + src[NONNUMERICIDENTIFIER] + ')'; + +var PRERELEASEIDENTIFIERLOOSE = R++; +src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + + '|' + src[NONNUMERICIDENTIFIER] + ')'; + + +// ## Pre-release Version +// Hyphen, followed by one or more dot-separated pre-release version +// identifiers. + +var PRERELEASE = R++; +src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))'; + +var PRERELEASELOOSE = R++; +src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; + +// ## Build Metadata Identifier +// Any combination of digits, letters, or hyphens. + +var BUILDIDENTIFIER = R++; +src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; + +// ## Build Metadata +// Plus sign, followed by one or more period-separated build metadata +// identifiers. + +var BUILD = R++; +src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; + + +// ## Full Version String +// A main version, followed optionally by a pre-release version and +// build metadata. + +// Note that the only major, minor, patch, and pre-release sections of +// the version string are capturing groups. The build metadata is not a +// capturing group, because it should not ever be used in version +// comparison. + +var FULL = R++; +var FULLPLAIN = 'v?' + src[MAINVERSION] + + src[PRERELEASE] + '?' + + src[BUILD] + '?'; + +src[FULL] = '^' + FULLPLAIN + '$'; + +// like full, but allows v1.2.3 and =1.2.3, which people do sometimes. +// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty +// common in the npm registry. +var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + + src[PRERELEASELOOSE] + '?' + + src[BUILD] + '?'; + +var LOOSE = R++; +src[LOOSE] = '^' + LOOSEPLAIN + '$'; + +var GTLT = R++; +src[GTLT] = '((?:<|>)?=?)'; + +// Something like "2.*" or "1.2.x". +// Note that "x.x" is a valid xRange identifer, meaning "any version" +// Only the first item is strictly required. +var XRANGEIDENTIFIERLOOSE = R++; +src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'; +var XRANGEIDENTIFIER = R++; +src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*'; + +var XRANGEPLAIN = R++; +src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + + '(?:' + src[PRERELEASE] + ')?' + + src[BUILD] + '?' + + ')?)?'; + +var XRANGEPLAINLOOSE = R++; +src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + + '(?:' + src[PRERELEASELOOSE] + ')?' + + src[BUILD] + '?' + + ')?)?'; + +var XRANGE = R++; +src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$'; +var XRANGELOOSE = R++; +src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; + +// Coercion. +// Extract anything that could conceivably be a part of a valid semver +var COERCE = R++; +src[COERCE] = '(?:^|[^\\d])' + + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + + '(?:$|[^\\d])'; + +// Tilde ranges. +// Meaning is "reasonably at or greater than" +var LONETILDE = R++; +src[LONETILDE] = '(?:~>?)'; + +var TILDETRIM = R++; +src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+'; +re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g'); +var tildeTrimReplace = '$1~'; + +var TILDE = R++; +src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$'; +var TILDELOOSE = R++; +src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; + +// Caret ranges. +// Meaning is "at least and backwards compatible with" +var LONECARET = R++; +src[LONECARET] = '(?:\\^)'; + +var CARETTRIM = R++; +src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+'; +re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g'); +var caretTrimReplace = '$1^'; + +var CARET = R++; +src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$'; +var CARETLOOSE = R++; +src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; + +// A simple gt/lt/eq thing, or just "" to indicate "any version" +var COMPARATORLOOSE = R++; +src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$'; +var COMPARATOR = R++; +src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; + + +// An expression to strip any whitespace between the gtlt and the thing +// it modifies, so that `> 1.2.3` ==> `>1.2.3` +var COMPARATORTRIM = R++; +src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; + +// this one has to use the /g flag +re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g'); +var comparatorTrimReplace = '$1$2$3'; + + +// Something like `1.2.3 - 1.2.4` +// Note that these all use the loose form, because they'll be +// checked against either the strict or loose comparator form +// later. +var HYPHENRANGE = R++; +src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + + '\\s+-\\s+' + + '(' + src[XRANGEPLAIN] + ')' + + '\\s*$'; + +var HYPHENRANGELOOSE = R++; +src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + + '\\s+-\\s+' + + '(' + src[XRANGEPLAINLOOSE] + ')' + + '\\s*$'; + +// Star ranges basically just allow anything at all. +var STAR = R++; +src[STAR] = '(<|>)?=?\\s*\\*'; + +// Compile to actual regexp objects. +// All are flag-free, unless they were created above with a flag. +for (var i = 0; i < R; i++) { + debug(i, src[i]); + if (!re[i]) + re[i] = new RegExp(src[i]); +} + +exports.parse = parse; +function parse(version, loose) { + if (version instanceof SemVer) + return version; + + if (typeof version !== 'string') + return null; + + if (version.length > MAX_LENGTH) + return null; + + var r = loose ? re[LOOSE] : re[FULL]; + if (!r.test(version)) + return null; + + try { + return new SemVer(version, loose); + } catch (er) { + return null; + } +} + +exports.valid = valid; +function valid(version, loose) { + var v = parse(version, loose); + return v ? v.version : null; +} + + +exports.clean = clean; +function clean(version, loose) { + var s = parse(version.trim().replace(/^[=v]+/, ''), loose); + return s ? s.version : null; +} + +exports.SemVer = SemVer; + +function SemVer(version, loose) { + if (version instanceof SemVer) { + if (version.loose === loose) + return version; + else + version = version.version; + } else if (typeof version !== 'string') { + throw new TypeError('Invalid Version: ' + version); + } + + if (version.length > MAX_LENGTH) + throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters') + + if (!(this instanceof SemVer)) + return new SemVer(version, loose); + + debug('SemVer', version, loose); + this.loose = loose; + var m = version.trim().match(loose ? re[LOOSE] : re[FULL]); + + if (!m) + throw new TypeError('Invalid Version: ' + version); + + this.raw = version; + + // these are actually numbers + this.major = +m[1]; + this.minor = +m[2]; + this.patch = +m[3]; + + if (this.major > MAX_SAFE_INTEGER || this.major < 0) + throw new TypeError('Invalid major version') + + if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) + throw new TypeError('Invalid minor version') + + if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) + throw new TypeError('Invalid patch version') + + // numberify any prerelease numeric ids + if (!m[4]) + this.prerelease = []; + else + this.prerelease = m[4].split('.').map(function(id) { + if (/^[0-9]+$/.test(id)) { + var num = +id; + if (num >= 0 && num < MAX_SAFE_INTEGER) + return num; + } + return id; + }); + + this.build = m[5] ? m[5].split('.') : []; + this.format(); +} + +SemVer.prototype.format = function() { + this.version = this.major + '.' + this.minor + '.' + this.patch; + if (this.prerelease.length) + this.version += '-' + this.prerelease.join('.'); + return this.version; +}; + +SemVer.prototype.toString = function() { + return this.version; +}; + +SemVer.prototype.compare = function(other) { + debug('SemVer.compare', this.version, this.loose, other); + if (!(other instanceof SemVer)) + other = new SemVer(other, this.loose); + + return this.compareMain(other) || this.comparePre(other); +}; + +SemVer.prototype.compareMain = function(other) { + if (!(other instanceof SemVer)) + other = new SemVer(other, this.loose); + + return compareIdentifiers(this.major, other.major) || + compareIdentifiers(this.minor, other.minor) || + compareIdentifiers(this.patch, other.patch); +}; + +SemVer.prototype.comparePre = function(other) { + if (!(other instanceof SemVer)) + other = new SemVer(other, this.loose); + + // NOT having a prerelease is > having one + if (this.prerelease.length && !other.prerelease.length) + return -1; + else if (!this.prerelease.length && other.prerelease.length) + return 1; + else if (!this.prerelease.length && !other.prerelease.length) + return 0; + + var i = 0; + do { + var a = this.prerelease[i]; + var b = other.prerelease[i]; + debug('prerelease compare', i, a, b); + if (a === undefined && b === undefined) + return 0; + else if (b === undefined) + return 1; + else if (a === undefined) + return -1; + else if (a === b) + continue; + else + return compareIdentifiers(a, b); + } while (++i); +}; + +// preminor will bump the version up to the next minor release, and immediately +// down to pre-release. premajor and prepatch work the same way. +SemVer.prototype.inc = function(release, identifier) { + switch (release) { + case 'premajor': + this.prerelease.length = 0; + this.patch = 0; + this.minor = 0; + this.major++; + this.inc('pre', identifier); + break; + case 'preminor': + this.prerelease.length = 0; + this.patch = 0; + this.minor++; + this.inc('pre', identifier); + break; + case 'prepatch': + // If this is already a prerelease, it will bump to the next version + // drop any prereleases that might already exist, since they are not + // relevant at this point. + this.prerelease.length = 0; + this.inc('patch', identifier); + this.inc('pre', identifier); + break; + // If the input is a non-prerelease version, this acts the same as + // prepatch. + case 'prerelease': + if (this.prerelease.length === 0) + this.inc('patch', identifier); + this.inc('pre', identifier); + break; + + case 'major': + // If this is a pre-major version, bump up to the same major version. + // Otherwise increment major. + // 1.0.0-5 bumps to 1.0.0 + // 1.1.0 bumps to 2.0.0 + if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) + this.major++; + this.minor = 0; + this.patch = 0; + this.prerelease = []; + break; + case 'minor': + // If this is a pre-minor version, bump up to the same minor version. + // Otherwise increment minor. + // 1.2.0-5 bumps to 1.2.0 + // 1.2.1 bumps to 1.3.0 + if (this.patch !== 0 || this.prerelease.length === 0) + this.minor++; + this.patch = 0; + this.prerelease = []; + break; + case 'patch': + // If this is not a pre-release version, it will increment the patch. + // If it is a pre-release it will bump up to the same patch version. + // 1.2.0-5 patches to 1.2.0 + // 1.2.0 patches to 1.2.1 + if (this.prerelease.length === 0) + this.patch++; + this.prerelease = []; + break; + // This probably shouldn't be used publicly. + // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction. + case 'pre': + if (this.prerelease.length === 0) + this.prerelease = [0]; + else { + var i = this.prerelease.length; + while (--i >= 0) { + if (typeof this.prerelease[i] === 'number') { + this.prerelease[i]++; + i = -2; + } + } + if (i === -1) // didn't increment anything + this.prerelease.push(0); + } + if (identifier) { + // 1.2.0-beta.1 bumps to 1.2.0-beta.2, + // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0 + if (this.prerelease[0] === identifier) { + if (isNaN(this.prerelease[1])) + this.prerelease = [identifier, 0]; + } else + this.prerelease = [identifier, 0]; + } + break; + + default: + throw new Error('invalid increment argument: ' + release); + } + this.format(); + this.raw = this.version; + return this; +}; + +exports.inc = inc; +function inc(version, release, loose, identifier) { + if (typeof(loose) === 'string') { + identifier = loose; + loose = undefined; + } + + try { + return new SemVer(version, loose).inc(release, identifier).version; + } catch (er) { + return null; + } +} + +exports.diff = diff; +function diff(version1, version2) { + if (eq(version1, version2)) { + return null; + } else { + var v1 = parse(version1); + var v2 = parse(version2); + if (v1.prerelease.length || v2.prerelease.length) { + for (var key in v1) { + if (key === 'major' || key === 'minor' || key === 'patch') { + if (v1[key] !== v2[key]) { + return 'pre'+key; + } + } + } + return 'prerelease'; + } + for (var key in v1) { + if (key === 'major' || key === 'minor' || key === 'patch') { + if (v1[key] !== v2[key]) { + return key; + } + } + } + } +} + +exports.compareIdentifiers = compareIdentifiers; + +var numeric = /^[0-9]+$/; +function compareIdentifiers(a, b) { + var anum = numeric.test(a); + var bnum = numeric.test(b); + + if (anum && bnum) { + a = +a; + b = +b; + } + + return (anum && !bnum) ? -1 : + (bnum && !anum) ? 1 : + a < b ? -1 : + a > b ? 1 : + 0; +} + +exports.rcompareIdentifiers = rcompareIdentifiers; +function rcompareIdentifiers(a, b) { + return compareIdentifiers(b, a); +} + +exports.major = major; +function major(a, loose) { + return new SemVer(a, loose).major; +} + +exports.minor = minor; +function minor(a, loose) { + return new SemVer(a, loose).minor; +} + +exports.patch = patch; +function patch(a, loose) { + return new SemVer(a, loose).patch; +} + +exports.compare = compare; +function compare(a, b, loose) { + return new SemVer(a, loose).compare(new SemVer(b, loose)); +} + +exports.compareLoose = compareLoose; +function compareLoose(a, b) { + return compare(a, b, true); +} + +exports.rcompare = rcompare; +function rcompare(a, b, loose) { + return compare(b, a, loose); +} + +exports.sort = sort; +function sort(list, loose) { + return list.sort(function(a, b) { + return exports.compare(a, b, loose); + }); +} + +exports.rsort = rsort; +function rsort(list, loose) { + return list.sort(function(a, b) { + return exports.rcompare(a, b, loose); + }); +} + +exports.gt = gt; +function gt(a, b, loose) { + return compare(a, b, loose) > 0; +} + +exports.lt = lt; +function lt(a, b, loose) { + return compare(a, b, loose) < 0; +} + +exports.eq = eq; +function eq(a, b, loose) { + return compare(a, b, loose) === 0; +} + +exports.neq = neq; +function neq(a, b, loose) { + return compare(a, b, loose) !== 0; +} + +exports.gte = gte; +function gte(a, b, loose) { + return compare(a, b, loose) >= 0; +} + +exports.lte = lte; +function lte(a, b, loose) { + return compare(a, b, loose) <= 0; +} + +exports.cmp = cmp; +function cmp(a, op, b, loose) { + var ret; + switch (op) { + case '===': + if (typeof a === 'object') a = a.version; + if (typeof b === 'object') b = b.version; + ret = a === b; + break; + case '!==': + if (typeof a === 'object') a = a.version; + if (typeof b === 'object') b = b.version; + ret = a !== b; + break; + case '': case '=': case '==': ret = eq(a, b, loose); break; + case '!=': ret = neq(a, b, loose); break; + case '>': ret = gt(a, b, loose); break; + case '>=': ret = gte(a, b, loose); break; + case '<': ret = lt(a, b, loose); break; + case '<=': ret = lte(a, b, loose); break; + default: throw new TypeError('Invalid operator: ' + op); + } + return ret; +} + +exports.Comparator = Comparator; +function Comparator(comp, loose) { + if (comp instanceof Comparator) { + if (comp.loose === loose) + return comp; + else + comp = comp.value; + } + + if (!(this instanceof Comparator)) + return new Comparator(comp, loose); + + debug('comparator', comp, loose); + this.loose = loose; + this.parse(comp); + + if (this.semver === ANY) + this.value = ''; + else + this.value = this.operator + this.semver.version; + + debug('comp', this); +} + +var ANY = {}; +Comparator.prototype.parse = function(comp) { + var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR]; + var m = comp.match(r); + + if (!m) + throw new TypeError('Invalid comparator: ' + comp); + + this.operator = m[1]; + if (this.operator === '=') + this.operator = ''; + + // if it literally is just '>' or '' then allow anything. + if (!m[2]) + this.semver = ANY; + else + this.semver = new SemVer(m[2], this.loose); +}; + +Comparator.prototype.toString = function() { + return this.value; +}; + +Comparator.prototype.test = function(version) { + debug('Comparator.test', version, this.loose); + + if (this.semver === ANY) + return true; + + if (typeof version === 'string') + version = new SemVer(version, this.loose); + + return cmp(version, this.operator, this.semver, this.loose); +}; + +Comparator.prototype.intersects = function(comp, loose) { + if (!(comp instanceof Comparator)) { + throw new TypeError('a Comparator is required'); + } + + var rangeTmp; + + if (this.operator === '') { + rangeTmp = new Range(comp.value, loose); + return satisfies(this.value, rangeTmp, loose); + } else if (comp.operator === '') { + rangeTmp = new Range(this.value, loose); + return satisfies(comp.semver, rangeTmp, loose); + } + + var sameDirectionIncreasing = + (this.operator === '>=' || this.operator === '>') && + (comp.operator === '>=' || comp.operator === '>'); + var sameDirectionDecreasing = + (this.operator === '<=' || this.operator === '<') && + (comp.operator === '<=' || comp.operator === '<'); + var sameSemVer = this.semver.version === comp.semver.version; + var differentDirectionsInclusive = + (this.operator === '>=' || this.operator === '<=') && + (comp.operator === '>=' || comp.operator === '<='); + var oppositeDirectionsLessThan = + cmp(this.semver, '<', comp.semver, loose) && + ((this.operator === '>=' || this.operator === '>') && + (comp.operator === '<=' || comp.operator === '<')); + var oppositeDirectionsGreaterThan = + cmp(this.semver, '>', comp.semver, loose) && + ((this.operator === '<=' || this.operator === '<') && + (comp.operator === '>=' || comp.operator === '>')); + + return sameDirectionIncreasing || sameDirectionDecreasing || + (sameSemVer && differentDirectionsInclusive) || + oppositeDirectionsLessThan || oppositeDirectionsGreaterThan; +}; + + +exports.Range = Range; +function Range(range, loose) { + if (range instanceof Range) { + if (range.loose === loose) { + return range; + } else { + return new Range(range.raw, loose); + } + } + + if (range instanceof Comparator) { + return new Range(range.value, loose); + } + + if (!(this instanceof Range)) + return new Range(range, loose); + + this.loose = loose; + + // First, split based on boolean or || + this.raw = range; + this.set = range.split(/\s*\|\|\s*/).map(function(range) { + return this.parseRange(range.trim()); + }, this).filter(function(c) { + // throw out any that are not relevant for whatever reason + return c.length; + }); + + if (!this.set.length) { + throw new TypeError('Invalid SemVer Range: ' + range); + } + + this.format(); +} + +Range.prototype.format = function() { + this.range = this.set.map(function(comps) { + return comps.join(' ').trim(); + }).join('||').trim(); + return this.range; +}; + +Range.prototype.toString = function() { + return this.range; +}; + +Range.prototype.parseRange = function(range) { + var loose = this.loose; + range = range.trim(); + debug('range', range, loose); + // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4` + var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE]; + range = range.replace(hr, hyphenReplace); + debug('hyphen replace', range); + // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5` + range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace); + debug('comparator trim', range, re[COMPARATORTRIM]); + + // `~ 1.2.3` => `~1.2.3` + range = range.replace(re[TILDETRIM], tildeTrimReplace); + + // `^ 1.2.3` => `^1.2.3` + range = range.replace(re[CARETTRIM], caretTrimReplace); + + // normalize spaces + range = range.split(/\s+/).join(' '); + + // At this point, the range is completely trimmed and + // ready to be split into comparators. + + var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR]; + var set = range.split(' ').map(function(comp) { + return parseComparator(comp, loose); + }).join(' ').split(/\s+/); + if (this.loose) { + // in loose mode, throw out any that are not valid comparators + set = set.filter(function(comp) { + return !!comp.match(compRe); + }); + } + set = set.map(function(comp) { + return new Comparator(comp, loose); + }); + + return set; +}; + +Range.prototype.intersects = function(range, loose) { + if (!(range instanceof Range)) { + throw new TypeError('a Range is required'); + } + + return this.set.some(function(thisComparators) { + return thisComparators.every(function(thisComparator) { + return range.set.some(function(rangeComparators) { + return rangeComparators.every(function(rangeComparator) { + return thisComparator.intersects(rangeComparator, loose); + }); + }); + }); + }); +}; + +// Mostly just for testing and legacy API reasons +exports.toComparators = toComparators; +function toComparators(range, loose) { + return new Range(range, loose).set.map(function(comp) { + return comp.map(function(c) { + return c.value; + }).join(' ').trim().split(' '); + }); +} + +// comprised of xranges, tildes, stars, and gtlt's at this point. +// already replaced the hyphen ranges +// turn into a set of JUST comparators. +function parseComparator(comp, loose) { + debug('comp', comp); + comp = replaceCarets(comp, loose); + debug('caret', comp); + comp = replaceTildes(comp, loose); + debug('tildes', comp); + comp = replaceXRanges(comp, loose); + debug('xrange', comp); + comp = replaceStars(comp, loose); + debug('stars', comp); + return comp; +} + +function isX(id) { + return !id || id.toLowerCase() === 'x' || id === '*'; +} + +// ~, ~> --> * (any, kinda silly) +// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0 +// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0 +// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0 +// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0 +// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0 +function replaceTildes(comp, loose) { + return comp.trim().split(/\s+/).map(function(comp) { + return replaceTilde(comp, loose); + }).join(' '); +} + +function replaceTilde(comp, loose) { + var r = loose ? re[TILDELOOSE] : re[TILDE]; + return comp.replace(r, function(_, M, m, p, pr) { + debug('tilde', comp, _, M, m, p, pr); + var ret; + + if (isX(M)) + ret = ''; + else if (isX(m)) + ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'; + else if (isX(p)) + // ~1.2 == >=1.2.0 <1.3.0 + ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'; + else if (pr) { + debug('replaceTilde pr', pr); + if (pr.charAt(0) !== '-') + pr = '-' + pr; + ret = '>=' + M + '.' + m + '.' + p + pr + + ' <' + M + '.' + (+m + 1) + '.0'; + } else + // ~1.2.3 == >=1.2.3 <1.3.0 + ret = '>=' + M + '.' + m + '.' + p + + ' <' + M + '.' + (+m + 1) + '.0'; + + debug('tilde return', ret); + return ret; + }); +} + +// ^ --> * (any, kinda silly) +// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0 +// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0 +// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0 +// ^1.2.3 --> >=1.2.3 <2.0.0 +// ^1.2.0 --> >=1.2.0 <2.0.0 +function replaceCarets(comp, loose) { + return comp.trim().split(/\s+/).map(function(comp) { + return replaceCaret(comp, loose); + }).join(' '); +} + +function replaceCaret(comp, loose) { + debug('caret', comp, loose); + var r = loose ? re[CARETLOOSE] : re[CARET]; + return comp.replace(r, function(_, M, m, p, pr) { + debug('caret', comp, _, M, m, p, pr); + var ret; + + if (isX(M)) + ret = ''; + else if (isX(m)) + ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'; + else if (isX(p)) { + if (M === '0') + ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'; + else + ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0'; + } else if (pr) { + debug('replaceCaret pr', pr); + if (pr.charAt(0) !== '-') + pr = '-' + pr; + if (M === '0') { + if (m === '0') + ret = '>=' + M + '.' + m + '.' + p + pr + + ' <' + M + '.' + m + '.' + (+p + 1); + else + ret = '>=' + M + '.' + m + '.' + p + pr + + ' <' + M + '.' + (+m + 1) + '.0'; + } else + ret = '>=' + M + '.' + m + '.' + p + pr + + ' <' + (+M + 1) + '.0.0'; + } else { + debug('no pr'); + if (M === '0') { + if (m === '0') + ret = '>=' + M + '.' + m + '.' + p + + ' <' + M + '.' + m + '.' + (+p + 1); + else + ret = '>=' + M + '.' + m + '.' + p + + ' <' + M + '.' + (+m + 1) + '.0'; + } else + ret = '>=' + M + '.' + m + '.' + p + + ' <' + (+M + 1) + '.0.0'; + } + + debug('caret return', ret); + return ret; + }); +} + +function replaceXRanges(comp, loose) { + debug('replaceXRanges', comp, loose); + return comp.split(/\s+/).map(function(comp) { + return replaceXRange(comp, loose); + }).join(' '); +} + +function replaceXRange(comp, loose) { + comp = comp.trim(); + var r = loose ? re[XRANGELOOSE] : re[XRANGE]; + return comp.replace(r, function(ret, gtlt, M, m, p, pr) { + debug('xRange', comp, ret, gtlt, M, m, p, pr); + var xM = isX(M); + var xm = xM || isX(m); + var xp = xm || isX(p); + var anyX = xp; + + if (gtlt === '=' && anyX) + gtlt = ''; + + if (xM) { + if (gtlt === '>' || gtlt === '<') { + // nothing is allowed + ret = '<0.0.0'; + } else { + // nothing is forbidden + ret = '*'; + } + } else if (gtlt && anyX) { + // replace X with 0 + if (xm) + m = 0; + if (xp) + p = 0; + + if (gtlt === '>') { + // >1 => >=2.0.0 + // >1.2 => >=1.3.0 + // >1.2.3 => >= 1.2.4 + gtlt = '>='; + if (xm) { + M = +M + 1; + m = 0; + p = 0; + } else if (xp) { + m = +m + 1; + p = 0; + } + } else if (gtlt === '<=') { + // <=0.7.x is actually <0.8.0, since any 0.7.x should + // pass. Similarly, <=7.x is actually <8.0.0, etc. + gtlt = '<'; + if (xm) + M = +M + 1; + else + m = +m + 1; + } + + ret = gtlt + M + '.' + m + '.' + p; + } else if (xm) { + ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'; + } else if (xp) { + ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'; + } + + debug('xRange return', ret); + + return ret; + }); +} + +// Because * is AND-ed with everything else in the comparator, +// and '' means "any version", just remove the *s entirely. +function replaceStars(comp, loose) { + debug('replaceStars', comp, loose); + // Looseness is ignored here. star is always as loose as it gets! + return comp.trim().replace(re[STAR], ''); +} + +// This function is passed to string.replace(re[HYPHENRANGE]) +// M, m, patch, prerelease, build +// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5 +// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do +// 1.2 - 3.4 => >=1.2.0 <3.5.0 +function hyphenReplace($0, + from, fM, fm, fp, fpr, fb, + to, tM, tm, tp, tpr, tb) { + + if (isX(fM)) + from = ''; + else if (isX(fm)) + from = '>=' + fM + '.0.0'; + else if (isX(fp)) + from = '>=' + fM + '.' + fm + '.0'; + else + from = '>=' + from; + + if (isX(tM)) + to = ''; + else if (isX(tm)) + to = '<' + (+tM + 1) + '.0.0'; + else if (isX(tp)) + to = '<' + tM + '.' + (+tm + 1) + '.0'; + else if (tpr) + to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr; + else + to = '<=' + to; + + return (from + ' ' + to).trim(); +} + + +// if ANY of the sets match ALL of its comparators, then pass +Range.prototype.test = function(version) { + if (!version) + return false; + + if (typeof version === 'string') + version = new SemVer(version, this.loose); + + for (var i = 0; i < this.set.length; i++) { + if (testSet(this.set[i], version)) + return true; + } + return false; +}; + +function testSet(set, version) { + for (var i = 0; i < set.length; i++) { + if (!set[i].test(version)) + return false; + } + + if (version.prerelease.length) { + // Find the set of versions that are allowed to have prereleases + // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0 + // That should allow `1.2.3-pr.2` to pass. + // However, `1.2.4-alpha.notready` should NOT be allowed, + // even though it's within the range set by the comparators. + for (var i = 0; i < set.length; i++) { + debug(set[i].semver); + if (set[i].semver === ANY) + continue; + + if (set[i].semver.prerelease.length > 0) { + var allowed = set[i].semver; + if (allowed.major === version.major && + allowed.minor === version.minor && + allowed.patch === version.patch) + return true; + } + } + + // Version has a -pre, but it's not one of the ones we like. + return false; + } + + return true; +} + +exports.satisfies = satisfies; +function satisfies(version, range, loose) { + try { + range = new Range(range, loose); + } catch (er) { + return false; + } + return range.test(version); +} + +exports.maxSatisfying = maxSatisfying; +function maxSatisfying(versions, range, loose) { + var max = null; + var maxSV = null; + try { + var rangeObj = new Range(range, loose); + } catch (er) { + return null; + } + versions.forEach(function (v) { + if (rangeObj.test(v)) { // satisfies(v, range, loose) + if (!max || maxSV.compare(v) === -1) { // compare(max, v, true) + max = v; + maxSV = new SemVer(max, loose); + } + } + }) + return max; +} + +exports.minSatisfying = minSatisfying; +function minSatisfying(versions, range, loose) { + var min = null; + var minSV = null; + try { + var rangeObj = new Range(range, loose); + } catch (er) { + return null; + } + versions.forEach(function (v) { + if (rangeObj.test(v)) { // satisfies(v, range, loose) + if (!min || minSV.compare(v) === 1) { // compare(min, v, true) + min = v; + minSV = new SemVer(min, loose); + } + } + }) + return min; +} + +exports.validRange = validRange; +function validRange(range, loose) { + try { + // Return '*' instead of '' so that truthiness works. + // This will throw if it's invalid anyway + return new Range(range, loose).range || '*'; + } catch (er) { + return null; + } +} + +// Determine if version is less than all the versions possible in the range +exports.ltr = ltr; +function ltr(version, range, loose) { + return outside(version, range, '<', loose); +} + +// Determine if version is greater than all the versions possible in the range. +exports.gtr = gtr; +function gtr(version, range, loose) { + return outside(version, range, '>', loose); +} + +exports.outside = outside; +function outside(version, range, hilo, loose) { + version = new SemVer(version, loose); + range = new Range(range, loose); + + var gtfn, ltefn, ltfn, comp, ecomp; + switch (hilo) { + case '>': + gtfn = gt; + ltefn = lte; + ltfn = lt; + comp = '>'; + ecomp = '>='; + break; + case '<': + gtfn = lt; + ltefn = gte; + ltfn = gt; + comp = '<'; + ecomp = '<='; + break; + default: + throw new TypeError('Must provide a hilo val of "<" or ">"'); + } + + // If it satisifes the range it is not outside + if (satisfies(version, range, loose)) { + return false; + } + + // From now on, variable terms are as if we're in "gtr" mode. + // but note that everything is flipped for the "ltr" function. + + for (var i = 0; i < range.set.length; ++i) { + var comparators = range.set[i]; + + var high = null; + var low = null; + + comparators.forEach(function(comparator) { + if (comparator.semver === ANY) { + comparator = new Comparator('>=0.0.0') + } + high = high || comparator; + low = low || comparator; + if (gtfn(comparator.semver, high.semver, loose)) { + high = comparator; + } else if (ltfn(comparator.semver, low.semver, loose)) { + low = comparator; + } + }); + + // If the edge version comparator has a operator then our version + // isn't outside it + if (high.operator === comp || high.operator === ecomp) { + return false; + } + + // If the lowest version comparator has an operator and our version + // is less than it then it isn't higher than the range + if ((!low.operator || low.operator === comp) && + ltefn(version, low.semver)) { + return false; + } else if (low.operator === ecomp && ltfn(version, low.semver)) { + return false; + } + } + return true; +} + +exports.prerelease = prerelease; +function prerelease(version, loose) { + var parsed = parse(version, loose); + return (parsed && parsed.prerelease.length) ? parsed.prerelease : null; +} + +exports.intersects = intersects; +function intersects(r1, r2, loose) { + r1 = new Range(r1, loose) + r2 = new Range(r2, loose) + return r1.intersects(r2) +} + +exports.coerce = coerce; +function coerce(version) { + if (version instanceof SemVer) + return version; + + if (typeof version !== 'string') + return null; + + var match = version.match(re[COERCE]); + + if (match == null) + return null; + + return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0')); +} + + +/***/ }), +/* 21 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +exports.__esModule = true; + +var _assign = __webpack_require__(558); + +var _assign2 = _interopRequireDefault(_assign); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = _assign2.default || function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + + return target; +}; + +/***/ }), +/* 22 */ +/***/ (function(module, exports) { + +module.exports = require("stream"); + +/***/ }), +/* 23 */ +/***/ (function(module, exports) { + +module.exports = require("url"); + +/***/ }), +/* 24 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Subscription; }); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__util_isArray__ = __webpack_require__(40); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_isObject__ = __webpack_require__(416); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__util_isFunction__ = __webpack_require__(145); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__util_tryCatch__ = __webpack_require__(51); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_errorObject__ = __webpack_require__(44); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__util_UnsubscriptionError__ = __webpack_require__(413); +/** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_tryCatch,_util_errorObject,_util_UnsubscriptionError PURE_IMPORTS_END */ + + + + + + +var Subscription = /*@__PURE__*/ (function () { + function Subscription(unsubscribe) { + this.closed = false; + this._parent = null; + this._parents = null; + this._subscriptions = null; + if (unsubscribe) { + this._unsubscribe = unsubscribe; + } + } + Subscription.prototype.unsubscribe = function () { + var hasErrors = false; + var errors; + if (this.closed) { + return; + } + var _a = this, _parent = _a._parent, _parents = _a._parents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions; + this.closed = true; + this._parent = null; + this._parents = null; + this._subscriptions = null; + var index = -1; + var len = _parents ? _parents.length : 0; + while (_parent) { + _parent.remove(this); + _parent = ++index < len && _parents[index] || null; + } + if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2__util_isFunction__["a" /* isFunction */])(_unsubscribe)) { + var trial = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__util_tryCatch__["a" /* tryCatch */])(_unsubscribe).call(this); + if (trial === __WEBPACK_IMPORTED_MODULE_4__util_errorObject__["a" /* errorObject */]) { + hasErrors = true; + errors = errors || (__WEBPACK_IMPORTED_MODULE_4__util_errorObject__["a" /* errorObject */].e instanceof __WEBPACK_IMPORTED_MODULE_5__util_UnsubscriptionError__["a" /* UnsubscriptionError */] ? + flattenUnsubscriptionErrors(__WEBPACK_IMPORTED_MODULE_4__util_errorObject__["a" /* errorObject */].e.errors) : [__WEBPACK_IMPORTED_MODULE_4__util_errorObject__["a" /* errorObject */].e]); + } + } + if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__util_isArray__["a" /* isArray */])(_subscriptions)) { + index = -1; + len = _subscriptions.length; + while (++index < len) { + var sub = _subscriptions[index]; + if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__util_isObject__["a" /* isObject */])(sub)) { + var trial = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__util_tryCatch__["a" /* tryCatch */])(sub.unsubscribe).call(sub); + if (trial === __WEBPACK_IMPORTED_MODULE_4__util_errorObject__["a" /* errorObject */]) { + hasErrors = true; + errors = errors || []; + var err = __WEBPACK_IMPORTED_MODULE_4__util_errorObject__["a" /* errorObject */].e; + if (err instanceof __WEBPACK_IMPORTED_MODULE_5__util_UnsubscriptionError__["a" /* UnsubscriptionError */]) { + errors = errors.concat(flattenUnsubscriptionErrors(err.errors)); + } + else { + errors.push(err); + } + } + } + } + } + if (hasErrors) { + throw new __WEBPACK_IMPORTED_MODULE_5__util_UnsubscriptionError__["a" /* UnsubscriptionError */](errors); + } + }; + Subscription.prototype.add = function (teardown) { + if (!teardown || (teardown === Subscription.EMPTY)) { + return Subscription.EMPTY; + } + if (teardown === this) { + return this; + } + var subscription = teardown; + switch (typeof teardown) { + case 'function': + subscription = new Subscription(teardown); + case 'object': + if (subscription.closed || typeof subscription.unsubscribe !== 'function') { + return subscription; + } + else if (this.closed) { + subscription.unsubscribe(); + return subscription; + } + else if (typeof subscription._addParent !== 'function') { + var tmp = subscription; + subscription = new Subscription(); + subscription._subscriptions = [tmp]; + } + break; + default: + throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.'); + } + var subscriptions = this._subscriptions || (this._subscriptions = []); + subscriptions.push(subscription); + subscription._addParent(this); + return subscription; + }; + Subscription.prototype.remove = function (subscription) { + var subscriptions = this._subscriptions; + if (subscriptions) { + var subscriptionIndex = subscriptions.indexOf(subscription); + if (subscriptionIndex !== -1) { + subscriptions.splice(subscriptionIndex, 1); + } + } + }; + Subscription.prototype._addParent = function (parent) { + var _a = this, _parent = _a._parent, _parents = _a._parents; + if (!_parent || _parent === parent) { + this._parent = parent; + } + else if (!_parents) { + this._parents = [parent]; + } + else if (_parents.indexOf(parent) === -1) { + _parents.push(parent); + } + }; + Subscription.EMPTY = (function (empty) { + empty.closed = true; + return empty; + }(new Subscription())); + return Subscription; +}()); + +function flattenUnsubscriptionErrors(errors) { + return errors.reduce(function (errs, err) { return errs.concat((err instanceof __WEBPACK_IMPORTED_MODULE_5__util_UnsubscriptionError__["a" /* UnsubscriptionError */]) ? err.errors : err); }, []); +} +//# sourceMappingURL=Subscription.js.map + + +/***/ }), +/* 25 */ +/***/ (function(module, exports, __webpack_require__) { + +// Copyright 2015 Joyent, Inc. + +module.exports = { + bufferSplit: bufferSplit, + addRSAMissing: addRSAMissing, + calculateDSAPublic: calculateDSAPublic, + calculateED25519Public: calculateED25519Public, + calculateX25519Public: calculateX25519Public, + mpNormalize: mpNormalize, + mpDenormalize: mpDenormalize, + ecNormalize: ecNormalize, + countZeros: countZeros, + assertCompatible: assertCompatible, + isCompatible: isCompatible, + opensslKeyDeriv: opensslKeyDeriv, + opensshCipherInfo: opensshCipherInfo, + publicFromPrivateECDSA: publicFromPrivateECDSA, + zeroPadToLength: zeroPadToLength, + writeBitString: writeBitString, + readBitString: readBitString +}; + +var assert = __webpack_require__(15); +var Buffer = __webpack_require__(14).Buffer; +var PrivateKey = __webpack_require__(32); +var Key = __webpack_require__(26); +var crypto = __webpack_require__(11); +var algs = __webpack_require__(31); +var asn1 = __webpack_require__(60); + +var ec, jsbn; +var nacl; + +var MAX_CLASS_DEPTH = 3; + +function isCompatible(obj, klass, needVer) { + if (obj === null || typeof (obj) !== 'object') + return (false); + if (needVer === undefined) + needVer = klass.prototype._sshpkApiVersion; + if (obj instanceof klass && + klass.prototype._sshpkApiVersion[0] == needVer[0]) + return (true); + var proto = Object.getPrototypeOf(obj); + var depth = 0; + while (proto.constructor.name !== klass.name) { + proto = Object.getPrototypeOf(proto); + if (!proto || ++depth > MAX_CLASS_DEPTH) + return (false); + } + if (proto.constructor.name !== klass.name) + return (false); + var ver = proto._sshpkApiVersion; + if (ver === undefined) + ver = klass._oldVersionDetect(obj); + if (ver[0] != needVer[0] || ver[1] < needVer[1]) + return (false); + return (true); +} + +function assertCompatible(obj, klass, needVer, name) { + if (name === undefined) + name = 'object'; + assert.ok(obj, name + ' must not be null'); + assert.object(obj, name + ' must be an object'); + if (needVer === undefined) + needVer = klass.prototype._sshpkApiVersion; + if (obj instanceof klass && + klass.prototype._sshpkApiVersion[0] == needVer[0]) + return; + var proto = Object.getPrototypeOf(obj); + var depth = 0; + while (proto.constructor.name !== klass.name) { + proto = Object.getPrototypeOf(proto); + assert.ok(proto && ++depth <= MAX_CLASS_DEPTH, + name + ' must be a ' + klass.name + ' instance'); + } + assert.strictEqual(proto.constructor.name, klass.name, + name + ' must be a ' + klass.name + ' instance'); + var ver = proto._sshpkApiVersion; + if (ver === undefined) + ver = klass._oldVersionDetect(obj); + assert.ok(ver[0] == needVer[0] && ver[1] >= needVer[1], + name + ' must be compatible with ' + klass.name + ' klass ' + + 'version ' + needVer[0] + '.' + needVer[1]); +} + +var CIPHER_LEN = { + 'des-ede3-cbc': { key: 7, iv: 8 }, + 'aes-128-cbc': { key: 16, iv: 16 } +}; +var PKCS5_SALT_LEN = 8; + +function opensslKeyDeriv(cipher, salt, passphrase, count) { + assert.buffer(salt, 'salt'); + assert.buffer(passphrase, 'passphrase'); + assert.number(count, 'iteration count'); + + var clen = CIPHER_LEN[cipher]; + assert.object(clen, 'supported cipher'); + + salt = salt.slice(0, PKCS5_SALT_LEN); + + var D, D_prev, bufs; + var material = Buffer.alloc(0); + while (material.length < clen.key + clen.iv) { + bufs = []; + if (D_prev) + bufs.push(D_prev); + bufs.push(passphrase); + bufs.push(salt); + D = Buffer.concat(bufs); + for (var j = 0; j < count; ++j) + D = crypto.createHash('md5').update(D).digest(); + material = Buffer.concat([material, D]); + D_prev = D; + } + + return ({ + key: material.slice(0, clen.key), + iv: material.slice(clen.key, clen.key + clen.iv) + }); +} + +/* Count leading zero bits on a buffer */ +function countZeros(buf) { + var o = 0, obit = 8; + while (o < buf.length) { + var mask = (1 << obit); + if ((buf[o] & mask) === mask) + break; + obit--; + if (obit < 0) { + o++; + obit = 8; + } + } + return (o*8 + (8 - obit) - 1); +} + +function bufferSplit(buf, chr) { + assert.buffer(buf); + assert.string(chr); + + var parts = []; + var lastPart = 0; + var matches = 0; + for (var i = 0; i < buf.length; ++i) { + if (buf[i] === chr.charCodeAt(matches)) + ++matches; + else if (buf[i] === chr.charCodeAt(0)) + matches = 1; + else + matches = 0; + + if (matches >= chr.length) { + var newPart = i + 1; + parts.push(buf.slice(lastPart, newPart - matches)); + lastPart = newPart; + matches = 0; + } + } + if (lastPart <= buf.length) + parts.push(buf.slice(lastPart, buf.length)); + + return (parts); +} + +function ecNormalize(buf, addZero) { + assert.buffer(buf); + if (buf[0] === 0x00 && buf[1] === 0x04) { + if (addZero) + return (buf); + return (buf.slice(1)); + } else if (buf[0] === 0x04) { + if (!addZero) + return (buf); + } else { + while (buf[0] === 0x00) + buf = buf.slice(1); + if (buf[0] === 0x02 || buf[0] === 0x03) + throw (new Error('Compressed elliptic curve points ' + + 'are not supported')); + if (buf[0] !== 0x04) + throw (new Error('Not a valid elliptic curve point')); + if (!addZero) + return (buf); + } + var b = Buffer.alloc(buf.length + 1); + b[0] = 0x0; + buf.copy(b, 1); + return (b); +} + +function readBitString(der, tag) { + if (tag === undefined) + tag = asn1.Ber.BitString; + var buf = der.readString(tag, true); + assert.strictEqual(buf[0], 0x00, 'bit strings with unused bits are ' + + 'not supported (0x' + buf[0].toString(16) + ')'); + return (buf.slice(1)); +} + +function writeBitString(der, buf, tag) { + if (tag === undefined) + tag = asn1.Ber.BitString; + var b = Buffer.alloc(buf.length + 1); + b[0] = 0x00; + buf.copy(b, 1); + der.writeBuffer(b, tag); +} + +function mpNormalize(buf) { + assert.buffer(buf); + while (buf.length > 1 && buf[0] === 0x00 && (buf[1] & 0x80) === 0x00) + buf = buf.slice(1); + if ((buf[0] & 0x80) === 0x80) { + var b = Buffer.alloc(buf.length + 1); + b[0] = 0x00; + buf.copy(b, 1); + buf = b; + } + return (buf); +} + +function mpDenormalize(buf) { + assert.buffer(buf); + while (buf.length > 1 && buf[0] === 0x00) + buf = buf.slice(1); + return (buf); +} + +function zeroPadToLength(buf, len) { + assert.buffer(buf); + assert.number(len); + while (buf.length > len) { + assert.equal(buf[0], 0x00); + buf = buf.slice(1); + } + while (buf.length < len) { + var b = Buffer.alloc(buf.length + 1); + b[0] = 0x00; + buf.copy(b, 1); + buf = b; + } + return (buf); +} + +function bigintToMpBuf(bigint) { + var buf = Buffer.from(bigint.toByteArray()); + buf = mpNormalize(buf); + return (buf); +} + +function calculateDSAPublic(g, p, x) { + assert.buffer(g); + assert.buffer(p); + assert.buffer(x); + try { + var bigInt = __webpack_require__(74).BigInteger; + } catch (e) { + throw (new Error('To load a PKCS#8 format DSA private key, ' + + 'the node jsbn library is required.')); + } + g = new bigInt(g); + p = new bigInt(p); + x = new bigInt(x); + var y = g.modPow(x, p); + var ybuf = bigintToMpBuf(y); + return (ybuf); +} + +function calculateED25519Public(k) { + assert.buffer(k); + + if (nacl === undefined) + nacl = __webpack_require__(69); + + var kp = nacl.sign.keyPair.fromSeed(new Uint8Array(k)); + return (Buffer.from(kp.publicKey)); +} + +function calculateX25519Public(k) { + assert.buffer(k); + + if (nacl === undefined) + nacl = __webpack_require__(69); + + var kp = nacl.box.keyPair.fromSeed(new Uint8Array(k)); + return (Buffer.from(kp.publicKey)); +} + +function addRSAMissing(key) { + assert.object(key); + assertCompatible(key, PrivateKey, [1, 1]); + try { + var bigInt = __webpack_require__(74).BigInteger; + } catch (e) { + throw (new Error('To write a PEM private key from ' + + 'this source, the node jsbn lib is required.')); + } + + var d = new bigInt(key.part.d.data); + var buf; + + if (!key.part.dmodp) { + var p = new bigInt(key.part.p.data); + var dmodp = d.mod(p.subtract(1)); + + buf = bigintToMpBuf(dmodp); + key.part.dmodp = {name: 'dmodp', data: buf}; + key.parts.push(key.part.dmodp); + } + if (!key.part.dmodq) { + var q = new bigInt(key.part.q.data); + var dmodq = d.mod(q.subtract(1)); + + buf = bigintToMpBuf(dmodq); + key.part.dmodq = {name: 'dmodq', data: buf}; + key.parts.push(key.part.dmodq); + } +} + +function publicFromPrivateECDSA(curveName, priv) { + assert.string(curveName, 'curveName'); + assert.buffer(priv); + if (ec === undefined) + ec = __webpack_require__(132); + if (jsbn === undefined) + jsbn = __webpack_require__(74).BigInteger; + var params = algs.curves[curveName]; + var p = new jsbn(params.p); + var a = new jsbn(params.a); + var b = new jsbn(params.b); + var curve = new ec.ECCurveFp(p, a, b); + var G = curve.decodePointHex(params.G.toString('hex')); + + var d = new jsbn(mpNormalize(priv)); + var pub = G.multiply(d); + pub = Buffer.from(curve.encodePointHex(pub), 'hex'); + + var parts = []; + parts.push({name: 'curve', data: Buffer.from(curveName)}); + parts.push({name: 'Q', data: pub}); + + var key = new Key({type: 'ecdsa', curve: curve, parts: parts}); + return (key); +} + +function opensshCipherInfo(cipher) { + var inf = {}; + switch (cipher) { + case '3des-cbc': + inf.keySize = 24; + inf.blockSize = 8; + inf.opensslName = 'des-ede3-cbc'; + break; + case 'blowfish-cbc': + inf.keySize = 16; + inf.blockSize = 8; + inf.opensslName = 'bf-cbc'; + break; + case 'aes128-cbc': + case 'aes128-ctr': + case 'aes128-gcm@openssh.com': + inf.keySize = 16; + inf.blockSize = 16; + inf.opensslName = 'aes-128-' + cipher.slice(7, 10); + break; + case 'aes192-cbc': + case 'aes192-ctr': + case 'aes192-gcm@openssh.com': + inf.keySize = 24; + inf.blockSize = 16; + inf.opensslName = 'aes-192-' + cipher.slice(7, 10); + break; + case 'aes256-cbc': + case 'aes256-ctr': + case 'aes256-gcm@openssh.com': + inf.keySize = 32; + inf.blockSize = 16; + inf.opensslName = 'aes-256-' + cipher.slice(7, 10); + break; + default: + throw (new Error( + 'Unsupported openssl cipher "' + cipher + '"')); + } + return (inf); +} + + +/***/ }), +/* 26 */ +/***/ (function(module, exports, __webpack_require__) { + +// Copyright 2017 Joyent, Inc. + +module.exports = Key; + +var assert = __webpack_require__(15); +var algs = __webpack_require__(31); +var crypto = __webpack_require__(11); +var Fingerprint = __webpack_require__(147); +var Signature = __webpack_require__(68); +var DiffieHellman = __webpack_require__(293).DiffieHellman; +var errs = __webpack_require__(67); +var utils = __webpack_require__(25); +var PrivateKey = __webpack_require__(32); +var edCompat; + +try { + edCompat = __webpack_require__(426); +} catch (e) { + /* Just continue through, and bail out if we try to use it. */ +} + +var InvalidAlgorithmError = errs.InvalidAlgorithmError; +var KeyParseError = errs.KeyParseError; + +var formats = {}; +formats['auto'] = __webpack_require__(427); +formats['pem'] = __webpack_require__(79); +formats['pkcs1'] = __webpack_require__(295); +formats['pkcs8'] = __webpack_require__(148); +formats['rfc4253'] = __webpack_require__(96); +formats['ssh'] = __webpack_require__(428); +formats['ssh-private'] = __webpack_require__(183); +formats['openssh'] = formats['ssh-private']; +formats['dnssec'] = __webpack_require__(294); + +function Key(opts) { + assert.object(opts, 'options'); + assert.arrayOfObject(opts.parts, 'options.parts'); + assert.string(opts.type, 'options.type'); + assert.optionalString(opts.comment, 'options.comment'); + + var algInfo = algs.info[opts.type]; + if (typeof (algInfo) !== 'object') + throw (new InvalidAlgorithmError(opts.type)); + + var partLookup = {}; + for (var i = 0; i < opts.parts.length; ++i) { + var part = opts.parts[i]; + partLookup[part.name] = part; + } + + this.type = opts.type; + this.parts = opts.parts; + this.part = partLookup; + this.comment = undefined; + this.source = opts.source; + + /* for speeding up hashing/fingerprint operations */ + this._rfc4253Cache = opts._rfc4253Cache; + this._hashCache = {}; + + var sz; + this.curve = undefined; + if (this.type === 'ecdsa') { + var curve = this.part.curve.data.toString(); + this.curve = curve; + sz = algs.curves[curve].size; + } else if (this.type === 'ed25519' || this.type === 'curve25519') { + sz = 256; + this.curve = 'curve25519'; + } else { + var szPart = this.part[algInfo.sizePart]; + sz = szPart.data.length; + sz = sz * 8 - utils.countZeros(szPart.data); + } + this.size = sz; +} + +Key.formats = formats; + +Key.prototype.toBuffer = function (format, options) { + if (format === undefined) + format = 'ssh'; + assert.string(format, 'format'); + assert.object(formats[format], 'formats[format]'); + assert.optionalObject(options, 'options'); + + if (format === 'rfc4253') { + if (this._rfc4253Cache === undefined) + this._rfc4253Cache = formats['rfc4253'].write(this); + return (this._rfc4253Cache); + } + + return (formats[format].write(this, options)); +}; + +Key.prototype.toString = function (format, options) { + return (this.toBuffer(format, options).toString()); +}; + +Key.prototype.hash = function (algo) { + assert.string(algo, 'algorithm'); + algo = algo.toLowerCase(); + if (algs.hashAlgs[algo] === undefined) + throw (new InvalidAlgorithmError(algo)); + + if (this._hashCache[algo]) + return (this._hashCache[algo]); + var hash = crypto.createHash(algo). + update(this.toBuffer('rfc4253')).digest(); + this._hashCache[algo] = hash; + return (hash); +}; + +Key.prototype.fingerprint = function (algo) { + if (algo === undefined) + algo = 'sha256'; + assert.string(algo, 'algorithm'); + var opts = { + type: 'key', + hash: this.hash(algo), + algorithm: algo + }; + return (new Fingerprint(opts)); +}; + +Key.prototype.defaultHashAlgorithm = function () { + var hashAlgo = 'sha1'; + if (this.type === 'rsa') + hashAlgo = 'sha256'; + if (this.type === 'dsa' && this.size > 1024) + hashAlgo = 'sha256'; + if (this.type === 'ed25519') + hashAlgo = 'sha512'; + if (this.type === 'ecdsa') { + if (this.size <= 256) + hashAlgo = 'sha256'; + else if (this.size <= 384) + hashAlgo = 'sha384'; + else + hashAlgo = 'sha512'; + } + return (hashAlgo); +}; + +Key.prototype.createVerify = function (hashAlgo) { + if (hashAlgo === undefined) + hashAlgo = this.defaultHashAlgorithm(); + assert.string(hashAlgo, 'hash algorithm'); + + /* ED25519 is not supported by OpenSSL, use a javascript impl. */ + if (this.type === 'ed25519' && edCompat !== undefined) + return (new edCompat.Verifier(this, hashAlgo)); + if (this.type === 'curve25519') + throw (new Error('Curve25519 keys are not suitable for ' + + 'signing or verification')); + + var v, nm, err; + try { + nm = hashAlgo.toUpperCase(); + v = crypto.createVerify(nm); + } catch (e) { + err = e; + } + if (v === undefined || (err instanceof Error && + err.message.match(/Unknown message digest/))) { + nm = 'RSA-'; + nm += hashAlgo.toUpperCase(); + v = crypto.createVerify(nm); + } + assert.ok(v, 'failed to create verifier'); + var oldVerify = v.verify.bind(v); + var key = this.toBuffer('pkcs8'); + var curve = this.curve; + var self = this; + v.verify = function (signature, fmt) { + if (Signature.isSignature(signature, [2, 0])) { + if (signature.type !== self.type) + return (false); + if (signature.hashAlgorithm && + signature.hashAlgorithm !== hashAlgo) + return (false); + if (signature.curve && self.type === 'ecdsa' && + signature.curve !== curve) + return (false); + return (oldVerify(key, signature.toBuffer('asn1'))); + + } else if (typeof (signature) === 'string' || + Buffer.isBuffer(signature)) { + return (oldVerify(key, signature, fmt)); + + /* + * Avoid doing this on valid arguments, walking the prototype + * chain can be quite slow. + */ + } else if (Signature.isSignature(signature, [1, 0])) { + throw (new Error('signature was created by too old ' + + 'a version of sshpk and cannot be verified')); + + } else { + throw (new TypeError('signature must be a string, ' + + 'Buffer, or Signature object')); + } + }; + return (v); +}; + +Key.prototype.createDiffieHellman = function () { + if (this.type === 'rsa') + throw (new Error('RSA keys do not support Diffie-Hellman')); + + return (new DiffieHellman(this)); +}; +Key.prototype.createDH = Key.prototype.createDiffieHellman; + +Key.parse = function (data, format, options) { + if (typeof (data) !== 'string') + assert.buffer(data, 'data'); + if (format === undefined) + format = 'auto'; + assert.string(format, 'format'); + if (typeof (options) === 'string') + options = { filename: options }; + assert.optionalObject(options, 'options'); + if (options === undefined) + options = {}; + assert.optionalString(options.filename, 'options.filename'); + if (options.filename === undefined) + options.filename = '(unnamed)'; + + assert.object(formats[format], 'formats[format]'); + + try { + var k = formats[format].read(data, options); + if (k instanceof PrivateKey) + k = k.toPublic(); + if (!k.comment) + k.comment = options.filename; + return (k); + } catch (e) { + if (e.name === 'KeyEncryptedError') + throw (e); + throw (new KeyParseError(options.filename, format, e)); + } +}; + +Key.isKey = function (obj, ver) { + return (utils.isCompatible(obj, Key, ver)); +}; + +/* + * API versions for Key: + * [1,0] -- initial ver, may take Signature for createVerify or may not + * [1,1] -- added pkcs1, pkcs8 formats + * [1,2] -- added auto, ssh-private, openssh formats + * [1,3] -- added defaultHashAlgorithm + * [1,4] -- added ed support, createDH + * [1,5] -- first explicitly tagged version + * [1,6] -- changed ed25519 part names + */ +Key.prototype._sshpkApiVersion = [1, 6]; + +Key._oldVersionDetect = function (obj) { + assert.func(obj.toBuffer); + assert.func(obj.fingerprint); + if (obj.createDH) + return ([1, 4]); + if (obj.defaultHashAlgorithm) + return ([1, 3]); + if (obj.formats['auto']) + return ([1, 2]); + if (obj.formats['pkcs1']) + return ([1, 1]); + return ([1, 0]); +}; + + +/***/ }), +/* 27 */ +/***/ (function(module, exports) { + +module.exports = require("assert"); + +/***/ }), +/* 28 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = nullify; +function nullify(obj = {}) { + if (Array.isArray(obj)) { + for (var _iterator = obj, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + const item = _ref; + + nullify(item); + } + } else if (obj !== null && typeof obj === 'object' || typeof obj === 'function') { + Object.setPrototypeOf(obj, null); + + // for..in can only be applied to 'object', not 'function' + if (typeof obj === 'object') { + for (const key in obj) { + nullify(obj[key]); + } + } + } + + return obj; +} + +/***/ }), +/* 29 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +const escapeStringRegexp = __webpack_require__(360); +const ansiStyles = __webpack_require__(477); +const stdoutColor = __webpack_require__(565).stdout; + +const template = __webpack_require__(566); + +const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); + +// `supportsColor.level` → `ansiStyles.color[name]` mapping +const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; + +// `color-convert` models to exclude from the Chalk API due to conflicts and such +const skipModels = new Set(['gray']); + +const styles = Object.create(null); + +function applyOptions(obj, options) { + options = options || {}; + + // Detect level if not set manually + const scLevel = stdoutColor ? stdoutColor.level : 0; + obj.level = options.level === undefined ? scLevel : options.level; + obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0; +} + +function Chalk(options) { + // We check for this.template here since calling `chalk.constructor()` + // by itself will have a `this` of a previously constructed chalk object + if (!this || !(this instanceof Chalk) || this.template) { + const chalk = {}; + applyOptions(chalk, options); + + chalk.template = function () { + const args = [].slice.call(arguments); + return chalkTag.apply(null, [chalk.template].concat(args)); + }; + + Object.setPrototypeOf(chalk, Chalk.prototype); + Object.setPrototypeOf(chalk.template, chalk); + + chalk.template.constructor = Chalk; + + return chalk.template; + } + + applyOptions(this, options); +} + +// Use bright blue on Windows as the normal blue color is illegible +if (isSimpleWindowsTerm) { + ansiStyles.blue.open = '\u001B[94m'; +} + +for (const key of Object.keys(ansiStyles)) { + ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g'); + + styles[key] = { + get() { + const codes = ansiStyles[key]; + return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key); + } + }; +} + +styles.visible = { + get() { + return build.call(this, this._styles || [], true, 'visible'); + } +}; + +ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g'); +for (const model of Object.keys(ansiStyles.color.ansi)) { + if (skipModels.has(model)) { + continue; + } + + styles[model] = { + get() { + const level = this.level; + return function () { + const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments); + const codes = { + open, + close: ansiStyles.color.close, + closeRe: ansiStyles.color.closeRe + }; + return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); + }; + } + }; +} + +ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g'); +for (const model of Object.keys(ansiStyles.bgColor.ansi)) { + if (skipModels.has(model)) { + continue; + } + + const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1); + styles[bgModel] = { + get() { + const level = this.level; + return function () { + const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments); + const codes = { + open, + close: ansiStyles.bgColor.close, + closeRe: ansiStyles.bgColor.closeRe + }; + return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); + }; + } + }; +} + +const proto = Object.defineProperties(() => {}, styles); + +function build(_styles, _empty, key) { + const builder = function () { + return applyStyle.apply(builder, arguments); + }; + + builder._styles = _styles; + builder._empty = _empty; + + const self = this; + + Object.defineProperty(builder, 'level', { + enumerable: true, + get() { + return self.level; + }, + set(level) { + self.level = level; + } + }); + + Object.defineProperty(builder, 'enabled', { + enumerable: true, + get() { + return self.enabled; + }, + set(enabled) { + self.enabled = enabled; + } + }); + + // See below for fix regarding invisible grey/dim combination on Windows + builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; + + // `__proto__` is used because we must return a function, but there is + // no way to create a function with a different prototype + builder.__proto__ = proto; // eslint-disable-line no-proto + + return builder; +} + +function applyStyle() { + // Support varags, but simply cast to string in case there's only one arg + const args = arguments; + const argsLen = args.length; + let str = String(arguments[0]); + + if (argsLen === 0) { + return ''; + } + + if (argsLen > 1) { + // Don't slice `arguments`, it prevents V8 optimizations + for (let a = 1; a < argsLen; a++) { + str += ' ' + args[a]; + } + } + + if (!this.enabled || this.level <= 0 || !str) { + return this._empty ? '' : str; + } + + // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe, + // see https://github.com/chalk/chalk/issues/58 + // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop. + const originalDim = ansiStyles.dim.open; + if (isSimpleWindowsTerm && this.hasGrey) { + ansiStyles.dim.open = ''; + } + + for (const code of this._styles.slice().reverse()) { + // Replace any instances already present with a re-opening code + // otherwise only the part of the string until said closing code + // will be colored, and the rest will simply be 'plain'. + str = code.open + str.replace(code.closeRe, code.open) + code.close; + + // Close the styling before a linebreak and reopen + // after next line to fix a bleed issue on macOS + // https://github.com/chalk/chalk/pull/92 + str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`); + } + + // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue + ansiStyles.dim.open = originalDim; + + return str; +} + +function chalkTag(chalk, strings) { + if (!Array.isArray(strings)) { + // If chalk() was called by itself or with a string, + // return the string itself as a string. + return [].slice.call(arguments, 1).join(' '); + } + + const args = [].slice.call(arguments, 2); + const parts = [strings.raw[0]]; + + for (let i = 1; i < strings.length; i++) { + parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&')); + parts.push(String(strings.raw[i])); + } + + return template(chalk, parts.join('')); +} + +Object.defineProperties(Chalk.prototype, styles); + +module.exports = Chalk(); // eslint-disable-line new-cap +module.exports.supportsColor = stdoutColor; +module.exports.default = module.exports; // For TypeScript + + +/***/ }), +/* 30 */ +/***/ (function(module, exports) { + +var core = module.exports = { version: '2.5.7' }; +if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef + + +/***/ }), +/* 31 */ +/***/ (function(module, exports, __webpack_require__) { + +// Copyright 2015 Joyent, Inc. + +var Buffer = __webpack_require__(14).Buffer; + +var algInfo = { + 'dsa': { + parts: ['p', 'q', 'g', 'y'], + sizePart: 'p' + }, + 'rsa': { + parts: ['e', 'n'], + sizePart: 'n' + }, + 'ecdsa': { + parts: ['curve', 'Q'], + sizePart: 'Q' + }, + 'ed25519': { + parts: ['A'], + sizePart: 'A' + } +}; +algInfo['curve25519'] = algInfo['ed25519']; + +var algPrivInfo = { + 'dsa': { + parts: ['p', 'q', 'g', 'y', 'x'] + }, + 'rsa': { + parts: ['n', 'e', 'd', 'iqmp', 'p', 'q'] + }, + 'ecdsa': { + parts: ['curve', 'Q', 'd'] + }, + 'ed25519': { + parts: ['A', 'k'] + } +}; +algPrivInfo['curve25519'] = algPrivInfo['ed25519']; + +var hashAlgs = { + 'md5': true, + 'sha1': true, + 'sha256': true, + 'sha384': true, + 'sha512': true +}; + +/* + * Taken from + * http://csrc.nist.gov/groups/ST/toolkit/documents/dss/NISTReCur.pdf + */ +var curves = { + 'nistp256': { + size: 256, + pkcs8oid: '1.2.840.10045.3.1.7', + p: Buffer.from(('00' + + 'ffffffff 00000001 00000000 00000000' + + '00000000 ffffffff ffffffff ffffffff'). + replace(/ /g, ''), 'hex'), + a: Buffer.from(('00' + + 'FFFFFFFF 00000001 00000000 00000000' + + '00000000 FFFFFFFF FFFFFFFF FFFFFFFC'). + replace(/ /g, ''), 'hex'), + b: Buffer.from(( + '5ac635d8 aa3a93e7 b3ebbd55 769886bc' + + '651d06b0 cc53b0f6 3bce3c3e 27d2604b'). + replace(/ /g, ''), 'hex'), + s: Buffer.from(('00' + + 'c49d3608 86e70493 6a6678e1 139d26b7' + + '819f7e90'). + replace(/ /g, ''), 'hex'), + n: Buffer.from(('00' + + 'ffffffff 00000000 ffffffff ffffffff' + + 'bce6faad a7179e84 f3b9cac2 fc632551'). + replace(/ /g, ''), 'hex'), + G: Buffer.from(('04' + + '6b17d1f2 e12c4247 f8bce6e5 63a440f2' + + '77037d81 2deb33a0 f4a13945 d898c296' + + '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16' + + '2bce3357 6b315ece cbb64068 37bf51f5'). + replace(/ /g, ''), 'hex') + }, + 'nistp384': { + size: 384, + pkcs8oid: '1.3.132.0.34', + p: Buffer.from(('00' + + 'ffffffff ffffffff ffffffff ffffffff' + + 'ffffffff ffffffff ffffffff fffffffe' + + 'ffffffff 00000000 00000000 ffffffff'). + replace(/ /g, ''), 'hex'), + a: Buffer.from(('00' + + 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' + + 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE' + + 'FFFFFFFF 00000000 00000000 FFFFFFFC'). + replace(/ /g, ''), 'hex'), + b: Buffer.from(( + 'b3312fa7 e23ee7e4 988e056b e3f82d19' + + '181d9c6e fe814112 0314088f 5013875a' + + 'c656398d 8a2ed19d 2a85c8ed d3ec2aef'). + replace(/ /g, ''), 'hex'), + s: Buffer.from(('00' + + 'a335926a a319a27a 1d00896a 6773a482' + + '7acdac73'). + replace(/ /g, ''), 'hex'), + n: Buffer.from(('00' + + 'ffffffff ffffffff ffffffff ffffffff' + + 'ffffffff ffffffff c7634d81 f4372ddf' + + '581a0db2 48b0a77a ecec196a ccc52973'). + replace(/ /g, ''), 'hex'), + G: Buffer.from(('04' + + 'aa87ca22 be8b0537 8eb1c71e f320ad74' + + '6e1d3b62 8ba79b98 59f741e0 82542a38' + + '5502f25d bf55296c 3a545e38 72760ab7' + + '3617de4a 96262c6f 5d9e98bf 9292dc29' + + 'f8f41dbd 289a147c e9da3113 b5f0b8c0' + + '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f'). + replace(/ /g, ''), 'hex') + }, + 'nistp521': { + size: 521, + pkcs8oid: '1.3.132.0.35', + p: Buffer.from(( + '01ffffff ffffffff ffffffff ffffffff' + + 'ffffffff ffffffff ffffffff ffffffff' + + 'ffffffff ffffffff ffffffff ffffffff' + + 'ffffffff ffffffff ffffffff ffffffff' + + 'ffff').replace(/ /g, ''), 'hex'), + a: Buffer.from(('01FF' + + 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' + + 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' + + 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' + + 'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFC'). + replace(/ /g, ''), 'hex'), + b: Buffer.from(('51' + + '953eb961 8e1c9a1f 929a21a0 b68540ee' + + 'a2da725b 99b315f3 b8b48991 8ef109e1' + + '56193951 ec7e937b 1652c0bd 3bb1bf07' + + '3573df88 3d2c34f1 ef451fd4 6b503f00'). + replace(/ /g, ''), 'hex'), + s: Buffer.from(('00' + + 'd09e8800 291cb853 96cc6717 393284aa' + + 'a0da64ba').replace(/ /g, ''), 'hex'), + n: Buffer.from(('01ff' + + 'ffffffff ffffffff ffffffff ffffffff' + + 'ffffffff ffffffff ffffffff fffffffa' + + '51868783 bf2f966b 7fcc0148 f709a5d0' + + '3bb5c9b8 899c47ae bb6fb71e 91386409'). + replace(/ /g, ''), 'hex'), + G: Buffer.from(('04' + + '00c6 858e06b7 0404e9cd 9e3ecb66 2395b442' + + '9c648139 053fb521 f828af60 6b4d3dba' + + 'a14b5e77 efe75928 fe1dc127 a2ffa8de' + + '3348b3c1 856a429b f97e7e31 c2e5bd66' + + '0118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9' + + '98f54449 579b4468 17afbd17 273e662c' + + '97ee7299 5ef42640 c550b901 3fad0761' + + '353c7086 a272c240 88be9476 9fd16650'). + replace(/ /g, ''), 'hex') + } +}; + +module.exports = { + info: algInfo, + privInfo: algPrivInfo, + hashAlgs: hashAlgs, + curves: curves +}; + + +/***/ }), +/* 32 */ +/***/ (function(module, exports, __webpack_require__) { + +// Copyright 2017 Joyent, Inc. + +module.exports = PrivateKey; + +var assert = __webpack_require__(15); +var Buffer = __webpack_require__(14).Buffer; +var algs = __webpack_require__(31); +var crypto = __webpack_require__(11); +var Fingerprint = __webpack_require__(147); +var Signature = __webpack_require__(68); +var errs = __webpack_require__(67); +var util = __webpack_require__(3); +var utils = __webpack_require__(25); +var dhe = __webpack_require__(293); +var generateECDSA = dhe.generateECDSA; +var generateED25519 = dhe.generateED25519; +var edCompat; +var nacl; + +try { + edCompat = __webpack_require__(426); +} catch (e) { + /* Just continue through, and bail out if we try to use it. */ +} + +var Key = __webpack_require__(26); + +var InvalidAlgorithmError = errs.InvalidAlgorithmError; +var KeyParseError = errs.KeyParseError; +var KeyEncryptedError = errs.KeyEncryptedError; + +var formats = {}; +formats['auto'] = __webpack_require__(427); +formats['pem'] = __webpack_require__(79); +formats['pkcs1'] = __webpack_require__(295); +formats['pkcs8'] = __webpack_require__(148); +formats['rfc4253'] = __webpack_require__(96); +formats['ssh-private'] = __webpack_require__(183); +formats['openssh'] = formats['ssh-private']; +formats['ssh'] = formats['ssh-private']; +formats['dnssec'] = __webpack_require__(294); + +function PrivateKey(opts) { + assert.object(opts, 'options'); + Key.call(this, opts); + + this._pubCache = undefined; +} +util.inherits(PrivateKey, Key); + +PrivateKey.formats = formats; + +PrivateKey.prototype.toBuffer = function (format, options) { + if (format === undefined) + format = 'pkcs1'; + assert.string(format, 'format'); + assert.object(formats[format], 'formats[format]'); + assert.optionalObject(options, 'options'); + + return (formats[format].write(this, options)); +}; + +PrivateKey.prototype.hash = function (algo) { + return (this.toPublic().hash(algo)); +}; + +PrivateKey.prototype.toPublic = function () { + if (this._pubCache) + return (this._pubCache); + + var algInfo = algs.info[this.type]; + var pubParts = []; + for (var i = 0; i < algInfo.parts.length; ++i) { + var p = algInfo.parts[i]; + pubParts.push(this.part[p]); + } + + this._pubCache = new Key({ + type: this.type, + source: this, + parts: pubParts + }); + if (this.comment) + this._pubCache.comment = this.comment; + return (this._pubCache); +}; + +PrivateKey.prototype.derive = function (newType) { + assert.string(newType, 'type'); + var priv, pub, pair; + + if (this.type === 'ed25519' && newType === 'curve25519') { + if (nacl === undefined) + nacl = __webpack_require__(69); + + priv = this.part.k.data; + if (priv[0] === 0x00) + priv = priv.slice(1); + + pair = nacl.box.keyPair.fromSecretKey(new Uint8Array(priv)); + pub = Buffer.from(pair.publicKey); + + return (new PrivateKey({ + type: 'curve25519', + parts: [ + { name: 'A', data: utils.mpNormalize(pub) }, + { name: 'k', data: utils.mpNormalize(priv) } + ] + })); + } else if (this.type === 'curve25519' && newType === 'ed25519') { + if (nacl === undefined) + nacl = __webpack_require__(69); + + priv = this.part.k.data; + if (priv[0] === 0x00) + priv = priv.slice(1); + + pair = nacl.sign.keyPair.fromSeed(new Uint8Array(priv)); + pub = Buffer.from(pair.publicKey); + + return (new PrivateKey({ + type: 'ed25519', + parts: [ + { name: 'A', data: utils.mpNormalize(pub) }, + { name: 'k', data: utils.mpNormalize(priv) } + ] + })); + } + throw (new Error('Key derivation not supported from ' + this.type + + ' to ' + newType)); +}; + +PrivateKey.prototype.createVerify = function (hashAlgo) { + return (this.toPublic().createVerify(hashAlgo)); +}; + +PrivateKey.prototype.createSign = function (hashAlgo) { + if (hashAlgo === undefined) + hashAlgo = this.defaultHashAlgorithm(); + assert.string(hashAlgo, 'hash algorithm'); + + /* ED25519 is not supported by OpenSSL, use a javascript impl. */ + if (this.type === 'ed25519' && edCompat !== undefined) + return (new edCompat.Signer(this, hashAlgo)); + if (this.type === 'curve25519') + throw (new Error('Curve25519 keys are not suitable for ' + + 'signing or verification')); + + var v, nm, err; + try { + nm = hashAlgo.toUpperCase(); + v = crypto.createSign(nm); + } catch (e) { + err = e; + } + if (v === undefined || (err instanceof Error && + err.message.match(/Unknown message digest/))) { + nm = 'RSA-'; + nm += hashAlgo.toUpperCase(); + v = crypto.createSign(nm); + } + assert.ok(v, 'failed to create verifier'); + var oldSign = v.sign.bind(v); + var key = this.toBuffer('pkcs1'); + var type = this.type; + var curve = this.curve; + v.sign = function () { + var sig = oldSign(key); + if (typeof (sig) === 'string') + sig = Buffer.from(sig, 'binary'); + sig = Signature.parse(sig, type, 'asn1'); + sig.hashAlgorithm = hashAlgo; + sig.curve = curve; + return (sig); + }; + return (v); +}; + +PrivateKey.parse = function (data, format, options) { + if (typeof (data) !== 'string') + assert.buffer(data, 'data'); + if (format === undefined) + format = 'auto'; + assert.string(format, 'format'); + if (typeof (options) === 'string') + options = { filename: options }; + assert.optionalObject(options, 'options'); + if (options === undefined) + options = {}; + assert.optionalString(options.filename, 'options.filename'); + if (options.filename === undefined) + options.filename = '(unnamed)'; + + assert.object(formats[format], 'formats[format]'); + + try { + var k = formats[format].read(data, options); + assert.ok(k instanceof PrivateKey, 'key is not a private key'); + if (!k.comment) + k.comment = options.filename; + return (k); + } catch (e) { + if (e.name === 'KeyEncryptedError') + throw (e); + throw (new KeyParseError(options.filename, format, e)); + } +}; + +PrivateKey.isPrivateKey = function (obj, ver) { + return (utils.isCompatible(obj, PrivateKey, ver)); +}; + +PrivateKey.generate = function (type, options) { + if (options === undefined) + options = {}; + assert.object(options, 'options'); + + switch (type) { + case 'ecdsa': + if (options.curve === undefined) + options.curve = 'nistp256'; + assert.string(options.curve, 'options.curve'); + return (generateECDSA(options.curve)); + case 'ed25519': + return (generateED25519()); + default: + throw (new Error('Key generation not supported with key ' + + 'type "' + type + '"')); + } +}; + +/* + * API versions for PrivateKey: + * [1,0] -- initial ver + * [1,1] -- added auto, pkcs[18], openssh/ssh-private formats + * [1,2] -- added defaultHashAlgorithm + * [1,3] -- added derive, ed, createDH + * [1,4] -- first tagged version + * [1,5] -- changed ed25519 part names and format + */ +PrivateKey.prototype._sshpkApiVersion = [1, 5]; + +PrivateKey._oldVersionDetect = function (obj) { + assert.func(obj.toPublic); + assert.func(obj.createSign); + if (obj.derive) + return ([1, 3]); + if (obj.defaultHashAlgorithm) + return ([1, 2]); + if (obj.formats['auto']) + return ([1, 1]); + return ([1, 0]); +}; + + +/***/ }), +/* 33 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.wrapLifecycle = exports.run = exports.install = exports.Install = undefined; + +var _extends2; + +function _load_extends() { + return _extends2 = _interopRequireDefault(__webpack_require__(21)); +} + +var _asyncToGenerator2; + +function _load_asyncToGenerator() { + return _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(2)); +} + +let install = exports.install = (() => { + var _ref29 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (config, reporter, flags, lockfile) { + yield wrapLifecycle(config, flags, (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + const install = new Install(flags, config, reporter, lockfile); + yield install.init(); + })); + }); + + return function install(_x7, _x8, _x9, _x10) { + return _ref29.apply(this, arguments); + }; +})(); + +let run = exports.run = (() => { + var _ref31 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (config, reporter, flags, args) { + let lockfile; + let error = 'installCommandRenamed'; + if (flags.lockfile === false) { + lockfile = new (_lockfile || _load_lockfile()).default(); + } else { + lockfile = yield (_lockfile || _load_lockfile()).default.fromDirectory(config.lockfileFolder, reporter); + } + + if (args.length) { + const exampleArgs = args.slice(); + + if (flags.saveDev) { + exampleArgs.push('--dev'); + } + if (flags.savePeer) { + exampleArgs.push('--peer'); + } + if (flags.saveOptional) { + exampleArgs.push('--optional'); + } + if (flags.saveExact) { + exampleArgs.push('--exact'); + } + if (flags.saveTilde) { + exampleArgs.push('--tilde'); + } + let command = 'add'; + if (flags.global) { + error = 'globalFlagRemoved'; + command = 'global add'; + } + throw new (_errors || _load_errors()).MessageError(reporter.lang(error, `yarn ${command} ${exampleArgs.join(' ')}`)); + } + + yield install(config, reporter, flags, lockfile); + }); + + return function run(_x11, _x12, _x13, _x14) { + return _ref31.apply(this, arguments); + }; +})(); + +let wrapLifecycle = exports.wrapLifecycle = (() => { + var _ref32 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (config, flags, factory) { + yield config.executeLifecycleScript('preinstall'); + + yield factory(); + + // npm behaviour, seems kinda funky but yay compatibility + yield config.executeLifecycleScript('install'); + yield config.executeLifecycleScript('postinstall'); + + if (!config.production) { + if (!config.disablePrepublish) { + yield config.executeLifecycleScript('prepublish'); + } + yield config.executeLifecycleScript('prepare'); + } + }); + + return function wrapLifecycle(_x15, _x16, _x17) { + return _ref32.apply(this, arguments); + }; +})(); + +exports.hasWrapper = hasWrapper; +exports.setFlags = setFlags; + +var _hooks; + +function _load_hooks() { + return _hooks = __webpack_require__(549); +} + +var _index; + +function _load_index() { + return _index = _interopRequireDefault(__webpack_require__(209)); +} + +var _errors; + +function _load_errors() { + return _errors = __webpack_require__(7); +} + +var _integrityChecker; + +function _load_integrityChecker() { + return _integrityChecker = _interopRequireDefault(__webpack_require__(198)); +} + +var _lockfile; + +function _load_lockfile() { + return _lockfile = _interopRequireDefault(__webpack_require__(18)); +} + +var _lockfile2; + +function _load_lockfile2() { + return _lockfile2 = __webpack_require__(18); +} + +var _packageFetcher; + +function _load_packageFetcher() { + return _packageFetcher = _interopRequireWildcard(__webpack_require__(199)); +} + +var _packageInstallScripts; + +function _load_packageInstallScripts() { + return _packageInstallScripts = _interopRequireDefault(__webpack_require__(528)); +} + +var _packageCompatibility; + +function _load_packageCompatibility() { + return _packageCompatibility = _interopRequireWildcard(__webpack_require__(333)); +} + +var _packageResolver; + +function _load_packageResolver() { + return _packageResolver = _interopRequireDefault(__webpack_require__(335)); +} + +var _packageLinker; + +function _load_packageLinker() { + return _packageLinker = _interopRequireDefault(__webpack_require__(200)); +} + +var _index2; + +function _load_index2() { + return _index2 = __webpack_require__(52); +} + +var _index3; + +function _load_index3() { + return _index3 = __webpack_require__(55); +} + +var _autoclean; + +function _load_autoclean() { + return _autoclean = __webpack_require__(322); +} + +var _constants; + +function _load_constants() { + return _constants = _interopRequireWildcard(__webpack_require__(9)); +} + +var _normalizePattern; + +function _load_normalizePattern() { + return _normalizePattern = __webpack_require__(36); +} + +var _fs; + +function _load_fs() { + return _fs = _interopRequireWildcard(__webpack_require__(5)); +} + +var _map; + +function _load_map() { + return _map = _interopRequireDefault(__webpack_require__(28)); +} + +var _yarnVersion; + +function _load_yarnVersion() { + return _yarnVersion = __webpack_require__(112); +} + +var _generatePnpMap; + +function _load_generatePnpMap() { + return _generatePnpMap = __webpack_require__(547); +} + +var _workspaceLayout; + +function _load_workspaceLayout() { + return _workspaceLayout = _interopRequireDefault(__webpack_require__(84)); +} + +var _resolutionMap; + +function _load_resolutionMap() { + return _resolutionMap = _interopRequireDefault(__webpack_require__(203)); +} + +var _guessName; + +function _load_guessName() { + return _guessName = _interopRequireDefault(__webpack_require__(160)); +} + +var _audit; + +function _load_audit() { + return _audit = _interopRequireDefault(__webpack_require__(321)); +} + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +const deepEqual = __webpack_require__(598); + +const emoji = __webpack_require__(271); +const invariant = __webpack_require__(8); +const path = __webpack_require__(0); +const semver = __webpack_require__(20); +const uuid = __webpack_require__(111); +const ssri = __webpack_require__(71); + +const ONE_DAY = 1000 * 60 * 60 * 24; + +/** + * Try and detect the installation method for Yarn and provide a command to update it with. + */ + +function getUpdateCommand(installationMethod) { + if (installationMethod === 'tar') { + return `curl --compressed -o- -L ${(_constants || _load_constants()).YARN_INSTALLER_SH} | bash`; + } + + if (installationMethod === 'homebrew') { + return 'brew upgrade yarn'; + } + + if (installationMethod === 'deb') { + return 'sudo apt-get update && sudo apt-get install yarn'; + } + + if (installationMethod === 'rpm') { + return 'sudo yum install yarn'; + } + + if (installationMethod === 'npm') { + return 'npm install --global yarn'; + } + + if (installationMethod === 'chocolatey') { + return 'choco upgrade yarn'; + } + + if (installationMethod === 'apk') { + return 'apk update && apk add -u yarn'; + } + + return null; +} + +function getUpdateInstaller(installationMethod) { + // Windows + if (installationMethod === 'msi') { + return (_constants || _load_constants()).YARN_INSTALLER_MSI; + } + + return null; +} + +function normalizeFlags(config, rawFlags) { + const flags = { + // install + har: !!rawFlags.har, + ignorePlatform: !!rawFlags.ignorePlatform, + ignoreEngines: !!rawFlags.ignoreEngines, + ignoreScripts: !!rawFlags.ignoreScripts, + ignoreOptional: !!rawFlags.ignoreOptional, + force: !!rawFlags.force, + flat: !!rawFlags.flat, + lockfile: rawFlags.lockfile !== false, + pureLockfile: !!rawFlags.pureLockfile, + updateChecksums: !!rawFlags.updateChecksums, + skipIntegrityCheck: !!rawFlags.skipIntegrityCheck, + frozenLockfile: !!rawFlags.frozenLockfile, + linkDuplicates: !!rawFlags.linkDuplicates, + checkFiles: !!rawFlags.checkFiles, + audit: !!rawFlags.audit, + + // add + peer: !!rawFlags.peer, + dev: !!rawFlags.dev, + optional: !!rawFlags.optional, + exact: !!rawFlags.exact, + tilde: !!rawFlags.tilde, + ignoreWorkspaceRootCheck: !!rawFlags.ignoreWorkspaceRootCheck, + + // outdated, update-interactive + includeWorkspaceDeps: !!rawFlags.includeWorkspaceDeps, + + // add, remove, update + workspaceRootIsCwd: rawFlags.workspaceRootIsCwd !== false + }; + + if (config.getOption('ignore-scripts')) { + flags.ignoreScripts = true; + } + + if (config.getOption('ignore-platform')) { + flags.ignorePlatform = true; + } + + if (config.getOption('ignore-engines')) { + flags.ignoreEngines = true; + } + + if (config.getOption('ignore-optional')) { + flags.ignoreOptional = true; + } + + if (config.getOption('force')) { + flags.force = true; + } + + return flags; +} + +class Install { + constructor(flags, config, reporter, lockfile) { + this.rootManifestRegistries = []; + this.rootPatternsToOrigin = (0, (_map || _load_map()).default)(); + this.lockfile = lockfile; + this.reporter = reporter; + this.config = config; + this.flags = normalizeFlags(config, flags); + this.resolutions = (0, (_map || _load_map()).default)(); // Legacy resolutions field used for flat install mode + this.resolutionMap = new (_resolutionMap || _load_resolutionMap()).default(config); // Selective resolutions for nested dependencies + this.resolver = new (_packageResolver || _load_packageResolver()).default(config, lockfile, this.resolutionMap); + this.integrityChecker = new (_integrityChecker || _load_integrityChecker()).default(config); + this.linker = new (_packageLinker || _load_packageLinker()).default(config, this.resolver); + this.scripts = new (_packageInstallScripts || _load_packageInstallScripts()).default(config, this.resolver, this.flags.force); + } + + /** + * Create a list of dependency requests from the current directories manifests. + */ + + fetchRequestFromCwd(excludePatterns = [], ignoreUnusedPatterns = false) { + var _this = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + const patterns = []; + const deps = []; + let resolutionDeps = []; + const manifest = {}; + + const ignorePatterns = []; + const usedPatterns = []; + let workspaceLayout; + + // some commands should always run in the context of the entire workspace + const cwd = _this.flags.includeWorkspaceDeps || _this.flags.workspaceRootIsCwd ? _this.config.lockfileFolder : _this.config.cwd; + + // non-workspaces are always root, otherwise check for workspace root + const cwdIsRoot = !_this.config.workspaceRootFolder || _this.config.lockfileFolder === cwd; + + // exclude package names that are in install args + const excludeNames = []; + for (var _iterator = excludePatterns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + const pattern = _ref; + + if ((0, (_index3 || _load_index3()).getExoticResolver)(pattern)) { + excludeNames.push((0, (_guessName || _load_guessName()).default)(pattern)); + } else { + // extract the name + const parts = (0, (_normalizePattern || _load_normalizePattern()).normalizePattern)(pattern); + excludeNames.push(parts.name); + } + } + + const stripExcluded = function stripExcluded(manifest) { + for (var _iterator2 = excludeNames, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + const exclude = _ref2; + + if (manifest.dependencies && manifest.dependencies[exclude]) { + delete manifest.dependencies[exclude]; + } + if (manifest.devDependencies && manifest.devDependencies[exclude]) { + delete manifest.devDependencies[exclude]; + } + if (manifest.optionalDependencies && manifest.optionalDependencies[exclude]) { + delete manifest.optionalDependencies[exclude]; + } + } + }; + + for (var _iterator3 = Object.keys((_index2 || _load_index2()).registries), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { + var _ref3; + + if (_isArray3) { + if (_i3 >= _iterator3.length) break; + _ref3 = _iterator3[_i3++]; + } else { + _i3 = _iterator3.next(); + if (_i3.done) break; + _ref3 = _i3.value; + } + + const registry = _ref3; + + const filename = (_index2 || _load_index2()).registries[registry].filename; + + const loc = path.join(cwd, filename); + if (!(yield (_fs || _load_fs()).exists(loc))) { + continue; + } + + _this.rootManifestRegistries.push(registry); + + const projectManifestJson = yield _this.config.readJson(loc); + yield (0, (_index || _load_index()).default)(projectManifestJson, cwd, _this.config, cwdIsRoot); + + Object.assign(_this.resolutions, projectManifestJson.resolutions); + Object.assign(manifest, projectManifestJson); + + _this.resolutionMap.init(_this.resolutions); + for (var _iterator4 = Object.keys(_this.resolutionMap.resolutionsByPackage), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { + var _ref4; + + if (_isArray4) { + if (_i4 >= _iterator4.length) break; + _ref4 = _iterator4[_i4++]; + } else { + _i4 = _iterator4.next(); + if (_i4.done) break; + _ref4 = _i4.value; + } + + const packageName = _ref4; + + for (var _iterator8 = _this.resolutionMap.resolutionsByPackage[packageName], _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { + var _ref9; + + if (_isArray8) { + if (_i8 >= _iterator8.length) break; + _ref9 = _iterator8[_i8++]; + } else { + _i8 = _iterator8.next(); + if (_i8.done) break; + _ref9 = _i8.value; + } + + const _ref8 = _ref9; + const pattern = _ref8.pattern; + + resolutionDeps = [...resolutionDeps, { registry, pattern, optional: false, hint: 'resolution' }]; + } + } + + const pushDeps = function pushDeps(depType, manifest, { hint, optional }, isUsed) { + if (ignoreUnusedPatterns && !isUsed) { + return; + } + // We only take unused dependencies into consideration to get deterministic hoisting. + // Since flat mode doesn't care about hoisting and everything is top level and specified then we can safely + // leave these out. + if (_this.flags.flat && !isUsed) { + return; + } + const depMap = manifest[depType]; + for (const name in depMap) { + if (excludeNames.indexOf(name) >= 0) { + continue; + } + + let pattern = name; + if (!_this.lockfile.getLocked(pattern)) { + // when we use --save we save the dependency to the lockfile with just the name rather than the + // version combo + pattern += '@' + depMap[name]; + } + + // normalization made sure packages are mentioned only once + if (isUsed) { + usedPatterns.push(pattern); + } else { + ignorePatterns.push(pattern); + } + + _this.rootPatternsToOrigin[pattern] = depType; + patterns.push(pattern); + deps.push({ pattern, registry, hint, optional, workspaceName: manifest.name, workspaceLoc: manifest._loc }); + } + }; + + if (cwdIsRoot) { + pushDeps('dependencies', projectManifestJson, { hint: null, optional: false }, true); + pushDeps('devDependencies', projectManifestJson, { hint: 'dev', optional: false }, !_this.config.production); + pushDeps('optionalDependencies', projectManifestJson, { hint: 'optional', optional: true }, true); + } + + if (_this.config.workspaceRootFolder) { + const workspaceLoc = cwdIsRoot ? loc : path.join(_this.config.lockfileFolder, filename); + const workspacesRoot = path.dirname(workspaceLoc); + + let workspaceManifestJson = projectManifestJson; + if (!cwdIsRoot) { + // the manifest we read before was a child workspace, so get the root + workspaceManifestJson = yield _this.config.readJson(workspaceLoc); + yield (0, (_index || _load_index()).default)(workspaceManifestJson, workspacesRoot, _this.config, true); + } + + const workspaces = yield _this.config.resolveWorkspaces(workspacesRoot, workspaceManifestJson); + workspaceLayout = new (_workspaceLayout || _load_workspaceLayout()).default(workspaces, _this.config); + + // add virtual manifest that depends on all workspaces, this way package hoisters and resolvers will work fine + const workspaceDependencies = (0, (_extends2 || _load_extends()).default)({}, workspaceManifestJson.dependencies); + for (var _iterator5 = Object.keys(workspaces), _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { + var _ref5; + + if (_isArray5) { + if (_i5 >= _iterator5.length) break; + _ref5 = _iterator5[_i5++]; + } else { + _i5 = _iterator5.next(); + if (_i5.done) break; + _ref5 = _i5.value; + } + + const workspaceName = _ref5; + + const workspaceManifest = workspaces[workspaceName].manifest; + workspaceDependencies[workspaceName] = workspaceManifest.version; + + // include dependencies from all workspaces + if (_this.flags.includeWorkspaceDeps) { + pushDeps('dependencies', workspaceManifest, { hint: null, optional: false }, true); + pushDeps('devDependencies', workspaceManifest, { hint: 'dev', optional: false }, !_this.config.production); + pushDeps('optionalDependencies', workspaceManifest, { hint: 'optional', optional: true }, true); + } + } + const virtualDependencyManifest = { + _uid: '', + name: `workspace-aggregator-${uuid.v4()}`, + version: '1.0.0', + _registry: 'npm', + _loc: workspacesRoot, + dependencies: workspaceDependencies, + devDependencies: (0, (_extends2 || _load_extends()).default)({}, workspaceManifestJson.devDependencies), + optionalDependencies: (0, (_extends2 || _load_extends()).default)({}, workspaceManifestJson.optionalDependencies), + private: workspaceManifestJson.private, + workspaces: workspaceManifestJson.workspaces + }; + workspaceLayout.virtualManifestName = virtualDependencyManifest.name; + const virtualDep = {}; + virtualDep[virtualDependencyManifest.name] = virtualDependencyManifest.version; + workspaces[virtualDependencyManifest.name] = { loc: workspacesRoot, manifest: virtualDependencyManifest }; + + // ensure dependencies that should be excluded are stripped from the correct manifest + stripExcluded(cwdIsRoot ? virtualDependencyManifest : workspaces[projectManifestJson.name].manifest); + + pushDeps('workspaces', { workspaces: virtualDep }, { hint: 'workspaces', optional: false }, true); + + const implicitWorkspaceDependencies = (0, (_extends2 || _load_extends()).default)({}, workspaceDependencies); + + for (var _iterator6 = (_constants || _load_constants()).OWNED_DEPENDENCY_TYPES, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { + var _ref6; + + if (_isArray6) { + if (_i6 >= _iterator6.length) break; + _ref6 = _iterator6[_i6++]; + } else { + _i6 = _iterator6.next(); + if (_i6.done) break; + _ref6 = _i6.value; + } + + const type = _ref6; + + for (var _iterator7 = Object.keys(projectManifestJson[type] || {}), _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { + var _ref7; + + if (_isArray7) { + if (_i7 >= _iterator7.length) break; + _ref7 = _iterator7[_i7++]; + } else { + _i7 = _iterator7.next(); + if (_i7.done) break; + _ref7 = _i7.value; + } + + const dependencyName = _ref7; + + delete implicitWorkspaceDependencies[dependencyName]; + } + } + + pushDeps('dependencies', { dependencies: implicitWorkspaceDependencies }, { hint: 'workspaces', optional: false }, true); + } + + break; + } + + // inherit root flat flag + if (manifest.flat) { + _this.flags.flat = true; + } + + return { + requests: [...resolutionDeps, ...deps], + patterns, + manifest, + usedPatterns, + ignorePatterns, + workspaceLayout + }; + })(); + } + + /** + * TODO description + */ + + prepareRequests(requests) { + return requests; + } + + preparePatterns(patterns) { + return patterns; + } + preparePatternsForLinking(patterns, cwdManifest, cwdIsRoot) { + return patterns; + } + + prepareManifests() { + var _this2 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + const manifests = yield _this2.config.getRootManifests(); + return manifests; + })(); + } + + bailout(patterns, workspaceLayout) { + var _this3 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + // We don't want to skip the audit - it could yield important errors + if (_this3.flags.audit) { + return false; + } + // PNP is so fast that the integrity check isn't pertinent + if (_this3.config.plugnplayEnabled) { + return false; + } + if (_this3.flags.skipIntegrityCheck || _this3.flags.force) { + return false; + } + const lockfileCache = _this3.lockfile.cache; + if (!lockfileCache) { + return false; + } + const lockfileClean = _this3.lockfile.parseResultType === 'success'; + const match = yield _this3.integrityChecker.check(patterns, lockfileCache, _this3.flags, workspaceLayout); + if (_this3.flags.frozenLockfile && (!lockfileClean || match.missingPatterns.length > 0)) { + throw new (_errors || _load_errors()).MessageError(_this3.reporter.lang('frozenLockfileError')); + } + + const haveLockfile = yield (_fs || _load_fs()).exists(path.join(_this3.config.lockfileFolder, (_constants || _load_constants()).LOCKFILE_FILENAME)); + + const lockfileIntegrityPresent = !_this3.lockfile.hasEntriesExistWithoutIntegrity(); + const integrityBailout = lockfileIntegrityPresent || !_this3.config.autoAddIntegrity; + + if (match.integrityMatches && haveLockfile && lockfileClean && integrityBailout) { + _this3.reporter.success(_this3.reporter.lang('upToDate')); + return true; + } + + if (match.integrityFileMissing && haveLockfile) { + // Integrity file missing, force script installations + _this3.scripts.setForce(true); + return false; + } + + if (match.hardRefreshRequired) { + // e.g. node version doesn't match, force script installations + _this3.scripts.setForce(true); + return false; + } + + if (!patterns.length && !match.integrityFileMissing) { + _this3.reporter.success(_this3.reporter.lang('nothingToInstall')); + yield _this3.createEmptyManifestFolders(); + yield _this3.saveLockfileAndIntegrity(patterns, workspaceLayout); + return true; + } + + return false; + })(); + } + + /** + * Produce empty folders for all used root manifests. + */ + + createEmptyManifestFolders() { + var _this4 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + if (_this4.config.modulesFolder) { + // already created + return; + } + + for (var _iterator9 = _this4.rootManifestRegistries, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { + var _ref10; + + if (_isArray9) { + if (_i9 >= _iterator9.length) break; + _ref10 = _iterator9[_i9++]; + } else { + _i9 = _iterator9.next(); + if (_i9.done) break; + _ref10 = _i9.value; + } + + const registryName = _ref10; + const folder = _this4.config.registries[registryName].folder; + + yield (_fs || _load_fs()).mkdirp(path.join(_this4.config.lockfileFolder, folder)); + } + })(); + } + + /** + * TODO description + */ + + markIgnored(patterns) { + for (var _iterator10 = patterns, _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) { + var _ref11; + + if (_isArray10) { + if (_i10 >= _iterator10.length) break; + _ref11 = _iterator10[_i10++]; + } else { + _i10 = _iterator10.next(); + if (_i10.done) break; + _ref11 = _i10.value; + } + + const pattern = _ref11; + + const manifest = this.resolver.getStrictResolvedPattern(pattern); + const ref = manifest._reference; + invariant(ref, 'expected package reference'); + + // just mark the package as ignored. if the package is used by a required package, the hoister + // will take care of that. + ref.ignore = true; + } + } + + /** + * helper method that gets only recent manifests + * used by global.ls command + */ + getFlattenedDeps() { + var _this5 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + var _ref12 = yield _this5.fetchRequestFromCwd(); + + const depRequests = _ref12.requests, + rawPatterns = _ref12.patterns; + + + yield _this5.resolver.init(depRequests, {}); + + const manifests = yield (_packageFetcher || _load_packageFetcher()).fetch(_this5.resolver.getManifests(), _this5.config); + _this5.resolver.updateManifests(manifests); + + return _this5.flatten(rawPatterns); + })(); + } + + /** + * TODO description + */ + + init() { + var _this6 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + _this6.checkUpdate(); + + // warn if we have a shrinkwrap + if (yield (_fs || _load_fs()).exists(path.join(_this6.config.lockfileFolder, (_constants || _load_constants()).NPM_SHRINKWRAP_FILENAME))) { + _this6.reporter.warn(_this6.reporter.lang('shrinkwrapWarning')); + } + + // warn if we have an npm lockfile + if (yield (_fs || _load_fs()).exists(path.join(_this6.config.lockfileFolder, (_constants || _load_constants()).NPM_LOCK_FILENAME))) { + _this6.reporter.warn(_this6.reporter.lang('npmLockfileWarning')); + } + + let flattenedTopLevelPatterns = []; + const steps = []; + + var _ref13 = yield _this6.fetchRequestFromCwd(); + + const depRequests = _ref13.requests, + rawPatterns = _ref13.patterns, + ignorePatterns = _ref13.ignorePatterns, + workspaceLayout = _ref13.workspaceLayout, + manifest = _ref13.manifest; + + let topLevelPatterns = []; + + const artifacts = yield _this6.integrityChecker.getArtifacts(); + if (artifacts) { + _this6.linker.setArtifacts(artifacts); + _this6.scripts.setArtifacts(artifacts); + } + + if (!_this6.flags.ignoreEngines && typeof manifest.engines === 'object') { + steps.push((() => { + var _ref14 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (curr, total) { + _this6.reporter.step(curr, total, _this6.reporter.lang('checkingManifest'), emoji.get('mag')); + yield _this6.checkCompatibility(); + }); + + return function (_x, _x2) { + return _ref14.apply(this, arguments); + }; + })()); + } + + const audit = new (_audit || _load_audit()).default(_this6.config, _this6.reporter); + let auditFoundProblems = false; + + steps.push(function (curr, total) { + return (0, (_hooks || _load_hooks()).callThroughHook)('resolveStep', (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + _this6.reporter.step(curr, total, _this6.reporter.lang('resolvingPackages'), emoji.get('mag')); + yield _this6.resolver.init(_this6.prepareRequests(depRequests), { + isFlat: _this6.flags.flat, + isFrozen: _this6.flags.frozenLockfile, + workspaceLayout + }); + topLevelPatterns = _this6.preparePatterns(rawPatterns); + flattenedTopLevelPatterns = yield _this6.flatten(topLevelPatterns); + return { bailout: !_this6.flags.audit && (yield _this6.bailout(topLevelPatterns, workspaceLayout)) }; + })); + }); + + if (_this6.flags.audit) { + steps.push(function (curr, total) { + return (0, (_hooks || _load_hooks()).callThroughHook)('auditStep', (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + _this6.reporter.step(curr, total, _this6.reporter.lang('auditRunning'), emoji.get('mag')); + if (_this6.flags.offline) { + _this6.reporter.warn(_this6.reporter.lang('auditOffline')); + return { bailout: false }; + } + const preparedManifests = yield _this6.prepareManifests(); + // $FlowFixMe - Flow considers `m` in the map operation to be "mixed", so does not recognize `m.object` + const mergedManifest = Object.assign({}, ...Object.values(preparedManifests).map(function (m) { + return m.object; + })); + const auditVulnerabilityCounts = yield audit.performAudit(mergedManifest, _this6.resolver, _this6.linker, topLevelPatterns); + auditFoundProblems = auditVulnerabilityCounts.info || auditVulnerabilityCounts.low || auditVulnerabilityCounts.moderate || auditVulnerabilityCounts.high || auditVulnerabilityCounts.critical; + return { bailout: yield _this6.bailout(topLevelPatterns, workspaceLayout) }; + })); + }); + } + + steps.push(function (curr, total) { + return (0, (_hooks || _load_hooks()).callThroughHook)('fetchStep', (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + _this6.markIgnored(ignorePatterns); + _this6.reporter.step(curr, total, _this6.reporter.lang('fetchingPackages'), emoji.get('truck')); + const manifests = yield (_packageFetcher || _load_packageFetcher()).fetch(_this6.resolver.getManifests(), _this6.config); + _this6.resolver.updateManifests(manifests); + yield (_packageCompatibility || _load_packageCompatibility()).check(_this6.resolver.getManifests(), _this6.config, _this6.flags.ignoreEngines); + })); + }); + + steps.push(function (curr, total) { + return (0, (_hooks || _load_hooks()).callThroughHook)('linkStep', (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + // remove integrity hash to make this operation atomic + yield _this6.integrityChecker.removeIntegrityFile(); + _this6.reporter.step(curr, total, _this6.reporter.lang('linkingDependencies'), emoji.get('link')); + flattenedTopLevelPatterns = _this6.preparePatternsForLinking(flattenedTopLevelPatterns, manifest, _this6.config.lockfileFolder === _this6.config.cwd); + yield _this6.linker.init(flattenedTopLevelPatterns, workspaceLayout, { + linkDuplicates: _this6.flags.linkDuplicates, + ignoreOptional: _this6.flags.ignoreOptional + }); + })); + }); + + if (_this6.config.plugnplayEnabled) { + steps.push(function (curr, total) { + return (0, (_hooks || _load_hooks()).callThroughHook)('pnpStep', (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + const pnpPath = `${_this6.config.lockfileFolder}/${(_constants || _load_constants()).PNP_FILENAME}`; + + const code = yield (0, (_generatePnpMap || _load_generatePnpMap()).generatePnpMap)(_this6.config, flattenedTopLevelPatterns, { + resolver: _this6.resolver, + reporter: _this6.reporter, + targetPath: pnpPath, + workspaceLayout + }); + + try { + const file = yield (_fs || _load_fs()).readFile(pnpPath); + if (file === code) { + return; + } + } catch (error) {} + + yield (_fs || _load_fs()).writeFile(pnpPath, code); + yield (_fs || _load_fs()).chmod(pnpPath, 0o755); + })); + }); + } + + steps.push(function (curr, total) { + return (0, (_hooks || _load_hooks()).callThroughHook)('buildStep', (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + _this6.reporter.step(curr, total, _this6.flags.force ? _this6.reporter.lang('rebuildingPackages') : _this6.reporter.lang('buildingFreshPackages'), emoji.get('hammer')); + + if (_this6.flags.ignoreScripts) { + _this6.reporter.warn(_this6.reporter.lang('ignoredScripts')); + } else { + yield _this6.scripts.init(flattenedTopLevelPatterns); + } + })); + }); + + if (_this6.flags.har) { + steps.push((() => { + var _ref21 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (curr, total) { + const formattedDate = new Date().toISOString().replace(/:/g, '-'); + const filename = `yarn-install_${formattedDate}.har`; + _this6.reporter.step(curr, total, _this6.reporter.lang('savingHar', filename), emoji.get('black_circle_for_record')); + yield _this6.config.requestManager.saveHar(filename); + }); + + return function (_x3, _x4) { + return _ref21.apply(this, arguments); + }; + })()); + } + + if (yield _this6.shouldClean()) { + steps.push((() => { + var _ref22 = (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* (curr, total) { + _this6.reporter.step(curr, total, _this6.reporter.lang('cleaningModules'), emoji.get('recycle')); + yield (0, (_autoclean || _load_autoclean()).clean)(_this6.config, _this6.reporter); + }); + + return function (_x5, _x6) { + return _ref22.apply(this, arguments); + }; + })()); + } + + let currentStep = 0; + for (var _iterator11 = steps, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) { + var _ref23; + + if (_isArray11) { + if (_i11 >= _iterator11.length) break; + _ref23 = _iterator11[_i11++]; + } else { + _i11 = _iterator11.next(); + if (_i11.done) break; + _ref23 = _i11.value; + } + + const step = _ref23; + + const stepResult = yield step(++currentStep, steps.length); + if (stepResult && stepResult.bailout) { + if (_this6.flags.audit) { + audit.summary(); + } + if (auditFoundProblems) { + _this6.reporter.warn(_this6.reporter.lang('auditRunAuditForDetails')); + } + _this6.maybeOutputUpdate(); + return flattenedTopLevelPatterns; + } + } + + // fin! + if (_this6.flags.audit) { + audit.summary(); + } + if (auditFoundProblems) { + _this6.reporter.warn(_this6.reporter.lang('auditRunAuditForDetails')); + } + yield _this6.saveLockfileAndIntegrity(topLevelPatterns, workspaceLayout); + yield _this6.persistChanges(); + _this6.maybeOutputUpdate(); + _this6.config.requestManager.clearCache(); + return flattenedTopLevelPatterns; + })(); + } + + checkCompatibility() { + var _this7 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + var _ref24 = yield _this7.fetchRequestFromCwd(); + + const manifest = _ref24.manifest; + + yield (_packageCompatibility || _load_packageCompatibility()).checkOne((0, (_extends2 || _load_extends()).default)({ _reference: {} }, manifest), _this7.config, _this7.flags.ignoreEngines); + })(); + } + + persistChanges() { + var _this8 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + // get all the different registry manifests in this folder + const manifests = yield _this8.config.getRootManifests(); + + if (yield _this8.applyChanges(manifests)) { + yield _this8.config.saveRootManifests(manifests); + } + })(); + } + + applyChanges(manifests) { + let hasChanged = false; + + if (this.config.plugnplayPersist) { + const object = manifests.npm.object; + + + if (typeof object.installConfig !== 'object') { + object.installConfig = {}; + } + + if (this.config.plugnplayEnabled && object.installConfig.pnp !== true) { + object.installConfig.pnp = true; + hasChanged = true; + } else if (!this.config.plugnplayEnabled && typeof object.installConfig.pnp !== 'undefined') { + delete object.installConfig.pnp; + hasChanged = true; + } + + if (Object.keys(object.installConfig).length === 0) { + delete object.installConfig; + } + } + + return Promise.resolve(hasChanged); + } + + /** + * Check if we should run the cleaning step. + */ + + shouldClean() { + return (_fs || _load_fs()).exists(path.join(this.config.lockfileFolder, (_constants || _load_constants()).CLEAN_FILENAME)); + } + + /** + * TODO + */ + + flatten(patterns) { + var _this9 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + if (!_this9.flags.flat) { + return patterns; + } + + const flattenedPatterns = []; + + for (var _iterator12 = _this9.resolver.getAllDependencyNamesByLevelOrder(patterns), _isArray12 = Array.isArray(_iterator12), _i12 = 0, _iterator12 = _isArray12 ? _iterator12 : _iterator12[Symbol.iterator]();;) { + var _ref25; + + if (_isArray12) { + if (_i12 >= _iterator12.length) break; + _ref25 = _iterator12[_i12++]; + } else { + _i12 = _iterator12.next(); + if (_i12.done) break; + _ref25 = _i12.value; + } + + const name = _ref25; + + const infos = _this9.resolver.getAllInfoForPackageName(name).filter(function (manifest) { + const ref = manifest._reference; + invariant(ref, 'expected package reference'); + return !ref.ignore; + }); + + if (infos.length === 0) { + continue; + } + + if (infos.length === 1) { + // single version of this package + // take out a single pattern as multiple patterns may have resolved to this package + flattenedPatterns.push(_this9.resolver.patternsByPackage[name][0]); + continue; + } + + const options = infos.map(function (info) { + const ref = info._reference; + invariant(ref, 'expected reference'); + return { + // TODO `and is required by {PARENT}`, + name: _this9.reporter.lang('manualVersionResolutionOption', ref.patterns.join(', '), info.version), + + value: info.version + }; + }); + const versions = infos.map(function (info) { + return info.version; + }); + let version; + + const resolutionVersion = _this9.resolutions[name]; + if (resolutionVersion && versions.indexOf(resolutionVersion) >= 0) { + // use json `resolution` version + version = resolutionVersion; + } else { + version = yield _this9.reporter.select(_this9.reporter.lang('manualVersionResolution', name), _this9.reporter.lang('answer'), options); + _this9.resolutions[name] = version; + } + + flattenedPatterns.push(_this9.resolver.collapseAllVersionsOfPackage(name, version)); + } + + // save resolutions to their appropriate root manifest + if (Object.keys(_this9.resolutions).length) { + const manifests = yield _this9.config.getRootManifests(); + + for (const name in _this9.resolutions) { + const version = _this9.resolutions[name]; + + const patterns = _this9.resolver.patternsByPackage[name]; + if (!patterns) { + continue; + } + + let manifest; + for (var _iterator13 = patterns, _isArray13 = Array.isArray(_iterator13), _i13 = 0, _iterator13 = _isArray13 ? _iterator13 : _iterator13[Symbol.iterator]();;) { + var _ref26; + + if (_isArray13) { + if (_i13 >= _iterator13.length) break; + _ref26 = _iterator13[_i13++]; + } else { + _i13 = _iterator13.next(); + if (_i13.done) break; + _ref26 = _i13.value; + } + + const pattern = _ref26; + + manifest = _this9.resolver.getResolvedPattern(pattern); + if (manifest) { + break; + } + } + invariant(manifest, 'expected manifest'); + + const ref = manifest._reference; + invariant(ref, 'expected reference'); + + const object = manifests[ref.registry].object; + object.resolutions = object.resolutions || {}; + object.resolutions[name] = version; + } + + yield _this9.config.saveRootManifests(manifests); + } + + return flattenedPatterns; + })(); + } + + /** + * Remove offline tarballs that are no longer required + */ + + pruneOfflineMirror(lockfile) { + var _this10 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + const mirror = _this10.config.getOfflineMirrorPath(); + if (!mirror) { + return; + } + + const requiredTarballs = new Set(); + for (const dependency in lockfile) { + const resolved = lockfile[dependency].resolved; + if (resolved) { + const basename = path.basename(resolved.split('#')[0]); + if (dependency[0] === '@' && basename[0] !== '@') { + requiredTarballs.add(`${dependency.split('/')[0]}-${basename}`); + } + requiredTarballs.add(basename); + } + } + + const mirrorFiles = yield (_fs || _load_fs()).walk(mirror); + for (var _iterator14 = mirrorFiles, _isArray14 = Array.isArray(_iterator14), _i14 = 0, _iterator14 = _isArray14 ? _iterator14 : _iterator14[Symbol.iterator]();;) { + var _ref27; + + if (_isArray14) { + if (_i14 >= _iterator14.length) break; + _ref27 = _iterator14[_i14++]; + } else { + _i14 = _iterator14.next(); + if (_i14.done) break; + _ref27 = _i14.value; + } + + const file = _ref27; + + const isTarball = path.extname(file.basename) === '.tgz'; + // if using experimental-pack-script-packages-in-mirror flag, don't unlink prebuilt packages + const hasPrebuiltPackage = file.relative.startsWith('prebuilt/'); + if (isTarball && !hasPrebuiltPackage && !requiredTarballs.has(file.basename)) { + yield (_fs || _load_fs()).unlink(file.absolute); + } + } + })(); + } + + /** + * Save updated integrity and lockfiles. + */ + + saveLockfileAndIntegrity(patterns, workspaceLayout) { + var _this11 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + const resolvedPatterns = {}; + Object.keys(_this11.resolver.patterns).forEach(function (pattern) { + if (!workspaceLayout || !workspaceLayout.getManifestByPattern(pattern)) { + resolvedPatterns[pattern] = _this11.resolver.patterns[pattern]; + } + }); + + // TODO this code is duplicated in a few places, need a common way to filter out workspace patterns from lockfile + patterns = patterns.filter(function (p) { + return !workspaceLayout || !workspaceLayout.getManifestByPattern(p); + }); + + const lockfileBasedOnResolver = _this11.lockfile.getLockfile(resolvedPatterns); + + if (_this11.config.pruneOfflineMirror) { + yield _this11.pruneOfflineMirror(lockfileBasedOnResolver); + } + + // write integrity hash + if (!_this11.config.plugnplayEnabled) { + yield _this11.integrityChecker.save(patterns, lockfileBasedOnResolver, _this11.flags, workspaceLayout, _this11.scripts.getArtifacts()); + } + + // --no-lockfile or --pure-lockfile or --frozen-lockfile + if (_this11.flags.lockfile === false || _this11.flags.pureLockfile || _this11.flags.frozenLockfile) { + return; + } + + const lockFileHasAllPatterns = patterns.every(function (p) { + return _this11.lockfile.getLocked(p); + }); + const lockfilePatternsMatch = Object.keys(_this11.lockfile.cache || {}).every(function (p) { + return lockfileBasedOnResolver[p]; + }); + const resolverPatternsAreSameAsInLockfile = Object.keys(lockfileBasedOnResolver).every(function (pattern) { + const manifest = _this11.lockfile.getLocked(pattern); + return manifest && manifest.resolved === lockfileBasedOnResolver[pattern].resolved && deepEqual(manifest.prebuiltVariants, lockfileBasedOnResolver[pattern].prebuiltVariants); + }); + const integrityPatternsAreSameAsInLockfile = Object.keys(lockfileBasedOnResolver).every(function (pattern) { + const existingIntegrityInfo = lockfileBasedOnResolver[pattern].integrity; + if (!existingIntegrityInfo) { + // if this entry does not have an integrity, no need to re-write the lockfile because of it + return true; + } + const manifest = _this11.lockfile.getLocked(pattern); + if (manifest && manifest.integrity) { + const manifestIntegrity = ssri.stringify(manifest.integrity); + return manifestIntegrity === existingIntegrityInfo; + } + return false; + }); + + // remove command is followed by install with force, lockfile will be rewritten in any case then + if (!_this11.flags.force && _this11.lockfile.parseResultType === 'success' && lockFileHasAllPatterns && lockfilePatternsMatch && resolverPatternsAreSameAsInLockfile && integrityPatternsAreSameAsInLockfile && patterns.length) { + return; + } + + // build lockfile location + const loc = path.join(_this11.config.lockfileFolder, (_constants || _load_constants()).LOCKFILE_FILENAME); + + // write lockfile + const lockSource = (0, (_lockfile2 || _load_lockfile2()).stringify)(lockfileBasedOnResolver, false, _this11.config.enableLockfileVersions); + yield (_fs || _load_fs()).writeFilePreservingEol(loc, lockSource); + + _this11._logSuccessSaveLockfile(); + })(); + } + + _logSuccessSaveLockfile() { + this.reporter.success(this.reporter.lang('savedLockfile')); + } + + /** + * Load the dependency graph of the current install. Only does package resolving and wont write to the cwd. + */ + hydrate(ignoreUnusedPatterns) { + var _this12 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + const request = yield _this12.fetchRequestFromCwd([], ignoreUnusedPatterns); + const depRequests = request.requests, + rawPatterns = request.patterns, + ignorePatterns = request.ignorePatterns, + workspaceLayout = request.workspaceLayout; + + + yield _this12.resolver.init(depRequests, { + isFlat: _this12.flags.flat, + isFrozen: _this12.flags.frozenLockfile, + workspaceLayout + }); + yield _this12.flatten(rawPatterns); + _this12.markIgnored(ignorePatterns); + + // fetch packages, should hit cache most of the time + const manifests = yield (_packageFetcher || _load_packageFetcher()).fetch(_this12.resolver.getManifests(), _this12.config); + _this12.resolver.updateManifests(manifests); + yield (_packageCompatibility || _load_packageCompatibility()).check(_this12.resolver.getManifests(), _this12.config, _this12.flags.ignoreEngines); + + // expand minimal manifests + for (var _iterator15 = _this12.resolver.getManifests(), _isArray15 = Array.isArray(_iterator15), _i15 = 0, _iterator15 = _isArray15 ? _iterator15 : _iterator15[Symbol.iterator]();;) { + var _ref28; + + if (_isArray15) { + if (_i15 >= _iterator15.length) break; + _ref28 = _iterator15[_i15++]; + } else { + _i15 = _iterator15.next(); + if (_i15.done) break; + _ref28 = _i15.value; + } + + const manifest = _ref28; + + const ref = manifest._reference; + invariant(ref, 'expected reference'); + const type = ref.remote.type; + // link specifier won't ever hit cache + + let loc = ''; + if (type === 'link') { + continue; + } else if (type === 'workspace') { + if (!ref.remote.reference) { + continue; + } + loc = ref.remote.reference; + } else { + loc = _this12.config.generateModuleCachePath(ref); + } + const newPkg = yield _this12.config.readManifest(loc); + yield _this12.resolver.updateManifest(ref, newPkg); + } + + return request; + })(); + } + + /** + * Check for updates every day and output a nag message if there's a newer version. + */ + + checkUpdate() { + if (this.config.nonInteractive) { + // don't show upgrade dialog on CI or non-TTY terminals + return; + } + + // don't check if disabled + if (this.config.getOption('disable-self-update-check')) { + return; + } + + // only check for updates once a day + const lastUpdateCheck = Number(this.config.getOption('lastUpdateCheck')) || 0; + if (lastUpdateCheck && Date.now() - lastUpdateCheck < ONE_DAY) { + return; + } + + // don't bug for updates on tagged releases + if ((_yarnVersion || _load_yarnVersion()).version.indexOf('-') >= 0) { + return; + } + + this._checkUpdate().catch(() => { + // swallow errors + }); + } + + _checkUpdate() { + var _this13 = this; + + return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () { + let latestVersion = yield _this13.config.requestManager.request({ + url: (_constants || _load_constants()).SELF_UPDATE_VERSION_URL + }); + invariant(typeof latestVersion === 'string', 'expected string'); + latestVersion = latestVersion.trim(); + if (!semver.valid(latestVersion)) { + return; + } + + // ensure we only check for updates periodically + _this13.config.registries.yarn.saveHomeConfig({ + lastUpdateCheck: Date.now() + }); + + if (semver.gt(latestVersion, (_yarnVersion || _load_yarnVersion()).version)) { + const installationMethod = yield (0, (_yarnVersion || _load_yarnVersion()).getInstallationMethod)(); + _this13.maybeOutputUpdate = function () { + _this13.reporter.warn(_this13.reporter.lang('yarnOutdated', latestVersion, (_yarnVersion || _load_yarnVersion()).version)); + + const command = getUpdateCommand(installationMethod); + if (command) { + _this13.reporter.info(_this13.reporter.lang('yarnOutdatedCommand')); + _this13.reporter.command(command); + } else { + const installer = getUpdateInstaller(installationMethod); + if (installer) { + _this13.reporter.info(_this13.reporter.lang('yarnOutdatedInstaller', installer)); + } + } + }; + } + })(); + } + + /** + * Method to override with a possible upgrade message. + */ + + maybeOutputUpdate() {} +} + +exports.Install = Install; +function hasWrapper(commander, args) { + return true; +} + +function setFlags(commander) { + commander.description('Yarn install is used to install all dependencies for a project.'); + commander.usage('install [flags]'); + commander.option('-A, --audit', 'Run vulnerability audit on installed packages'); + commander.option('-g, --global', 'DEPRECATED'); + commander.option('-S, --save', 'DEPRECATED - save package to your `dependencies`'); + commander.option('-D, --save-dev', 'DEPRECATED - save package to your `devDependencies`'); + commander.option('-P, --save-peer', 'DEPRECATED - save package to your `peerDependencies`'); + commander.option('-O, --save-optional', 'DEPRECATED - save package to your `optionalDependencies`'); + commander.option('-E, --save-exact', 'DEPRECATED'); + commander.option('-T, --save-tilde', 'DEPRECATED'); +} + +/***/ }), +/* 34 */ +/***/ (function(module, exports, __webpack_require__) { + +var isObject = __webpack_require__(49); +module.exports = function (it) { + if (!isObject(it)) throw TypeError(it + ' is not an object!'); + return it; +}; + + +/***/ }), +/* 35 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return SubjectSubscriber; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Subject; }); +/* unused harmony export AnonymousSubject */ +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tslib__ = __webpack_require__(1); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Observable__ = __webpack_require__(10); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Subscriber__ = __webpack_require__(6); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__Subscription__ = __webpack_require__(24); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__util_ObjectUnsubscribedError__ = __webpack_require__(180); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__SubjectSubscription__ = __webpack_require__(394); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__internal_symbol_rxSubscriber__ = __webpack_require__(289); +/** PURE_IMPORTS_START tslib,_Observable,_Subscriber,_Subscription,_util_ObjectUnsubscribedError,_SubjectSubscription,_internal_symbol_rxSubscriber PURE_IMPORTS_END */ + + + + + + + +var SubjectSubscriber = /*@__PURE__*/ (function (_super) { + __WEBPACK_IMPORTED_MODULE_0_tslib__["a" /* __extends */](SubjectSubscriber, _super); + function SubjectSubscriber(destination) { + var _this = _super.call(this, destination) || this; + _this.destination = destination; + return _this; + } + return SubjectSubscriber; +}(__WEBPACK_IMPORTED_MODULE_2__Subscriber__["a" /* Subscriber */])); + +var Subject = /*@__PURE__*/ (function (_super) { + __WEBPACK_IMPORTED_MODULE_0_tslib__["a" /* __extends */](Subject, _super); + function Subject() { + var _this = _super.call(this) || this; + _this.observers = []; + _this.closed = false; + _this.isStopped = false; + _this.hasError = false; + _this.thrownError = null; + return _this; + } + Subject.prototype[__WEBPACK_IMPORTED_MODULE_6__internal_symbol_rxSubscriber__["a" /* rxSubscriber */]] = function () { + return new SubjectSubscriber(this); + }; + Subject.prototype.lift = function (operator) { + var subject = new AnonymousSubject(this, this); + subject.operator = operator; + return subject; + }; + Subject.prototype.next = function (value) { + if (this.closed) { + throw new __WEBPACK_IMPORTED_MODULE_4__util_ObjectUnsubscribedError__["a" /* ObjectUnsubscribedError */](); + } + if (!this.isStopped) { + var observers = this.observers; + var len = observers.length; + var copy = observers.slice(); + for (var i = 0; i < len; i++) { + copy[i].next(value); + } + } + }; + Subject.prototype.error = function (err) { + if (this.closed) { + throw new __WEBPACK_IMPORTED_MODULE_4__util_ObjectUnsubscribedError__["a" /* ObjectUnsubscribedError */](); + } + this.hasError = true; + this.thrownError = err; + this.isStopped = true; + var observers = this.observers; + var len = observers.length; + var copy = observers.slice(); + for (var i = 0; i < len; i++) { + copy[i].error(err); + } + this.observers.length = 0; + }; + Subject.prototype.complete = function () { + if (this.closed) { + throw new __WEBPACK_IMPORTED_MODULE_4__util_ObjectUnsubscribedError__["a" /* ObjectUnsubscribedError */](); + } + this.isStopped = true; + var observers = this.observers; + var len = observers.length; + var copy = observers.slice(); + for (var i = 0; i < len; i++) { + copy[i].complete(); + } + this.observers.length = 0; + }; + Subject.prototype.unsubscribe = function () { + this.isStopped = true; + this.closed = true; + this.observers = null; + }; + Subject.prototype._trySubscribe = function (subscriber) { + if (this.closed) { + throw new __WEBPACK_IMPORTED_MODULE_4__util_ObjectUnsubscribedError__["a" /* ObjectUnsubscribedError */](); + } + else { + return _super.prototype._trySubscribe.call(this, subscriber); + } + }; + Subject.prototype._subscribe = function (subscriber) { + if (this.closed) { + throw new __WEBPACK_IMPORTED_MODULE_4__util_ObjectUnsubscribedError__["a" /* ObjectUnsubscribedError */](); + } + else if (this.hasError) { + subscriber.error(this.thrownError); + return __WEBPACK_IMPORTED_MODULE_3__Subscription__["a" /* Subscription */].EMPTY; + } + else if (this.isStopped) { + subscriber.complete(); + return __WEBPACK_IMPORTED_MODULE_3__Subscription__["a" /* Subscription */].EMPTY; + } + else { + this.observers.push(subscriber); + return new __WEBPACK_IMPORTED_MODULE_5__SubjectSubscription__["a" /* SubjectSubscription */](this, subscriber); + } + }; + Subject.prototype.asObservable = function () { + var observable = new __WEBPACK_IMPORTED_MODULE_1__Observable__["a" /* Observable */](); + observable.source = this; + return observable; + }; + Subject.create = function (destination, source) { + return new AnonymousSubject(destination, source); + }; + return Subject; +}(__WEBPACK_IMPORTED_MODULE_1__Observable__["a" /* Observable */])); + +var AnonymousSubject = /*@__PURE__*/ (function (_super) { + __WEBPACK_IMPORTED_MODULE_0_tslib__["a" /* __extends */](AnonymousSubject, _super); + function AnonymousSubject(destination, source) { + var _this = _super.call(this) || this; + _this.destination = destination; + _this.source = source; + return _this; + } + AnonymousSubject.prototype.next = function (value) { + var destination = this.destination; + if (destination && destination.next) { + destination.next(value); + } + }; + AnonymousSubject.prototype.error = function (err) { + var destination = this.destination; + if (destination && destination.error) { + this.destination.error(err); + } + }; + AnonymousSubject.prototype.complete = function () { + var destination = this.destination; + if (destination && destination.complete) { + this.destination.complete(); + } + }; + AnonymousSubject.prototype._subscribe = function (subscriber) { + var source = this.source; + if (source) { + return this.source.subscribe(subscriber); + } + else { + return __WEBPACK_IMPORTED_MODULE_3__Subscription__["a" /* Subscription */].EMPTY; + } + }; + return AnonymousSubject; +}(Subject)); + +//# sourceMappingURL=Subject.js.map + + +/***/ }), +/* 36 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.normalizePattern = normalizePattern; + +/** + * Explode and normalize a pattern into its name and range. + */ + +function normalizePattern(pattern) { + let hasVersion = false; + let range = 'latest'; + let name = pattern; + + // if we're a scope then remove the @ and add it back later + let isScoped = false; + if (name[0] === '@') { + isScoped = true; + name = name.slice(1); + } + + // take first part as the name + const parts = name.split('@'); + if (parts.length > 1) { + name = parts.shift(); + range = parts.join('@'); + + if (range) { + hasVersion = true; + } else { + range = '*'; + } + } + + // add back @ scope suffix + if (isScoped) { + name = `@${name}`; + } + + return { name, range, hasVersion }; +} + +/***/ }), +/* 37 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(module) {var __WEBPACK_AMD_DEFINE_RESULT__;/** + * @license + * Lodash + * Copyright JS Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + */ +;(function() { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** Used as the semantic version number. */ + var VERSION = '4.17.10'; + + /** Used as the size to enable large array optimizations. */ + var LARGE_ARRAY_SIZE = 200; + + /** Error message constants. */ + var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.', + FUNC_ERROR_TEXT = 'Expected a function'; + + /** Used to stand-in for `undefined` hash values. */ + var HASH_UNDEFINED = '__lodash_hash_undefined__'; + + /** Used as the maximum memoize cache size. */ + var MAX_MEMOIZE_SIZE = 500; + + /** Used as the internal argument placeholder. */ + var PLACEHOLDER = '__lodash_placeholder__'; + + /** Used to compose bitmasks for cloning. */ + var CLONE_DEEP_FLAG = 1, + CLONE_FLAT_FLAG = 2, + CLONE_SYMBOLS_FLAG = 4; + + /** Used to compose bitmasks for value comparisons. */ + var COMPARE_PARTIAL_FLAG = 1, + COMPARE_UNORDERED_FLAG = 2; + + /** Used to compose bitmasks for function metadata. */ + var WRAP_BIND_FLAG = 1, + WRAP_BIND_KEY_FLAG = 2, + WRAP_CURRY_BOUND_FLAG = 4, + WRAP_CURRY_FLAG = 8, + WRAP_CURRY_RIGHT_FLAG = 16, + WRAP_PARTIAL_FLAG = 32, + WRAP_PARTIAL_RIGHT_FLAG = 64, + WRAP_ARY_FLAG = 128, + WRAP_REARG_FLAG = 256, + WRAP_FLIP_FLAG = 512; + + /** Used as default options for `_.truncate`. */ + var DEFAULT_TRUNC_LENGTH = 30, + DEFAULT_TRUNC_OMISSION = '...'; + + /** Used to detect hot functions by number of calls within a span of milliseconds. */ + var HOT_COUNT = 800, + HOT_SPAN = 16; + + /** Used to indicate the type of lazy iteratees. */ + var LAZY_FILTER_FLAG = 1, + LAZY_MAP_FLAG = 2, + LAZY_WHILE_FLAG = 3; + + /** Used as references for various `Number` constants. */ + var INFINITY = 1 / 0, + MAX_SAFE_INTEGER = 9007199254740991, + MAX_INTEGER = 1.7976931348623157e+308, + NAN = 0 / 0; + + /** Used as references for the maximum length and index of an array. */ + var MAX_ARRAY_LENGTH = 4294967295, + MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, + HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; + + /** Used to associate wrap methods with their bit flags. */ + var wrapFlags = [ + ['ary', WRAP_ARY_FLAG], + ['bind', WRAP_BIND_FLAG], + ['bindKey', WRAP_BIND_KEY_FLAG], + ['curry', WRAP_CURRY_FLAG], + ['curryRight', WRAP_CURRY_RIGHT_FLAG], + ['flip', WRAP_FLIP_FLAG], + ['partial', WRAP_PARTIAL_FLAG], + ['partialRight', WRAP_PARTIAL_RIGHT_FLAG], + ['rearg', WRAP_REARG_FLAG] + ]; + + /** `Object#toString` result references. */ + var argsTag = '[object Arguments]', + arrayTag = '[object Array]', + asyncTag = '[object AsyncFunction]', + boolTag = '[object Boolean]', + dateTag = '[object Date]', + domExcTag = '[object DOMException]', + errorTag = '[object Error]', + funcTag = '[object Function]', + genTag = '[object GeneratorFunction]', + mapTag = '[object Map]', + numberTag = '[object Number]', + nullTag = '[object Null]', + objectTag = '[object Object]', + promiseTag = '[object Promise]', + proxyTag = '[object Proxy]', + regexpTag = '[object RegExp]', + setTag = '[object Set]', + stringTag = '[object String]', + symbolTag = '[object Symbol]', + undefinedTag = '[object Undefined]', + weakMapTag = '[object WeakMap]', + weakSetTag = '[object WeakSet]'; + + var arrayBufferTag = '[object ArrayBuffer]', + dataViewTag = '[object DataView]', + float32Tag = '[object Float32Array]', + float64Tag = '[object Float64Array]', + int8Tag = '[object Int8Array]', + int16Tag = '[object Int16Array]', + int32Tag = '[object Int32Array]', + uint8Tag = '[object Uint8Array]', + uint8ClampedTag = '[object Uint8ClampedArray]', + uint16Tag = '[object Uint16Array]', + uint32Tag = '[object Uint32Array]'; + + /** Used to match empty string literals in compiled template source. */ + var reEmptyStringLeading = /\b__p \+= '';/g, + reEmptyStringMiddle = /\b(__p \+=) '' \+/g, + reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; + + /** Used to match HTML entities and HTML characters. */ + var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, + reUnescapedHtml = /[&<>"']/g, + reHasEscapedHtml = RegExp(reEscapedHtml.source), + reHasUnescapedHtml = RegExp(reUnescapedHtml.source); + + /** Used to match template delimiters. */ + var reEscape = /<%-([\s\S]+?)%>/g, + reEvaluate = /<%([\s\S]+?)%>/g, + reInterpolate = /<%=([\s\S]+?)%>/g; + + /** Used to match property names within property paths. */ + var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, + reIsPlainProp = /^\w*$/, + rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; + + /** + * Used to match `RegExp` + * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). + */ + var reRegExpChar = /[\\^$.*+?()[\]{}|]/g, + reHasRegExpChar = RegExp(reRegExpChar.source); + + /** Used to match leading and trailing whitespace. */ + var reTrim = /^\s+|\s+$/g, + reTrimStart = /^\s+/, + reTrimEnd = /\s+$/; + + /** Used to match wrap detail comments. */ + var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/, + reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, + reSplitDetails = /,? & /; + + /** Used to match words composed of alphanumeric characters. */ + var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; + + /** Used to match backslashes in property paths. */ + var reEscapeChar = /\\(\\)?/g; + + /** + * Used to match + * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). + */ + var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; + + /** Used to match `RegExp` flags from their coerced string values. */ + var reFlags = /\w*$/; + + /** Used to detect bad signed hexadecimal string values. */ + var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; + + /** Used to detect binary string values. */ + var reIsBinary = /^0b[01]+$/i; + + /** Used to detect host constructors (Safari). */ + var reIsHostCtor = /^\[object .+?Constructor\]$/; + + /** Used to detect octal string values. */ + var reIsOctal = /^0o[0-7]+$/i; + + /** Used to detect unsigned integer values. */ + var reIsUint = /^(?:0|[1-9]\d*)$/; + + /** Used to match Latin Unicode letters (excluding mathematical operators). */ + var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; + + /** Used to ensure capturing order of template delimiters. */ + var reNoMatch = /($^)/; + + /** Used to match unescaped characters in compiled string literals. */ + var reUnescapedString = /['\n\r\u2028\u2029\\]/g; + + /** Used to compose unicode character classes. */ + var rsAstralRange = '\\ud800-\\udfff', + rsComboMarksRange = '\\u0300-\\u036f', + reComboHalfMarksRange = '\\ufe20-\\ufe2f', + rsComboSymbolsRange = '\\u20d0-\\u20ff', + rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, + rsDingbatRange = '\\u2700-\\u27bf', + rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', + rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', + rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', + rsPunctuationRange = '\\u2000-\\u206f', + rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', + rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', + rsVarRange = '\\ufe0e\\ufe0f', + rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; + + /** Used to compose unicode capture groups. */ + var rsApos = "['\u2019]", + rsAstral = '[' + rsAstralRange + ']', + rsBreak = '[' + rsBreakRange + ']', + rsCombo = '[' + rsComboRange + ']', + rsDigits = '\\d+', + rsDingbat = '[' + rsDingbatRange + ']', + rsLower = '[' + rsLowerRange + ']', + rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', + rsFitz = '\\ud83c[\\udffb-\\udfff]', + rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', + rsNonAstral = '[^' + rsAstralRange + ']', + rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', + rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', + rsUpper = '[' + rsUpperRange + ']', + rsZWJ = '\\u200d'; + + /** Used to compose unicode regexes. */ + var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', + rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', + rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', + rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', + reOptMod = rsModifier + '?', + rsOptVar = '[' + rsVarRange + ']?', + rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', + rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])', + rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])', + rsSeq = rsOptVar + reOptMod + rsOptJoin, + rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq, + rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; + + /** Used to match apostrophes. */ + var reApos = RegExp(rsApos, 'g'); + + /** + * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and + * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). + */ + var reComboMark = RegExp(rsCombo, 'g'); + + /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ + var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); + + /** Used to match complex or compound words. */ + var reUnicodeWord = RegExp([ + rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', + rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', + rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, + rsUpper + '+' + rsOptContrUpper, + rsOrdUpper, + rsOrdLower, + rsDigits, + rsEmoji + ].join('|'), 'g'); + + /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ + var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']'); + + /** Used to detect strings that need a more robust regexp to match words. */ + var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; + + /** Used to assign default `context` object properties. */ + var contextProps = [ + 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array', + 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', + 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', + 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', + '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' + ]; + + /** Used to make template sourceURLs easier to identify. */ + var templateCounter = -1; + + /** Used to identify `toStringTag` values of typed arrays. */ + var typedArrayTags = {}; + typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = + typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = + typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = + typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = + typedArrayTags[uint32Tag] = true; + typedArrayTags[argsTag] = typedArrayTags[arrayTag] = + typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = + typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = + typedArrayTags[errorTag] = typedArrayTags[funcTag] = + typedArrayTags[mapTag] = typedArrayTags[numberTag] = + typedArrayTags[objectTag] = typedArrayTags[regexpTag] = + typedArrayTags[setTag] = typedArrayTags[stringTag] = + typedArrayTags[weakMapTag] = false; + + /** Used to identify `toStringTag` values supported by `_.clone`. */ + var cloneableTags = {}; + cloneableTags[argsTag] = cloneableTags[arrayTag] = + cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = + cloneableTags[boolTag] = cloneableTags[dateTag] = + cloneableTags[float32Tag] = cloneableTags[float64Tag] = + cloneableTags[int8Tag] = cloneableTags[int16Tag] = + cloneableTags[int32Tag] = cloneableTags[mapTag] = + cloneableTags[numberTag] = cloneableTags[objectTag] = + cloneableTags[regexpTag] = cloneableTags[setTag] = + cloneableTags[stringTag] = cloneableTags[symbolTag] = + cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = + cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; + cloneableTags[errorTag] = cloneableTags[funcTag] = + cloneableTags[weakMapTag] = false; + + /** Used to map Latin Unicode letters to basic Latin letters. */ + var deburredLetters = { + // Latin-1 Supplement block. + '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', + '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', + '\xc7': 'C', '\xe7': 'c', + '\xd0': 'D', '\xf0': 'd', + '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', + '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', + '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', + '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', + '\xd1': 'N', '\xf1': 'n', + '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', + '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', + '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', + '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', + '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', + '\xc6': 'Ae', '\xe6': 'ae', + '\xde': 'Th', '\xfe': 'th', + '\xdf': 'ss', + // Latin Extended-A block. + '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', + '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', + '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', + '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', + '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', + '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', + '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', + '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', + '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', + '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', + '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', + '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', + '\u0134': 'J', '\u0135': 'j', + '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', + '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', + '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', + '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', + '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', + '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', + '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', + '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', + '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', + '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', + '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', + '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', + '\u0163': 't', '\u0165': 't', '\u0167': 't', + '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', + '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', + '\u0174': 'W', '\u0175': 'w', + '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', + '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', + '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', + '\u0132': 'IJ', '\u0133': 'ij', + '\u0152': 'Oe', '\u0153': 'oe', + '\u0149': "'n", '\u017f': 's' + }; + + /** Used to map characters to HTML entities. */ + var htmlEscapes = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + + /** Used to map HTML entities to characters. */ + var htmlUnescapes = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'" + }; + + /** Used to escape characters for inclusion in compiled string literals. */ + var stringEscapes = { + '\\': '\\', + "'": "'", + '\n': 'n', + '\r': 'r', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + /** Built-in method references without a dependency on `root`. */ + var freeParseFloat = parseFloat, + freeParseInt = parseInt; + + /** Detect free variable `global` from Node.js. */ + var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + + /** Detect free variable `self`. */ + var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + + /** Used as a reference to the global object. */ + var root = freeGlobal || freeSelf || Function('return this')(); + + /** Detect free variable `exports`. */ + var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; + + /** Detect free variable `module`. */ + var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; + + /** Detect the popular CommonJS extension `module.exports`. */ + var moduleExports = freeModule && freeModule.exports === freeExports; + + /** Detect free variable `process` from Node.js. */ + var freeProcess = moduleExports && freeGlobal.process; + + /** Used to access faster Node.js helpers. */ + var nodeUtil = (function() { + try { + // Use `util.types` for Node.js 10+. + var types = freeModule && freeModule.require && freeModule.require('util').types; + + if (types) { + return types; + } + + // Legacy `process.binding('util')` for Node.js < 10. + return freeProcess && freeProcess.binding && freeProcess.binding('util'); + } catch (e) {} + }()); + + /* Node.js helper references. */ + var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer, + nodeIsDate = nodeUtil && nodeUtil.isDate, + nodeIsMap = nodeUtil && nodeUtil.isMap, + nodeIsRegExp = nodeUtil && nodeUtil.isRegExp, + nodeIsSet = nodeUtil && nodeUtil.isSet, + nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; + + /*--------------------------------------------------------------------------*/ + + /** + * A faster alternative to `Function#apply`, this function invokes `func` + * with the `this` binding of `thisArg` and the arguments of `args`. + * + * @private + * @param {Function} func The function to invoke. + * @param {*} thisArg The `this` binding of `func`. + * @param {Array} args The arguments to invoke `func` with. + * @returns {*} Returns the result of `func`. + */ + function apply(func, thisArg, args) { + switch (args.length) { + case 0: return func.call(thisArg); + case 1: return func.call(thisArg, args[0]); + case 2: return func.call(thisArg, args[0], args[1]); + case 3: return func.call(thisArg, args[0], args[1], args[2]); + } + return func.apply(thisArg, args); + } + + /** + * A specialized version of `baseAggregator` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function arrayAggregator(array, setter, iteratee, accumulator) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + var value = array[index]; + setter(accumulator, value, iteratee(value), array); + } + return accumulator; + } + + /** + * A specialized version of `_.forEach` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ + function arrayEach(array, iteratee) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + if (iteratee(array[index], index, array) === false) { + break; + } + } + return array; + } + + /** + * A specialized version of `_.forEachRight` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ + function arrayEachRight(array, iteratee) { + var length = array == null ? 0 : array.length; + + while (length--) { + if (iteratee(array[length], length, array) === false) { + break; + } + } + return array; + } + + /** + * A specialized version of `_.every` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. + */ + function arrayEvery(array, predicate) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + if (!predicate(array[index], index, array)) { + return false; + } + } + return true; + } + + /** + * A specialized version of `_.filter` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + */ + function arrayFilter(array, predicate) { + var index = -1, + length = array == null ? 0 : array.length, + resIndex = 0, + result = []; + + while (++index < length) { + var value = array[index]; + if (predicate(value, index, array)) { + result[resIndex++] = value; + } + } + return result; + } + + /** + * A specialized version of `_.includes` for arrays without support for + * specifying an index to search from. + * + * @private + * @param {Array} [array] The array to inspect. + * @param {*} target The value to search for. + * @returns {boolean} Returns `true` if `target` is found, else `false`. + */ + function arrayIncludes(array, value) { + var length = array == null ? 0 : array.length; + return !!length && baseIndexOf(array, value, 0) > -1; + } + + /** + * This function is like `arrayIncludes` except that it accepts a comparator. + * + * @private + * @param {Array} [array] The array to inspect. + * @param {*} target The value to search for. + * @param {Function} comparator The comparator invoked per element. + * @returns {boolean} Returns `true` if `target` is found, else `false`. + */ + function arrayIncludesWith(array, value, comparator) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + if (comparator(value, array[index])) { + return true; + } + } + return false; + } + + /** + * A specialized version of `_.map` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ + function arrayMap(array, iteratee) { + var index = -1, + length = array == null ? 0 : array.length, + result = Array(length); + + while (++index < length) { + result[index] = iteratee(array[index], index, array); + } + return result; + } + + /** + * Appends the elements of `values` to `array`. + * + * @private + * @param {Array} array The array to modify. + * @param {Array} values The values to append. + * @returns {Array} Returns `array`. + */ + function arrayPush(array, values) { + var index = -1, + length = values.length, + offset = array.length; + + while (++index < length) { + array[offset + index] = values[index]; + } + return array; + } + + /** + * A specialized version of `_.reduce` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initAccum] Specify using the first element of `array` as + * the initial value. + * @returns {*} Returns the accumulated value. + */ + function arrayReduce(array, iteratee, accumulator, initAccum) { + var index = -1, + length = array == null ? 0 : array.length; + + if (initAccum && length) { + accumulator = array[++index]; + } + while (++index < length) { + accumulator = iteratee(accumulator, array[index], index, array); + } + return accumulator; + } + + /** + * A specialized version of `_.reduceRight` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initAccum] Specify using the last element of `array` as + * the initial value. + * @returns {*} Returns the accumulated value. + */ + function arrayReduceRight(array, iteratee, accumulator, initAccum) { + var length = array == null ? 0 : array.length; + if (initAccum && length) { + accumulator = array[--length]; + } + while (length--) { + accumulator = iteratee(accumulator, array[length], length, array); + } + return accumulator; + } + + /** + * A specialized version of `_.some` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + */ + function arraySome(array, predicate) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + if (predicate(array[index], index, array)) { + return true; + } + } + return false; + } + + /** + * Gets the size of an ASCII `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ + var asciiSize = baseProperty('length'); + + /** + * Converts an ASCII `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function asciiToArray(string) { + return string.split(''); + } + + /** + * Splits an ASCII `string` into an array of its words. + * + * @private + * @param {string} The string to inspect. + * @returns {Array} Returns the words of `string`. + */ + function asciiWords(string) { + return string.match(reAsciiWord) || []; + } + + /** + * The base implementation of methods like `_.findKey` and `_.findLastKey`, + * without support for iteratee shorthands, which iterates over `collection` + * using `eachFunc`. + * + * @private + * @param {Array|Object} collection The collection to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {Function} eachFunc The function to iterate over `collection`. + * @returns {*} Returns the found element or its key, else `undefined`. + */ + function baseFindKey(collection, predicate, eachFunc) { + var result; + eachFunc(collection, function(value, key, collection) { + if (predicate(value, key, collection)) { + result = key; + return false; + } + }); + return result; + } + + /** + * The base implementation of `_.findIndex` and `_.findLastIndex` without + * support for iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {number} fromIndex The index to search from. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function baseFindIndex(array, predicate, fromIndex, fromRight) { + var length = array.length, + index = fromIndex + (fromRight ? 1 : -1); + + while ((fromRight ? index-- : ++index < length)) { + if (predicate(array[index], index, array)) { + return index; + } + } + return -1; + } + + /** + * The base implementation of `_.indexOf` without `fromIndex` bounds checks. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function baseIndexOf(array, value, fromIndex) { + return value === value + ? strictIndexOf(array, value, fromIndex) + : baseFindIndex(array, baseIsNaN, fromIndex); + } + + /** + * This function is like `baseIndexOf` except that it accepts a comparator. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @param {Function} comparator The comparator invoked per element. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function baseIndexOfWith(array, value, fromIndex, comparator) { + var index = fromIndex - 1, + length = array.length; + + while (++index < length) { + if (comparator(array[index], value)) { + return index; + } + } + return -1; + } + + /** + * The base implementation of `_.isNaN` without support for number objects. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + */ + function baseIsNaN(value) { + return value !== value; + } + + /** + * The base implementation of `_.mean` and `_.meanBy` without support for + * iteratee shorthands. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {number} Returns the mean. + */ + function baseMean(array, iteratee) { + var length = array == null ? 0 : array.length; + return length ? (baseSum(array, iteratee) / length) : NAN; + } + + /** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new accessor function. + */ + function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; + } + + /** + * The base implementation of `_.propertyOf` without support for deep paths. + * + * @private + * @param {Object} object The object to query. + * @returns {Function} Returns the new accessor function. + */ + function basePropertyOf(object) { + return function(key) { + return object == null ? undefined : object[key]; + }; + } + + /** + * The base implementation of `_.reduce` and `_.reduceRight`, without support + * for iteratee shorthands, which iterates over `collection` using `eachFunc`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} accumulator The initial value. + * @param {boolean} initAccum Specify using the first or last element of + * `collection` as the initial value. + * @param {Function} eachFunc The function to iterate over `collection`. + * @returns {*} Returns the accumulated value. + */ + function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { + eachFunc(collection, function(value, index, collection) { + accumulator = initAccum + ? (initAccum = false, value) + : iteratee(accumulator, value, index, collection); + }); + return accumulator; + } + + /** + * The base implementation of `_.sortBy` which uses `comparer` to define the + * sort order of `array` and replaces criteria objects with their corresponding + * values. + * + * @private + * @param {Array} array The array to sort. + * @param {Function} comparer The function to define sort order. + * @returns {Array} Returns `array`. + */ + function baseSortBy(array, comparer) { + var length = array.length; + + array.sort(comparer); + while (length--) { + array[length] = array[length].value; + } + return array; + } + + /** + * The base implementation of `_.sum` and `_.sumBy` without support for + * iteratee shorthands. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {number} Returns the sum. + */ + function baseSum(array, iteratee) { + var result, + index = -1, + length = array.length; + + while (++index < length) { + var current = iteratee(array[index]); + if (current !== undefined) { + result = result === undefined ? current : (result + current); + } + } + return result; + } + + /** + * The base implementation of `_.times` without support for iteratee shorthands + * or max array length checks. + * + * @private + * @param {number} n The number of times to invoke `iteratee`. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the array of results. + */ + function baseTimes(n, iteratee) { + var index = -1, + result = Array(n); + + while (++index < n) { + result[index] = iteratee(index); + } + return result; + } + + /** + * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array + * of key-value pairs for `object` corresponding to the property names of `props`. + * + * @private + * @param {Object} object The object to query. + * @param {Array} props The property names to get values for. + * @returns {Object} Returns the key-value pairs. + */ + function baseToPairs(object, props) { + return arrayMap(props, function(key) { + return [key, object[key]]; + }); + } + + /** + * The base implementation of `_.unary` without support for storing metadata. + * + * @private + * @param {Function} func The function to cap arguments for. + * @returns {Function} Returns the new capped function. + */ + function baseUnary(func) { + return function(value) { + return func(value); + }; + } + + /** + * The base implementation of `_.values` and `_.valuesIn` which creates an + * array of `object` property values corresponding to the property names + * of `props`. + * + * @private + * @param {Object} object The object to query. + * @param {Array} props The property names to get values for. + * @returns {Object} Returns the array of property values. + */ + function baseValues(object, props) { + return arrayMap(props, function(key) { + return object[key]; + }); + } + + /** + * Checks if a `cache` value for `key` exists. + * + * @private + * @param {Object} cache The cache to query. + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function cacheHas(cache, key) { + return cache.has(key); + } + + /** + * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the first unmatched string symbol. + */ + function charsStartIndex(strSymbols, chrSymbols) { + var index = -1, + length = strSymbols.length; + + while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index; + } + + /** + * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the last unmatched string symbol. + */ + function charsEndIndex(strSymbols, chrSymbols) { + var index = strSymbols.length; + + while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index; + } + + /** + * Gets the number of `placeholder` occurrences in `array`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} placeholder The placeholder to search for. + * @returns {number} Returns the placeholder count. + */ + function countHolders(array, placeholder) { + var length = array.length, + result = 0; + + while (length--) { + if (array[length] === placeholder) { + ++result; + } + } + return result; + } + + /** + * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A + * letters to basic Latin letters. + * + * @private + * @param {string} letter The matched letter to deburr. + * @returns {string} Returns the deburred letter. + */ + var deburrLetter = basePropertyOf(deburredLetters); + + /** + * Used by `_.escape` to convert characters to HTML entities. + * + * @private + * @param {string} chr The matched character to escape. + * @returns {string} Returns the escaped character. + */ + var escapeHtmlChar = basePropertyOf(htmlEscapes); + + /** + * Used by `_.template` to escape characters for inclusion in compiled string literals. + * + * @private + * @param {string} chr The matched character to escape. + * @returns {string} Returns the escaped character. + */ + function escapeStringChar(chr) { + return '\\' + stringEscapes[chr]; + } + + /** + * Gets the value at `key` of `object`. + * + * @private + * @param {Object} [object] The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. + */ + function getValue(object, key) { + return object == null ? undefined : object[key]; + } + + /** + * Checks if `string` contains Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a symbol is found, else `false`. + */ + function hasUnicode(string) { + return reHasUnicode.test(string); + } + + /** + * Checks if `string` contains a word composed of Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a word is found, else `false`. + */ + function hasUnicodeWord(string) { + return reHasUnicodeWord.test(string); + } + + /** + * Converts `iterator` to an array. + * + * @private + * @param {Object} iterator The iterator to convert. + * @returns {Array} Returns the converted array. + */ + function iteratorToArray(iterator) { + var data, + result = []; + + while (!(data = iterator.next()).done) { + result.push(data.value); + } + return result; + } + + /** + * Converts `map` to its key-value pairs. + * + * @private + * @param {Object} map The map to convert. + * @returns {Array} Returns the key-value pairs. + */ + function mapToArray(map) { + var index = -1, + result = Array(map.size); + + map.forEach(function(value, key) { + result[++index] = [key, value]; + }); + return result; + } + + /** + * Creates a unary function that invokes `func` with its argument transformed. + * + * @private + * @param {Function} func The function to wrap. + * @param {Function} transform The argument transform. + * @returns {Function} Returns the new function. + */ + function overArg(func, transform) { + return function(arg) { + return func(transform(arg)); + }; + } + + /** + * Replaces all `placeholder` elements in `array` with an internal placeholder + * and returns an array of their indexes. + * + * @private + * @param {Array} array The array to modify. + * @param {*} placeholder The placeholder to replace. + * @returns {Array} Returns the new array of placeholder indexes. + */ + function replaceHolders(array, placeholder) { + var index = -1, + length = array.length, + resIndex = 0, + result = []; + + while (++index < length) { + var value = array[index]; + if (value === placeholder || value === PLACEHOLDER) { + array[index] = PLACEHOLDER; + result[resIndex++] = index; + } + } + return result; + } + + /** + * Gets the value at `key`, unless `key` is "__proto__". + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. + */ + function safeGet(object, key) { + return key == '__proto__' + ? undefined + : object[key]; + } + + /** + * Converts `set` to an array of its values. + * + * @private + * @param {Object} set The set to convert. + * @returns {Array} Returns the values. + */ + function setToArray(set) { + var index = -1, + result = Array(set.size); + + set.forEach(function(value) { + result[++index] = value; + }); + return result; + } + + /** + * Converts `set` to its value-value pairs. + * + * @private + * @param {Object} set The set to convert. + * @returns {Array} Returns the value-value pairs. + */ + function setToPairs(set) { + var index = -1, + result = Array(set.size); + + set.forEach(function(value) { + result[++index] = [value, value]; + }); + return result; + } + + /** + * A specialized version of `_.indexOf` which performs strict equality + * comparisons of values, i.e. `===`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function strictIndexOf(array, value, fromIndex) { + var index = fromIndex - 1, + length = array.length; + + while (++index < length) { + if (array[index] === value) { + return index; + } + } + return -1; + } + + /** + * A specialized version of `_.lastIndexOf` which performs strict equality + * comparisons of values, i.e. `===`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function strictLastIndexOf(array, value, fromIndex) { + var index = fromIndex + 1; + while (index--) { + if (array[index] === value) { + return index; + } + } + return index; + } + + /** + * Gets the number of symbols in `string`. + * + * @private + * @param {string} string The string to inspect. + * @returns {number} Returns the string size. + */ + function stringSize(string) { + return hasUnicode(string) + ? unicodeSize(string) + : asciiSize(string); + } + + /** + * Converts `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function stringToArray(string) { + return hasUnicode(string) + ? unicodeToArray(string) + : asciiToArray(string); + } + + /** + * Used by `_.unescape` to convert HTML entities to characters. + * + * @private + * @param {string} chr The matched character to unescape. + * @returns {string} Returns the unescaped character. + */ + var unescapeHtmlChar = basePropertyOf(htmlUnescapes); + + /** + * Gets the size of a Unicode `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ + function unicodeSize(string) { + var result = reUnicode.lastIndex = 0; + while (reUnicode.test(string)) { + ++result; + } + return result; + } + + /** + * Converts a Unicode `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function unicodeToArray(string) { + return string.match(reUnicode) || []; + } + + /** + * Splits a Unicode `string` into an array of its words. + * + * @private + * @param {string} The string to inspect. + * @returns {Array} Returns the words of `string`. + */ + function unicodeWords(string) { + return string.match(reUnicodeWord) || []; + } + + /*--------------------------------------------------------------------------*/ + + /** + * Create a new pristine `lodash` function using the `context` object. + * + * @static + * @memberOf _ + * @since 1.1.0 + * @category Util + * @param {Object} [context=root] The context object. + * @returns {Function} Returns a new `lodash` function. + * @example + * + * _.mixin({ 'foo': _.constant('foo') }); + * + * var lodash = _.runInContext(); + * lodash.mixin({ 'bar': lodash.constant('bar') }); + * + * _.isFunction(_.foo); + * // => true + * _.isFunction(_.bar); + * // => false + * + * lodash.isFunction(lodash.foo); + * // => false + * lodash.isFunction(lodash.bar); + * // => true + * + * // Create a suped-up `defer` in Node.js. + * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; + */ + var runInContext = (function runInContext(context) { + context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps)); + + /** Built-in constructor references. */ + var Array = context.Array, + Date = context.Date, + Error = context.Error, + Function = context.Function, + Math = context.Math, + Object = context.Object, + RegExp = context.RegExp, + String = context.String, + TypeError = context.TypeError; + + /** Used for built-in method references. */ + var arrayProto = Array.prototype, + funcProto = Function.prototype, + objectProto = Object.prototype; + + /** Used to detect overreaching core-js shims. */ + var coreJsData = context['__core-js_shared__']; + + /** Used to resolve the decompiled source of functions. */ + var funcToString = funcProto.toString; + + /** Used to check objects for own properties. */ + var hasOwnProperty = objectProto.hasOwnProperty; + + /** Used to generate unique IDs. */ + var idCounter = 0; + + /** Used to detect methods masquerading as native. */ + var maskSrcKey = (function() { + var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); + return uid ? ('Symbol(src)_1.' + uid) : ''; + }()); + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString = objectProto.toString; + + /** Used to infer the `Object` constructor. */ + var objectCtorString = funcToString.call(Object); + + /** Used to restore the original `_` reference in `_.noConflict`. */ + var oldDash = root._; + + /** Used to detect if a method is native. */ + var reIsNative = RegExp('^' + + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') + .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' + ); + + /** Built-in value references. */ + var Buffer = moduleExports ? context.Buffer : undefined, + Symbol = context.Symbol, + Uint8Array = context.Uint8Array, + allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined, + getPrototype = overArg(Object.getPrototypeOf, Object), + objectCreate = Object.create, + propertyIsEnumerable = objectProto.propertyIsEnumerable, + splice = arrayProto.splice, + spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined, + symIterator = Symbol ? Symbol.iterator : undefined, + symToStringTag = Symbol ? Symbol.toStringTag : undefined; + + var defineProperty = (function() { + try { + var func = getNative(Object, 'defineProperty'); + func({}, '', {}); + return func; + } catch (e) {} + }()); + + /** Mocked built-ins. */ + var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, + ctxNow = Date && Date.now !== root.Date.now && Date.now, + ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout; + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeCeil = Math.ceil, + nativeFloor = Math.floor, + nativeGetSymbols = Object.getOwnPropertySymbols, + nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined, + nativeIsFinite = context.isFinite, + nativeJoin = arrayProto.join, + nativeKeys = overArg(Object.keys, Object), + nativeMax = Math.max, + nativeMin = Math.min, + nativeNow = Date.now, + nativeParseInt = context.parseInt, + nativeRandom = Math.random, + nativeReverse = arrayProto.reverse; + + /* Built-in method references that are verified to be native. */ + var DataView = getNative(context, 'DataView'), + Map = getNative(context, 'Map'), + Promise = getNative(context, 'Promise'), + Set = getNative(context, 'Set'), + WeakMap = getNative(context, 'WeakMap'), + nativeCreate = getNative(Object, 'create'); + + /** Used to store function metadata. */ + var metaMap = WeakMap && new WeakMap; + + /** Used to lookup unminified function names. */ + var realNames = {}; + + /** Used to detect maps, sets, and weakmaps. */ + var dataViewCtorString = toSource(DataView), + mapCtorString = toSource(Map), + promiseCtorString = toSource(Promise), + setCtorString = toSource(Set), + weakMapCtorString = toSource(WeakMap); + + /** Used to convert symbols to primitives and strings. */ + var symbolProto = Symbol ? Symbol.prototype : undefined, + symbolValueOf = symbolProto ? symbolProto.valueOf : undefined, + symbolToString = symbolProto ? symbolProto.toString : undefined; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a `lodash` object which wraps `value` to enable implicit method + * chain sequences. Methods that operate on and return arrays, collections, + * and functions can be chained together. Methods that retrieve a single value + * or may return a primitive value will automatically end the chain sequence + * and return the unwrapped value. Otherwise, the value must be unwrapped + * with `_#value`. + * + * Explicit chain sequences, which must be unwrapped with `_#value`, may be + * enabled using `_.chain`. + * + * The execution of chained methods is lazy, that is, it's deferred until + * `_#value` is implicitly or explicitly called. + * + * Lazy evaluation allows several methods to support shortcut fusion. + * Shortcut fusion is an optimization to merge iteratee calls; this avoids + * the creation of intermediate arrays and can greatly reduce the number of + * iteratee executions. Sections of a chain sequence qualify for shortcut + * fusion if the section is applied to an array and iteratees accept only + * one argument. The heuristic for whether a section qualifies for shortcut + * fusion is subject to change. + * + * Chaining is supported in custom builds as long as the `_#value` method is + * directly or indirectly included in the build. + * + * In addition to lodash methods, wrappers have `Array` and `String` methods. + * + * The wrapper `Array` methods are: + * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift` + * + * The wrapper `String` methods are: + * `replace` and `split` + * + * The wrapper methods that support shortcut fusion are: + * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`, + * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`, + * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` + * + * The chainable wrapper methods are: + * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`, + * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`, + * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, + * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, + * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`, + * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`, + * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`, + * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, + * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`, + * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, + * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, + * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, + * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, + * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`, + * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, + * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`, + * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, + * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`, + * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, + * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`, + * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, + * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`, + * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, + * `zipObject`, `zipObjectDeep`, and `zipWith` + * + * The wrapper methods that are **not** chainable by default are: + * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, + * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`, + * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`, + * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, + * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`, + * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, + * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, + * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, + * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, + * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, + * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, + * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, + * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`, + * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`, + * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, + * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`, + * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, + * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`, + * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, + * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`, + * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`, + * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`, + * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, + * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, + * `upperFirst`, `value`, and `words` + * + * @name _ + * @constructor + * @category Seq + * @param {*} value The value to wrap in a `lodash` instance. + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * function square(n) { + * return n * n; + * } + * + * var wrapped = _([1, 2, 3]); + * + * // Returns an unwrapped value. + * wrapped.reduce(_.add); + * // => 6 + * + * // Returns a wrapped value. + * var squares = wrapped.map(square); + * + * _.isArray(squares); + * // => false + * + * _.isArray(squares.value()); + * // => true + */ + function lodash(value) { + if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { + if (value instanceof LodashWrapper) { + return value; + } + if (hasOwnProperty.call(value, '__wrapped__')) { + return wrapperClone(value); + } + } + return new LodashWrapper(value); + } + + /** + * The base implementation of `_.create` without support for assigning + * properties to the created object. + * + * @private + * @param {Object} proto The object to inherit from. + * @returns {Object} Returns the new object. + */ + var baseCreate = (function() { + function object() {} + return function(proto) { + if (!isObject(proto)) { + return {}; + } + if (objectCreate) { + return objectCreate(proto); + } + object.prototype = proto; + var result = new object; + object.prototype = undefined; + return result; + }; + }()); + + /** + * The function whose prototype chain sequence wrappers inherit from. + * + * @private + */ + function baseLodash() { + // No operation performed. + } + + /** + * The base constructor for creating `lodash` wrapper objects. + * + * @private + * @param {*} value The value to wrap. + * @param {boolean} [chainAll] Enable explicit method chain sequences. + */ + function LodashWrapper(value, chainAll) { + this.__wrapped__ = value; + this.__actions__ = []; + this.__chain__ = !!chainAll; + this.__index__ = 0; + this.__values__ = undefined; + } + + /** + * By default, the template delimiters used by lodash are like those in + * embedded Ruby (ERB) as well as ES2015 template strings. Change the + * following template settings to use alternative delimiters. + * + * @static + * @memberOf _ + * @type {Object} + */ + lodash.templateSettings = { + + /** + * Used to detect `data` property values to be HTML-escaped. + * + * @memberOf _.templateSettings + * @type {RegExp} + */ + 'escape': reEscape, + + /** + * Used to detect code to be evaluated. + * + * @memberOf _.templateSettings + * @type {RegExp} + */ + 'evaluate': reEvaluate, + + /** + * Used to detect `data` property values to inject. + * + * @memberOf _.templateSettings + * @type {RegExp} + */ + 'interpolate': reInterpolate, + + /** + * Used to reference the data object in the template text. + * + * @memberOf _.templateSettings + * @type {string} + */ + 'variable': '', + + /** + * Used to import variables into the compiled template. + * + * @memberOf _.templateSettings + * @type {Object} + */ + 'imports': { + + /** + * A reference to the `lodash` function. + * + * @memberOf _.templateSettings.imports + * @type {Function} + */ + '_': lodash + } + }; + + // Ensure wrappers are instances of `baseLodash`. + lodash.prototype = baseLodash.prototype; + lodash.prototype.constructor = lodash; + + LodashWrapper.prototype = baseCreate(baseLodash.prototype); + LodashWrapper.prototype.constructor = LodashWrapper; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. + * + * @private + * @constructor + * @param {*} value The value to wrap. + */ + function LazyWrapper(value) { + this.__wrapped__ = value; + this.__actions__ = []; + this.__dir__ = 1; + this.__filtered__ = false; + this.__iteratees__ = []; + this.__takeCount__ = MAX_ARRAY_LENGTH; + this.__views__ = []; + } + + /** + * Creates a clone of the lazy wrapper object. + * + * @private + * @name clone + * @memberOf LazyWrapper + * @returns {Object} Returns the cloned `LazyWrapper` object. + */ + function lazyClone() { + var result = new LazyWrapper(this.__wrapped__); + result.__actions__ = copyArray(this.__actions__); + result.__dir__ = this.__dir__; + result.__filtered__ = this.__filtered__; + result.__iteratees__ = copyArray(this.__iteratees__); + result.__takeCount__ = this.__takeCount__; + result.__views__ = copyArray(this.__views__); + return result; + } + + /** + * Reverses the direction of lazy iteration. + * + * @private + * @name reverse + * @memberOf LazyWrapper + * @returns {Object} Returns the new reversed `LazyWrapper` object. + */ + function lazyReverse() { + if (this.__filtered__) { + var result = new LazyWrapper(this); + result.__dir__ = -1; + result.__filtered__ = true; + } else { + result = this.clone(); + result.__dir__ *= -1; + } + return result; + } + + /** + * Extracts the unwrapped value from its lazy wrapper. + * + * @private + * @name value + * @memberOf LazyWrapper + * @returns {*} Returns the unwrapped value. + */ + function lazyValue() { + var array = this.__wrapped__.value(), + dir = this.__dir__, + isArr = isArray(array), + isRight = dir < 0, + arrLength = isArr ? array.length : 0, + view = getView(0, arrLength, this.__views__), + start = view.start, + end = view.end, + length = end - start, + index = isRight ? end : (start - 1), + iteratees = this.__iteratees__, + iterLength = iteratees.length, + resIndex = 0, + takeCount = nativeMin(length, this.__takeCount__); + + if (!isArr || (!isRight && arrLength == length && takeCount == length)) { + return baseWrapperValue(array, this.__actions__); + } + var result = []; + + outer: + while (length-- && resIndex < takeCount) { + index += dir; + + var iterIndex = -1, + value = array[index]; + + while (++iterIndex < iterLength) { + var data = iteratees[iterIndex], + iteratee = data.iteratee, + type = data.type, + computed = iteratee(value); + + if (type == LAZY_MAP_FLAG) { + value = computed; + } else if (!computed) { + if (type == LAZY_FILTER_FLAG) { + continue outer; + } else { + break outer; + } + } + } + result[resIndex++] = value; + } + return result; + } + + // Ensure `LazyWrapper` is an instance of `baseLodash`. + LazyWrapper.prototype = baseCreate(baseLodash.prototype); + LazyWrapper.prototype.constructor = LazyWrapper; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a hash object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + function Hash(entries) { + var index = -1, + length = entries == null ? 0 : entries.length; + + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } + } + + /** + * Removes all key-value entries from the hash. + * + * @private + * @name clear + * @memberOf Hash + */ + function hashClear() { + this.__data__ = nativeCreate ? nativeCreate(null) : {}; + this.size = 0; + } + + /** + * Removes `key` and its value from the hash. + * + * @private + * @name delete + * @memberOf Hash + * @param {Object} hash The hash to modify. + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + function hashDelete(key) { + var result = this.has(key) && delete this.__data__[key]; + this.size -= result ? 1 : 0; + return result; + } + + /** + * Gets the hash value for `key`. + * + * @private + * @name get + * @memberOf Hash + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + function hashGet(key) { + var data = this.__data__; + if (nativeCreate) { + var result = data[key]; + return result === HASH_UNDEFINED ? undefined : result; + } + return hasOwnProperty.call(data, key) ? data[key] : undefined; + } + + /** + * Checks if a hash value for `key` exists. + * + * @private + * @name has + * @memberOf Hash + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function hashHas(key) { + var data = this.__data__; + return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key); + } + + /** + * Sets the hash `key` to `value`. + * + * @private + * @name set + * @memberOf Hash + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the hash instance. + */ + function hashSet(key, value) { + var data = this.__data__; + this.size += this.has(key) ? 0 : 1; + data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; + return this; + } + + // Add methods to `Hash`. + Hash.prototype.clear = hashClear; + Hash.prototype['delete'] = hashDelete; + Hash.prototype.get = hashGet; + Hash.prototype.has = hashHas; + Hash.prototype.set = hashSet; + + /*------------------------------------------------------------------------*/ + + /** + * Creates an list cache object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + function ListCache(entries) { + var index = -1, + length = entries == null ? 0 : entries.length; + + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } + } + + /** + * Removes all key-value entries from the list cache. + * + * @private + * @name clear + * @memberOf ListCache + */ + function listCacheClear() { + this.__data__ = []; + this.size = 0; + } + + /** + * Removes `key` and its value from the list cache. + * + * @private + * @name delete + * @memberOf ListCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + function listCacheDelete(key) { + var data = this.__data__, + index = assocIndexOf(data, key); + + if (index < 0) { + return false; + } + var lastIndex = data.length - 1; + if (index == lastIndex) { + data.pop(); + } else { + splice.call(data, index, 1); + } + --this.size; + return true; + } + + /** + * Gets the list cache value for `key`. + * + * @private + * @name get + * @memberOf ListCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + function listCacheGet(key) { + var data = this.__data__, + index = assocIndexOf(data, key); + + return index < 0 ? undefined : data[index][1]; + } + + /** + * Checks if a list cache value for `key` exists. + * + * @private + * @name has + * @memberOf ListCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function listCacheHas(key) { + return assocIndexOf(this.__data__, key) > -1; + } + + /** + * Sets the list cache `key` to `value`. + * + * @private + * @name set + * @memberOf ListCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the list cache instance. + */ + function listCacheSet(key, value) { + var data = this.__data__, + index = assocIndexOf(data, key); + + if (index < 0) { + ++this.size; + data.push([key, value]); + } else { + data[index][1] = value; + } + return this; + } + + // Add methods to `ListCache`. + ListCache.prototype.clear = listCacheClear; + ListCache.prototype['delete'] = listCacheDelete; + ListCache.prototype.get = listCacheGet; + ListCache.prototype.has = listCacheHas; + ListCache.prototype.set = listCacheSet; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a map cache object to store key-value pairs. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + function MapCache(entries) { + var index = -1, + length = entries == null ? 0 : entries.length; + + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } + } + + /** + * Removes all key-value entries from the map. + * + * @private + * @name clear + * @memberOf MapCache + */ + function mapCacheClear() { + this.size = 0; + this.__data__ = { + 'hash': new Hash, + 'map': new (Map || ListCache), + 'string': new Hash + }; + } + + /** + * Removes `key` and its value from the map. + * + * @private + * @name delete + * @memberOf MapCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + function mapCacheDelete(key) { + var result = getMapData(this, key)['delete'](key); + this.size -= result ? 1 : 0; + return result; + } + + /** + * Gets the map value for `key`. + * + * @private + * @name get + * @memberOf MapCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + function mapCacheGet(key) { + return getMapData(this, key).get(key); + } + + /** + * Checks if a map value for `key` exists. + * + * @private + * @name has + * @memberOf MapCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function mapCacheHas(key) { + return getMapData(this, key).has(key); + } + + /** + * Sets the map `key` to `value`. + * + * @private + * @name set + * @memberOf MapCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the map cache instance. + */ + function mapCacheSet(key, value) { + var data = getMapData(this, key), + size = data.size; + + data.set(key, value); + this.size += data.size == size ? 0 : 1; + return this; + } + + // Add methods to `MapCache`. + MapCache.prototype.clear = mapCacheClear; + MapCache.prototype['delete'] = mapCacheDelete; + MapCache.prototype.get = mapCacheGet; + MapCache.prototype.has = mapCacheHas; + MapCache.prototype.set = mapCacheSet; + + /*------------------------------------------------------------------------*/ + + /** + * + * Creates an array cache object to store unique values. + * + * @private + * @constructor + * @param {Array} [values] The values to cache. + */ + function SetCache(values) { + var index = -1, + length = values == null ? 0 : values.length; + + this.__data__ = new MapCache; + while (++index < length) { + this.add(values[index]); + } + } + + /** + * Adds `value` to the array cache. + * + * @private + * @name add + * @memberOf SetCache + * @alias push + * @param {*} value The value to cache. + * @returns {Object} Returns the cache instance. + */ + function setCacheAdd(value) { + this.__data__.set(value, HASH_UNDEFINED); + return this; + } + + /** + * Checks if `value` is in the array cache. + * + * @private + * @name has + * @memberOf SetCache + * @param {*} value The value to search for. + * @returns {number} Returns `true` if `value` is found, else `false`. + */ + function setCacheHas(value) { + return this.__data__.has(value); + } + + // Add methods to `SetCache`. + SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; + SetCache.prototype.has = setCacheHas; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a stack cache object to store key-value pairs. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + function Stack(entries) { + var data = this.__data__ = new ListCache(entries); + this.size = data.size; + } + + /** + * Removes all key-value entries from the stack. + * + * @private + * @name clear + * @memberOf Stack + */ + function stackClear() { + this.__data__ = new ListCache; + this.size = 0; + } + + /** + * Removes `key` and its value from the stack. + * + * @private + * @name delete + * @memberOf Stack + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + function stackDelete(key) { + var data = this.__data__, + result = data['delete'](key); + + this.size = data.size; + return result; + } + + /** + * Gets the stack value for `key`. + * + * @private + * @name get + * @memberOf Stack + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + function stackGet(key) { + return this.__data__.get(key); + } + + /** + * Checks if a stack value for `key` exists. + * + * @private + * @name has + * @memberOf Stack + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function stackHas(key) { + return this.__data__.has(key); + } + + /** + * Sets the stack `key` to `value`. + * + * @private + * @name set + * @memberOf Stack + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the stack cache instance. + */ + function stackSet(key, value) { + var data = this.__data__; + if (data instanceof ListCache) { + var pairs = data.__data__; + if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { + pairs.push([key, value]); + this.size = ++data.size; + return this; + } + data = this.__data__ = new MapCache(pairs); + } + data.set(key, value); + this.size = data.size; + return this; + } + + // Add methods to `Stack`. + Stack.prototype.clear = stackClear; + Stack.prototype['delete'] = stackDelete; + Stack.prototype.get = stackGet; + Stack.prototype.has = stackHas; + Stack.prototype.set = stackSet; + + /*------------------------------------------------------------------------*/ + + /** + * Creates an array of the enumerable property names of the array-like `value`. + * + * @private + * @param {*} value The value to query. + * @param {boolean} inherited Specify returning inherited property names. + * @returns {Array} Returns the array of property names. + */ + function arrayLikeKeys(value, inherited) { + var isArr = isArray(value), + isArg = !isArr && isArguments(value), + isBuff = !isArr && !isArg && isBuffer(value), + isType = !isArr && !isArg && !isBuff && isTypedArray(value), + skipIndexes = isArr || isArg || isBuff || isType, + result = skipIndexes ? baseTimes(value.length, String) : [], + length = result.length; + + for (var key in value) { + if ((inherited || hasOwnProperty.call(value, key)) && + !(skipIndexes && ( + // Safari 9 has enumerable `arguments.length` in strict mode. + key == 'length' || + // Node.js 0.10 has enumerable non-index properties on buffers. + (isBuff && (key == 'offset' || key == 'parent')) || + // PhantomJS 2 has enumerable non-index properties on typed arrays. + (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) || + // Skip index properties. + isIndex(key, length) + ))) { + result.push(key); + } + } + return result; + } + + /** + * A specialized version of `_.sample` for arrays. + * + * @private + * @param {Array} array The array to sample. + * @returns {*} Returns the random element. + */ + function arraySample(array) { + var length = array.length; + return length ? array[baseRandom(0, length - 1)] : undefined; + } + + /** + * A specialized version of `_.sampleSize` for arrays. + * + * @private + * @param {Array} array The array to sample. + * @param {number} n The number of elements to sample. + * @returns {Array} Returns the random elements. + */ + function arraySampleSize(array, n) { + return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length)); + } + + /** + * A specialized version of `_.shuffle` for arrays. + * + * @private + * @param {Array} array The array to shuffle. + * @returns {Array} Returns the new shuffled array. + */ + function arrayShuffle(array) { + return shuffleSelf(copyArray(array)); + } + + /** + * This function is like `assignValue` except that it doesn't assign + * `undefined` values. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ + function assignMergeValue(object, key, value) { + if ((value !== undefined && !eq(object[key], value)) || + (value === undefined && !(key in object))) { + baseAssignValue(object, key, value); + } + } + + /** + * Assigns `value` to `key` of `object` if the existing value is not equivalent + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ + function assignValue(object, key, value) { + var objValue = object[key]; + if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || + (value === undefined && !(key in object))) { + baseAssignValue(object, key, value); + } + } + + /** + * Gets the index at which the `key` is found in `array` of key-value pairs. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} key The key to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function assocIndexOf(array, key) { + var length = array.length; + while (length--) { + if (eq(array[length][0], key)) { + return length; + } + } + return -1; + } + + /** + * Aggregates elements of `collection` on `accumulator` with keys transformed + * by `iteratee` and values set by `setter`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function baseAggregator(collection, setter, iteratee, accumulator) { + baseEach(collection, function(value, key, collection) { + setter(accumulator, value, iteratee(value), collection); + }); + return accumulator; + } + + /** + * The base implementation of `_.assign` without support for multiple sources + * or `customizer` functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @returns {Object} Returns `object`. + */ + function baseAssign(object, source) { + return object && copyObject(source, keys(source), object); + } + + /** + * The base implementation of `_.assignIn` without support for multiple sources + * or `customizer` functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @returns {Object} Returns `object`. + */ + function baseAssignIn(object, source) { + return object && copyObject(source, keysIn(source), object); + } + + /** + * The base implementation of `assignValue` and `assignMergeValue` without + * value checks. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ + function baseAssignValue(object, key, value) { + if (key == '__proto__' && defineProperty) { + defineProperty(object, key, { + 'configurable': true, + 'enumerable': true, + 'value': value, + 'writable': true + }); + } else { + object[key] = value; + } + } + + /** + * The base implementation of `_.at` without support for individual paths. + * + * @private + * @param {Object} object The object to iterate over. + * @param {string[]} paths The property paths to pick. + * @returns {Array} Returns the picked elements. + */ + function baseAt(object, paths) { + var index = -1, + length = paths.length, + result = Array(length), + skip = object == null; + + while (++index < length) { + result[index] = skip ? undefined : get(object, paths[index]); + } + return result; + } + + /** + * The base implementation of `_.clamp` which doesn't coerce arguments. + * + * @private + * @param {number} number The number to clamp. + * @param {number} [lower] The lower bound. + * @param {number} upper The upper bound. + * @returns {number} Returns the clamped number. + */ + function baseClamp(number, lower, upper) { + if (number === number) { + if (upper !== undefined) { + number = number <= upper ? number : upper; + } + if (lower !== undefined) { + number = number >= lower ? number : lower; + } + } + return number; + } + + /** + * The base implementation of `_.clone` and `_.cloneDeep` which tracks + * traversed objects. + * + * @private + * @param {*} value The value to clone. + * @param {boolean} bitmask The bitmask flags. + * 1 - Deep clone + * 2 - Flatten inherited properties + * 4 - Clone symbols + * @param {Function} [customizer] The function to customize cloning. + * @param {string} [key] The key of `value`. + * @param {Object} [object] The parent object of `value`. + * @param {Object} [stack] Tracks traversed objects and their clone counterparts. + * @returns {*} Returns the cloned value. + */ + function baseClone(value, bitmask, customizer, key, object, stack) { + var result, + isDeep = bitmask & CLONE_DEEP_FLAG, + isFlat = bitmask & CLONE_FLAT_FLAG, + isFull = bitmask & CLONE_SYMBOLS_FLAG; + + if (customizer) { + result = object ? customizer(value, key, object, stack) : customizer(value); + } + if (result !== undefined) { + return result; + } + if (!isObject(value)) { + return value; + } + var isArr = isArray(value); + if (isArr) { + result = initCloneArray(value); + if (!isDeep) { + return copyArray(value, result); + } + } else { + var tag = getTag(value), + isFunc = tag == funcTag || tag == genTag; + + if (isBuffer(value)) { + return cloneBuffer(value, isDeep); + } + if (tag == objectTag || tag == argsTag || (isFunc && !object)) { + result = (isFlat || isFunc) ? {} : initCloneObject(value); + if (!isDeep) { + return isFlat + ? copySymbolsIn(value, baseAssignIn(result, value)) + : copySymbols(value, baseAssign(result, value)); + } + } else { + if (!cloneableTags[tag]) { + return object ? value : {}; + } + result = initCloneByTag(value, tag, isDeep); + } + } + // Check for circular references and return its corresponding clone. + stack || (stack = new Stack); + var stacked = stack.get(value); + if (stacked) { + return stacked; + } + stack.set(value, result); + + if (isSet(value)) { + value.forEach(function(subValue) { + result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack)); + }); + + return result; + } + + if (isMap(value)) { + value.forEach(function(subValue, key) { + result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack)); + }); + + return result; + } + + var keysFunc = isFull + ? (isFlat ? getAllKeysIn : getAllKeys) + : (isFlat ? keysIn : keys); + + var props = isArr ? undefined : keysFunc(value); + arrayEach(props || value, function(subValue, key) { + if (props) { + key = subValue; + subValue = value[key]; + } + // Recursively populate clone (susceptible to call stack limits). + assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack)); + }); + return result; + } + + /** + * The base implementation of `_.conforms` which doesn't clone `source`. + * + * @private + * @param {Object} source The object of property predicates to conform to. + * @returns {Function} Returns the new spec function. + */ + function baseConforms(source) { + var props = keys(source); + return function(object) { + return baseConformsTo(object, source, props); + }; + } + + /** + * The base implementation of `_.conformsTo` which accepts `props` to check. + * + * @private + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + */ + function baseConformsTo(object, source, props) { + var length = props.length; + if (object == null) { + return !length; + } + object = Object(object); + while (length--) { + var key = props[length], + predicate = source[key], + value = object[key]; + + if ((value === undefined && !(key in object)) || !predicate(value)) { + return false; + } + } + return true; + } + + /** + * The base implementation of `_.delay` and `_.defer` which accepts `args` + * to provide to `func`. + * + * @private + * @param {Function} func The function to delay. + * @param {number} wait The number of milliseconds to delay invocation. + * @param {Array} args The arguments to provide to `func`. + * @returns {number|Object} Returns the timer id or timeout object. + */ + function baseDelay(func, wait, args) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + return setTimeout(function() { func.apply(undefined, args); }, wait); + } + + /** + * The base implementation of methods like `_.difference` without support + * for excluding multiple arrays or iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Array} values The values to exclude. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of filtered values. + */ + function baseDifference(array, values, iteratee, comparator) { + var index = -1, + includes = arrayIncludes, + isCommon = true, + length = array.length, + result = [], + valuesLength = values.length; + + if (!length) { + return result; + } + if (iteratee) { + values = arrayMap(values, baseUnary(iteratee)); + } + if (comparator) { + includes = arrayIncludesWith; + isCommon = false; + } + else if (values.length >= LARGE_ARRAY_SIZE) { + includes = cacheHas; + isCommon = false; + values = new SetCache(values); + } + outer: + while (++index < length) { + var value = array[index], + computed = iteratee == null ? value : iteratee(value); + + value = (comparator || value !== 0) ? value : 0; + if (isCommon && computed === computed) { + var valuesIndex = valuesLength; + while (valuesIndex--) { + if (values[valuesIndex] === computed) { + continue outer; + } + } + result.push(value); + } + else if (!includes(values, computed, comparator)) { + result.push(value); + } + } + return result; + } + + /** + * The base implementation of `_.forEach` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + */ + var baseEach = createBaseEach(baseForOwn); + + /** + * The base implementation of `_.forEachRight` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + */ + var baseEachRight = createBaseEach(baseForOwnRight, true); + + /** + * The base implementation of `_.every` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false` + */ + function baseEvery(collection, predicate) { + var result = true; + baseEach(collection, function(value, index, collection) { + result = !!predicate(value, index, collection); + return result; + }); + return result; + } + + /** + * The base implementation of methods like `_.max` and `_.min` which accepts a + * `comparator` to determine the extremum value. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The iteratee invoked per iteration. + * @param {Function} comparator The comparator used to compare values. + * @returns {*} Returns the extremum value. + */ + function baseExtremum(array, iteratee, comparator) { + var index = -1, + length = array.length; + + while (++index < length) { + var value = array[index], + current = iteratee(value); + + if (current != null && (computed === undefined + ? (current === current && !isSymbol(current)) + : comparator(current, computed) + )) { + var computed = current, + result = value; + } + } + return result; + } + + /** + * The base implementation of `_.fill` without an iteratee call guard. + * + * @private + * @param {Array} array The array to fill. + * @param {*} value The value to fill `array` with. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns `array`. + */ + function baseFill(array, value, start, end) { + var length = array.length; + + start = toInteger(start); + if (start < 0) { + start = -start > length ? 0 : (length + start); + } + end = (end === undefined || end > length) ? length : toInteger(end); + if (end < 0) { + end += length; + } + end = start > end ? 0 : toLength(end); + while (start < end) { + array[start++] = value; + } + return array; + } + + /** + * The base implementation of `_.filter` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + */ + function baseFilter(collection, predicate) { + var result = []; + baseEach(collection, function(value, index, collection) { + if (predicate(value, index, collection)) { + result.push(value); + } + }); + return result; + } + + /** + * The base implementation of `_.flatten` with support for restricting flattening. + * + * @private + * @param {Array} array The array to flatten. + * @param {number} depth The maximum recursion depth. + * @param {boolean} [predicate=isFlattenable] The function invoked per iteration. + * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. + * @param {Array} [result=[]] The initial result value. + * @returns {Array} Returns the new flattened array. + */ + function baseFlatten(array, depth, predicate, isStrict, result) { + var index = -1, + length = array.length; + + predicate || (predicate = isFlattenable); + result || (result = []); + + while (++index < length) { + var value = array[index]; + if (depth > 0 && predicate(value)) { + if (depth > 1) { + // Recursively flatten arrays (susceptible to call stack limits). + baseFlatten(value, depth - 1, predicate, isStrict, result); + } else { + arrayPush(result, value); + } + } else if (!isStrict) { + result[result.length] = value; + } + } + return result; + } + + /** + * The base implementation of `baseForOwn` which iterates over `object` + * properties returned by `keysFunc` and invokes `iteratee` for each property. + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ + var baseFor = createBaseFor(); + + /** + * This function is like `baseFor` except that it iterates over properties + * in the opposite order. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ + var baseForRight = createBaseFor(true); + + /** + * The base implementation of `_.forOwn` without support for iteratee shorthands. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, iteratee) { + return object && baseFor(object, iteratee, keys); + } + + /** + * The base implementation of `_.forOwnRight` without support for iteratee shorthands. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwnRight(object, iteratee) { + return object && baseForRight(object, iteratee, keys); + } + + /** + * The base implementation of `_.functions` which creates an array of + * `object` function property names filtered from `props`. + * + * @private + * @param {Object} object The object to inspect. + * @param {Array} props The property names to filter. + * @returns {Array} Returns the function names. + */ + function baseFunctions(object, props) { + return arrayFilter(props, function(key) { + return isFunction(object[key]); + }); + } + + /** + * The base implementation of `_.get` without support for default values. + * + * @private + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to get. + * @returns {*} Returns the resolved value. + */ + function baseGet(object, path) { + path = castPath(path, object); + + var index = 0, + length = path.length; + + while (object != null && index < length) { + object = object[toKey(path[index++])]; + } + return (index && index == length) ? object : undefined; + } + + /** + * The base implementation of `getAllKeys` and `getAllKeysIn` which uses + * `keysFunc` and `symbolsFunc` to get the enumerable property names and + * symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {Function} keysFunc The function to get the keys of `object`. + * @param {Function} symbolsFunc The function to get the symbols of `object`. + * @returns {Array} Returns the array of property names and symbols. + */ + function baseGetAllKeys(object, keysFunc, symbolsFunc) { + var result = keysFunc(object); + return isArray(object) ? result : arrayPush(result, symbolsFunc(object)); + } + + /** + * The base implementation of `getTag` without fallbacks for buggy environments. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + function baseGetTag(value) { + if (value == null) { + return value === undefined ? undefinedTag : nullTag; + } + return (symToStringTag && symToStringTag in Object(value)) + ? getRawTag(value) + : objectToString(value); + } + + /** + * The base implementation of `_.gt` which doesn't coerce arguments. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than `other`, + * else `false`. + */ + function baseGt(value, other) { + return value > other; + } + + /** + * The base implementation of `_.has` without support for deep paths. + * + * @private + * @param {Object} [object] The object to query. + * @param {Array|string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + */ + function baseHas(object, key) { + return object != null && hasOwnProperty.call(object, key); + } + + /** + * The base implementation of `_.hasIn` without support for deep paths. + * + * @private + * @param {Object} [object] The object to query. + * @param {Array|string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + */ + function baseHasIn(object, key) { + return object != null && key in Object(object); + } + + /** + * The base implementation of `_.inRange` which doesn't coerce arguments. + * + * @private + * @param {number} number The number to check. + * @param {number} start The start of the range. + * @param {number} end The end of the range. + * @returns {boolean} Returns `true` if `number` is in the range, else `false`. + */ + function baseInRange(number, start, end) { + return number >= nativeMin(start, end) && number < nativeMax(start, end); + } + + /** + * The base implementation of methods like `_.intersection`, without support + * for iteratee shorthands, that accepts an array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of shared values. + */ + function baseIntersection(arrays, iteratee, comparator) { + var includes = comparator ? arrayIncludesWith : arrayIncludes, + length = arrays[0].length, + othLength = arrays.length, + othIndex = othLength, + caches = Array(othLength), + maxLength = Infinity, + result = []; + + while (othIndex--) { + var array = arrays[othIndex]; + if (othIndex && iteratee) { + array = arrayMap(array, baseUnary(iteratee)); + } + maxLength = nativeMin(array.length, maxLength); + caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) + ? new SetCache(othIndex && array) + : undefined; + } + array = arrays[0]; + + var index = -1, + seen = caches[0]; + + outer: + while (++index < length && result.length < maxLength) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + value = (comparator || value !== 0) ? value : 0; + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { + othIndex = othLength; + while (--othIndex) { + var cache = caches[othIndex]; + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { + continue outer; + } + } + if (seen) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + + /** + * The base implementation of `_.invert` and `_.invertBy` which inverts + * `object` with values transformed by `iteratee` and set by `setter`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform values. + * @param {Object} accumulator The initial inverted object. + * @returns {Function} Returns `accumulator`. + */ + function baseInverter(object, setter, iteratee, accumulator) { + baseForOwn(object, function(value, key, object) { + setter(accumulator, iteratee(value), key, object); + }); + return accumulator; + } + + /** + * The base implementation of `_.invoke` without support for individual + * method arguments. + * + * @private + * @param {Object} object The object to query. + * @param {Array|string} path The path of the method to invoke. + * @param {Array} args The arguments to invoke the method with. + * @returns {*} Returns the result of the invoked method. + */ + function baseInvoke(object, path, args) { + path = castPath(path, object); + object = parent(object, path); + var func = object == null ? object : object[toKey(last(path))]; + return func == null ? undefined : apply(func, object, args); + } + + /** + * The base implementation of `_.isArguments`. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, + */ + function baseIsArguments(value) { + return isObjectLike(value) && baseGetTag(value) == argsTag; + } + + /** + * The base implementation of `_.isArrayBuffer` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. + */ + function baseIsArrayBuffer(value) { + return isObjectLike(value) && baseGetTag(value) == arrayBufferTag; + } + + /** + * The base implementation of `_.isDate` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a date object, else `false`. + */ + function baseIsDate(value) { + return isObjectLike(value) && baseGetTag(value) == dateTag; + } + + /** + * The base implementation of `_.isEqual` which supports partial comparisons + * and tracks traversed objects. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @param {boolean} bitmask The bitmask flags. + * 1 - Unordered comparison + * 2 - Partial comparison + * @param {Function} [customizer] The function to customize comparisons. + * @param {Object} [stack] Tracks traversed `value` and `other` objects. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + */ + function baseIsEqual(value, other, bitmask, customizer, stack) { + if (value === other) { + return true; + } + if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) { + return value !== value && other !== other; + } + return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack); + } + + /** + * A specialized version of `baseIsEqual` for arrays and objects which performs + * deep comparisons and tracks traversed objects enabling objects with circular + * references to be compared. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} [stack] Tracks traversed `object` and `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ + function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { + var objIsArr = isArray(object), + othIsArr = isArray(other), + objTag = objIsArr ? arrayTag : getTag(object), + othTag = othIsArr ? arrayTag : getTag(other); + + objTag = objTag == argsTag ? objectTag : objTag; + othTag = othTag == argsTag ? objectTag : othTag; + + var objIsObj = objTag == objectTag, + othIsObj = othTag == objectTag, + isSameTag = objTag == othTag; + + if (isSameTag && isBuffer(object)) { + if (!isBuffer(other)) { + return false; + } + objIsArr = true; + objIsObj = false; + } + if (isSameTag && !objIsObj) { + stack || (stack = new Stack); + return (objIsArr || isTypedArray(object)) + ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) + : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack); + } + if (!(bitmask & COMPARE_PARTIAL_FLAG)) { + var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), + othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); + + if (objIsWrapped || othIsWrapped) { + var objUnwrapped = objIsWrapped ? object.value() : object, + othUnwrapped = othIsWrapped ? other.value() : other; + + stack || (stack = new Stack); + return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack); + } + } + if (!isSameTag) { + return false; + } + stack || (stack = new Stack); + return equalObjects(object, other, bitmask, customizer, equalFunc, stack); + } + + /** + * The base implementation of `_.isMap` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a map, else `false`. + */ + function baseIsMap(value) { + return isObjectLike(value) && getTag(value) == mapTag; + } + + /** + * The base implementation of `_.isMatch` without support for iteratee shorthands. + * + * @private + * @param {Object} object The object to inspect. + * @param {Object} source The object of property values to match. + * @param {Array} matchData The property names, values, and compare flags to match. + * @param {Function} [customizer] The function to customize comparisons. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + */ + function baseIsMatch(object, source, matchData, customizer) { + var index = matchData.length, + length = index, + noCustomizer = !customizer; + + if (object == null) { + return !length; + } + object = Object(object); + while (index--) { + var data = matchData[index]; + if ((noCustomizer && data[2]) + ? data[1] !== object[data[0]] + : !(data[0] in object) + ) { + return false; + } + } + while (++index < length) { + data = matchData[index]; + var key = data[0], + objValue = object[key], + srcValue = data[1]; + + if (noCustomizer && data[2]) { + if (objValue === undefined && !(key in object)) { + return false; + } + } else { + var stack = new Stack; + if (customizer) { + var result = customizer(objValue, srcValue, key, object, source, stack); + } + if (!(result === undefined + ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) + : result + )) { + return false; + } + } + } + return true; + } + + /** + * The base implementation of `_.isNative` without bad shim checks. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, + * else `false`. + */ + function baseIsNative(value) { + if (!isObject(value) || isMasked(value)) { + return false; + } + var pattern = isFunction(value) ? reIsNative : reIsHostCtor; + return pattern.test(toSource(value)); + } + + /** + * The base implementation of `_.isRegExp` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. + */ + function baseIsRegExp(value) { + return isObjectLike(value) && baseGetTag(value) == regexpTag; + } + + /** + * The base implementation of `_.isSet` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a set, else `false`. + */ + function baseIsSet(value) { + return isObjectLike(value) && getTag(value) == setTag; + } + + /** + * The base implementation of `_.isTypedArray` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. + */ + function baseIsTypedArray(value) { + return isObjectLike(value) && + isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; + } + + /** + * The base implementation of `_.iteratee`. + * + * @private + * @param {*} [value=_.identity] The value to convert to an iteratee. + * @returns {Function} Returns the iteratee. + */ + function baseIteratee(value) { + // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9. + // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details. + if (typeof value == 'function') { + return value; + } + if (value == null) { + return identity; + } + if (typeof value == 'object') { + return isArray(value) + ? baseMatchesProperty(value[0], value[1]) + : baseMatches(value); + } + return property(value); + } + + /** + * The base implementation of `_.keys` which doesn't treat sparse arrays as dense. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ + function baseKeys(object) { + if (!isPrototype(object)) { + return nativeKeys(object); + } + var result = []; + for (var key in Object(object)) { + if (hasOwnProperty.call(object, key) && key != 'constructor') { + result.push(key); + } + } + return result; + } + + /** + * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ + function baseKeysIn(object) { + if (!isObject(object)) { + return nativeKeysIn(object); + } + var isProto = isPrototype(object), + result = []; + + for (var key in object) { + if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { + result.push(key); + } + } + return result; + } + + /** + * The base implementation of `_.lt` which doesn't coerce arguments. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than `other`, + * else `false`. + */ + function baseLt(value, other) { + return value < other; + } + + /** + * The base implementation of `_.map` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ + function baseMap(collection, iteratee) { + var index = -1, + result = isArrayLike(collection) ? Array(collection.length) : []; + + baseEach(collection, function(value, key, collection) { + result[++index] = iteratee(value, key, collection); + }); + return result; + } + + /** + * The base implementation of `_.matches` which doesn't clone `source`. + * + * @private + * @param {Object} source The object of property values to match. + * @returns {Function} Returns the new spec function. + */ + function baseMatches(source) { + var matchData = getMatchData(source); + if (matchData.length == 1 && matchData[0][2]) { + return matchesStrictComparable(matchData[0][0], matchData[0][1]); + } + return function(object) { + return object === source || baseIsMatch(object, source, matchData); + }; + } + + /** + * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`. + * + * @private + * @param {string} path The path of the property to get. + * @param {*} srcValue The value to match. + * @returns {Function} Returns the new spec function. + */ + function baseMatchesProperty(path, srcValue) { + if (isKey(path) && isStrictComparable(srcValue)) { + return matchesStrictComparable(toKey(path), srcValue); + } + return function(object) { + var objValue = get(object, path); + return (objValue === undefined && objValue === srcValue) + ? hasIn(object, path) + : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG); + }; + } + + /** + * The base implementation of `_.merge` without support for multiple sources. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {number} srcIndex The index of `source`. + * @param {Function} [customizer] The function to customize merged values. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + */ + function baseMerge(object, source, srcIndex, customizer, stack) { + if (object === source) { + return; + } + baseFor(source, function(srcValue, key) { + if (isObject(srcValue)) { + stack || (stack = new Stack); + baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); + } + else { + var newValue = customizer + ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack) + : undefined; + + if (newValue === undefined) { + newValue = srcValue; + } + assignMergeValue(object, key, newValue); + } + }, keysIn); + } + + /** + * A specialized version of `baseMerge` for arrays and objects which performs + * deep merges and tracks traversed objects enabling objects with circular + * references to be merged. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {string} key The key of the value to merge. + * @param {number} srcIndex The index of `source`. + * @param {Function} mergeFunc The function to merge values. + * @param {Function} [customizer] The function to customize assigned values. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + */ + function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { + var objValue = safeGet(object, key), + srcValue = safeGet(source, key), + stacked = stack.get(srcValue); + + if (stacked) { + assignMergeValue(object, key, stacked); + return; + } + var newValue = customizer + ? customizer(objValue, srcValue, (key + ''), object, source, stack) + : undefined; + + var isCommon = newValue === undefined; + + if (isCommon) { + var isArr = isArray(srcValue), + isBuff = !isArr && isBuffer(srcValue), + isTyped = !isArr && !isBuff && isTypedArray(srcValue); + + newValue = srcValue; + if (isArr || isBuff || isTyped) { + if (isArray(objValue)) { + newValue = objValue; + } + else if (isArrayLikeObject(objValue)) { + newValue = copyArray(objValue); + } + else if (isBuff) { + isCommon = false; + newValue = cloneBuffer(srcValue, true); + } + else if (isTyped) { + isCommon = false; + newValue = cloneTypedArray(srcValue, true); + } + else { + newValue = []; + } + } + else if (isPlainObject(srcValue) || isArguments(srcValue)) { + newValue = objValue; + if (isArguments(objValue)) { + newValue = toPlainObject(objValue); + } + else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { + newValue = initCloneObject(srcValue); + } + } + else { + isCommon = false; + } + } + if (isCommon) { + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, newValue); + mergeFunc(newValue, srcValue, srcIndex, customizer, stack); + stack['delete'](srcValue); + } + assignMergeValue(object, key, newValue); + } + + /** + * The base implementation of `_.nth` which doesn't coerce arguments. + * + * @private + * @param {Array} array The array to query. + * @param {number} n The index of the element to return. + * @returns {*} Returns the nth element of `array`. + */ + function baseNth(array, n) { + var length = array.length; + if (!length) { + return; + } + n += n < 0 ? length : 0; + return isIndex(n, length) ? array[n] : undefined; + } + + /** + * The base implementation of `_.orderBy` without param guards. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by. + * @param {string[]} orders The sort orders of `iteratees`. + * @returns {Array} Returns the new sorted array. + */ + function baseOrderBy(collection, iteratees, orders) { + var index = -1; + iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee())); + + var result = baseMap(collection, function(value, key, collection) { + var criteria = arrayMap(iteratees, function(iteratee) { + return iteratee(value); + }); + return { 'criteria': criteria, 'index': ++index, 'value': value }; + }); + + return baseSortBy(result, function(object, other) { + return compareMultiple(object, other, orders); + }); + } + + /** + * The base implementation of `_.pick` without support for individual + * property identifiers. + * + * @private + * @param {Object} object The source object. + * @param {string[]} paths The property paths to pick. + * @returns {Object} Returns the new object. + */ + function basePick(object, paths) { + return basePickBy(object, paths, function(value, path) { + return hasIn(object, path); + }); + } + + /** + * The base implementation of `_.pickBy` without support for iteratee shorthands. + * + * @private + * @param {Object} object The source object. + * @param {string[]} paths The property paths to pick. + * @param {Function} predicate The function invoked per property. + * @returns {Object} Returns the new object. + */ + function basePickBy(object, paths, predicate) { + var index = -1, + length = paths.length, + result = {}; + + while (++index < length) { + var path = paths[index], + value = baseGet(object, path); + + if (predicate(value, path)) { + baseSet(result, castPath(path, object), value); + } + } + return result; + } + + /** + * A specialized version of `baseProperty` which supports deep paths. + * + * @private + * @param {Array|string} path The path of the property to get. + * @returns {Function} Returns the new accessor function. + */ + function basePropertyDeep(path) { + return function(object) { + return baseGet(object, path); + }; + } + + /** + * The base implementation of `_.pullAllBy` without support for iteratee + * shorthands. + * + * @private + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns `array`. + */ + function basePullAll(array, values, iteratee, comparator) { + var indexOf = comparator ? baseIndexOfWith : baseIndexOf, + index = -1, + length = values.length, + seen = array; + + if (array === values) { + values = copyArray(values); + } + if (iteratee) { + seen = arrayMap(array, baseUnary(iteratee)); + } + while (++index < length) { + var fromIndex = 0, + value = values[index], + computed = iteratee ? iteratee(value) : value; + + while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) { + if (seen !== array) { + splice.call(seen, fromIndex, 1); + } + splice.call(array, fromIndex, 1); + } + } + return array; + } + + /** + * The base implementation of `_.pullAt` without support for individual + * indexes or capturing the removed elements. + * + * @private + * @param {Array} array The array to modify. + * @param {number[]} indexes The indexes of elements to remove. + * @returns {Array} Returns `array`. + */ + function basePullAt(array, indexes) { + var length = array ? indexes.length : 0, + lastIndex = length - 1; + + while (length--) { + var index = indexes[length]; + if (length == lastIndex || index !== previous) { + var previous = index; + if (isIndex(index)) { + splice.call(array, index, 1); + } else { + baseUnset(array, index); + } + } + } + return array; + } + + /** + * The base implementation of `_.random` without support for returning + * floating-point numbers. + * + * @private + * @param {number} lower The lower bound. + * @param {number} upper The upper bound. + * @returns {number} Returns the random number. + */ + function baseRandom(lower, upper) { + return lower + nativeFloor(nativeRandom() * (upper - lower + 1)); + } + + /** + * The base implementation of `_.range` and `_.rangeRight` which doesn't + * coerce arguments. + * + * @private + * @param {number} start The start of the range. + * @param {number} end The end of the range. + * @param {number} step The value to increment or decrement by. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Array} Returns the range of numbers. + */ + function baseRange(start, end, step, fromRight) { + var index = -1, + length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), + result = Array(length); + + while (length--) { + result[fromRight ? length : ++index] = start; + start += step; + } + return result; + } + + /** + * The base implementation of `_.repeat` which doesn't coerce arguments. + * + * @private + * @param {string} string The string to repeat. + * @param {number} n The number of times to repeat the string. + * @returns {string} Returns the repeated string. + */ + function baseRepeat(string, n) { + var result = ''; + if (!string || n < 1 || n > MAX_SAFE_INTEGER) { + return result; + } + // Leverage the exponentiation by squaring algorithm for a faster repeat. + // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. + do { + if (n % 2) { + result += string; + } + n = nativeFloor(n / 2); + if (n) { + string += string; + } + } while (n); + + return result; + } + + /** + * The base implementation of `_.rest` which doesn't validate or coerce arguments. + * + * @private + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @returns {Function} Returns the new function. + */ + function baseRest(func, start) { + return setToString(overRest(func, start, identity), func + ''); + } + + /** + * The base implementation of `_.sample`. + * + * @private + * @param {Array|Object} collection The collection to sample. + * @returns {*} Returns the random element. + */ + function baseSample(collection) { + return arraySample(values(collection)); + } + + /** + * The base implementation of `_.sampleSize` without param guards. + * + * @private + * @param {Array|Object} collection The collection to sample. + * @param {number} n The number of elements to sample. + * @returns {Array} Returns the random elements. + */ + function baseSampleSize(collection, n) { + var array = values(collection); + return shuffleSelf(array, baseClamp(n, 0, array.length)); + } + + /** + * The base implementation of `_.set`. + * + * @private + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @param {Function} [customizer] The function to customize path creation. + * @returns {Object} Returns `object`. + */ + function baseSet(object, path, value, customizer) { + if (!isObject(object)) { + return object; + } + path = castPath(path, object); + + var index = -1, + length = path.length, + lastIndex = length - 1, + nested = object; + + while (nested != null && ++index < length) { + var key = toKey(path[index]), + newValue = value; + + if (index != lastIndex) { + var objValue = nested[key]; + newValue = customizer ? customizer(objValue, key, nested) : undefined; + if (newValue === undefined) { + newValue = isObject(objValue) + ? objValue + : (isIndex(path[index + 1]) ? [] : {}); + } + } + assignValue(nested, key, newValue); + nested = nested[key]; + } + return object; + } + + /** + * The base implementation of `setData` without support for hot loop shorting. + * + * @private + * @param {Function} func The function to associate metadata with. + * @param {*} data The metadata. + * @returns {Function} Returns `func`. + */ + var baseSetData = !metaMap ? identity : function(func, data) { + metaMap.set(func, data); + return func; + }; + + /** + * The base implementation of `setToString` without support for hot loop shorting. + * + * @private + * @param {Function} func The function to modify. + * @param {Function} string The `toString` result. + * @returns {Function} Returns `func`. + */ + var baseSetToString = !defineProperty ? identity : function(func, string) { + return defineProperty(func, 'toString', { + 'configurable': true, + 'enumerable': false, + 'value': constant(string), + 'writable': true + }); + }; + + /** + * The base implementation of `_.shuffle`. + * + * @private + * @param {Array|Object} collection The collection to shuffle. + * @returns {Array} Returns the new shuffled array. + */ + function baseShuffle(collection) { + return shuffleSelf(values(collection)); + } + + /** + * The base implementation of `_.slice` without an iteratee call guard. + * + * @private + * @param {Array} array The array to slice. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the slice of `array`. + */ + function baseSlice(array, start, end) { + var index = -1, + length = array.length; + + if (start < 0) { + start = -start > length ? 0 : (length + start); + } + end = end > length ? length : end; + if (end < 0) { + end += length; + } + length = start > end ? 0 : ((end - start) >>> 0); + start >>>= 0; + + var result = Array(length); + while (++index < length) { + result[index] = array[index + start]; + } + return result; + } + + /** + * The base implementation of `_.some` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + */ + function baseSome(collection, predicate) { + var result; + + baseEach(collection, function(value, index, collection) { + result = predicate(value, index, collection); + return !result; + }); + return !!result; + } + + /** + * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which + * performs a binary search of `array` to determine the index at which `value` + * should be inserted into `array` in order to maintain its sort order. + * + * @private + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {boolean} [retHighest] Specify returning the highest qualified index. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + */ + function baseSortedIndex(array, value, retHighest) { + var low = 0, + high = array == null ? low : array.length; + + if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { + while (low < high) { + var mid = (low + high) >>> 1, + computed = array[mid]; + + if (computed !== null && !isSymbol(computed) && + (retHighest ? (computed <= value) : (computed < value))) { + low = mid + 1; + } else { + high = mid; + } + } + return high; + } + return baseSortedIndexBy(array, value, identity, retHighest); + } + + /** + * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy` + * which invokes `iteratee` for `value` and each element of `array` to compute + * their sort ranking. The iteratee is invoked with one argument; (value). + * + * @private + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} iteratee The iteratee invoked per element. + * @param {boolean} [retHighest] Specify returning the highest qualified index. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + */ + function baseSortedIndexBy(array, value, iteratee, retHighest) { + value = iteratee(value); + + var low = 0, + high = array == null ? 0 : array.length, + valIsNaN = value !== value, + valIsNull = value === null, + valIsSymbol = isSymbol(value), + valIsUndefined = value === undefined; + + while (low < high) { + var mid = nativeFloor((low + high) / 2), + computed = iteratee(array[mid]), + othIsDefined = computed !== undefined, + othIsNull = computed === null, + othIsReflexive = computed === computed, + othIsSymbol = isSymbol(computed); + + if (valIsNaN) { + var setLow = retHighest || othIsReflexive; + } else if (valIsUndefined) { + setLow = othIsReflexive && (retHighest || othIsDefined); + } else if (valIsNull) { + setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull); + } else if (valIsSymbol) { + setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol); + } else if (othIsNull || othIsSymbol) { + setLow = false; + } else { + setLow = retHighest ? (computed <= value) : (computed < value); + } + if (setLow) { + low = mid + 1; + } else { + high = mid; + } + } + return nativeMin(high, MAX_ARRAY_INDEX); + } + + /** + * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without + * support for iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @returns {Array} Returns the new duplicate free array. + */ + function baseSortedUniq(array, iteratee) { + var index = -1, + length = array.length, + resIndex = 0, + result = []; + + while (++index < length) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + if (!index || !eq(computed, seen)) { + var seen = computed; + result[resIndex++] = value === 0 ? 0 : value; + } + } + return result; + } + + /** + * The base implementation of `_.toNumber` which doesn't ensure correct + * conversions of binary, hexadecimal, or octal string values. + * + * @private + * @param {*} value The value to process. + * @returns {number} Returns the number. + */ + function baseToNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } + return +value; + } + + /** + * The base implementation of `_.toString` which doesn't convert nullish + * values to empty strings. + * + * @private + * @param {*} value The value to process. + * @returns {string} Returns the string. + */ + function baseToString(value) { + // Exit early for strings to avoid a performance hit in some environments. + if (typeof value == 'string') { + return value; + } + if (isArray(value)) { + // Recursively convert values (susceptible to call stack limits). + return arrayMap(value, baseToString) + ''; + } + if (isSymbol(value)) { + return symbolToString ? symbolToString.call(value) : ''; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; + } + + /** + * The base implementation of `_.uniqBy` without support for iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new duplicate free array. + */ + function baseUniq(array, iteratee, comparator) { + var index = -1, + includes = arrayIncludes, + length = array.length, + isCommon = true, + result = [], + seen = result; + + if (comparator) { + isCommon = false; + includes = arrayIncludesWith; + } + else if (length >= LARGE_ARRAY_SIZE) { + var set = iteratee ? null : createSet(array); + if (set) { + return setToArray(set); + } + isCommon = false; + includes = cacheHas; + seen = new SetCache; + } + else { + seen = iteratee ? [] : result; + } + outer: + while (++index < length) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + value = (comparator || value !== 0) ? value : 0; + if (isCommon && computed === computed) { + var seenIndex = seen.length; + while (seenIndex--) { + if (seen[seenIndex] === computed) { + continue outer; + } + } + if (iteratee) { + seen.push(computed); + } + result.push(value); + } + else if (!includes(seen, computed, comparator)) { + if (seen !== result) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + + /** + * The base implementation of `_.unset`. + * + * @private + * @param {Object} object The object to modify. + * @param {Array|string} path The property path to unset. + * @returns {boolean} Returns `true` if the property is deleted, else `false`. + */ + function baseUnset(object, path) { + path = castPath(path, object); + object = parent(object, path); + return object == null || delete object[toKey(last(path))]; + } + + /** + * The base implementation of `_.update`. + * + * @private + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to update. + * @param {Function} updater The function to produce the updated value. + * @param {Function} [customizer] The function to customize path creation. + * @returns {Object} Returns `object`. + */ + function baseUpdate(object, path, updater, customizer) { + return baseSet(object, path, updater(baseGet(object, path)), customizer); + } + + /** + * The base implementation of methods like `_.dropWhile` and `_.takeWhile` + * without support for iteratee shorthands. + * + * @private + * @param {Array} array The array to query. + * @param {Function} predicate The function invoked per iteration. + * @param {boolean} [isDrop] Specify dropping elements instead of taking them. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Array} Returns the slice of `array`. + */ + function baseWhile(array, predicate, isDrop, fromRight) { + var length = array.length, + index = fromRight ? length : -1; + + while ((fromRight ? index-- : ++index < length) && + predicate(array[index], index, array)) {} + + return isDrop + ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) + : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index)); + } + + /** + * The base implementation of `wrapperValue` which returns the result of + * performing a sequence of actions on the unwrapped `value`, where each + * successive action is supplied the return value of the previous. + * + * @private + * @param {*} value The unwrapped value. + * @param {Array} actions Actions to perform to resolve the unwrapped value. + * @returns {*} Returns the resolved value. + */ + function baseWrapperValue(value, actions) { + var result = value; + if (result instanceof LazyWrapper) { + result = result.value(); + } + return arrayReduce(actions, function(result, action) { + return action.func.apply(action.thisArg, arrayPush([result], action.args)); + }, result); + } + + /** + * The base implementation of methods like `_.xor`, without support for + * iteratee shorthands, that accepts an array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of values. + */ + function baseXor(arrays, iteratee, comparator) { + var length = arrays.length; + if (length < 2) { + return length ? baseUniq(arrays[0]) : []; + } + var index = -1, + result = Array(length); + + while (++index < length) { + var array = arrays[index], + othIndex = -1; + + while (++othIndex < length) { + if (othIndex != index) { + result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator); + } + } + } + return baseUniq(baseFlatten(result, 1), iteratee, comparator); + } + + /** + * This base implementation of `_.zipObject` which assigns values using `assignFunc`. + * + * @private + * @param {Array} props The property identifiers. + * @param {Array} values The property values. + * @param {Function} assignFunc The function to assign values. + * @returns {Object} Returns the new object. + */ + function baseZipObject(props, values, assignFunc) { + var index = -1, + length = props.length, + valsLength = values.length, + result = {}; + + while (++index < length) { + var value = index < valsLength ? values[index] : undefined; + assignFunc(result, props[index], value); + } + return result; + } + + /** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array|Object} Returns the cast array-like object. + */ + function castArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : []; + } + + /** + * Casts `value` to `identity` if it's not a function. + * + * @private + * @param {*} value The value to inspect. + * @returns {Function} Returns cast function. + */ + function castFunction(value) { + return typeof value == 'function' ? value : identity; + } + + /** + * Casts `value` to a path array if it's not one. + * + * @private + * @param {*} value The value to inspect. + * @param {Object} [object] The object to query keys on. + * @returns {Array} Returns the cast property path array. + */ + function castPath(value, object) { + if (isArray(value)) { + return value; + } + return isKey(value, object) ? [value] : stringToPath(toString(value)); + } + + /** + * A `baseRest` alias which can be replaced with `identity` by module + * replacement plugins. + * + * @private + * @type {Function} + * @param {Function} func The function to apply a rest parameter to. + * @returns {Function} Returns the new function. + */ + var castRest = baseRest; + + /** + * Casts `array` to a slice if it's needed. + * + * @private + * @param {Array} array The array to inspect. + * @param {number} start The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the cast slice. + */ + function castSlice(array, start, end) { + var length = array.length; + end = end === undefined ? length : end; + return (!start && end >= length) ? array : baseSlice(array, start, end); + } + + /** + * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout). + * + * @private + * @param {number|Object} id The timer id or timeout object of the timer to clear. + */ + var clearTimeout = ctxClearTimeout || function(id) { + return root.clearTimeout(id); + }; + + /** + * Creates a clone of `buffer`. + * + * @private + * @param {Buffer} buffer The buffer to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Buffer} Returns the cloned buffer. + */ + function cloneBuffer(buffer, isDeep) { + if (isDeep) { + return buffer.slice(); + } + var length = buffer.length, + result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length); + + buffer.copy(result); + return result; + } + + /** + * Creates a clone of `arrayBuffer`. + * + * @private + * @param {ArrayBuffer} arrayBuffer The array buffer to clone. + * @returns {ArrayBuffer} Returns the cloned array buffer. + */ + function cloneArrayBuffer(arrayBuffer) { + var result = new arrayBuffer.constructor(arrayBuffer.byteLength); + new Uint8Array(result).set(new Uint8Array(arrayBuffer)); + return result; + } + + /** + * Creates a clone of `dataView`. + * + * @private + * @param {Object} dataView The data view to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the cloned data view. + */ + function cloneDataView(dataView, isDeep) { + var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer; + return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength); + } + + /** + * Creates a clone of `regexp`. + * + * @private + * @param {Object} regexp The regexp to clone. + * @returns {Object} Returns the cloned regexp. + */ + function cloneRegExp(regexp) { + var result = new regexp.constructor(regexp.source, reFlags.exec(regexp)); + result.lastIndex = regexp.lastIndex; + return result; + } + + /** + * Creates a clone of the `symbol` object. + * + * @private + * @param {Object} symbol The symbol object to clone. + * @returns {Object} Returns the cloned symbol object. + */ + function cloneSymbol(symbol) { + return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {}; + } + + /** + * Creates a clone of `typedArray`. + * + * @private + * @param {Object} typedArray The typed array to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the cloned typed array. + */ + function cloneTypedArray(typedArray, isDeep) { + var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer; + return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length); + } + + /** + * Compares values to sort them in ascending order. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {number} Returns the sort order indicator for `value`. + */ + function compareAscending(value, other) { + if (value !== other) { + var valIsDefined = value !== undefined, + valIsNull = value === null, + valIsReflexive = value === value, + valIsSymbol = isSymbol(value); + + var othIsDefined = other !== undefined, + othIsNull = other === null, + othIsReflexive = other === other, + othIsSymbol = isSymbol(other); + + if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || + (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || + (valIsNull && othIsDefined && othIsReflexive) || + (!valIsDefined && othIsReflexive) || + !valIsReflexive) { + return 1; + } + if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) || + (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || + (othIsNull && valIsDefined && valIsReflexive) || + (!othIsDefined && valIsReflexive) || + !othIsReflexive) { + return -1; + } + } + return 0; + } + + /** + * Used by `_.orderBy` to compare multiple properties of a value to another + * and stable sort them. + * + * If `orders` is unspecified, all values are sorted in ascending order. Otherwise, + * specify an order of "desc" for descending or "asc" for ascending sort order + * of corresponding values. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {boolean[]|string[]} orders The order to sort by for each property. + * @returns {number} Returns the sort order indicator for `object`. + */ + function compareMultiple(object, other, orders) { + var index = -1, + objCriteria = object.criteria, + othCriteria = other.criteria, + length = objCriteria.length, + ordersLength = orders.length; + + while (++index < length) { + var result = compareAscending(objCriteria[index], othCriteria[index]); + if (result) { + if (index >= ordersLength) { + return result; + } + var order = orders[index]; + return result * (order == 'desc' ? -1 : 1); + } + } + // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications + // that causes it, under certain circumstances, to provide the same value for + // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247 + // for more details. + // + // This also ensures a stable sort in V8 and other engines. + // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details. + return object.index - other.index; + } + + /** + * Creates an array that is the composition of partially applied arguments, + * placeholders, and provided arguments into a single array of arguments. + * + * @private + * @param {Array} args The provided arguments. + * @param {Array} partials The arguments to prepend to those provided. + * @param {Array} holders The `partials` placeholder indexes. + * @params {boolean} [isCurried] Specify composing for a curried function. + * @returns {Array} Returns the new array of composed arguments. + */ + function composeArgs(args, partials, holders, isCurried) { + var argsIndex = -1, + argsLength = args.length, + holdersLength = holders.length, + leftIndex = -1, + leftLength = partials.length, + rangeLength = nativeMax(argsLength - holdersLength, 0), + result = Array(leftLength + rangeLength), + isUncurried = !isCurried; + + while (++leftIndex < leftLength) { + result[leftIndex] = partials[leftIndex]; + } + while (++argsIndex < holdersLength) { + if (isUncurried || argsIndex < argsLength) { + result[holders[argsIndex]] = args[argsIndex]; + } + } + while (rangeLength--) { + result[leftIndex++] = args[argsIndex++]; + } + return result; + } + + /** + * This function is like `composeArgs` except that the arguments composition + * is tailored for `_.partialRight`. + * + * @private + * @param {Array} args The provided arguments. + * @param {Array} partials The arguments to append to those provided. + * @param {Array} holders The `partials` placeholder indexes. + * @params {boolean} [isCurried] Specify composing for a curried function. + * @returns {Array} Returns the new array of composed arguments. + */ + function composeArgsRight(args, partials, holders, isCurried) { + var argsIndex = -1, + argsLength = args.length, + holdersIndex = -1, + holdersLength = holders.length, + rightIndex = -1, + rightLength = partials.length, + rangeLength = nativeMax(argsLength - holdersLength, 0), + result = Array(rangeLength + rightLength), + isUncurried = !isCurried; + + while (++argsIndex < rangeLength) { + result[argsIndex] = args[argsIndex]; + } + var offset = argsIndex; + while (++rightIndex < rightLength) { + result[offset + rightIndex] = partials[rightIndex]; + } + while (++holdersIndex < holdersLength) { + if (isUncurried || argsIndex < argsLength) { + result[offset + holders[holdersIndex]] = args[argsIndex++]; + } + } + return result; + } + + /** + * Copies the values of `source` to `array`. + * + * @private + * @param {Array} source The array to copy values from. + * @param {Array} [array=[]] The array to copy values to. + * @returns {Array} Returns `array`. + */ + function copyArray(source, array) { + var index = -1, + length = source.length; + + array || (array = Array(length)); + while (++index < length) { + array[index] = source[index]; + } + return array; + } + + /** + * Copies properties of `source` to `object`. + * + * @private + * @param {Object} source The object to copy properties from. + * @param {Array} props The property identifiers to copy. + * @param {Object} [object={}] The object to copy properties to. + * @param {Function} [customizer] The function to customize copied values. + * @returns {Object} Returns `object`. + */ + function copyObject(source, props, object, customizer) { + var isNew = !object; + object || (object = {}); + + var index = -1, + length = props.length; + + while (++index < length) { + var key = props[index]; + + var newValue = customizer + ? customizer(object[key], source[key], key, object, source) + : undefined; + + if (newValue === undefined) { + newValue = source[key]; + } + if (isNew) { + baseAssignValue(object, key, newValue); + } else { + assignValue(object, key, newValue); + } + } + return object; + } + + /** + * Copies own symbols of `source` to `object`. + * + * @private + * @param {Object} source The object to copy symbols from. + * @param {Object} [object={}] The object to copy symbols to. + * @returns {Object} Returns `object`. + */ + function copySymbols(source, object) { + return copyObject(source, getSymbols(source), object); + } + + /** + * Copies own and inherited symbols of `source` to `object`. + * + * @private + * @param {Object} source The object to copy symbols from. + * @param {Object} [object={}] The object to copy symbols to. + * @returns {Object} Returns `object`. + */ + function copySymbolsIn(source, object) { + return copyObject(source, getSymbolsIn(source), object); + } + + /** + * Creates a function like `_.groupBy`. + * + * @private + * @param {Function} setter The function to set accumulator values. + * @param {Function} [initializer] The accumulator object initializer. + * @returns {Function} Returns the new aggregator function. + */ + function createAggregator(setter, initializer) { + return function(collection, iteratee) { + var func = isArray(collection) ? arrayAggregator : baseAggregator, + accumulator = initializer ? initializer() : {}; + + return func(collection, setter, getIteratee(iteratee, 2), accumulator); + }; + } + + /** + * Creates a function like `_.assign`. + * + * @private + * @param {Function} assigner The function to assign values. + * @returns {Function} Returns the new assigner function. + */ + function createAssigner(assigner) { + return baseRest(function(object, sources) { + var index = -1, + length = sources.length, + customizer = length > 1 ? sources[length - 1] : undefined, + guard = length > 2 ? sources[2] : undefined; + + customizer = (assigner.length > 3 && typeof customizer == 'function') + ? (length--, customizer) + : undefined; + + if (guard && isIterateeCall(sources[0], sources[1], guard)) { + customizer = length < 3 ? undefined : customizer; + length = 1; + } + object = Object(object); + while (++index < length) { + var source = sources[index]; + if (source) { + assigner(object, source, index, customizer); + } + } + return object; + }); + } + + /** + * Creates a `baseEach` or `baseEachRight` function. + * + * @private + * @param {Function} eachFunc The function to iterate over a collection. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ + function createBaseEach(eachFunc, fromRight) { + return function(collection, iteratee) { + if (collection == null) { + return collection; + } + if (!isArrayLike(collection)) { + return eachFunc(collection, iteratee); + } + var length = collection.length, + index = fromRight ? length : -1, + iterable = Object(collection); + + while ((fromRight ? index-- : ++index < length)) { + if (iteratee(iterable[index], index, iterable) === false) { + break; + } + } + return collection; + }; + } + + /** + * Creates a base function for methods like `_.forIn` and `_.forOwn`. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ + function createBaseFor(fromRight) { + return function(object, iteratee, keysFunc) { + var index = -1, + iterable = Object(object), + props = keysFunc(object), + length = props.length; + + while (length--) { + var key = props[fromRight ? length : ++index]; + if (iteratee(iterable[key], key, iterable) === false) { + break; + } + } + return object; + }; + } + + /** + * Creates a function that wraps `func` to invoke it with the optional `this` + * binding of `thisArg`. + * + * @private + * @param {Function} func The function to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {*} [thisArg] The `this` binding of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createBind(func, bitmask, thisArg) { + var isBind = bitmask & WRAP_BIND_FLAG, + Ctor = createCtor(func); + + function wrapper() { + var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + return fn.apply(isBind ? thisArg : this, arguments); + } + return wrapper; + } + + /** + * Creates a function like `_.lowerFirst`. + * + * @private + * @param {string} methodName The name of the `String` case method to use. + * @returns {Function} Returns the new case function. + */ + function createCaseFirst(methodName) { + return function(string) { + string = toString(string); + + var strSymbols = hasUnicode(string) + ? stringToArray(string) + : undefined; + + var chr = strSymbols + ? strSymbols[0] + : string.charAt(0); + + var trailing = strSymbols + ? castSlice(strSymbols, 1).join('') + : string.slice(1); + + return chr[methodName]() + trailing; + }; + } + + /** + * Creates a function like `_.camelCase`. + * + * @private + * @param {Function} callback The function to combine each word. + * @returns {Function} Returns the new compounder function. + */ + function createCompounder(callback) { + return function(string) { + return arrayReduce(words(deburr(string).replace(reApos, '')), callback, ''); + }; + } + + /** + * Creates a function that produces an instance of `Ctor` regardless of + * whether it was invoked as part of a `new` expression or by `call` or `apply`. + * + * @private + * @param {Function} Ctor The constructor to wrap. + * @returns {Function} Returns the new wrapped function. + */ + function createCtor(Ctor) { + return function() { + // Use a `switch` statement to work with class constructors. See + // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist + // for more details. + var args = arguments; + switch (args.length) { + case 0: return new Ctor; + case 1: return new Ctor(args[0]); + case 2: return new Ctor(args[0], args[1]); + case 3: return new Ctor(args[0], args[1], args[2]); + case 4: return new Ctor(args[0], args[1], args[2], args[3]); + case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); + case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]); + case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + } + var thisBinding = baseCreate(Ctor.prototype), + result = Ctor.apply(thisBinding, args); + + // Mimic the constructor's `return` behavior. + // See https://es5.github.io/#x13.2.2 for more details. + return isObject(result) ? result : thisBinding; + }; + } + + /** + * Creates a function that wraps `func` to enable currying. + * + * @private + * @param {Function} func The function to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {number} arity The arity of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createCurry(func, bitmask, arity) { + var Ctor = createCtor(func); + + function wrapper() { + var length = arguments.length, + args = Array(length), + index = length, + placeholder = getHolder(wrapper); + + while (index--) { + args[index] = arguments[index]; + } + var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder) + ? [] + : replaceHolders(args, placeholder); + + length -= holders.length; + if (length < arity) { + return createRecurry( + func, bitmask, createHybrid, wrapper.placeholder, undefined, + args, holders, undefined, undefined, arity - length); + } + var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + return apply(fn, this, args); + } + return wrapper; + } + + /** + * Creates a `_.find` or `_.findLast` function. + * + * @private + * @param {Function} findIndexFunc The function to find the collection index. + * @returns {Function} Returns the new find function. + */ + function createFind(findIndexFunc) { + return function(collection, predicate, fromIndex) { + var iterable = Object(collection); + if (!isArrayLike(collection)) { + var iteratee = getIteratee(predicate, 3); + collection = keys(collection); + predicate = function(key) { return iteratee(iterable[key], key, iterable); }; + } + var index = findIndexFunc(collection, predicate, fromIndex); + return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined; + }; + } + + /** + * Creates a `_.flow` or `_.flowRight` function. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new flow function. + */ + function createFlow(fromRight) { + return flatRest(function(funcs) { + var length = funcs.length, + index = length, + prereq = LodashWrapper.prototype.thru; + + if (fromRight) { + funcs.reverse(); + } + while (index--) { + var func = funcs[index]; + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + if (prereq && !wrapper && getFuncName(func) == 'wrapper') { + var wrapper = new LodashWrapper([], true); + } + } + index = wrapper ? index : length; + while (++index < length) { + func = funcs[index]; + + var funcName = getFuncName(func), + data = funcName == 'wrapper' ? getData(func) : undefined; + + if (data && isLaziable(data[0]) && + data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) && + !data[4].length && data[9] == 1 + ) { + wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); + } else { + wrapper = (func.length == 1 && isLaziable(func)) + ? wrapper[funcName]() + : wrapper.thru(func); + } + } + return function() { + var args = arguments, + value = args[0]; + + if (wrapper && args.length == 1 && isArray(value)) { + return wrapper.plant(value).value(); + } + var index = 0, + result = length ? funcs[index].apply(this, args) : value; + + while (++index < length) { + result = funcs[index].call(this, result); + } + return result; + }; + }); + } + + /** + * Creates a function that wraps `func` to invoke it with optional `this` + * binding of `thisArg`, partial application, and currying. + * + * @private + * @param {Function|string} func The function or method name to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {*} [thisArg] The `this` binding of `func`. + * @param {Array} [partials] The arguments to prepend to those provided to + * the new function. + * @param {Array} [holders] The `partials` placeholder indexes. + * @param {Array} [partialsRight] The arguments to append to those provided + * to the new function. + * @param {Array} [holdersRight] The `partialsRight` placeholder indexes. + * @param {Array} [argPos] The argument positions of the new function. + * @param {number} [ary] The arity cap of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { + var isAry = bitmask & WRAP_ARY_FLAG, + isBind = bitmask & WRAP_BIND_FLAG, + isBindKey = bitmask & WRAP_BIND_KEY_FLAG, + isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG), + isFlip = bitmask & WRAP_FLIP_FLAG, + Ctor = isBindKey ? undefined : createCtor(func); + + function wrapper() { + var length = arguments.length, + args = Array(length), + index = length; + + while (index--) { + args[index] = arguments[index]; + } + if (isCurried) { + var placeholder = getHolder(wrapper), + holdersCount = countHolders(args, placeholder); + } + if (partials) { + args = composeArgs(args, partials, holders, isCurried); + } + if (partialsRight) { + args = composeArgsRight(args, partialsRight, holdersRight, isCurried); + } + length -= holdersCount; + if (isCurried && length < arity) { + var newHolders = replaceHolders(args, placeholder); + return createRecurry( + func, bitmask, createHybrid, wrapper.placeholder, thisArg, + args, newHolders, argPos, ary, arity - length + ); + } + var thisBinding = isBind ? thisArg : this, + fn = isBindKey ? thisBinding[func] : func; + + length = args.length; + if (argPos) { + args = reorder(args, argPos); + } else if (isFlip && length > 1) { + args.reverse(); + } + if (isAry && ary < length) { + args.length = ary; + } + if (this && this !== root && this instanceof wrapper) { + fn = Ctor || createCtor(fn); + } + return fn.apply(thisBinding, args); + } + return wrapper; + } + + /** + * Creates a function like `_.invertBy`. + * + * @private + * @param {Function} setter The function to set accumulator values. + * @param {Function} toIteratee The function to resolve iteratees. + * @returns {Function} Returns the new inverter function. + */ + function createInverter(setter, toIteratee) { + return function(object, iteratee) { + return baseInverter(object, setter, toIteratee(iteratee), {}); + }; + } + + /** + * Creates a function that performs a mathematical operation on two values. + * + * @private + * @param {Function} operator The function to perform the operation. + * @param {number} [defaultValue] The value used for `undefined` arguments. + * @returns {Function} Returns the new mathematical operation function. + */ + function createMathOperation(operator, defaultValue) { + return function(value, other) { + var result; + if (value === undefined && other === undefined) { + return defaultValue; + } + if (value !== undefined) { + result = value; + } + if (other !== undefined) { + if (result === undefined) { + return other; + } + if (typeof value == 'string' || typeof other == 'string') { + value = baseToString(value); + other = baseToString(other); + } else { + value = baseToNumber(value); + other = baseToNumber(other); + } + result = operator(value, other); + } + return result; + }; + } + + /** + * Creates a function like `_.over`. + * + * @private + * @param {Function} arrayFunc The function to iterate over iteratees. + * @returns {Function} Returns the new over function. + */ + function createOver(arrayFunc) { + return flatRest(function(iteratees) { + iteratees = arrayMap(iteratees, baseUnary(getIteratee())); + return baseRest(function(args) { + var thisArg = this; + return arrayFunc(iteratees, function(iteratee) { + return apply(iteratee, thisArg, args); + }); + }); + }); + } + + /** + * Creates the padding for `string` based on `length`. The `chars` string + * is truncated if the number of characters exceeds `length`. + * + * @private + * @param {number} length The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padding for `string`. + */ + function createPadding(length, chars) { + chars = chars === undefined ? ' ' : baseToString(chars); + + var charsLength = chars.length; + if (charsLength < 2) { + return charsLength ? baseRepeat(chars, length) : chars; + } + var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); + return hasUnicode(chars) + ? castSlice(stringToArray(result), 0, length).join('') + : result.slice(0, length); + } + + /** + * Creates a function that wraps `func` to invoke it with the `this` binding + * of `thisArg` and `partials` prepended to the arguments it receives. + * + * @private + * @param {Function} func The function to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {*} thisArg The `this` binding of `func`. + * @param {Array} partials The arguments to prepend to those provided to + * the new function. + * @returns {Function} Returns the new wrapped function. + */ + function createPartial(func, bitmask, thisArg, partials) { + var isBind = bitmask & WRAP_BIND_FLAG, + Ctor = createCtor(func); + + function wrapper() { + var argsIndex = -1, + argsLength = arguments.length, + leftIndex = -1, + leftLength = partials.length, + args = Array(leftLength + argsLength), + fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + + while (++leftIndex < leftLength) { + args[leftIndex] = partials[leftIndex]; + } + while (argsLength--) { + args[leftIndex++] = arguments[++argsIndex]; + } + return apply(fn, isBind ? thisArg : this, args); + } + return wrapper; + } + + /** + * Creates a `_.range` or `_.rangeRight` function. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new range function. + */ + function createRange(fromRight) { + return function(start, end, step) { + if (step && typeof step != 'number' && isIterateeCall(start, end, step)) { + end = step = undefined; + } + // Ensure the sign of `-0` is preserved. + start = toFinite(start); + if (end === undefined) { + end = start; + start = 0; + } else { + end = toFinite(end); + } + step = step === undefined ? (start < end ? 1 : -1) : toFinite(step); + return baseRange(start, end, step, fromRight); + }; + } + + /** + * Creates a function that performs a relational operation on two values. + * + * @private + * @param {Function} operator The function to perform the operation. + * @returns {Function} Returns the new relational operation function. + */ + function createRelationalOperation(operator) { + return function(value, other) { + if (!(typeof value == 'string' && typeof other == 'string')) { + value = toNumber(value); + other = toNumber(other); + } + return operator(value, other); + }; + } + + /** + * Creates a function that wraps `func` to continue currying. + * + * @private + * @param {Function} func The function to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {Function} wrapFunc The function to create the `func` wrapper. + * @param {*} placeholder The placeholder value. + * @param {*} [thisArg] The `this` binding of `func`. + * @param {Array} [partials] The arguments to prepend to those provided to + * the new function. + * @param {Array} [holders] The `partials` placeholder indexes. + * @param {Array} [argPos] The argument positions of the new function. + * @param {number} [ary] The arity cap of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { + var isCurry = bitmask & WRAP_CURRY_FLAG, + newHolders = isCurry ? holders : undefined, + newHoldersRight = isCurry ? undefined : holders, + newPartials = isCurry ? partials : undefined, + newPartialsRight = isCurry ? undefined : partials; + + bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG); + bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG); + + if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) { + bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG); + } + var newData = [ + func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, + newHoldersRight, argPos, ary, arity + ]; + + var result = wrapFunc.apply(undefined, newData); + if (isLaziable(func)) { + setData(result, newData); + } + result.placeholder = placeholder; + return setWrapToString(result, func, bitmask); + } + + /** + * Creates a function like `_.round`. + * + * @private + * @param {string} methodName The name of the `Math` method to use when rounding. + * @returns {Function} Returns the new round function. + */ + function createRound(methodName) { + var func = Math[methodName]; + return function(number, precision) { + number = toNumber(number); + precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); + if (precision) { + // Shift with exponential notation to avoid floating-point issues. + // See [MDN](https://mdn.io/round#Examples) for more details. + var pair = (toString(number) + 'e').split('e'), + value = func(pair[0] + 'e' + (+pair[1] + precision)); + + pair = (toString(value) + 'e').split('e'); + return +(pair[0] + 'e' + (+pair[1] - precision)); + } + return func(number); + }; + } + + /** + * Creates a set object of `values`. + * + * @private + * @param {Array} values The values to add to the set. + * @returns {Object} Returns the new set. + */ + var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { + return new Set(values); + }; + + /** + * Creates a `_.toPairs` or `_.toPairsIn` function. + * + * @private + * @param {Function} keysFunc The function to get the keys of a given object. + * @returns {Function} Returns the new pairs function. + */ + function createToPairs(keysFunc) { + return function(object) { + var tag = getTag(object); + if (tag == mapTag) { + return mapToArray(object); + } + if (tag == setTag) { + return setToPairs(object); + } + return baseToPairs(object, keysFunc(object)); + }; + } + + /** + * Creates a function that either curries or invokes `func` with optional + * `this` binding and partially applied arguments. + * + * @private + * @param {Function|string} func The function or method name to wrap. + * @param {number} bitmask The bitmask flags. + * 1 - `_.bind` + * 2 - `_.bindKey` + * 4 - `_.curry` or `_.curryRight` of a bound function + * 8 - `_.curry` + * 16 - `_.curryRight` + * 32 - `_.partial` + * 64 - `_.partialRight` + * 128 - `_.rearg` + * 256 - `_.ary` + * 512 - `_.flip` + * @param {*} [thisArg] The `this` binding of `func`. + * @param {Array} [partials] The arguments to be partially applied. + * @param {Array} [holders] The `partials` placeholder indexes. + * @param {Array} [argPos] The argument positions of the new function. + * @param {number} [ary] The arity cap of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { + var isBindKey = bitmask & WRAP_BIND_KEY_FLAG; + if (!isBindKey && typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + var length = partials ? partials.length : 0; + if (!length) { + bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG); + partials = holders = undefined; + } + ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0); + arity = arity === undefined ? arity : toInteger(arity); + length -= holders ? holders.length : 0; + + if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) { + var partialsRight = partials, + holdersRight = holders; + + partials = holders = undefined; + } + var data = isBindKey ? undefined : getData(func); + + var newData = [ + func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, + argPos, ary, arity + ]; + + if (data) { + mergeData(newData, data); + } + func = newData[0]; + bitmask = newData[1]; + thisArg = newData[2]; + partials = newData[3]; + holders = newData[4]; + arity = newData[9] = newData[9] === undefined + ? (isBindKey ? 0 : func.length) + : nativeMax(newData[9] - length, 0); + + if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) { + bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG); + } + if (!bitmask || bitmask == WRAP_BIND_FLAG) { + var result = createBind(func, bitmask, thisArg); + } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) { + result = createCurry(func, bitmask, arity); + } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) { + result = createPartial(func, bitmask, thisArg, partials); + } else { + result = createHybrid.apply(undefined, newData); + } + var setter = data ? baseSetData : setData; + return setWrapToString(setter(result, newData), func, bitmask); + } + + /** + * Used by `_.defaults` to customize its `_.assignIn` use to assign properties + * of source objects to the destination object for all destination properties + * that resolve to `undefined`. + * + * @private + * @param {*} objValue The destination value. + * @param {*} srcValue The source value. + * @param {string} key The key of the property to assign. + * @param {Object} object The parent object of `objValue`. + * @returns {*} Returns the value to assign. + */ + function customDefaultsAssignIn(objValue, srcValue, key, object) { + if (objValue === undefined || + (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) { + return srcValue; + } + return objValue; + } + + /** + * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source + * objects into destination objects that are passed thru. + * + * @private + * @param {*} objValue The destination value. + * @param {*} srcValue The source value. + * @param {string} key The key of the property to merge. + * @param {Object} object The parent object of `objValue`. + * @param {Object} source The parent object of `srcValue`. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + * @returns {*} Returns the value to assign. + */ + function customDefaultsMerge(objValue, srcValue, key, object, source, stack) { + if (isObject(objValue) && isObject(srcValue)) { + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, objValue); + baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack); + stack['delete'](srcValue); + } + return objValue; + } + + /** + * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain + * objects. + * + * @private + * @param {*} value The value to inspect. + * @param {string} key The key of the property to inspect. + * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`. + */ + function customOmitClone(value) { + return isPlainObject(value) ? undefined : value; + } + + /** + * A specialized version of `baseIsEqualDeep` for arrays with support for + * partial deep comparisons. + * + * @private + * @param {Array} array The array to compare. + * @param {Array} other The other array to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} stack Tracks traversed `array` and `other` objects. + * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. + */ + function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { + var isPartial = bitmask & COMPARE_PARTIAL_FLAG, + arrLength = array.length, + othLength = other.length; + + if (arrLength != othLength && !(isPartial && othLength > arrLength)) { + return false; + } + // Assume cyclic values are equal. + var stacked = stack.get(array); + if (stacked && stack.get(other)) { + return stacked == other; + } + var index = -1, + result = true, + seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined; + + stack.set(array, other); + stack.set(other, array); + + // Ignore non-index properties. + while (++index < arrLength) { + var arrValue = array[index], + othValue = other[index]; + + if (customizer) { + var compared = isPartial + ? customizer(othValue, arrValue, index, other, array, stack) + : customizer(arrValue, othValue, index, array, other, stack); + } + if (compared !== undefined) { + if (compared) { + continue; + } + result = false; + break; + } + // Recursively compare arrays (susceptible to call stack limits). + if (seen) { + if (!arraySome(other, function(othValue, othIndex) { + if (!cacheHas(seen, othIndex) && + (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) { + return seen.push(othIndex); + } + })) { + result = false; + break; + } + } else if (!( + arrValue === othValue || + equalFunc(arrValue, othValue, bitmask, customizer, stack) + )) { + result = false; + break; + } + } + stack['delete'](array); + stack['delete'](other); + return result; + } + + /** + * A specialized version of `baseIsEqualDeep` for comparing objects of + * the same `toStringTag`. + * + * **Note:** This function only supports comparing values with tags of + * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {string} tag The `toStringTag` of the objects to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} stack Tracks traversed `object` and `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ + function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { + switch (tag) { + case dataViewTag: + if ((object.byteLength != other.byteLength) || + (object.byteOffset != other.byteOffset)) { + return false; + } + object = object.buffer; + other = other.buffer; + + case arrayBufferTag: + if ((object.byteLength != other.byteLength) || + !equalFunc(new Uint8Array(object), new Uint8Array(other))) { + return false; + } + return true; + + case boolTag: + case dateTag: + case numberTag: + // Coerce booleans to `1` or `0` and dates to milliseconds. + // Invalid dates are coerced to `NaN`. + return eq(+object, +other); + + case errorTag: + return object.name == other.name && object.message == other.message; + + case regexpTag: + case stringTag: + // Coerce regexes to strings and treat strings, primitives and objects, + // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring + // for more details. + return object == (other + ''); + + case mapTag: + var convert = mapToArray; + + case setTag: + var isPartial = bitmask & COMPARE_PARTIAL_FLAG; + convert || (convert = setToArray); + + if (object.size != other.size && !isPartial) { + return false; + } + // Assume cyclic values are equal. + var stacked = stack.get(object); + if (stacked) { + return stacked == other; + } + bitmask |= COMPARE_UNORDERED_FLAG; + + // Recursively compare objects (susceptible to call stack limits). + stack.set(object, other); + var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack); + stack['delete'](object); + return result; + + case symbolTag: + if (symbolValueOf) { + return symbolValueOf.call(object) == symbolValueOf.call(other); + } + } + return false; + } + + /** + * A specialized version of `baseIsEqualDeep` for objects with support for + * partial deep comparisons. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} stack Tracks traversed `object` and `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ + function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { + var isPartial = bitmask & COMPARE_PARTIAL_FLAG, + objProps = getAllKeys(object), + objLength = objProps.length, + othProps = getAllKeys(other), + othLength = othProps.length; + + if (objLength != othLength && !isPartial) { + return false; + } + var index = objLength; + while (index--) { + var key = objProps[index]; + if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { + return false; + } + } + // Assume cyclic values are equal. + var stacked = stack.get(object); + if (stacked && stack.get(other)) { + return stacked == other; + } + var result = true; + stack.set(object, other); + stack.set(other, object); + + var skipCtor = isPartial; + while (++index < objLength) { + key = objProps[index]; + var objValue = object[key], + othValue = other[key]; + + if (customizer) { + var compared = isPartial + ? customizer(othValue, objValue, key, other, object, stack) + : customizer(objValue, othValue, key, object, other, stack); + } + // Recursively compare objects (susceptible to call stack limits). + if (!(compared === undefined + ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) + : compared + )) { + result = false; + break; + } + skipCtor || (skipCtor = key == 'constructor'); + } + if (result && !skipCtor) { + var objCtor = object.constructor, + othCtor = other.constructor; + + // Non `Object` object instances with different constructors are not equal. + if (objCtor != othCtor && + ('constructor' in object && 'constructor' in other) && + !(typeof objCtor == 'function' && objCtor instanceof objCtor && + typeof othCtor == 'function' && othCtor instanceof othCtor)) { + result = false; + } + } + stack['delete'](object); + stack['delete'](other); + return result; + } + + /** + * A specialized version of `baseRest` which flattens the rest array. + * + * @private + * @param {Function} func The function to apply a rest parameter to. + * @returns {Function} Returns the new function. + */ + function flatRest(func) { + return setToString(overRest(func, undefined, flatten), func + ''); + } + + /** + * Creates an array of own enumerable property names and symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ + function getAllKeys(object) { + return baseGetAllKeys(object, keys, getSymbols); + } + + /** + * Creates an array of own and inherited enumerable property names and + * symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ + function getAllKeysIn(object) { + return baseGetAllKeys(object, keysIn, getSymbolsIn); + } + + /** + * Gets metadata for `func`. + * + * @private + * @param {Function} func The function to query. + * @returns {*} Returns the metadata for `func`. + */ + var getData = !metaMap ? noop : function(func) { + return metaMap.get(func); + }; + + /** + * Gets the name of `func`. + * + * @private + * @param {Function} func The function to query. + * @returns {string} Returns the function name. + */ + function getFuncName(func) { + var result = (func.name + ''), + array = realNames[result], + length = hasOwnProperty.call(realNames, result) ? array.length : 0; + + while (length--) { + var data = array[length], + otherFunc = data.func; + if (otherFunc == null || otherFunc == func) { + return data.name; + } + } + return result; + } + + /** + * Gets the argument placeholder value for `func`. + * + * @private + * @param {Function} func The function to inspect. + * @returns {*} Returns the placeholder value. + */ + function getHolder(func) { + var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func; + return object.placeholder; + } + + /** + * Gets the appropriate "iteratee" function. If `_.iteratee` is customized, + * this function returns the custom method, otherwise it returns `baseIteratee`. + * If arguments are provided, the chosen function is invoked with them and + * its result is returned. + * + * @private + * @param {*} [value] The value to convert to an iteratee. + * @param {number} [arity] The arity of the created iteratee. + * @returns {Function} Returns the chosen function or its result. + */ + function getIteratee() { + var result = lodash.iteratee || iteratee; + result = result === iteratee ? baseIteratee : result; + return arguments.length ? result(arguments[0], arguments[1]) : result; + } + + /** + * Gets the data for `map`. + * + * @private + * @param {Object} map The map to query. + * @param {string} key The reference key. + * @returns {*} Returns the map data. + */ + function getMapData(map, key) { + var data = map.__data__; + return isKeyable(key) + ? data[typeof key == 'string' ? 'string' : 'hash'] + : data.map; + } + + /** + * Gets the property names, values, and compare flags of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the match data of `object`. + */ + function getMatchData(object) { + var result = keys(object), + length = result.length; + + while (length--) { + var key = result[length], + value = object[key]; + + result[length] = [key, value, isStrictComparable(value)]; + } + return result; + } + + /** + * Gets the native function at `key` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the method to get. + * @returns {*} Returns the function if it's native, else `undefined`. + */ + function getNative(object, key) { + var value = getValue(object, key); + return baseIsNative(value) ? value : undefined; + } + + /** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ + function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag), + tag = value[symToStringTag]; + + try { + value[symToStringTag] = undefined; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag; + } else { + delete value[symToStringTag]; + } + } + return result; + } + + /** + * Creates an array of the own enumerable symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of symbols. + */ + var getSymbols = !nativeGetSymbols ? stubArray : function(object) { + if (object == null) { + return []; + } + object = Object(object); + return arrayFilter(nativeGetSymbols(object), function(symbol) { + return propertyIsEnumerable.call(object, symbol); + }); + }; + + /** + * Creates an array of the own and inherited enumerable symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of symbols. + */ + var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) { + var result = []; + while (object) { + arrayPush(result, getSymbols(object)); + object = getPrototype(object); + } + return result; + }; + + /** + * Gets the `toStringTag` of `value`. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + var getTag = baseGetTag; + + // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6. + if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || + (Map && getTag(new Map) != mapTag) || + (Promise && getTag(Promise.resolve()) != promiseTag) || + (Set && getTag(new Set) != setTag) || + (WeakMap && getTag(new WeakMap) != weakMapTag)) { + getTag = function(value) { + var result = baseGetTag(value), + Ctor = result == objectTag ? value.constructor : undefined, + ctorString = Ctor ? toSource(Ctor) : ''; + + if (ctorString) { + switch (ctorString) { + case dataViewCtorString: return dataViewTag; + case mapCtorString: return mapTag; + case promiseCtorString: return promiseTag; + case setCtorString: return setTag; + case weakMapCtorString: return weakMapTag; + } + } + return result; + }; + } + + /** + * Gets the view, applying any `transforms` to the `start` and `end` positions. + * + * @private + * @param {number} start The start of the view. + * @param {number} end The end of the view. + * @param {Array} transforms The transformations to apply to the view. + * @returns {Object} Returns an object containing the `start` and `end` + * positions of the view. + */ + function getView(start, end, transforms) { + var index = -1, + length = transforms.length; + + while (++index < length) { + var data = transforms[index], + size = data.size; + + switch (data.type) { + case 'drop': start += size; break; + case 'dropRight': end -= size; break; + case 'take': end = nativeMin(end, start + size); break; + case 'takeRight': start = nativeMax(start, end - size); break; + } + } + return { 'start': start, 'end': end }; + } + + /** + * Extracts wrapper details from the `source` body comment. + * + * @private + * @param {string} source The source to inspect. + * @returns {Array} Returns the wrapper details. + */ + function getWrapDetails(source) { + var match = source.match(reWrapDetails); + return match ? match[1].split(reSplitDetails) : []; + } + + /** + * Checks if `path` exists on `object`. + * + * @private + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @param {Function} hasFunc The function to check properties. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + */ + function hasPath(object, path, hasFunc) { + path = castPath(path, object); + + var index = -1, + length = path.length, + result = false; + + while (++index < length) { + var key = toKey(path[index]); + if (!(result = object != null && hasFunc(object, key))) { + break; + } + object = object[key]; + } + if (result || ++index != length) { + return result; + } + length = object == null ? 0 : object.length; + return !!length && isLength(length) && isIndex(key, length) && + (isArray(object) || isArguments(object)); + } + + /** + * Initializes an array clone. + * + * @private + * @param {Array} array The array to clone. + * @returns {Array} Returns the initialized clone. + */ + function initCloneArray(array) { + var length = array.length, + result = new array.constructor(length); + + // Add properties assigned by `RegExp#exec`. + if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { + result.index = array.index; + result.input = array.input; + } + return result; + } + + /** + * Initializes an object clone. + * + * @private + * @param {Object} object The object to clone. + * @returns {Object} Returns the initialized clone. + */ + function initCloneObject(object) { + return (typeof object.constructor == 'function' && !isPrototype(object)) + ? baseCreate(getPrototype(object)) + : {}; + } + + /** + * Initializes an object clone based on its `toStringTag`. + * + * **Note:** This function only supports cloning values with tags of + * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`. + * + * @private + * @param {Object} object The object to clone. + * @param {string} tag The `toStringTag` of the object to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the initialized clone. + */ + function initCloneByTag(object, tag, isDeep) { + var Ctor = object.constructor; + switch (tag) { + case arrayBufferTag: + return cloneArrayBuffer(object); + + case boolTag: + case dateTag: + return new Ctor(+object); + + case dataViewTag: + return cloneDataView(object, isDeep); + + case float32Tag: case float64Tag: + case int8Tag: case int16Tag: case int32Tag: + case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: + return cloneTypedArray(object, isDeep); + + case mapTag: + return new Ctor; + + case numberTag: + case stringTag: + return new Ctor(object); + + case regexpTag: + return cloneRegExp(object); + + case setTag: + return new Ctor; + + case symbolTag: + return cloneSymbol(object); + } + } + + /** + * Inserts wrapper `details` in a comment at the top of the `source` body. + * + * @private + * @param {string} source The source to modify. + * @returns {Array} details The details to insert. + * @returns {string} Returns the modified source. + */ + function insertWrapDetails(source, details) { + var length = details.length; + if (!length) { + return source; + } + var lastIndex = length - 1; + details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex]; + details = details.join(length > 2 ? ', ' : ' '); + return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n'); + } + + /** + * Checks if `value` is a flattenable `arguments` object or array. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. + */ + function isFlattenable(value) { + return isArray(value) || isArguments(value) || + !!(spreadableSymbol && value && value[spreadableSymbol]); + } + + /** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ + function isIndex(value, length) { + var type = typeof value; + length = length == null ? MAX_SAFE_INTEGER : length; + + return !!length && + (type == 'number' || + (type != 'symbol' && reIsUint.test(value))) && + (value > -1 && value % 1 == 0 && value < length); + } + + /** + * Checks if the given arguments are from an iteratee call. + * + * @private + * @param {*} value The potential iteratee value argument. + * @param {*} index The potential iteratee index or key argument. + * @param {*} object The potential iteratee object argument. + * @returns {boolean} Returns `true` if the arguments are from an iteratee call, + * else `false`. + */ + function isIterateeCall(value, index, object) { + if (!isObject(object)) { + return false; + } + var type = typeof index; + if (type == 'number' + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object) + ) { + return eq(object[index], value); + } + return false; + } + + /** + * Checks if `value` is a property name and not a property path. + * + * @private + * @param {*} value The value to check. + * @param {Object} [object] The object to query keys on. + * @returns {boolean} Returns `true` if `value` is a property name, else `false`. + */ + function isKey(value, object) { + if (isArray(value)) { + return false; + } + var type = typeof value; + if (type == 'number' || type == 'symbol' || type == 'boolean' || + value == null || isSymbol(value)) { + return true; + } + return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || + (object != null && value in Object(object)); + } + + /** + * Checks if `value` is suitable for use as unique object key. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is suitable, else `false`. + */ + function isKeyable(value) { + var type = typeof value; + return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') + ? (value !== '__proto__') + : (value === null); + } + + /** + * Checks if `func` has a lazy counterpart. + * + * @private + * @param {Function} func The function to check. + * @returns {boolean} Returns `true` if `func` has a lazy counterpart, + * else `false`. + */ + function isLaziable(func) { + var funcName = getFuncName(func), + other = lodash[funcName]; + + if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) { + return false; + } + if (func === other) { + return true; + } + var data = getData(other); + return !!data && func === data[0]; + } + + /** + * Checks if `func` has its source masked. + * + * @private + * @param {Function} func The function to check. + * @returns {boolean} Returns `true` if `func` is masked, else `false`. + */ + function isMasked(func) { + return !!maskSrcKey && (maskSrcKey in func); + } + + /** + * Checks if `func` is capable of being masked. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `func` is maskable, else `false`. + */ + var isMaskable = coreJsData ? isFunction : stubFalse; + + /** + * Checks if `value` is likely a prototype object. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. + */ + function isPrototype(value) { + var Ctor = value && value.constructor, + proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; + + return value === proto; + } + + /** + * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` if suitable for strict + * equality comparisons, else `false`. + */ + function isStrictComparable(value) { + return value === value && !isObject(value); + } + + /** + * A specialized version of `matchesProperty` for source values suitable + * for strict equality comparisons, i.e. `===`. + * + * @private + * @param {string} key The key of the property to get. + * @param {*} srcValue The value to match. + * @returns {Function} Returns the new spec function. + */ + function matchesStrictComparable(key, srcValue) { + return function(object) { + if (object == null) { + return false; + } + return object[key] === srcValue && + (srcValue !== undefined || (key in Object(object))); + }; + } + + /** + * A specialized version of `_.memoize` which clears the memoized function's + * cache when it exceeds `MAX_MEMOIZE_SIZE`. + * + * @private + * @param {Function} func The function to have its output memoized. + * @returns {Function} Returns the new memoized function. + */ + function memoizeCapped(func) { + var result = memoize(func, function(key) { + if (cache.size === MAX_MEMOIZE_SIZE) { + cache.clear(); + } + return key; + }); + + var cache = result.cache; + return result; + } + + /** + * Merges the function metadata of `source` into `data`. + * + * Merging metadata reduces the number of wrappers used to invoke a function. + * This is possible because methods like `_.bind`, `_.curry`, and `_.partial` + * may be applied regardless of execution order. Methods like `_.ary` and + * `_.rearg` modify function arguments, making the order in which they are + * executed important, preventing the merging of metadata. However, we make + * an exception for a safe combined case where curried functions have `_.ary` + * and or `_.rearg` applied. + * + * @private + * @param {Array} data The destination metadata. + * @param {Array} source The source metadata. + * @returns {Array} Returns `data`. + */ + function mergeData(data, source) { + var bitmask = data[1], + srcBitmask = source[1], + newBitmask = bitmask | srcBitmask, + isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG); + + var isCombo = + ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) || + ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) || + ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG)); + + // Exit early if metadata can't be merged. + if (!(isCommon || isCombo)) { + return data; + } + // Use source `thisArg` if available. + if (srcBitmask & WRAP_BIND_FLAG) { + data[2] = source[2]; + // Set when currying a bound function. + newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG; + } + // Compose partial arguments. + var value = source[3]; + if (value) { + var partials = data[3]; + data[3] = partials ? composeArgs(partials, value, source[4]) : value; + data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4]; + } + // Compose partial right arguments. + value = source[5]; + if (value) { + partials = data[5]; + data[5] = partials ? composeArgsRight(partials, value, source[6]) : value; + data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6]; + } + // Use source `argPos` if available. + value = source[7]; + if (value) { + data[7] = value; + } + // Use source `ary` if it's smaller. + if (srcBitmask & WRAP_ARY_FLAG) { + data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]); + } + // Use source `arity` if one is not provided. + if (data[9] == null) { + data[9] = source[9]; + } + // Use source `func` and merge bitmasks. + data[0] = source[0]; + data[1] = newBitmask; + + return data; + } + + /** + * This function is like + * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) + * except that it includes inherited enumerable properties. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ + function nativeKeysIn(object) { + var result = []; + if (object != null) { + for (var key in Object(object)) { + result.push(key); + } + } + return result; + } + + /** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ + function objectToString(value) { + return nativeObjectToString.call(value); + } + + /** + * A specialized version of `baseRest` which transforms the rest array. + * + * @private + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @param {Function} transform The rest array transform. + * @returns {Function} Returns the new function. + */ + function overRest(func, start, transform) { + start = nativeMax(start === undefined ? (func.length - 1) : start, 0); + return function() { + var args = arguments, + index = -1, + length = nativeMax(args.length - start, 0), + array = Array(length); + + while (++index < length) { + array[index] = args[start + index]; + } + index = -1; + var otherArgs = Array(start + 1); + while (++index < start) { + otherArgs[index] = args[index]; + } + otherArgs[start] = transform(array); + return apply(func, this, otherArgs); + }; + } + + /** + * Gets the parent value at `path` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {Array} path The path to get the parent value of. + * @returns {*} Returns the parent value. + */ + function parent(object, path) { + return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1)); + } + + /** + * Reorder `array` according to the specified indexes where the element at + * the first index is assigned as the first element, the element at + * the second index is assigned as the second element, and so on. + * + * @private + * @param {Array} array The array to reorder. + * @param {Array} indexes The arranged array indexes. + * @returns {Array} Returns `array`. + */ + function reorder(array, indexes) { + var arrLength = array.length, + length = nativeMin(indexes.length, arrLength), + oldArray = copyArray(array); + + while (length--) { + var index = indexes[length]; + array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined; + } + return array; + } + + /** + * Sets metadata for `func`. + * + * **Note:** If this function becomes hot, i.e. is invoked a lot in a short + * period of time, it will trip its breaker and transition to an identity + * function to avoid garbage collection pauses in V8. See + * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070) + * for more details. + * + * @private + * @param {Function} func The function to associate metadata with. + * @param {*} data The metadata. + * @returns {Function} Returns `func`. + */ + var setData = shortOut(baseSetData); + + /** + * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout). + * + * @private + * @param {Function} func The function to delay. + * @param {number} wait The number of milliseconds to delay invocation. + * @returns {number|Object} Returns the timer id or timeout object. + */ + var setTimeout = ctxSetTimeout || function(func, wait) { + return root.setTimeout(func, wait); + }; + + /** + * Sets the `toString` method of `func` to return `string`. + * + * @private + * @param {Function} func The function to modify. + * @param {Function} string The `toString` result. + * @returns {Function} Returns `func`. + */ + var setToString = shortOut(baseSetToString); + + /** + * Sets the `toString` method of `wrapper` to mimic the source of `reference` + * with wrapper details in a comment at the top of the source body. + * + * @private + * @param {Function} wrapper The function to modify. + * @param {Function} reference The reference function. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @returns {Function} Returns `wrapper`. + */ + function setWrapToString(wrapper, reference, bitmask) { + var source = (reference + ''); + return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask))); + } + + /** + * Creates a function that'll short out and invoke `identity` instead + * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN` + * milliseconds. + * + * @private + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new shortable function. + */ + function shortOut(func) { + var count = 0, + lastCalled = 0; + + return function() { + var stamp = nativeNow(), + remaining = HOT_SPAN - (stamp - lastCalled); + + lastCalled = stamp; + if (remaining > 0) { + if (++count >= HOT_COUNT) { + return arguments[0]; + } + } else { + count = 0; + } + return func.apply(undefined, arguments); + }; + } + + /** + * A specialized version of `_.shuffle` which mutates and sets the size of `array`. + * + * @private + * @param {Array} array The array to shuffle. + * @param {number} [size=array.length] The size of `array`. + * @returns {Array} Returns `array`. + */ + function shuffleSelf(array, size) { + var index = -1, + length = array.length, + lastIndex = length - 1; + + size = size === undefined ? length : size; + while (++index < size) { + var rand = baseRandom(index, lastIndex), + value = array[rand]; + + array[rand] = array[index]; + array[index] = value; + } + array.length = size; + return array; + } + + /** + * Converts `string` to a property path array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the property path array. + */ + var stringToPath = memoizeCapped(function(string) { + var result = []; + if (string.charCodeAt(0) === 46 /* . */) { + result.push(''); + } + string.replace(rePropName, function(match, number, quote, subString) { + result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match)); + }); + return result; + }); + + /** + * Converts `value` to a string key if it's not a string or symbol. + * + * @private + * @param {*} value The value to inspect. + * @returns {string|symbol} Returns the key. + */ + function toKey(value) { + if (typeof value == 'string' || isSymbol(value)) { + return value; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; + } + + /** + * Converts `func` to its source code. + * + * @private + * @param {Function} func The function to convert. + * @returns {string} Returns the source code. + */ + function toSource(func) { + if (func != null) { + try { + return funcToString.call(func); + } catch (e) {} + try { + return (func + ''); + } catch (e) {} + } + return ''; + } + + /** + * Updates wrapper `details` based on `bitmask` flags. + * + * @private + * @returns {Array} details The details to modify. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @returns {Array} Returns `details`. + */ + function updateWrapDetails(details, bitmask) { + arrayEach(wrapFlags, function(pair) { + var value = '_.' + pair[0]; + if ((bitmask & pair[1]) && !arrayIncludes(details, value)) { + details.push(value); + } + }); + return details.sort(); + } + + /** + * Creates a clone of `wrapper`. + * + * @private + * @param {Object} wrapper The wrapper to clone. + * @returns {Object} Returns the cloned wrapper. + */ + function wrapperClone(wrapper) { + if (wrapper instanceof LazyWrapper) { + return wrapper.clone(); + } + var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); + result.__actions__ = copyArray(wrapper.__actions__); + result.__index__ = wrapper.__index__; + result.__values__ = wrapper.__values__; + return result; + } + + /*------------------------------------------------------------------------*/ + + /** + * Creates an array of elements split into groups the length of `size`. + * If `array` can't be split evenly, the final chunk will be the remaining + * elements. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to process. + * @param {number} [size=1] The length of each chunk + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the new array of chunks. + * @example + * + * _.chunk(['a', 'b', 'c', 'd'], 2); + * // => [['a', 'b'], ['c', 'd']] + * + * _.chunk(['a', 'b', 'c', 'd'], 3); + * // => [['a', 'b', 'c'], ['d']] + */ + function chunk(array, size, guard) { + if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) { + size = 1; + } else { + size = nativeMax(toInteger(size), 0); + } + var length = array == null ? 0 : array.length; + if (!length || size < 1) { + return []; + } + var index = 0, + resIndex = 0, + result = Array(nativeCeil(length / size)); + + while (index < length) { + result[resIndex++] = baseSlice(array, index, (index += size)); + } + return result; + } + + /** + * Creates an array with all falsey values removed. The values `false`, `null`, + * `0`, `""`, `undefined`, and `NaN` are falsey. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to compact. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * _.compact([0, 1, false, 2, '', 3]); + * // => [1, 2, 3] + */ + function compact(array) { + var index = -1, + length = array == null ? 0 : array.length, + resIndex = 0, + result = []; + + while (++index < length) { + var value = array[index]; + if (value) { + result[resIndex++] = value; + } + } + return result; + } + + /** + * Creates a new array concatenating `array` with any additional arrays + * and/or values. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to concatenate. + * @param {...*} [values] The values to concatenate. + * @returns {Array} Returns the new concatenated array. + * @example + * + * var array = [1]; + * var other = _.concat(array, 2, [3], [[4]]); + * + * console.log(other); + * // => [1, 2, 3, [4]] + * + * console.log(array); + * // => [1] + */ + function concat() { + var length = arguments.length; + if (!length) { + return []; + } + var args = Array(length - 1), + array = arguments[0], + index = length; + + while (index--) { + args[index - 1] = arguments[index]; + } + return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); + } + + /** + * Creates an array of `array` values not included in the other given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * **Note:** Unlike `_.pullAll`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @returns {Array} Returns the new array of filtered values. + * @see _.without, _.xor + * @example + * + * _.difference([2, 1], [2, 3]); + * // => [1] + */ + var difference = baseRest(function(array, values) { + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) + : []; + }); + + /** + * This method is like `_.difference` except that it accepts `iteratee` which + * is invoked for each element of `array` and `values` to generate the criterion + * by which they're compared. The order and references of result values are + * determined by the first array. The iteratee is invoked with one argument: + * (value). + * + * **Note:** Unlike `_.pullAllBy`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); + * // => [1.2] + * + * // The `_.property` iteratee shorthand. + * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); + * // => [{ 'x': 2 }] + */ + var differenceBy = baseRest(function(array, values) { + var iteratee = last(values); + if (isArrayLikeObject(iteratee)) { + iteratee = undefined; + } + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)) + : []; + }); + + /** + * This method is like `_.difference` except that it accepts `comparator` + * which is invoked to compare elements of `array` to `values`. The order and + * references of result values are determined by the first array. The comparator + * is invoked with two arguments: (arrVal, othVal). + * + * **Note:** Unlike `_.pullAllWith`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; + * + * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); + * // => [{ 'x': 2, 'y': 1 }] + */ + var differenceWith = baseRest(function(array, values) { + var comparator = last(values); + if (isArrayLikeObject(comparator)) { + comparator = undefined; + } + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator) + : []; + }); + + /** + * Creates a slice of `array` with `n` elements dropped from the beginning. + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.drop([1, 2, 3]); + * // => [2, 3] + * + * _.drop([1, 2, 3], 2); + * // => [3] + * + * _.drop([1, 2, 3], 5); + * // => [] + * + * _.drop([1, 2, 3], 0); + * // => [1, 2, 3] + */ + function drop(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined) ? 1 : toInteger(n); + return baseSlice(array, n < 0 ? 0 : n, length); + } + + /** + * Creates a slice of `array` with `n` elements dropped from the end. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.dropRight([1, 2, 3]); + * // => [1, 2] + * + * _.dropRight([1, 2, 3], 2); + * // => [1] + * + * _.dropRight([1, 2, 3], 5); + * // => [] + * + * _.dropRight([1, 2, 3], 0); + * // => [1, 2, 3] + */ + function dropRight(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined) ? 1 : toInteger(n); + n = length - n; + return baseSlice(array, 0, n < 0 ? 0 : n); + } + + /** + * Creates a slice of `array` excluding elements dropped from the end. + * Elements are dropped until `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index, array). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } + * ]; + * + * _.dropRightWhile(users, function(o) { return !o.active; }); + * // => objects for ['barney'] + * + * // The `_.matches` iteratee shorthand. + * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); + * // => objects for ['barney', 'fred'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.dropRightWhile(users, ['active', false]); + * // => objects for ['barney'] + * + * // The `_.property` iteratee shorthand. + * _.dropRightWhile(users, 'active'); + * // => objects for ['barney', 'fred', 'pebbles'] + */ + function dropRightWhile(array, predicate) { + return (array && array.length) + ? baseWhile(array, getIteratee(predicate, 3), true, true) + : []; + } + + /** + * Creates a slice of `array` excluding elements dropped from the beginning. + * Elements are dropped until `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index, array). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } + * ]; + * + * _.dropWhile(users, function(o) { return !o.active; }); + * // => objects for ['pebbles'] + * + * // The `_.matches` iteratee shorthand. + * _.dropWhile(users, { 'user': 'barney', 'active': false }); + * // => objects for ['fred', 'pebbles'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.dropWhile(users, ['active', false]); + * // => objects for ['pebbles'] + * + * // The `_.property` iteratee shorthand. + * _.dropWhile(users, 'active'); + * // => objects for ['barney', 'fred', 'pebbles'] + */ + function dropWhile(array, predicate) { + return (array && array.length) + ? baseWhile(array, getIteratee(predicate, 3), true) + : []; + } + + /** + * Fills elements of `array` with `value` from `start` up to, but not + * including, `end`. + * + * **Note:** This method mutates `array`. + * + * @static + * @memberOf _ + * @since 3.2.0 + * @category Array + * @param {Array} array The array to fill. + * @param {*} value The value to fill `array` with. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns `array`. + * @example + * + * var array = [1, 2, 3]; + * + * _.fill(array, 'a'); + * console.log(array); + * // => ['a', 'a', 'a'] + * + * _.fill(Array(3), 2); + * // => [2, 2, 2] + * + * _.fill([4, 6, 8, 10], '*', 1, 3); + * // => [4, '*', '*', 10] + */ + function fill(array, value, start, end) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + if (start && typeof start != 'number' && isIterateeCall(array, value, start)) { + start = 0; + end = length; + } + return baseFill(array, value, start, end); + } + + /** + * This method is like `_.find` except that it returns the index of the first + * element `predicate` returns truthy for instead of the element itself. + * + * @static + * @memberOf _ + * @since 1.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param {number} [fromIndex=0] The index to search from. + * @returns {number} Returns the index of the found element, else `-1`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } + * ]; + * + * _.findIndex(users, function(o) { return o.user == 'barney'; }); + * // => 0 + * + * // The `_.matches` iteratee shorthand. + * _.findIndex(users, { 'user': 'fred', 'active': false }); + * // => 1 + * + * // The `_.matchesProperty` iteratee shorthand. + * _.findIndex(users, ['active', false]); + * // => 0 + * + * // The `_.property` iteratee shorthand. + * _.findIndex(users, 'active'); + * // => 2 + */ + function findIndex(array, predicate, fromIndex) { + var length = array == null ? 0 : array.length; + if (!length) { + return -1; + } + var index = fromIndex == null ? 0 : toInteger(fromIndex); + if (index < 0) { + index = nativeMax(length + index, 0); + } + return baseFindIndex(array, getIteratee(predicate, 3), index); + } + + /** + * This method is like `_.findIndex` except that it iterates over elements + * of `collection` from right to left. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param {number} [fromIndex=array.length-1] The index to search from. + * @returns {number} Returns the index of the found element, else `-1`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } + * ]; + * + * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); + * // => 2 + * + * // The `_.matches` iteratee shorthand. + * _.findLastIndex(users, { 'user': 'barney', 'active': true }); + * // => 0 + * + * // The `_.matchesProperty` iteratee shorthand. + * _.findLastIndex(users, ['active', false]); + * // => 2 + * + * // The `_.property` iteratee shorthand. + * _.findLastIndex(users, 'active'); + * // => 0 + */ + function findLastIndex(array, predicate, fromIndex) { + var length = array == null ? 0 : array.length; + if (!length) { + return -1; + } + var index = length - 1; + if (fromIndex !== undefined) { + index = toInteger(fromIndex); + index = fromIndex < 0 + ? nativeMax(length + index, 0) + : nativeMin(index, length - 1); + } + return baseFindIndex(array, getIteratee(predicate, 3), index, true); + } + + /** + * Flattens `array` a single level deep. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to flatten. + * @returns {Array} Returns the new flattened array. + * @example + * + * _.flatten([1, [2, [3, [4]], 5]]); + * // => [1, 2, [3, [4]], 5] + */ + function flatten(array) { + var length = array == null ? 0 : array.length; + return length ? baseFlatten(array, 1) : []; + } + + /** + * Recursively flattens `array`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to flatten. + * @returns {Array} Returns the new flattened array. + * @example + * + * _.flattenDeep([1, [2, [3, [4]], 5]]); + * // => [1, 2, 3, 4, 5] + */ + function flattenDeep(array) { + var length = array == null ? 0 : array.length; + return length ? baseFlatten(array, INFINITY) : []; + } + + /** + * Recursively flatten `array` up to `depth` times. + * + * @static + * @memberOf _ + * @since 4.4.0 + * @category Array + * @param {Array} array The array to flatten. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @example + * + * var array = [1, [2, [3, [4]], 5]]; + * + * _.flattenDepth(array, 1); + * // => [1, 2, [3, [4]], 5] + * + * _.flattenDepth(array, 2); + * // => [1, 2, 3, [4], 5] + */ + function flattenDepth(array, depth) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + depth = depth === undefined ? 1 : toInteger(depth); + return baseFlatten(array, depth); + } + + /** + * The inverse of `_.toPairs`; this method returns an object composed + * from key-value `pairs`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} pairs The key-value pairs. + * @returns {Object} Returns the new object. + * @example + * + * _.fromPairs([['a', 1], ['b', 2]]); + * // => { 'a': 1, 'b': 2 } + */ + function fromPairs(pairs) { + var index = -1, + length = pairs == null ? 0 : pairs.length, + result = {}; + + while (++index < length) { + var pair = pairs[index]; + result[pair[0]] = pair[1]; + } + return result; + } + + /** + * Gets the first element of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @alias first + * @category Array + * @param {Array} array The array to query. + * @returns {*} Returns the first element of `array`. + * @example + * + * _.head([1, 2, 3]); + * // => 1 + * + * _.head([]); + * // => undefined + */ + function head(array) { + return (array && array.length) ? array[0] : undefined; + } + + /** + * Gets the index at which the first occurrence of `value` is found in `array` + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it's used as the + * offset from the end of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} [fromIndex=0] The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.indexOf([1, 2, 1, 2], 2); + * // => 1 + * + * // Search from the `fromIndex`. + * _.indexOf([1, 2, 1, 2], 2, 2); + * // => 3 + */ + function indexOf(array, value, fromIndex) { + var length = array == null ? 0 : array.length; + if (!length) { + return -1; + } + var index = fromIndex == null ? 0 : toInteger(fromIndex); + if (index < 0) { + index = nativeMax(length + index, 0); + } + return baseIndexOf(array, value, index); + } + + /** + * Gets all but the last element of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.initial([1, 2, 3]); + * // => [1, 2] + */ + function initial(array) { + var length = array == null ? 0 : array.length; + return length ? baseSlice(array, 0, -1) : []; + } + + /** + * Creates an array of unique values that are included in all given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * _.intersection([2, 1], [2, 3]); + * // => [2] + */ + var intersection = baseRest(function(arrays) { + var mapped = arrayMap(arrays, castArrayLikeObject); + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped) + : []; + }); + + /** + * This method is like `_.intersection` except that it accepts `iteratee` + * which is invoked for each element of each `arrays` to generate the criterion + * by which they're compared. The order and references of result values are + * determined by the first array. The iteratee is invoked with one argument: + * (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); + * // => [2.1] + * + * // The `_.property` iteratee shorthand. + * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 1 }] + */ + var intersectionBy = baseRest(function(arrays) { + var iteratee = last(arrays), + mapped = arrayMap(arrays, castArrayLikeObject); + + if (iteratee === last(mapped)) { + iteratee = undefined; + } else { + mapped.pop(); + } + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped, getIteratee(iteratee, 2)) + : []; + }); + + /** + * This method is like `_.intersection` except that it accepts `comparator` + * which is invoked to compare elements of `arrays`. The order and references + * of result values are determined by the first array. The comparator is + * invoked with two arguments: (arrVal, othVal). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; + * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; + * + * _.intersectionWith(objects, others, _.isEqual); + * // => [{ 'x': 1, 'y': 2 }] + */ + var intersectionWith = baseRest(function(arrays) { + var comparator = last(arrays), + mapped = arrayMap(arrays, castArrayLikeObject); + + comparator = typeof comparator == 'function' ? comparator : undefined; + if (comparator) { + mapped.pop(); + } + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped, undefined, comparator) + : []; + }); + + /** + * Converts all elements in `array` into a string separated by `separator`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to convert. + * @param {string} [separator=','] The element separator. + * @returns {string} Returns the joined string. + * @example + * + * _.join(['a', 'b', 'c'], '~'); + * // => 'a~b~c' + */ + function join(array, separator) { + return array == null ? '' : nativeJoin.call(array, separator); + } + + /** + * Gets the last element of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @returns {*} Returns the last element of `array`. + * @example + * + * _.last([1, 2, 3]); + * // => 3 + */ + function last(array) { + var length = array == null ? 0 : array.length; + return length ? array[length - 1] : undefined; + } + + /** + * This method is like `_.indexOf` except that it iterates over elements of + * `array` from right to left. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} [fromIndex=array.length-1] The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.lastIndexOf([1, 2, 1, 2], 2); + * // => 3 + * + * // Search from the `fromIndex`. + * _.lastIndexOf([1, 2, 1, 2], 2, 2); + * // => 1 + */ + function lastIndexOf(array, value, fromIndex) { + var length = array == null ? 0 : array.length; + if (!length) { + return -1; + } + var index = length; + if (fromIndex !== undefined) { + index = toInteger(fromIndex); + index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1); + } + return value === value + ? strictLastIndexOf(array, value, index) + : baseFindIndex(array, baseIsNaN, index, true); + } + + /** + * Gets the element at index `n` of `array`. If `n` is negative, the nth + * element from the end is returned. + * + * @static + * @memberOf _ + * @since 4.11.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=0] The index of the element to return. + * @returns {*} Returns the nth element of `array`. + * @example + * + * var array = ['a', 'b', 'c', 'd']; + * + * _.nth(array, 1); + * // => 'b' + * + * _.nth(array, -2); + * // => 'c'; + */ + function nth(array, n) { + return (array && array.length) ? baseNth(array, toInteger(n)) : undefined; + } + + /** + * Removes all given values from `array` using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove` + * to remove elements from an array by predicate. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {...*} [values] The values to remove. + * @returns {Array} Returns `array`. + * @example + * + * var array = ['a', 'b', 'c', 'a', 'b', 'c']; + * + * _.pull(array, 'a', 'c'); + * console.log(array); + * // => ['b', 'b'] + */ + var pull = baseRest(pullAll); + + /** + * This method is like `_.pull` except that it accepts an array of values to remove. + * + * **Note:** Unlike `_.difference`, this method mutates `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @returns {Array} Returns `array`. + * @example + * + * var array = ['a', 'b', 'c', 'a', 'b', 'c']; + * + * _.pullAll(array, ['a', 'c']); + * console.log(array); + * // => ['b', 'b'] + */ + function pullAll(array, values) { + return (array && array.length && values && values.length) + ? basePullAll(array, values) + : array; + } + + /** + * This method is like `_.pullAll` except that it accepts `iteratee` which is + * invoked for each element of `array` and `values` to generate the criterion + * by which they're compared. The iteratee is invoked with one argument: (value). + * + * **Note:** Unlike `_.differenceBy`, this method mutates `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns `array`. + * @example + * + * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }]; + * + * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x'); + * console.log(array); + * // => [{ 'x': 2 }] + */ + function pullAllBy(array, values, iteratee) { + return (array && array.length && values && values.length) + ? basePullAll(array, values, getIteratee(iteratee, 2)) + : array; + } + + /** + * This method is like `_.pullAll` except that it accepts `comparator` which + * is invoked to compare elements of `array` to `values`. The comparator is + * invoked with two arguments: (arrVal, othVal). + * + * **Note:** Unlike `_.differenceWith`, this method mutates `array`. + * + * @static + * @memberOf _ + * @since 4.6.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns `array`. + * @example + * + * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }]; + * + * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual); + * console.log(array); + * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }] + */ + function pullAllWith(array, values, comparator) { + return (array && array.length && values && values.length) + ? basePullAll(array, values, undefined, comparator) + : array; + } + + /** + * Removes elements from `array` corresponding to `indexes` and returns an + * array of removed elements. + * + * **Note:** Unlike `_.at`, this method mutates `array`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {...(number|number[])} [indexes] The indexes of elements to remove. + * @returns {Array} Returns the new array of removed elements. + * @example + * + * var array = ['a', 'b', 'c', 'd']; + * var pulled = _.pullAt(array, [1, 3]); + * + * console.log(array); + * // => ['a', 'c'] + * + * console.log(pulled); + * // => ['b', 'd'] + */ + var pullAt = flatRest(function(array, indexes) { + var length = array == null ? 0 : array.length, + result = baseAt(array, indexes); + + basePullAt(array, arrayMap(indexes, function(index) { + return isIndex(index, length) ? +index : index; + }).sort(compareAscending)); + + return result; + }); + + /** + * Removes all elements from `array` that `predicate` returns truthy for + * and returns an array of the removed elements. The predicate is invoked + * with three arguments: (value, index, array). + * + * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull` + * to pull elements from an array by value. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new array of removed elements. + * @example + * + * var array = [1, 2, 3, 4]; + * var evens = _.remove(array, function(n) { + * return n % 2 == 0; + * }); + * + * console.log(array); + * // => [1, 3] + * + * console.log(evens); + * // => [2, 4] + */ + function remove(array, predicate) { + var result = []; + if (!(array && array.length)) { + return result; + } + var index = -1, + indexes = [], + length = array.length; + + predicate = getIteratee(predicate, 3); + while (++index < length) { + var value = array[index]; + if (predicate(value, index, array)) { + result.push(value); + indexes.push(index); + } + } + basePullAt(array, indexes); + return result; + } + + /** + * Reverses `array` so that the first element becomes the last, the second + * element becomes the second to last, and so on. + * + * **Note:** This method mutates `array` and is based on + * [`Array#reverse`](https://mdn.io/Array/reverse). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to modify. + * @returns {Array} Returns `array`. + * @example + * + * var array = [1, 2, 3]; + * + * _.reverse(array); + * // => [3, 2, 1] + * + * console.log(array); + * // => [3, 2, 1] + */ + function reverse(array) { + return array == null ? array : nativeReverse.call(array); + } + + /** + * Creates a slice of `array` from `start` up to, but not including, `end`. + * + * **Note:** This method is used instead of + * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are + * returned. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to slice. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the slice of `array`. + */ + function slice(array, start, end) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + if (end && typeof end != 'number' && isIterateeCall(array, start, end)) { + start = 0; + end = length; + } + else { + start = start == null ? 0 : toInteger(start); + end = end === undefined ? length : toInteger(end); + } + return baseSlice(array, start, end); + } + + /** + * Uses a binary search to determine the lowest index at which `value` + * should be inserted into `array` in order to maintain its sort order. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * _.sortedIndex([30, 50], 40); + * // => 1 + */ + function sortedIndex(array, value) { + return baseSortedIndex(array, value); + } + + /** + * This method is like `_.sortedIndex` except that it accepts `iteratee` + * which is invoked for `value` and each element of `array` to compute their + * sort ranking. The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * var objects = [{ 'x': 4 }, { 'x': 5 }]; + * + * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); + * // => 0 + * + * // The `_.property` iteratee shorthand. + * _.sortedIndexBy(objects, { 'x': 4 }, 'x'); + * // => 0 + */ + function sortedIndexBy(array, value, iteratee) { + return baseSortedIndexBy(array, value, getIteratee(iteratee, 2)); + } + + /** + * This method is like `_.indexOf` except that it performs a binary + * search on a sorted `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.sortedIndexOf([4, 5, 5, 5, 6], 5); + * // => 1 + */ + function sortedIndexOf(array, value) { + var length = array == null ? 0 : array.length; + if (length) { + var index = baseSortedIndex(array, value); + if (index < length && eq(array[index], value)) { + return index; + } + } + return -1; + } + + /** + * This method is like `_.sortedIndex` except that it returns the highest + * index at which `value` should be inserted into `array` in order to + * maintain its sort order. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * _.sortedLastIndex([4, 5, 5, 5, 6], 5); + * // => 4 + */ + function sortedLastIndex(array, value) { + return baseSortedIndex(array, value, true); + } + + /** + * This method is like `_.sortedLastIndex` except that it accepts `iteratee` + * which is invoked for `value` and each element of `array` to compute their + * sort ranking. The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * var objects = [{ 'x': 4 }, { 'x': 5 }]; + * + * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); + * // => 1 + * + * // The `_.property` iteratee shorthand. + * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x'); + * // => 1 + */ + function sortedLastIndexBy(array, value, iteratee) { + return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true); + } + + /** + * This method is like `_.lastIndexOf` except that it performs a binary + * search on a sorted `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5); + * // => 3 + */ + function sortedLastIndexOf(array, value) { + var length = array == null ? 0 : array.length; + if (length) { + var index = baseSortedIndex(array, value, true) - 1; + if (eq(array[index], value)) { + return index; + } + } + return -1; + } + + /** + * This method is like `_.uniq` except that it's designed and optimized + * for sorted arrays. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * _.sortedUniq([1, 1, 2]); + * // => [1, 2] + */ + function sortedUniq(array) { + return (array && array.length) + ? baseSortedUniq(array) + : []; + } + + /** + * This method is like `_.uniqBy` except that it's designed and optimized + * for sorted arrays. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); + * // => [1.1, 2.3] + */ + function sortedUniqBy(array, iteratee) { + return (array && array.length) + ? baseSortedUniq(array, getIteratee(iteratee, 2)) + : []; + } + + /** + * Gets all but the first element of `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to query. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.tail([1, 2, 3]); + * // => [2, 3] + */ + function tail(array) { + var length = array == null ? 0 : array.length; + return length ? baseSlice(array, 1, length) : []; + } + + /** + * Creates a slice of `array` with `n` elements taken from the beginning. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to take. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.take([1, 2, 3]); + * // => [1] + * + * _.take([1, 2, 3], 2); + * // => [1, 2] + * + * _.take([1, 2, 3], 5); + * // => [1, 2, 3] + * + * _.take([1, 2, 3], 0); + * // => [] + */ + function take(array, n, guard) { + if (!(array && array.length)) { + return []; + } + n = (guard || n === undefined) ? 1 : toInteger(n); + return baseSlice(array, 0, n < 0 ? 0 : n); + } + + /** + * Creates a slice of `array` with `n` elements taken from the end. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to take. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.takeRight([1, 2, 3]); + * // => [3] + * + * _.takeRight([1, 2, 3], 2); + * // => [2, 3] + * + * _.takeRight([1, 2, 3], 5); + * // => [1, 2, 3] + * + * _.takeRight([1, 2, 3], 0); + * // => [] + */ + function takeRight(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined) ? 1 : toInteger(n); + n = length - n; + return baseSlice(array, n < 0 ? 0 : n, length); + } + + /** + * Creates a slice of `array` with elements taken from the end. Elements are + * taken until `predicate` returns falsey. The predicate is invoked with + * three arguments: (value, index, array). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } + * ]; + * + * _.takeRightWhile(users, function(o) { return !o.active; }); + * // => objects for ['fred', 'pebbles'] + * + * // The `_.matches` iteratee shorthand. + * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false }); + * // => objects for ['pebbles'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.takeRightWhile(users, ['active', false]); + * // => objects for ['fred', 'pebbles'] + * + * // The `_.property` iteratee shorthand. + * _.takeRightWhile(users, 'active'); + * // => [] + */ + function takeRightWhile(array, predicate) { + return (array && array.length) + ? baseWhile(array, getIteratee(predicate, 3), false, true) + : []; + } + + /** + * Creates a slice of `array` with elements taken from the beginning. Elements + * are taken until `predicate` returns falsey. The predicate is invoked with + * three arguments: (value, index, array). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } + * ]; + * + * _.takeWhile(users, function(o) { return !o.active; }); + * // => objects for ['barney', 'fred'] + * + * // The `_.matches` iteratee shorthand. + * _.takeWhile(users, { 'user': 'barney', 'active': false }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.takeWhile(users, ['active', false]); + * // => objects for ['barney', 'fred'] + * + * // The `_.property` iteratee shorthand. + * _.takeWhile(users, 'active'); + * // => [] + */ + function takeWhile(array, predicate) { + return (array && array.length) + ? baseWhile(array, getIteratee(predicate, 3)) + : []; + } + + /** + * Creates an array of unique values, in order, from all given arrays using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of combined values. + * @example + * + * _.union([2], [1, 2]); + * // => [2, 1] + */ + var union = baseRest(function(arrays) { + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); + }); + + /** + * This method is like `_.union` except that it accepts `iteratee` which is + * invoked for each element of each `arrays` to generate the criterion by + * which uniqueness is computed. Result values are chosen from the first + * array in which the value occurs. The iteratee is invoked with one argument: + * (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new array of combined values. + * @example + * + * _.unionBy([2.1], [1.2, 2.3], Math.floor); + * // => [2.1, 1.2] + * + * // The `_.property` iteratee shorthand. + * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 1 }, { 'x': 2 }] + */ + var unionBy = baseRest(function(arrays) { + var iteratee = last(arrays); + if (isArrayLikeObject(iteratee)) { + iteratee = undefined; + } + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)); + }); + + /** + * This method is like `_.union` except that it accepts `comparator` which + * is invoked to compare elements of `arrays`. Result values are chosen from + * the first array in which the value occurs. The comparator is invoked + * with two arguments: (arrVal, othVal). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of combined values. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; + * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; + * + * _.unionWith(objects, others, _.isEqual); + * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] + */ + var unionWith = baseRest(function(arrays) { + var comparator = last(arrays); + comparator = typeof comparator == 'function' ? comparator : undefined; + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator); + }); + + /** + * Creates a duplicate-free version of an array, using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons, in which only the first occurrence of each element + * is kept. The order of result values is determined by the order they occur + * in the array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * _.uniq([2, 1, 2]); + * // => [2, 1] + */ + function uniq(array) { + return (array && array.length) ? baseUniq(array) : []; + } + + /** + * This method is like `_.uniq` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the criterion by which + * uniqueness is computed. The order of result values is determined by the + * order they occur in the array. The iteratee is invoked with one argument: + * (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * _.uniqBy([2.1, 1.2, 2.3], Math.floor); + * // => [2.1, 1.2] + * + * // The `_.property` iteratee shorthand. + * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 1 }, { 'x': 2 }] + */ + function uniqBy(array, iteratee) { + return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : []; + } + + /** + * This method is like `_.uniq` except that it accepts `comparator` which + * is invoked to compare elements of `array`. The order of result values is + * determined by the order they occur in the array.The comparator is invoked + * with two arguments: (arrVal, othVal). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; + * + * _.uniqWith(objects, _.isEqual); + * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] + */ + function uniqWith(array, comparator) { + comparator = typeof comparator == 'function' ? comparator : undefined; + return (array && array.length) ? baseUniq(array, undefined, comparator) : []; + } + + /** + * This method is like `_.zip` except that it accepts an array of grouped + * elements and creates an array regrouping the elements to their pre-zip + * configuration. + * + * @static + * @memberOf _ + * @since 1.2.0 + * @category Array + * @param {Array} array The array of grouped elements to process. + * @returns {Array} Returns the new array of regrouped elements. + * @example + * + * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]); + * // => [['a', 1, true], ['b', 2, false]] + * + * _.unzip(zipped); + * // => [['a', 'b'], [1, 2], [true, false]] + */ + function unzip(array) { + if (!(array && array.length)) { + return []; + } + var length = 0; + array = arrayFilter(array, function(group) { + if (isArrayLikeObject(group)) { + length = nativeMax(group.length, length); + return true; + } + }); + return baseTimes(length, function(index) { + return arrayMap(array, baseProperty(index)); + }); + } + + /** + * This method is like `_.unzip` except that it accepts `iteratee` to specify + * how regrouped values should be combined. The iteratee is invoked with the + * elements of each group: (...group). + * + * @static + * @memberOf _ + * @since 3.8.0 + * @category Array + * @param {Array} array The array of grouped elements to process. + * @param {Function} [iteratee=_.identity] The function to combine + * regrouped values. + * @returns {Array} Returns the new array of regrouped elements. + * @example + * + * var zipped = _.zip([1, 2], [10, 20], [100, 200]); + * // => [[1, 10, 100], [2, 20, 200]] + * + * _.unzipWith(zipped, _.add); + * // => [3, 30, 300] + */ + function unzipWith(array, iteratee) { + if (!(array && array.length)) { + return []; + } + var result = unzip(array); + if (iteratee == null) { + return result; + } + return arrayMap(result, function(group) { + return apply(iteratee, undefined, group); + }); + } + + /** + * Creates an array excluding all given values using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * **Note:** Unlike `_.pull`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...*} [values] The values to exclude. + * @returns {Array} Returns the new array of filtered values. + * @see _.difference, _.xor + * @example + * + * _.without([2, 1, 2, 3], 1, 2); + * // => [3] + */ + var without = baseRest(function(array, values) { + return isArrayLikeObject(array) + ? baseDifference(array, values) + : []; + }); + + /** + * Creates an array of unique values that is the + * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) + * of the given arrays. The order of result values is determined by the order + * they occur in the arrays. + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of filtered values. + * @see _.difference, _.without + * @example + * + * _.xor([2, 1], [2, 3]); + * // => [1, 3] + */ + var xor = baseRest(function(arrays) { + return baseXor(arrayFilter(arrays, isArrayLikeObject)); + }); + + /** + * This method is like `_.xor` except that it accepts `iteratee` which is + * invoked for each element of each `arrays` to generate the criterion by + * which by which they're compared. The order of result values is determined + * by the order they occur in the arrays. The iteratee is invoked with one + * argument: (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor); + * // => [1.2, 3.4] + * + * // The `_.property` iteratee shorthand. + * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 2 }] + */ + var xorBy = baseRest(function(arrays) { + var iteratee = last(arrays); + if (isArrayLikeObject(iteratee)) { + iteratee = undefined; + } + return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2)); + }); + + /** + * This method is like `_.xor` except that it accepts `comparator` which is + * invoked to compare elements of `arrays`. The order of result values is + * determined by the order they occur in the arrays. The comparator is invoked + * with two arguments: (arrVal, othVal). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; + * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; + * + * _.xorWith(objects, others, _.isEqual); + * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] + */ + var xorWith = baseRest(function(arrays) { + var comparator = last(arrays); + comparator = typeof comparator == 'function' ? comparator : undefined; + return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator); + }); + + /** + * Creates an array of grouped elements, the first of which contains the + * first elements of the given arrays, the second of which contains the + * second elements of the given arrays, and so on. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to process. + * @returns {Array} Returns the new array of grouped elements. + * @example + * + * _.zip(['a', 'b'], [1, 2], [true, false]); + * // => [['a', 1, true], ['b', 2, false]] + */ + var zip = baseRest(unzip); + + /** + * This method is like `_.fromPairs` except that it accepts two arrays, + * one of property identifiers and one of corresponding values. + * + * @static + * @memberOf _ + * @since 0.4.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @example + * + * _.zipObject(['a', 'b'], [1, 2]); + * // => { 'a': 1, 'b': 2 } + */ + function zipObject(props, values) { + return baseZipObject(props || [], values || [], assignValue); + } + + /** + * This method is like `_.zipObject` except that it supports property paths. + * + * @static + * @memberOf _ + * @since 4.1.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @example + * + * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]); + * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } } + */ + function zipObjectDeep(props, values) { + return baseZipObject(props || [], values || [], baseSet); + } + + /** + * This method is like `_.zip` except that it accepts `iteratee` to specify + * how grouped values should be combined. The iteratee is invoked with the + * elements of each group: (...group). + * + * @static + * @memberOf _ + * @since 3.8.0 + * @category Array + * @param {...Array} [arrays] The arrays to process. + * @param {Function} [iteratee=_.identity] The function to combine + * grouped values. + * @returns {Array} Returns the new array of grouped elements. + * @example + * + * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) { + * return a + b + c; + * }); + * // => [111, 222] + */ + var zipWith = baseRest(function(arrays) { + var length = arrays.length, + iteratee = length > 1 ? arrays[length - 1] : undefined; + + iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined; + return unzipWith(arrays, iteratee); + }); + + /*------------------------------------------------------------------------*/ + + /** + * Creates a `lodash` wrapper instance that wraps `value` with explicit method + * chain sequences enabled. The result of such sequences must be unwrapped + * with `_#value`. + * + * @static + * @memberOf _ + * @since 1.3.0 + * @category Seq + * @param {*} value The value to wrap. + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36 }, + * { 'user': 'fred', 'age': 40 }, + * { 'user': 'pebbles', 'age': 1 } + * ]; + * + * var youngest = _ + * .chain(users) + * .sortBy('age') + * .map(function(o) { + * return o.user + ' is ' + o.age; + * }) + * .head() + * .value(); + * // => 'pebbles is 1' + */ + function chain(value) { + var result = lodash(value); + result.__chain__ = true; + return result; + } + + /** + * This method invokes `interceptor` and returns `value`. The interceptor + * is invoked with one argument; (value). The purpose of this method is to + * "tap into" a method chain sequence in order to modify intermediate results. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Seq + * @param {*} value The value to provide to `interceptor`. + * @param {Function} interceptor The function to invoke. + * @returns {*} Returns `value`. + * @example + * + * _([1, 2, 3]) + * .tap(function(array) { + * // Mutate input array. + * array.pop(); + * }) + * .reverse() + * .value(); + * // => [2, 1] + */ + function tap(value, interceptor) { + interceptor(value); + return value; + } + + /** + * This method is like `_.tap` except that it returns the result of `interceptor`. + * The purpose of this method is to "pass thru" values replacing intermediate + * results in a method chain sequence. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Seq + * @param {*} value The value to provide to `interceptor`. + * @param {Function} interceptor The function to invoke. + * @returns {*} Returns the result of `interceptor`. + * @example + * + * _(' abc ') + * .chain() + * .trim() + * .thru(function(value) { + * return [value]; + * }) + * .value(); + * // => ['abc'] + */ + function thru(value, interceptor) { + return interceptor(value); + } + + /** + * This method is the wrapper version of `_.at`. + * + * @name at + * @memberOf _ + * @since 1.0.0 + * @category Seq + * @param {...(string|string[])} [paths] The property paths to pick. + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; + * + * _(object).at(['a[0].b.c', 'a[1]']).value(); + * // => [3, 4] + */ + var wrapperAt = flatRest(function(paths) { + var length = paths.length, + start = length ? paths[0] : 0, + value = this.__wrapped__, + interceptor = function(object) { return baseAt(object, paths); }; + + if (length > 1 || this.__actions__.length || + !(value instanceof LazyWrapper) || !isIndex(start)) { + return this.thru(interceptor); + } + value = value.slice(start, +start + (length ? 1 : 0)); + value.__actions__.push({ + 'func': thru, + 'args': [interceptor], + 'thisArg': undefined + }); + return new LodashWrapper(value, this.__chain__).thru(function(array) { + if (length && !array.length) { + array.push(undefined); + } + return array; + }); + }); + + /** + * Creates a `lodash` wrapper instance with explicit method chain sequences enabled. + * + * @name chain + * @memberOf _ + * @since 0.1.0 + * @category Seq + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36 }, + * { 'user': 'fred', 'age': 40 } + * ]; + * + * // A sequence without explicit chaining. + * _(users).head(); + * // => { 'user': 'barney', 'age': 36 } + * + * // A sequence with explicit chaining. + * _(users) + * .chain() + * .head() + * .pick('user') + * .value(); + * // => { 'user': 'barney' } + */ + function wrapperChain() { + return chain(this); + } + + /** + * Executes the chain sequence and returns the wrapped result. + * + * @name commit + * @memberOf _ + * @since 3.2.0 + * @category Seq + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var array = [1, 2]; + * var wrapped = _(array).push(3); + * + * console.log(array); + * // => [1, 2] + * + * wrapped = wrapped.commit(); + * console.log(array); + * // => [1, 2, 3] + * + * wrapped.last(); + * // => 3 + * + * console.log(array); + * // => [1, 2, 3] + */ + function wrapperCommit() { + return new LodashWrapper(this.value(), this.__chain__); + } + + /** + * Gets the next value on a wrapped object following the + * [iterator protocol](https://mdn.io/iteration_protocols#iterator). + * + * @name next + * @memberOf _ + * @since 4.0.0 + * @category Seq + * @returns {Object} Returns the next iterator value. + * @example + * + * var wrapped = _([1, 2]); + * + * wrapped.next(); + * // => { 'done': false, 'value': 1 } + * + * wrapped.next(); + * // => { 'done': false, 'value': 2 } + * + * wrapped.next(); + * // => { 'done': true, 'value': undefined } + */ + function wrapperNext() { + if (this.__values__ === undefined) { + this.__values__ = toArray(this.value()); + } + var done = this.__index__ >= this.__values__.length, + value = done ? undefined : this.__values__[this.__index__++]; + + return { 'done': done, 'value': value }; + } + + /** + * Enables the wrapper to be iterable. + * + * @name Symbol.iterator + * @memberOf _ + * @since 4.0.0 + * @category Seq + * @returns {Object} Returns the wrapper object. + * @example + * + * var wrapped = _([1, 2]); + * + * wrapped[Symbol.iterator]() === wrapped; + * // => true + * + * Array.from(wrapped); + * // => [1, 2] + */ + function wrapperToIterator() { + return this; + } + + /** + * Creates a clone of the chain sequence planting `value` as the wrapped value. + * + * @name plant + * @memberOf _ + * @since 3.2.0 + * @category Seq + * @param {*} value The value to plant. + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * function square(n) { + * return n * n; + * } + * + * var wrapped = _([1, 2]).map(square); + * var other = wrapped.plant([3, 4]); + * + * other.value(); + * // => [9, 16] + * + * wrapped.value(); + * // => [1, 4] + */ + function wrapperPlant(value) { + var result, + parent = this; + + while (parent instanceof baseLodash) { + var clone = wrapperClone(parent); + clone.__index__ = 0; + clone.__values__ = undefined; + if (result) { + previous.__wrapped__ = clone; + } else { + result = clone; + } + var previous = clone; + parent = parent.__wrapped__; + } + previous.__wrapped__ = value; + return result; + } + + /** + * This method is the wrapper version of `_.reverse`. + * + * **Note:** This method mutates the wrapped array. + * + * @name reverse + * @memberOf _ + * @since 0.1.0 + * @category Seq + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var array = [1, 2, 3]; + * + * _(array).reverse().value() + * // => [3, 2, 1] + * + * console.log(array); + * // => [3, 2, 1] + */ + function wrapperReverse() { + var value = this.__wrapped__; + if (value instanceof LazyWrapper) { + var wrapped = value; + if (this.__actions__.length) { + wrapped = new LazyWrapper(this); + } + wrapped = wrapped.reverse(); + wrapped.__actions__.push({ + 'func': thru, + 'args': [reverse], + 'thisArg': undefined + }); + return new LodashWrapper(wrapped, this.__chain__); + } + return this.thru(reverse); + } + + /** + * Executes the chain sequence to resolve the unwrapped value. + * + * @name value + * @memberOf _ + * @since 0.1.0 + * @alias toJSON, valueOf + * @category Seq + * @returns {*} Returns the resolved unwrapped value. + * @example + * + * _([1, 2, 3]).value(); + * // => [1, 2, 3] + */ + function wrapperValue() { + return baseWrapperValue(this.__wrapped__, this.__actions__); + } + + /*------------------------------------------------------------------------*/ + + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the number of times the key was returned by `iteratee`. The + * iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.countBy([6.1, 4.2, 6.3], Math.floor); + * // => { '4': 1, '6': 2 } + * + * // The `_.property` iteratee shorthand. + * _.countBy(['one', 'two', 'three'], 'length'); + * // => { '3': 2, '5': 1 } + */ + var countBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + ++result[key]; + } else { + baseAssignValue(result, key, 1); + } + }); + + /** + * Checks if `predicate` returns truthy for **all** elements of `collection`. + * Iteration is stopped once `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index|key, collection). + * + * **Note:** This method returns `true` for + * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because + * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of + * elements of empty collections. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. + * @example + * + * _.every([true, 1, null, 'yes'], Boolean); + * // => false + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': false } + * ]; + * + * // The `_.matches` iteratee shorthand. + * _.every(users, { 'user': 'barney', 'active': false }); + * // => false + * + * // The `_.matchesProperty` iteratee shorthand. + * _.every(users, ['active', false]); + * // => true + * + * // The `_.property` iteratee shorthand. + * _.every(users, 'active'); + * // => false + */ + function every(collection, predicate, guard) { + var func = isArray(collection) ? arrayEvery : baseEvery; + if (guard && isIterateeCall(collection, predicate, guard)) { + predicate = undefined; + } + return func(collection, getIteratee(predicate, 3)); + } + + /** + * Iterates over elements of `collection`, returning an array of all elements + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index|key, collection). + * + * **Note:** Unlike `_.remove`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see _.reject + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } + * ]; + * + * _.filter(users, function(o) { return !o.active; }); + * // => objects for ['fred'] + * + * // The `_.matches` iteratee shorthand. + * _.filter(users, { 'age': 36, 'active': true }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.filter(users, ['active', false]); + * // => objects for ['fred'] + * + * // The `_.property` iteratee shorthand. + * _.filter(users, 'active'); + * // => objects for ['barney'] + */ + function filter(collection, predicate) { + var func = isArray(collection) ? arrayFilter : baseFilter; + return func(collection, getIteratee(predicate, 3)); + } + + /** + * Iterates over elements of `collection`, returning the first element + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index|key, collection). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param {number} [fromIndex=0] The index to search from. + * @returns {*} Returns the matched element, else `undefined`. + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false }, + * { 'user': 'pebbles', 'age': 1, 'active': true } + * ]; + * + * _.find(users, function(o) { return o.age < 40; }); + * // => object for 'barney' + * + * // The `_.matches` iteratee shorthand. + * _.find(users, { 'age': 1, 'active': true }); + * // => object for 'pebbles' + * + * // The `_.matchesProperty` iteratee shorthand. + * _.find(users, ['active', false]); + * // => object for 'fred' + * + * // The `_.property` iteratee shorthand. + * _.find(users, 'active'); + * // => object for 'barney' + */ + var find = createFind(findIndex); + + /** + * This method is like `_.find` except that it iterates over elements of + * `collection` from right to left. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Collection + * @param {Array|Object} collection The collection to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param {number} [fromIndex=collection.length-1] The index to search from. + * @returns {*} Returns the matched element, else `undefined`. + * @example + * + * _.findLast([1, 2, 3, 4], function(n) { + * return n % 2 == 1; + * }); + * // => 3 + */ + var findLast = createFind(findLastIndex); + + /** + * Creates a flattened array of values by running each element in `collection` + * thru `iteratee` and flattening the mapped results. The iteratee is invoked + * with three arguments: (value, index|key, collection). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [n, n]; + * } + * + * _.flatMap([1, 2], duplicate); + * // => [1, 1, 2, 2] + */ + function flatMap(collection, iteratee) { + return baseFlatten(map(collection, iteratee), 1); + } + + /** + * This method is like `_.flatMap` except that it recursively flattens the + * mapped results. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [[[n, n]]]; + * } + * + * _.flatMapDeep([1, 2], duplicate); + * // => [1, 1, 2, 2] + */ + function flatMapDeep(collection, iteratee) { + return baseFlatten(map(collection, iteratee), INFINITY); + } + + /** + * This method is like `_.flatMap` except that it recursively flattens the + * mapped results up to `depth` times. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [[[n, n]]]; + * } + * + * _.flatMapDepth([1, 2], duplicate, 2); + * // => [[1, 1], [2, 2]] + */ + function flatMapDepth(collection, iteratee, depth) { + depth = depth === undefined ? 1 : toInteger(depth); + return baseFlatten(map(collection, iteratee), depth); + } + + /** + * Iterates over elements of `collection` and invokes `iteratee` for each element. + * The iteratee is invoked with three arguments: (value, index|key, collection). + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * **Note:** As with other "Collections" methods, objects with a "length" + * property are iterated like arrays. To avoid this behavior use `_.forIn` + * or `_.forOwn` for object iteration. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @alias each + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + * @see _.forEachRight + * @example + * + * _.forEach([1, 2], function(value) { + * console.log(value); + * }); + * // => Logs `1` then `2`. + * + * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { + * console.log(key); + * }); + * // => Logs 'a' then 'b' (iteration order is not guaranteed). + */ + function forEach(collection, iteratee) { + var func = isArray(collection) ? arrayEach : baseEach; + return func(collection, getIteratee(iteratee, 3)); + } + + /** + * This method is like `_.forEach` except that it iterates over elements of + * `collection` from right to left. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @alias eachRight + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + * @see _.forEach + * @example + * + * _.forEachRight([1, 2], function(value) { + * console.log(value); + * }); + * // => Logs `2` then `1`. + */ + function forEachRight(collection, iteratee) { + var func = isArray(collection) ? arrayEachRight : baseEachRight; + return func(collection, getIteratee(iteratee, 3)); + } + + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The order of grouped values + * is determined by the order they occur in `collection`. The corresponding + * value of each key is an array of elements responsible for generating the + * key. The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.groupBy([6.1, 4.2, 6.3], Math.floor); + * // => { '4': [4.2], '6': [6.1, 6.3] } + * + * // The `_.property` iteratee shorthand. + * _.groupBy(['one', 'two', 'three'], 'length'); + * // => { '3': ['one', 'two'], '5': ['three'] } + */ + var groupBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + result[key].push(value); + } else { + baseAssignValue(result, key, [value]); + } + }); + + /** + * Checks if `value` is in `collection`. If `collection` is a string, it's + * checked for a substring of `value`, otherwise + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * is used for equality comparisons. If `fromIndex` is negative, it's used as + * the offset from the end of `collection`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object|string} collection The collection to inspect. + * @param {*} value The value to search for. + * @param {number} [fromIndex=0] The index to search from. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. + * @returns {boolean} Returns `true` if `value` is found, else `false`. + * @example + * + * _.includes([1, 2, 3], 1); + * // => true + * + * _.includes([1, 2, 3], 1, 2); + * // => false + * + * _.includes({ 'a': 1, 'b': 2 }, 1); + * // => true + * + * _.includes('abcd', 'bc'); + * // => true + */ + function includes(collection, value, fromIndex, guard) { + collection = isArrayLike(collection) ? collection : values(collection); + fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0; + + var length = collection.length; + if (fromIndex < 0) { + fromIndex = nativeMax(length + fromIndex, 0); + } + return isString(collection) + ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1) + : (!!length && baseIndexOf(collection, value, fromIndex) > -1); + } + + /** + * Invokes the method at `path` of each element in `collection`, returning + * an array of the results of each invoked method. Any additional arguments + * are provided to each invoked method. If `path` is a function, it's invoked + * for, and `this` bound to, each element in `collection`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array|Function|string} path The path of the method to invoke or + * the function invoked per iteration. + * @param {...*} [args] The arguments to invoke each method with. + * @returns {Array} Returns the array of results. + * @example + * + * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort'); + * // => [[1, 5, 7], [1, 2, 3]] + * + * _.invokeMap([123, 456], String.prototype.split, ''); + * // => [['1', '2', '3'], ['4', '5', '6']] + */ + var invokeMap = baseRest(function(collection, path, args) { + var index = -1, + isFunc = typeof path == 'function', + result = isArrayLike(collection) ? Array(collection.length) : []; + + baseEach(collection, function(value) { + result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args); + }); + return result; + }); + + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the last element responsible for generating the key. The + * iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * var array = [ + * { 'dir': 'left', 'code': 97 }, + * { 'dir': 'right', 'code': 100 } + * ]; + * + * _.keyBy(array, function(o) { + * return String.fromCharCode(o.code); + * }); + * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } + * + * _.keyBy(array, 'dir'); + * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } + */ + var keyBy = createAggregator(function(result, value, key) { + baseAssignValue(result, key, value); + }); + + /** + * Creates an array of values by running each element in `collection` thru + * `iteratee`. The iteratee is invoked with three arguments: + * (value, index|key, collection). + * + * Many lodash methods are guarded to work as iteratees for methods like + * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. + * + * The guarded methods are: + * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, + * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`, + * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`, + * `template`, `trim`, `trimEnd`, `trimStart`, and `words` + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + * @example + * + * function square(n) { + * return n * n; + * } + * + * _.map([4, 8], square); + * // => [16, 64] + * + * _.map({ 'a': 4, 'b': 8 }, square); + * // => [16, 64] (iteration order is not guaranteed) + * + * var users = [ + * { 'user': 'barney' }, + * { 'user': 'fred' } + * ]; + * + * // The `_.property` iteratee shorthand. + * _.map(users, 'user'); + * // => ['barney', 'fred'] + */ + function map(collection, iteratee) { + var func = isArray(collection) ? arrayMap : baseMap; + return func(collection, getIteratee(iteratee, 3)); + } + + /** + * This method is like `_.sortBy` except that it allows specifying the sort + * orders of the iteratees to sort by. If `orders` is unspecified, all values + * are sorted in ascending order. Otherwise, specify an order of "desc" for + * descending or "asc" for ascending sort order of corresponding values. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]] + * The iteratees to sort by. + * @param {string[]} [orders] The sort orders of `iteratees`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. + * @returns {Array} Returns the new sorted array. + * @example + * + * var users = [ + * { 'user': 'fred', 'age': 48 }, + * { 'user': 'barney', 'age': 34 }, + * { 'user': 'fred', 'age': 40 }, + * { 'user': 'barney', 'age': 36 } + * ]; + * + * // Sort by `user` in ascending order and by `age` in descending order. + * _.orderBy(users, ['user', 'age'], ['asc', 'desc']); + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] + */ + function orderBy(collection, iteratees, orders, guard) { + if (collection == null) { + return []; + } + if (!isArray(iteratees)) { + iteratees = iteratees == null ? [] : [iteratees]; + } + orders = guard ? undefined : orders; + if (!isArray(orders)) { + orders = orders == null ? [] : [orders]; + } + return baseOrderBy(collection, iteratees, orders); + } + + /** + * Creates an array of elements split into two groups, the first of which + * contains elements `predicate` returns truthy for, the second of which + * contains elements `predicate` returns falsey for. The predicate is + * invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the array of grouped elements. + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true }, + * { 'user': 'pebbles', 'age': 1, 'active': false } + * ]; + * + * _.partition(users, function(o) { return o.active; }); + * // => objects for [['fred'], ['barney', 'pebbles']] + * + * // The `_.matches` iteratee shorthand. + * _.partition(users, { 'age': 1, 'active': false }); + * // => objects for [['pebbles'], ['barney', 'fred']] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.partition(users, ['active', false]); + * // => objects for [['barney', 'pebbles'], ['fred']] + * + * // The `_.property` iteratee shorthand. + * _.partition(users, 'active'); + * // => objects for [['fred'], ['barney', 'pebbles']] + */ + var partition = createAggregator(function(result, value, key) { + result[key ? 0 : 1].push(value); + }, function() { return [[], []]; }); + + /** + * Reduces `collection` to a value which is the accumulated result of running + * each element in `collection` thru `iteratee`, where each successive + * invocation is supplied the return value of the previous. If `accumulator` + * is not given, the first element of `collection` is used as the initial + * value. The iteratee is invoked with four arguments: + * (accumulator, value, index|key, collection). + * + * Many lodash methods are guarded to work as iteratees for methods like + * `_.reduce`, `_.reduceRight`, and `_.transform`. + * + * The guarded methods are: + * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, + * and `sortBy` + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @returns {*} Returns the accumulated value. + * @see _.reduceRight + * @example + * + * _.reduce([1, 2], function(sum, n) { + * return sum + n; + * }, 0); + * // => 3 + * + * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { + * (result[value] || (result[value] = [])).push(key); + * return result; + * }, {}); + * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) + */ + function reduce(collection, iteratee, accumulator) { + var func = isArray(collection) ? arrayReduce : baseReduce, + initAccum = arguments.length < 3; + + return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach); + } + + /** + * This method is like `_.reduce` except that it iterates over elements of + * `collection` from right to left. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @returns {*} Returns the accumulated value. + * @see _.reduce + * @example + * + * var array = [[0, 1], [2, 3], [4, 5]]; + * + * _.reduceRight(array, function(flattened, other) { + * return flattened.concat(other); + * }, []); + * // => [4, 5, 2, 3, 0, 1] + */ + function reduceRight(collection, iteratee, accumulator) { + var func = isArray(collection) ? arrayReduceRight : baseReduce, + initAccum = arguments.length < 3; + + return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight); + } + + /** + * The opposite of `_.filter`; this method returns the elements of `collection` + * that `predicate` does **not** return truthy for. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see _.filter + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true } + * ]; + * + * _.reject(users, function(o) { return !o.active; }); + * // => objects for ['fred'] + * + * // The `_.matches` iteratee shorthand. + * _.reject(users, { 'age': 40, 'active': true }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.reject(users, ['active', false]); + * // => objects for ['fred'] + * + * // The `_.property` iteratee shorthand. + * _.reject(users, 'active'); + * // => objects for ['barney'] + */ + function reject(collection, predicate) { + var func = isArray(collection) ? arrayFilter : baseFilter; + return func(collection, negate(getIteratee(predicate, 3))); + } + + /** + * Gets a random element from `collection`. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Collection + * @param {Array|Object} collection The collection to sample. + * @returns {*} Returns the random element. + * @example + * + * _.sample([1, 2, 3, 4]); + * // => 2 + */ + function sample(collection) { + var func = isArray(collection) ? arraySample : baseSample; + return func(collection); + } + + /** + * Gets `n` random elements at unique keys from `collection` up to the + * size of `collection`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to sample. + * @param {number} [n=1] The number of elements to sample. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the random elements. + * @example + * + * _.sampleSize([1, 2, 3], 2); + * // => [3, 1] + * + * _.sampleSize([1, 2, 3], 4); + * // => [2, 3, 1] + */ + function sampleSize(collection, n, guard) { + if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) { + n = 1; + } else { + n = toInteger(n); + } + var func = isArray(collection) ? arraySampleSize : baseSampleSize; + return func(collection, n); + } + + /** + * Creates an array of shuffled values, using a version of the + * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to shuffle. + * @returns {Array} Returns the new shuffled array. + * @example + * + * _.shuffle([1, 2, 3, 4]); + * // => [4, 1, 3, 2] + */ + function shuffle(collection) { + var func = isArray(collection) ? arrayShuffle : baseShuffle; + return func(collection); + } + + /** + * Gets the size of `collection` by returning its length for array-like + * values or the number of own enumerable string keyed properties for objects. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object|string} collection The collection to inspect. + * @returns {number} Returns the collection size. + * @example + * + * _.size([1, 2, 3]); + * // => 3 + * + * _.size({ 'a': 1, 'b': 2 }); + * // => 2 + * + * _.size('pebbles'); + * // => 7 + */ + function size(collection) { + if (collection == null) { + return 0; + } + if (isArrayLike(collection)) { + return isString(collection) ? stringSize(collection) : collection.length; + } + var tag = getTag(collection); + if (tag == mapTag || tag == setTag) { + return collection.size; + } + return baseKeys(collection).length; + } + + /** + * Checks if `predicate` returns truthy for **any** element of `collection`. + * Iteration is stopped once `predicate` returns truthy. The predicate is + * invoked with three arguments: (value, index|key, collection). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + * @example + * + * _.some([null, 0, 'yes', false], Boolean); + * // => true + * + * var users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false } + * ]; + * + * // The `_.matches` iteratee shorthand. + * _.some(users, { 'user': 'barney', 'active': false }); + * // => false + * + * // The `_.matchesProperty` iteratee shorthand. + * _.some(users, ['active', false]); + * // => true + * + * // The `_.property` iteratee shorthand. + * _.some(users, 'active'); + * // => true + */ + function some(collection, predicate, guard) { + var func = isArray(collection) ? arraySome : baseSome; + if (guard && isIterateeCall(collection, predicate, guard)) { + predicate = undefined; + } + return func(collection, getIteratee(predicate, 3)); + } + + /** + * Creates an array of elements, sorted in ascending order by the results of + * running each element in a collection thru each iteratee. This method + * performs a stable sort, that is, it preserves the original sort order of + * equal elements. The iteratees are invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {...(Function|Function[])} [iteratees=[_.identity]] + * The iteratees to sort by. + * @returns {Array} Returns the new sorted array. + * @example + * + * var users = [ + * { 'user': 'fred', 'age': 48 }, + * { 'user': 'barney', 'age': 36 }, + * { 'user': 'fred', 'age': 40 }, + * { 'user': 'barney', 'age': 34 } + * ]; + * + * _.sortBy(users, [function(o) { return o.user; }]); + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] + * + * _.sortBy(users, ['user', 'age']); + * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]] + */ + var sortBy = baseRest(function(collection, iteratees) { + if (collection == null) { + return []; + } + var length = iteratees.length; + if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) { + iteratees = []; + } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { + iteratees = [iteratees[0]]; + } + return baseOrderBy(collection, baseFlatten(iteratees, 1), []); + }); + + /*------------------------------------------------------------------------*/ + + /** + * Gets the timestamp of the number of milliseconds that have elapsed since + * the Unix epoch (1 January 1970 00:00:00 UTC). + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Date + * @returns {number} Returns the timestamp. + * @example + * + * _.defer(function(stamp) { + * console.log(_.now() - stamp); + * }, _.now()); + * // => Logs the number of milliseconds it took for the deferred invocation. + */ + var now = ctxNow || function() { + return root.Date.now(); + }; + + /*------------------------------------------------------------------------*/ + + /** + * The opposite of `_.before`; this method creates a function that invokes + * `func` once it's called `n` or more times. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {number} n The number of calls before `func` is invoked. + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * var saves = ['profile', 'settings']; + * + * var done = _.after(saves.length, function() { + * console.log('done saving!'); + * }); + * + * _.forEach(saves, function(type) { + * asyncSave({ 'type': type, 'complete': done }); + * }); + * // => Logs 'done saving!' after the two async saves have completed. + */ + function after(n, func) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + n = toInteger(n); + return function() { + if (--n < 1) { + return func.apply(this, arguments); + } + }; + } + + /** + * Creates a function that invokes `func`, with up to `n` arguments, + * ignoring any additional arguments. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {Function} func The function to cap arguments for. + * @param {number} [n=func.length] The arity cap. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Function} Returns the new capped function. + * @example + * + * _.map(['6', '8', '10'], _.ary(parseInt, 1)); + * // => [6, 8, 10] + */ + function ary(func, n, guard) { + n = guard ? undefined : n; + n = (func && n == null) ? func.length : n; + return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n); + } + + /** + * Creates a function that invokes `func`, with the `this` binding and arguments + * of the created function, while it's called less than `n` times. Subsequent + * calls to the created function return the result of the last `func` invocation. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {number} n The number of calls at which `func` is no longer invoked. + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * jQuery(element).on('click', _.before(5, addContactToList)); + * // => Allows adding up to 4 contacts to the list. + */ + function before(n, func) { + var result; + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + n = toInteger(n); + return function() { + if (--n > 0) { + result = func.apply(this, arguments); + } + if (n <= 1) { + func = undefined; + } + return result; + }; + } + + /** + * Creates a function that invokes `func` with the `this` binding of `thisArg` + * and `partials` prepended to the arguments it receives. + * + * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, + * may be used as a placeholder for partially applied arguments. + * + * **Note:** Unlike native `Function#bind`, this method doesn't set the "length" + * property of bound functions. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to bind. + * @param {*} thisArg The `this` binding of `func`. + * @param {...*} [partials] The arguments to be partially applied. + * @returns {Function} Returns the new bound function. + * @example + * + * function greet(greeting, punctuation) { + * return greeting + ' ' + this.user + punctuation; + * } + * + * var object = { 'user': 'fred' }; + * + * var bound = _.bind(greet, object, 'hi'); + * bound('!'); + * // => 'hi fred!' + * + * // Bound with placeholders. + * var bound = _.bind(greet, object, _, '!'); + * bound('hi'); + * // => 'hi fred!' + */ + var bind = baseRest(function(func, thisArg, partials) { + var bitmask = WRAP_BIND_FLAG; + if (partials.length) { + var holders = replaceHolders(partials, getHolder(bind)); + bitmask |= WRAP_PARTIAL_FLAG; + } + return createWrap(func, bitmask, thisArg, partials, holders); + }); + + /** + * Creates a function that invokes the method at `object[key]` with `partials` + * prepended to the arguments it receives. + * + * This method differs from `_.bind` by allowing bound functions to reference + * methods that may be redefined or don't yet exist. See + * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) + * for more details. + * + * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic + * builds, may be used as a placeholder for partially applied arguments. + * + * @static + * @memberOf _ + * @since 0.10.0 + * @category Function + * @param {Object} object The object to invoke the method on. + * @param {string} key The key of the method. + * @param {...*} [partials] The arguments to be partially applied. + * @returns {Function} Returns the new bound function. + * @example + * + * var object = { + * 'user': 'fred', + * 'greet': function(greeting, punctuation) { + * return greeting + ' ' + this.user + punctuation; + * } + * }; + * + * var bound = _.bindKey(object, 'greet', 'hi'); + * bound('!'); + * // => 'hi fred!' + * + * object.greet = function(greeting, punctuation) { + * return greeting + 'ya ' + this.user + punctuation; + * }; + * + * bound('!'); + * // => 'hiya fred!' + * + * // Bound with placeholders. + * var bound = _.bindKey(object, 'greet', _, '!'); + * bound('hi'); + * // => 'hiya fred!' + */ + var bindKey = baseRest(function(object, key, partials) { + var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG; + if (partials.length) { + var holders = replaceHolders(partials, getHolder(bindKey)); + bitmask |= WRAP_PARTIAL_FLAG; + } + return createWrap(key, bitmask, object, partials, holders); + }); + + /** + * Creates a function that accepts arguments of `func` and either invokes + * `func` returning its result, if at least `arity` number of arguments have + * been provided, or returns a function that accepts the remaining `func` + * arguments, and so on. The arity of `func` may be specified if `func.length` + * is not sufficient. + * + * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, + * may be used as a placeholder for provided arguments. + * + * **Note:** This method doesn't set the "length" property of curried functions. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Function + * @param {Function} func The function to curry. + * @param {number} [arity=func.length] The arity of `func`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Function} Returns the new curried function. + * @example + * + * var abc = function(a, b, c) { + * return [a, b, c]; + * }; + * + * var curried = _.curry(abc); + * + * curried(1)(2)(3); + * // => [1, 2, 3] + * + * curried(1, 2)(3); + * // => [1, 2, 3] + * + * curried(1, 2, 3); + * // => [1, 2, 3] + * + * // Curried with placeholders. + * curried(1)(_, 3)(2); + * // => [1, 2, 3] + */ + function curry(func, arity, guard) { + arity = guard ? undefined : arity; + var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); + result.placeholder = curry.placeholder; + return result; + } + + /** + * This method is like `_.curry` except that arguments are applied to `func` + * in the manner of `_.partialRight` instead of `_.partial`. + * + * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic + * builds, may be used as a placeholder for provided arguments. + * + * **Note:** This method doesn't set the "length" property of curried functions. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {Function} func The function to curry. + * @param {number} [arity=func.length] The arity of `func`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Function} Returns the new curried function. + * @example + * + * var abc = function(a, b, c) { + * return [a, b, c]; + * }; + * + * var curried = _.curryRight(abc); + * + * curried(3)(2)(1); + * // => [1, 2, 3] + * + * curried(2, 3)(1); + * // => [1, 2, 3] + * + * curried(1, 2, 3); + * // => [1, 2, 3] + * + * // Curried with placeholders. + * curried(3)(1, _)(2); + * // => [1, 2, 3] + */ + function curryRight(func, arity, guard) { + arity = guard ? undefined : arity; + var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); + result.placeholder = curryRight.placeholder; + return result; + } + + /** + * Creates a debounced function that delays invoking `func` until after `wait` + * milliseconds have elapsed since the last time the debounced function was + * invoked. The debounced function comes with a `cancel` method to cancel + * delayed `func` invocations and a `flush` method to immediately invoke them. + * Provide `options` to indicate whether `func` should be invoked on the + * leading and/or trailing edge of the `wait` timeout. The `func` is invoked + * with the last arguments provided to the debounced function. Subsequent + * calls to the debounced function return the result of the last `func` + * invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the debounced function + * is invoked more than once during the `wait` timeout. + * + * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred + * until to the next tick, similar to `setTimeout` with a timeout of `0`. + * + * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) + * for details over the differences between `_.debounce` and `_.throttle`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to debounce. + * @param {number} [wait=0] The number of milliseconds to delay. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=false] + * Specify invoking on the leading edge of the timeout. + * @param {number} [options.maxWait] + * The maximum time `func` is allowed to be delayed before it's invoked. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. + * @returns {Function} Returns the new debounced function. + * @example + * + * // Avoid costly calculations while the window size is in flux. + * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); + * + * // Invoke `sendMail` when clicked, debouncing subsequent calls. + * jQuery(element).on('click', _.debounce(sendMail, 300, { + * 'leading': true, + * 'trailing': false + * })); + * + * // Ensure `batchLog` is invoked once after 1 second of debounced calls. + * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); + * var source = new EventSource('/stream'); + * jQuery(source).on('message', debounced); + * + * // Cancel the trailing debounced invocation. + * jQuery(window).on('popstate', debounced.cancel); + */ + function debounce(func, wait, options) { + var lastArgs, + lastThis, + maxWait, + result, + timerId, + lastCallTime, + lastInvokeTime = 0, + leading = false, + maxing = false, + trailing = true; + + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + wait = toNumber(wait) || 0; + if (isObject(options)) { + leading = !!options.leading; + maxing = 'maxWait' in options; + maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait; + trailing = 'trailing' in options ? !!options.trailing : trailing; + } + + function invokeFunc(time) { + var args = lastArgs, + thisArg = lastThis; + + lastArgs = lastThis = undefined; + lastInvokeTime = time; + result = func.apply(thisArg, args); + return result; + } + + function leadingEdge(time) { + // Reset any `maxWait` timer. + lastInvokeTime = time; + // Start the timer for the trailing edge. + timerId = setTimeout(timerExpired, wait); + // Invoke the leading edge. + return leading ? invokeFunc(time) : result; + } + + function remainingWait(time) { + var timeSinceLastCall = time - lastCallTime, + timeSinceLastInvoke = time - lastInvokeTime, + timeWaiting = wait - timeSinceLastCall; + + return maxing + ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) + : timeWaiting; + } + + function shouldInvoke(time) { + var timeSinceLastCall = time - lastCallTime, + timeSinceLastInvoke = time - lastInvokeTime; + + // Either this is the first call, activity has stopped and we're at the + // trailing edge, the system time has gone backwards and we're treating + // it as the trailing edge, or we've hit the `maxWait` limit. + return (lastCallTime === undefined || (timeSinceLastCall >= wait) || + (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait)); + } + + function timerExpired() { + var time = now(); + if (shouldInvoke(time)) { + return trailingEdge(time); + } + // Restart the timer. + timerId = setTimeout(timerExpired, remainingWait(time)); + } + + function trailingEdge(time) { + timerId = undefined; + + // Only invoke if we have `lastArgs` which means `func` has been + // debounced at least once. + if (trailing && lastArgs) { + return invokeFunc(time); + } + lastArgs = lastThis = undefined; + return result; + } + + function cancel() { + if (timerId !== undefined) { + clearTimeout(timerId); + } + lastInvokeTime = 0; + lastArgs = lastCallTime = lastThis = timerId = undefined; + } + + function flush() { + return timerId === undefined ? result : trailingEdge(now()); + } + + function debounced() { + var time = now(), + isInvoking = shouldInvoke(time); + + lastArgs = arguments; + lastThis = this; + lastCallTime = time; + + if (isInvoking) { + if (timerId === undefined) { + return leadingEdge(lastCallTime); + } + if (maxing) { + // Handle invocations in a tight loop. + timerId = setTimeout(timerExpired, wait); + return invokeFunc(lastCallTime); + } + } + if (timerId === undefined) { + timerId = setTimeout(timerExpired, wait); + } + return result; + } + debounced.cancel = cancel; + debounced.flush = flush; + return debounced; + } + + /** + * Defers invoking the `func` until the current call stack has cleared. Any + * additional arguments are provided to `func` when it's invoked. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to defer. + * @param {...*} [args] The arguments to invoke `func` with. + * @returns {number} Returns the timer id. + * @example + * + * _.defer(function(text) { + * console.log(text); + * }, 'deferred'); + * // => Logs 'deferred' after one millisecond. + */ + var defer = baseRest(function(func, args) { + return baseDelay(func, 1, args); + }); + + /** + * Invokes `func` after `wait` milliseconds. Any additional arguments are + * provided to `func` when it's invoked. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to delay. + * @param {number} wait The number of milliseconds to delay invocation. + * @param {...*} [args] The arguments to invoke `func` with. + * @returns {number} Returns the timer id. + * @example + * + * _.delay(function(text) { + * console.log(text); + * }, 1000, 'later'); + * // => Logs 'later' after one second. + */ + var delay = baseRest(function(func, wait, args) { + return baseDelay(func, toNumber(wait) || 0, args); + }); + + /** + * Creates a function that invokes `func` with arguments reversed. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Function + * @param {Function} func The function to flip arguments for. + * @returns {Function} Returns the new flipped function. + * @example + * + * var flipped = _.flip(function() { + * return _.toArray(arguments); + * }); + * + * flipped('a', 'b', 'c', 'd'); + * // => ['d', 'c', 'b', 'a'] + */ + function flip(func) { + return createWrap(func, WRAP_FLIP_FLAG); + } + + /** + * Creates a function that memoizes the result of `func`. If `resolver` is + * provided, it determines the cache key for storing the result based on the + * arguments provided to the memoized function. By default, the first argument + * provided to the memoized function is used as the map cache key. The `func` + * is invoked with the `this` binding of the memoized function. + * + * **Note:** The cache is exposed as the `cache` property on the memoized + * function. Its creation may be customized by replacing the `_.memoize.Cache` + * constructor with one whose instances implement the + * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) + * method interface of `clear`, `delete`, `get`, `has`, and `set`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to have its output memoized. + * @param {Function} [resolver] The function to resolve the cache key. + * @returns {Function} Returns the new memoized function. + * @example + * + * var object = { 'a': 1, 'b': 2 }; + * var other = { 'c': 3, 'd': 4 }; + * + * var values = _.memoize(_.values); + * values(object); + * // => [1, 2] + * + * values(other); + * // => [3, 4] + * + * object.a = 2; + * values(object); + * // => [1, 2] + * + * // Modify the result cache. + * values.cache.set(object, ['a', 'b']); + * values(object); + * // => ['a', 'b'] + * + * // Replace `_.memoize.Cache`. + * _.memoize.Cache = WeakMap; + */ + function memoize(func, resolver) { + if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { + throw new TypeError(FUNC_ERROR_TEXT); + } + var memoized = function() { + var args = arguments, + key = resolver ? resolver.apply(this, args) : args[0], + cache = memoized.cache; + + if (cache.has(key)) { + return cache.get(key); + } + var result = func.apply(this, args); + memoized.cache = cache.set(key, result) || cache; + return result; + }; + memoized.cache = new (memoize.Cache || MapCache); + return memoized; + } + + // Expose `MapCache`. + memoize.Cache = MapCache; + + /** + * Creates a function that negates the result of the predicate `func`. The + * `func` predicate is invoked with the `this` binding and arguments of the + * created function. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {Function} predicate The predicate to negate. + * @returns {Function} Returns the new negated function. + * @example + * + * function isEven(n) { + * return n % 2 == 0; + * } + * + * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); + * // => [1, 3, 5] + */ + function negate(predicate) { + if (typeof predicate != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + return function() { + var args = arguments; + switch (args.length) { + case 0: return !predicate.call(this); + case 1: return !predicate.call(this, args[0]); + case 2: return !predicate.call(this, args[0], args[1]); + case 3: return !predicate.call(this, args[0], args[1], args[2]); + } + return !predicate.apply(this, args); + }; + } + + /** + * Creates a function that is restricted to invoking `func` once. Repeat calls + * to the function return the value of the first invocation. The `func` is + * invoked with the `this` binding and arguments of the created function. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * var initialize = _.once(createApplication); + * initialize(); + * initialize(); + * // => `createApplication` is invoked once + */ + function once(func) { + return before(2, func); + } + + /** + * Creates a function that invokes `func` with its arguments transformed. + * + * @static + * @since 4.0.0 + * @memberOf _ + * @category Function + * @param {Function} func The function to wrap. + * @param {...(Function|Function[])} [transforms=[_.identity]] + * The argument transforms. + * @returns {Function} Returns the new function. + * @example + * + * function doubled(n) { + * return n * 2; + * } + * + * function square(n) { + * return n * n; + * } + * + * var func = _.overArgs(function(x, y) { + * return [x, y]; + * }, [square, doubled]); + * + * func(9, 3); + * // => [81, 6] + * + * func(10, 5); + * // => [100, 10] + */ + var overArgs = castRest(function(func, transforms) { + transforms = (transforms.length == 1 && isArray(transforms[0])) + ? arrayMap(transforms[0], baseUnary(getIteratee())) + : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee())); + + var funcsLength = transforms.length; + return baseRest(function(args) { + var index = -1, + length = nativeMin(args.length, funcsLength); + + while (++index < length) { + args[index] = transforms[index].call(this, args[index]); + } + return apply(func, this, args); + }); + }); + + /** + * Creates a function that invokes `func` with `partials` prepended to the + * arguments it receives. This method is like `_.bind` except it does **not** + * alter the `this` binding. + * + * The `_.partial.placeholder` value, which defaults to `_` in monolithic + * builds, may be used as a placeholder for partially applied arguments. + * + * **Note:** This method doesn't set the "length" property of partially + * applied functions. + * + * @static + * @memberOf _ + * @since 0.2.0 + * @category Function + * @param {Function} func The function to partially apply arguments to. + * @param {...*} [partials] The arguments to be partially applied. + * @returns {Function} Returns the new partially applied function. + * @example + * + * function greet(greeting, name) { + * return greeting + ' ' + name; + * } + * + * var sayHelloTo = _.partial(greet, 'hello'); + * sayHelloTo('fred'); + * // => 'hello fred' + * + * // Partially applied with placeholders. + * var greetFred = _.partial(greet, _, 'fred'); + * greetFred('hi'); + * // => 'hi fred' + */ + var partial = baseRest(function(func, partials) { + var holders = replaceHolders(partials, getHolder(partial)); + return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders); + }); + + /** + * This method is like `_.partial` except that partially applied arguments + * are appended to the arguments it receives. + * + * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic + * builds, may be used as a placeholder for partially applied arguments. + * + * **Note:** This method doesn't set the "length" property of partially + * applied functions. + * + * @static + * @memberOf _ + * @since 1.0.0 + * @category Function + * @param {Function} func The function to partially apply arguments to. + * @param {...*} [partials] The arguments to be partially applied. + * @returns {Function} Returns the new partially applied function. + * @example + * + * function greet(greeting, name) { + * return greeting + ' ' + name; + * } + * + * var greetFred = _.partialRight(greet, 'fred'); + * greetFred('hi'); + * // => 'hi fred' + * + * // Partially applied with placeholders. + * var sayHelloTo = _.partialRight(greet, 'hello', _); + * sayHelloTo('fred'); + * // => 'hello fred' + */ + var partialRight = baseRest(function(func, partials) { + var holders = replaceHolders(partials, getHolder(partialRight)); + return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders); + }); + + /** + * Creates a function that invokes `func` with arguments arranged according + * to the specified `indexes` where the argument value at the first index is + * provided as the first argument, the argument value at the second index is + * provided as the second argument, and so on. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {Function} func The function to rearrange arguments for. + * @param {...(number|number[])} indexes The arranged argument indexes. + * @returns {Function} Returns the new function. + * @example + * + * var rearged = _.rearg(function(a, b, c) { + * return [a, b, c]; + * }, [2, 0, 1]); + * + * rearged('b', 'c', 'a') + * // => ['a', 'b', 'c'] + */ + var rearg = flatRest(function(func, indexes) { + return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes); + }); + + /** + * Creates a function that invokes `func` with the `this` binding of the + * created function and arguments from `start` and beyond provided as + * an array. + * + * **Note:** This method is based on the + * [rest parameter](https://mdn.io/rest_parameters). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Function + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @returns {Function} Returns the new function. + * @example + * + * var say = _.rest(function(what, names) { + * return what + ' ' + _.initial(names).join(', ') + + * (_.size(names) > 1 ? ', & ' : '') + _.last(names); + * }); + * + * say('hello', 'fred', 'barney', 'pebbles'); + * // => 'hello fred, barney, & pebbles' + */ + function rest(func, start) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + start = start === undefined ? start : toInteger(start); + return baseRest(func, start); + } + + /** + * Creates a function that invokes `func` with the `this` binding of the + * create function and an array of arguments much like + * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply). + * + * **Note:** This method is based on the + * [spread operator](https://mdn.io/spread_operator). + * + * @static + * @memberOf _ + * @since 3.2.0 + * @category Function + * @param {Function} func The function to spread arguments over. + * @param {number} [start=0] The start position of the spread. + * @returns {Function} Returns the new function. + * @example + * + * var say = _.spread(function(who, what) { + * return who + ' says ' + what; + * }); + * + * say(['fred', 'hello']); + * // => 'fred says hello' + * + * var numbers = Promise.all([ + * Promise.resolve(40), + * Promise.resolve(36) + * ]); + * + * numbers.then(_.spread(function(x, y) { + * return x + y; + * })); + * // => a Promise of 76 + */ + function spread(func, start) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + start = start == null ? 0 : nativeMax(toInteger(start), 0); + return baseRest(function(args) { + var array = args[start], + otherArgs = castSlice(args, 0, start); + + if (array) { + arrayPush(otherArgs, array); + } + return apply(func, this, otherArgs); + }); + } + + /** + * Creates a throttled function that only invokes `func` at most once per + * every `wait` milliseconds. The throttled function comes with a `cancel` + * method to cancel delayed `func` invocations and a `flush` method to + * immediately invoke them. Provide `options` to indicate whether `func` + * should be invoked on the leading and/or trailing edge of the `wait` + * timeout. The `func` is invoked with the last arguments provided to the + * throttled function. Subsequent calls to the throttled function return the + * result of the last `func` invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the throttled function + * is invoked more than once during the `wait` timeout. + * + * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred + * until to the next tick, similar to `setTimeout` with a timeout of `0`. + * + * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) + * for details over the differences between `_.throttle` and `_.debounce`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to throttle. + * @param {number} [wait=0] The number of milliseconds to throttle invocations to. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=true] + * Specify invoking on the leading edge of the timeout. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. + * @returns {Function} Returns the new throttled function. + * @example + * + * // Avoid excessively updating the position while scrolling. + * jQuery(window).on('scroll', _.throttle(updatePosition, 100)); + * + * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. + * var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); + * jQuery(element).on('click', throttled); + * + * // Cancel the trailing throttled invocation. + * jQuery(window).on('popstate', throttled.cancel); + */ + function throttle(func, wait, options) { + var leading = true, + trailing = true; + + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + if (isObject(options)) { + leading = 'leading' in options ? !!options.leading : leading; + trailing = 'trailing' in options ? !!options.trailing : trailing; + } + return debounce(func, wait, { + 'leading': leading, + 'maxWait': wait, + 'trailing': trailing + }); + } + + /** + * Creates a function that accepts up to one argument, ignoring any + * additional arguments. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Function + * @param {Function} func The function to cap arguments for. + * @returns {Function} Returns the new capped function. + * @example + * + * _.map(['6', '8', '10'], _.unary(parseInt)); + * // => [6, 8, 10] + */ + function unary(func) { + return ary(func, 1); + } + + /** + * Creates a function that provides `value` to `wrapper` as its first + * argument. Any additional arguments provided to the function are appended + * to those provided to the `wrapper`. The wrapper is invoked with the `this` + * binding of the created function. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {*} value The value to wrap. + * @param {Function} [wrapper=identity] The wrapper function. + * @returns {Function} Returns the new function. + * @example + * + * var p = _.wrap(_.escape, function(func, text) { + * return '

' + func(text) + '

'; + * }); + * + * p('fred, barney, & pebbles'); + * // => '

fred, barney, & pebbles

' + */ + function wrap(value, wrapper) { + return partial(castFunction(wrapper), value); + } + + /*------------------------------------------------------------------------*/ + + /** + * Casts `value` as an array if it's not one. + * + * @static + * @memberOf _ + * @since 4.4.0 + * @category Lang + * @param {*} value The value to inspect. + * @returns {Array} Returns the cast array. + * @example + * + * _.castArray(1); + * // => [1] + * + * _.castArray({ 'a': 1 }); + * // => [{ 'a': 1 }] + * + * _.castArray('abc'); + * // => ['abc'] + * + * _.castArray(null); + * // => [null] + * + * _.castArray(undefined); + * // => [undefined] + * + * _.castArray(); + * // => [] + * + * var array = [1, 2, 3]; + * console.log(_.castArray(array) === array); + * // => true + */ + function castArray() { + if (!arguments.length) { + return []; + } + var value = arguments[0]; + return isArray(value) ? value : [value]; + } + + /** + * Creates a shallow clone of `value`. + * + * **Note:** This method is loosely based on the + * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) + * and supports cloning arrays, array buffers, booleans, date objects, maps, + * numbers, `Object` objects, regexes, sets, strings, symbols, and typed + * arrays. The own enumerable properties of `arguments` objects are cloned + * as plain objects. An empty object is returned for uncloneable values such + * as error objects, functions, DOM nodes, and WeakMaps. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to clone. + * @returns {*} Returns the cloned value. + * @see _.cloneDeep + * @example + * + * var objects = [{ 'a': 1 }, { 'b': 2 }]; + * + * var shallow = _.clone(objects); + * console.log(shallow[0] === objects[0]); + * // => true + */ + function clone(value) { + return baseClone(value, CLONE_SYMBOLS_FLAG); + } + + /** + * This method is like `_.clone` except that it accepts `customizer` which + * is invoked to produce the cloned value. If `customizer` returns `undefined`, + * cloning is handled by the method instead. The `customizer` is invoked with + * up to four arguments; (value [, index|key, object, stack]). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to clone. + * @param {Function} [customizer] The function to customize cloning. + * @returns {*} Returns the cloned value. + * @see _.cloneDeepWith + * @example + * + * function customizer(value) { + * if (_.isElement(value)) { + * return value.cloneNode(false); + * } + * } + * + * var el = _.cloneWith(document.body, customizer); + * + * console.log(el === document.body); + * // => false + * console.log(el.nodeName); + * // => 'BODY' + * console.log(el.childNodes.length); + * // => 0 + */ + function cloneWith(value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; + return baseClone(value, CLONE_SYMBOLS_FLAG, customizer); + } + + /** + * This method is like `_.clone` except that it recursively clones `value`. + * + * @static + * @memberOf _ + * @since 1.0.0 + * @category Lang + * @param {*} value The value to recursively clone. + * @returns {*} Returns the deep cloned value. + * @see _.clone + * @example + * + * var objects = [{ 'a': 1 }, { 'b': 2 }]; + * + * var deep = _.cloneDeep(objects); + * console.log(deep[0] === objects[0]); + * // => false + */ + function cloneDeep(value) { + return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG); + } + + /** + * This method is like `_.cloneWith` except that it recursively clones `value`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to recursively clone. + * @param {Function} [customizer] The function to customize cloning. + * @returns {*} Returns the deep cloned value. + * @see _.cloneWith + * @example + * + * function customizer(value) { + * if (_.isElement(value)) { + * return value.cloneNode(true); + * } + * } + * + * var el = _.cloneDeepWith(document.body, customizer); + * + * console.log(el === document.body); + * // => false + * console.log(el.nodeName); + * // => 'BODY' + * console.log(el.childNodes.length); + * // => 20 + */ + function cloneDeepWith(value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; + return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer); + } + + /** + * Checks if `object` conforms to `source` by invoking the predicate + * properties of `source` with the corresponding property values of `object`. + * + * **Note:** This method is equivalent to `_.conforms` when `source` is + * partially applied. + * + * @static + * @memberOf _ + * @since 4.14.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + * @example + * + * var object = { 'a': 1, 'b': 2 }; + * + * _.conformsTo(object, { 'b': function(n) { return n > 1; } }); + * // => true + * + * _.conformsTo(object, { 'b': function(n) { return n > 2; } }); + * // => false + */ + function conformsTo(object, source) { + return source == null || baseConformsTo(object, source, keys(source)); + } + + /** + * Performs a + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * comparison between two values to determine if they are equivalent. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; + * + * _.eq(object, object); + * // => true + * + * _.eq(object, other); + * // => false + * + * _.eq('a', 'a'); + * // => true + * + * _.eq('a', Object('a')); + * // => false + * + * _.eq(NaN, NaN); + * // => true + */ + function eq(value, other) { + return value === other || (value !== value && other !== other); + } + + /** + * Checks if `value` is greater than `other`. + * + * @static + * @memberOf _ + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than `other`, + * else `false`. + * @see _.lt + * @example + * + * _.gt(3, 1); + * // => true + * + * _.gt(3, 3); + * // => false + * + * _.gt(1, 3); + * // => false + */ + var gt = createRelationalOperation(baseGt); + + /** + * Checks if `value` is greater than or equal to `other`. + * + * @static + * @memberOf _ + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than or equal to + * `other`, else `false`. + * @see _.lte + * @example + * + * _.gte(3, 1); + * // => true + * + * _.gte(3, 3); + * // => true + * + * _.gte(1, 3); + * // => false + */ + var gte = createRelationalOperation(function(value, other) { + return value >= other; + }); + + /** + * Checks if `value` is likely an `arguments` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, + * else `false`. + * @example + * + * _.isArguments(function() { return arguments; }()); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ + var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) { + return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && + !propertyIsEnumerable.call(value, 'callee'); + }; + + /** + * Checks if `value` is classified as an `Array` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array, else `false`. + * @example + * + * _.isArray([1, 2, 3]); + * // => true + * + * _.isArray(document.body.children); + * // => false + * + * _.isArray('abc'); + * // => false + * + * _.isArray(_.noop); + * // => false + */ + var isArray = Array.isArray; + + /** + * Checks if `value` is classified as an `ArrayBuffer` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. + * @example + * + * _.isArrayBuffer(new ArrayBuffer(2)); + * // => true + * + * _.isArrayBuffer(new Array(2)); + * // => false + */ + var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer; + + /** + * Checks if `value` is array-like. A value is considered array-like if it's + * not a function and has a `value.length` that's an integer greater than or + * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + * @example + * + * _.isArrayLike([1, 2, 3]); + * // => true + * + * _.isArrayLike(document.body.children); + * // => true + * + * _.isArrayLike('abc'); + * // => true + * + * _.isArrayLike(_.noop); + * // => false + */ + function isArrayLike(value) { + return value != null && isLength(value.length) && !isFunction(value); + } + + /** + * This method is like `_.isArrayLike` except that it also checks if `value` + * is an object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array-like object, + * else `false`. + * @example + * + * _.isArrayLikeObject([1, 2, 3]); + * // => true + * + * _.isArrayLikeObject(document.body.children); + * // => true + * + * _.isArrayLikeObject('abc'); + * // => false + * + * _.isArrayLikeObject(_.noop); + * // => false + */ + function isArrayLikeObject(value) { + return isObjectLike(value) && isArrayLike(value); + } + + /** + * Checks if `value` is classified as a boolean primitive or object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. + * @example + * + * _.isBoolean(false); + * // => true + * + * _.isBoolean(null); + * // => false + */ + function isBoolean(value) { + return value === true || value === false || + (isObjectLike(value) && baseGetTag(value) == boolTag); + } + + /** + * Checks if `value` is a buffer. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. + * @example + * + * _.isBuffer(new Buffer(2)); + * // => true + * + * _.isBuffer(new Uint8Array(2)); + * // => false + */ + var isBuffer = nativeIsBuffer || stubFalse; + + /** + * Checks if `value` is classified as a `Date` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a date object, else `false`. + * @example + * + * _.isDate(new Date); + * // => true + * + * _.isDate('Mon April 23 2012'); + * // => false + */ + var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; + + /** + * Checks if `value` is likely a DOM element. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. + * @example + * + * _.isElement(document.body); + * // => true + * + * _.isElement(''); + * // => false + */ + function isElement(value) { + return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value); + } + + /** + * Checks if `value` is an empty object, collection, map, or set. + * + * Objects are considered empty if they have no own enumerable string keyed + * properties. + * + * Array-like values such as `arguments` objects, arrays, buffers, strings, or + * jQuery-like collections are considered empty if they have a `length` of `0`. + * Similarly, maps and sets are considered empty if they have a `size` of `0`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is empty, else `false`. + * @example + * + * _.isEmpty(null); + * // => true + * + * _.isEmpty(true); + * // => true + * + * _.isEmpty(1); + * // => true + * + * _.isEmpty([1, 2, 3]); + * // => false + * + * _.isEmpty({ 'a': 1 }); + * // => false + */ + function isEmpty(value) { + if (value == null) { + return true; + } + if (isArrayLike(value) && + (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || + isBuffer(value) || isTypedArray(value) || isArguments(value))) { + return !value.length; + } + var tag = getTag(value); + if (tag == mapTag || tag == setTag) { + return !value.size; + } + if (isPrototype(value)) { + return !baseKeys(value).length; + } + for (var key in value) { + if (hasOwnProperty.call(value, key)) { + return false; + } + } + return true; + } + + /** + * Performs a deep comparison between two values to determine if they are + * equivalent. + * + * **Note:** This method supports comparing arrays, array buffers, booleans, + * date objects, error objects, maps, numbers, `Object` objects, regexes, + * sets, strings, symbols, and typed arrays. `Object` objects are compared + * by their own, not inherited, enumerable properties. Functions and DOM + * nodes are compared by strict equality, i.e. `===`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; + * + * _.isEqual(object, other); + * // => true + * + * object === other; + * // => false + */ + function isEqual(value, other) { + return baseIsEqual(value, other); + } + + /** + * This method is like `_.isEqual` except that it accepts `customizer` which + * is invoked to compare values. If `customizer` returns `undefined`, comparisons + * are handled by the method instead. The `customizer` is invoked with up to + * six arguments: (objValue, othValue [, index|key, object, other, stack]). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @param {Function} [customizer] The function to customize comparisons. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * function isGreeting(value) { + * return /^h(?:i|ello)$/.test(value); + * } + * + * function customizer(objValue, othValue) { + * if (isGreeting(objValue) && isGreeting(othValue)) { + * return true; + * } + * } + * + * var array = ['hello', 'goodbye']; + * var other = ['hi', 'goodbye']; + * + * _.isEqualWith(array, other, customizer); + * // => true + */ + function isEqualWith(value, other, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; + var result = customizer ? customizer(value, other) : undefined; + return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result; + } + + /** + * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, + * `SyntaxError`, `TypeError`, or `URIError` object. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an error object, else `false`. + * @example + * + * _.isError(new Error); + * // => true + * + * _.isError(Error); + * // => false + */ + function isError(value) { + if (!isObjectLike(value)) { + return false; + } + var tag = baseGetTag(value); + return tag == errorTag || tag == domExcTag || + (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); + } + + /** + * Checks if `value` is a finite primitive number. + * + * **Note:** This method is based on + * [`Number.isFinite`](https://mdn.io/Number/isFinite). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a finite number, else `false`. + * @example + * + * _.isFinite(3); + * // => true + * + * _.isFinite(Number.MIN_VALUE); + * // => true + * + * _.isFinite(Infinity); + * // => false + * + * _.isFinite('3'); + * // => false + */ + function isFinite(value) { + return typeof value == 'number' && nativeIsFinite(value); + } + + /** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ + function isFunction(value) { + if (!isObject(value)) { + return false; + } + // The use of `Object#toString` avoids issues with the `typeof` operator + // in Safari 9 which returns 'object' for typed arrays and other constructors. + var tag = baseGetTag(value); + return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; + } + + /** + * Checks if `value` is an integer. + * + * **Note:** This method is based on + * [`Number.isInteger`](https://mdn.io/Number/isInteger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an integer, else `false`. + * @example + * + * _.isInteger(3); + * // => true + * + * _.isInteger(Number.MIN_VALUE); + * // => false + * + * _.isInteger(Infinity); + * // => false + * + * _.isInteger('3'); + * // => false + */ + function isInteger(value) { + return typeof value == 'number' && value == toInteger(value); + } + + /** + * Checks if `value` is a valid array-like length. + * + * **Note:** This method is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + * @example + * + * _.isLength(3); + * // => true + * + * _.isLength(Number.MIN_VALUE); + * // => false + * + * _.isLength(Infinity); + * // => false + * + * _.isLength('3'); + * // => false + */ + function isLength(value) { + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; + } + + /** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); + * // => false + */ + function isObject(value) { + var type = typeof value; + return value != null && (type == 'object' || type == 'function'); + } + + /** + * Checks if `value` is object-like. A value is object-like if it's not `null` + * and has a `typeof` result of "object". + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + * @example + * + * _.isObjectLike({}); + * // => true + * + * _.isObjectLike([1, 2, 3]); + * // => true + * + * _.isObjectLike(_.noop); + * // => false + * + * _.isObjectLike(null); + * // => false + */ + function isObjectLike(value) { + return value != null && typeof value == 'object'; + } + + /** + * Checks if `value` is classified as a `Map` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a map, else `false`. + * @example + * + * _.isMap(new Map); + * // => true + * + * _.isMap(new WeakMap); + * // => false + */ + var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap; + + /** + * Performs a partial deep comparison between `object` and `source` to + * determine if `object` contains equivalent property values. + * + * **Note:** This method is equivalent to `_.matches` when `source` is + * partially applied. + * + * Partial comparisons will match empty array and empty object `source` + * values against any array or object value, respectively. See `_.isEqual` + * for a list of supported value comparisons. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property values to match. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + * @example + * + * var object = { 'a': 1, 'b': 2 }; + * + * _.isMatch(object, { 'b': 2 }); + * // => true + * + * _.isMatch(object, { 'b': 1 }); + * // => false + */ + function isMatch(object, source) { + return object === source || baseIsMatch(object, source, getMatchData(source)); + } + + /** + * This method is like `_.isMatch` except that it accepts `customizer` which + * is invoked to compare values. If `customizer` returns `undefined`, comparisons + * are handled by the method instead. The `customizer` is invoked with five + * arguments: (objValue, srcValue, index|key, object, source). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property values to match. + * @param {Function} [customizer] The function to customize comparisons. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + * @example + * + * function isGreeting(value) { + * return /^h(?:i|ello)$/.test(value); + * } + * + * function customizer(objValue, srcValue) { + * if (isGreeting(objValue) && isGreeting(srcValue)) { + * return true; + * } + * } + * + * var object = { 'greeting': 'hello' }; + * var source = { 'greeting': 'hi' }; + * + * _.isMatchWith(object, source, customizer); + * // => true + */ + function isMatchWith(object, source, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; + return baseIsMatch(object, source, getMatchData(source), customizer); + } + + /** + * Checks if `value` is `NaN`. + * + * **Note:** This method is based on + * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as + * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for + * `undefined` and other non-number values. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + * @example + * + * _.isNaN(NaN); + * // => true + * + * _.isNaN(new Number(NaN)); + * // => true + * + * isNaN(undefined); + * // => true + * + * _.isNaN(undefined); + * // => false + */ + function isNaN(value) { + // An `NaN` primitive is the only value that is not equal to itself. + // Perform the `toStringTag` check first to avoid errors with some + // ActiveX objects in IE. + return isNumber(value) && value != +value; + } + + /** + * Checks if `value` is a pristine native function. + * + * **Note:** This method can't reliably detect native functions in the presence + * of the core-js package because core-js circumvents this kind of detection. + * Despite multiple requests, the core-js maintainer has made it clear: any + * attempt to fix the detection will be obstructed. As a result, we're left + * with little choice but to throw an error. Unfortunately, this also affects + * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), + * which rely on core-js. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, + * else `false`. + * @example + * + * _.isNative(Array.prototype.push); + * // => true + * + * _.isNative(_); + * // => false + */ + function isNative(value) { + if (isMaskable(value)) { + throw new Error(CORE_ERROR_TEXT); + } + return baseIsNative(value); + } + + /** + * Checks if `value` is `null`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `null`, else `false`. + * @example + * + * _.isNull(null); + * // => true + * + * _.isNull(void 0); + * // => false + */ + function isNull(value) { + return value === null; + } + + /** + * Checks if `value` is `null` or `undefined`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is nullish, else `false`. + * @example + * + * _.isNil(null); + * // => true + * + * _.isNil(void 0); + * // => true + * + * _.isNil(NaN); + * // => false + */ + function isNil(value) { + return value == null; + } + + /** + * Checks if `value` is classified as a `Number` primitive or object. + * + * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are + * classified as numbers, use the `_.isFinite` method. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a number, else `false`. + * @example + * + * _.isNumber(3); + * // => true + * + * _.isNumber(Number.MIN_VALUE); + * // => true + * + * _.isNumber(Infinity); + * // => true + * + * _.isNumber('3'); + * // => false + */ + function isNumber(value) { + return typeof value == 'number' || + (isObjectLike(value) && baseGetTag(value) == numberTag); + } + + /** + * Checks if `value` is a plain object, that is, an object created by the + * `Object` constructor or one with a `[[Prototype]]` of `null`. + * + * @static + * @memberOf _ + * @since 0.8.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. + * @example + * + * function Foo() { + * this.a = 1; + * } + * + * _.isPlainObject(new Foo); + * // => false + * + * _.isPlainObject([1, 2, 3]); + * // => false + * + * _.isPlainObject({ 'x': 0, 'y': 0 }); + * // => true + * + * _.isPlainObject(Object.create(null)); + * // => true + */ + function isPlainObject(value) { + if (!isObjectLike(value) || baseGetTag(value) != objectTag) { + return false; + } + var proto = getPrototype(value); + if (proto === null) { + return true; + } + var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; + return typeof Ctor == 'function' && Ctor instanceof Ctor && + funcToString.call(Ctor) == objectCtorString; + } + + /** + * Checks if `value` is classified as a `RegExp` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. + * @example + * + * _.isRegExp(/abc/); + * // => true + * + * _.isRegExp('/abc/'); + * // => false + */ + var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; + + /** + * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 + * double precision number which isn't the result of a rounded unsafe integer. + * + * **Note:** This method is based on + * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`. + * @example + * + * _.isSafeInteger(3); + * // => true + * + * _.isSafeInteger(Number.MIN_VALUE); + * // => false + * + * _.isSafeInteger(Infinity); + * // => false + * + * _.isSafeInteger('3'); + * // => false + */ + function isSafeInteger(value) { + return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER; + } + + /** + * Checks if `value` is classified as a `Set` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a set, else `false`. + * @example + * + * _.isSet(new Set); + * // => true + * + * _.isSet(new WeakSet); + * // => false + */ + var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet; + + /** + * Checks if `value` is classified as a `String` primitive or object. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a string, else `false`. + * @example + * + * _.isString('abc'); + * // => true + * + * _.isString(1); + * // => false + */ + function isString(value) { + return typeof value == 'string' || + (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); + } + + /** + * Checks if `value` is classified as a `Symbol` primitive or object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. + * @example + * + * _.isSymbol(Symbol.iterator); + * // => true + * + * _.isSymbol('abc'); + * // => false + */ + function isSymbol(value) { + return typeof value == 'symbol' || + (isObjectLike(value) && baseGetTag(value) == symbolTag); + } + + /** + * Checks if `value` is classified as a typed array. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. + * @example + * + * _.isTypedArray(new Uint8Array); + * // => true + * + * _.isTypedArray([]); + * // => false + */ + var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; + + /** + * Checks if `value` is `undefined`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. + * @example + * + * _.isUndefined(void 0); + * // => true + * + * _.isUndefined(null); + * // => false + */ + function isUndefined(value) { + return value === undefined; + } + + /** + * Checks if `value` is classified as a `WeakMap` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a weak map, else `false`. + * @example + * + * _.isWeakMap(new WeakMap); + * // => true + * + * _.isWeakMap(new Map); + * // => false + */ + function isWeakMap(value) { + return isObjectLike(value) && getTag(value) == weakMapTag; + } + + /** + * Checks if `value` is classified as a `WeakSet` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a weak set, else `false`. + * @example + * + * _.isWeakSet(new WeakSet); + * // => true + * + * _.isWeakSet(new Set); + * // => false + */ + function isWeakSet(value) { + return isObjectLike(value) && baseGetTag(value) == weakSetTag; + } + + /** + * Checks if `value` is less than `other`. + * + * @static + * @memberOf _ + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than `other`, + * else `false`. + * @see _.gt + * @example + * + * _.lt(1, 3); + * // => true + * + * _.lt(3, 3); + * // => false + * + * _.lt(3, 1); + * // => false + */ + var lt = createRelationalOperation(baseLt); + + /** + * Checks if `value` is less than or equal to `other`. + * + * @static + * @memberOf _ + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than or equal to + * `other`, else `false`. + * @see _.gte + * @example + * + * _.lte(1, 3); + * // => true + * + * _.lte(3, 3); + * // => true + * + * _.lte(3, 1); + * // => false + */ + var lte = createRelationalOperation(function(value, other) { + return value <= other; + }); + + /** + * Converts `value` to an array. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to convert. + * @returns {Array} Returns the converted array. + * @example + * + * _.toArray({ 'a': 1, 'b': 2 }); + * // => [1, 2] + * + * _.toArray('abc'); + * // => ['a', 'b', 'c'] + * + * _.toArray(1); + * // => [] + * + * _.toArray(null); + * // => [] + */ + function toArray(value) { + if (!value) { + return []; + } + if (isArrayLike(value)) { + return isString(value) ? stringToArray(value) : copyArray(value); + } + if (symIterator && value[symIterator]) { + return iteratorToArray(value[symIterator]()); + } + var tag = getTag(value), + func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); + + return func(value); + } + + /** + * Converts `value` to a finite number. + * + * @static + * @memberOf _ + * @since 4.12.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted number. + * @example + * + * _.toFinite(3.2); + * // => 3.2 + * + * _.toFinite(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toFinite(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toFinite('3.2'); + * // => 3.2 + */ + function toFinite(value) { + if (!value) { + return value === 0 ? value : 0; + } + value = toNumber(value); + if (value === INFINITY || value === -INFINITY) { + var sign = (value < 0 ? -1 : 1); + return sign * MAX_INTEGER; + } + return value === value ? value : 0; + } + + /** + * Converts `value` to an integer. + * + * **Note:** This method is loosely based on + * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * _.toInteger(3.2); + * // => 3 + * + * _.toInteger(Number.MIN_VALUE); + * // => 0 + * + * _.toInteger(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toInteger('3.2'); + * // => 3 + */ + function toInteger(value) { + var result = toFinite(value), + remainder = result % 1; + + return result === result ? (remainder ? result - remainder : result) : 0; + } + + /** + * Converts `value` to an integer suitable for use as the length of an + * array-like object. + * + * **Note:** This method is based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * _.toLength(3.2); + * // => 3 + * + * _.toLength(Number.MIN_VALUE); + * // => 0 + * + * _.toLength(Infinity); + * // => 4294967295 + * + * _.toLength('3.2'); + * // => 3 + */ + function toLength(value) { + return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0; + } + + /** + * Converts `value` to a number. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to process. + * @returns {number} Returns the number. + * @example + * + * _.toNumber(3.2); + * // => 3.2 + * + * _.toNumber(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toNumber(Infinity); + * // => Infinity + * + * _.toNumber('3.2'); + * // => 3.2 + */ + function toNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } + if (isObject(value)) { + var other = typeof value.valueOf == 'function' ? value.valueOf() : value; + value = isObject(other) ? (other + '') : other; + } + if (typeof value != 'string') { + return value === 0 ? value : +value; + } + value = value.replace(reTrim, ''); + var isBinary = reIsBinary.test(value); + return (isBinary || reIsOctal.test(value)) + ? freeParseInt(value.slice(2), isBinary ? 2 : 8) + : (reIsBadHex.test(value) ? NAN : +value); + } + + /** + * Converts `value` to a plain object flattening inherited enumerable string + * keyed properties of `value` to own properties of the plain object. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {Object} Returns the converted plain object. + * @example + * + * function Foo() { + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.assign({ 'a': 1 }, new Foo); + * // => { 'a': 1, 'b': 2 } + * + * _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); + * // => { 'a': 1, 'b': 2, 'c': 3 } + */ + function toPlainObject(value) { + return copyObject(value, keysIn(value)); + } + + /** + * Converts `value` to a safe integer. A safe integer can be compared and + * represented correctly. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * _.toSafeInteger(3.2); + * // => 3 + * + * _.toSafeInteger(Number.MIN_VALUE); + * // => 0 + * + * _.toSafeInteger(Infinity); + * // => 9007199254740991 + * + * _.toSafeInteger('3.2'); + * // => 3 + */ + function toSafeInteger(value) { + return value + ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) + : (value === 0 ? value : 0); + } + + /** + * Converts `value` to a string. An empty string is returned for `null` + * and `undefined` values. The sign of `-0` is preserved. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + * @example + * + * _.toString(null); + * // => '' + * + * _.toString(-0); + * // => '-0' + * + * _.toString([1, 2, 3]); + * // => '1,2,3' + */ + function toString(value) { + return value == null ? '' : baseToString(value); + } + + /*------------------------------------------------------------------------*/ + + /** + * Assigns own enumerable string keyed properties of source objects to the + * destination object. Source objects are applied from left to right. + * Subsequent sources overwrite property assignments of previous sources. + * + * **Note:** This method mutates `object` and is loosely based on + * [`Object.assign`](https://mdn.io/Object/assign). + * + * @static + * @memberOf _ + * @since 0.10.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see _.assignIn + * @example + * + * function Foo() { + * this.a = 1; + * } + * + * function Bar() { + * this.c = 3; + * } + * + * Foo.prototype.b = 2; + * Bar.prototype.d = 4; + * + * _.assign({ 'a': 0 }, new Foo, new Bar); + * // => { 'a': 1, 'c': 3 } + */ + var assign = createAssigner(function(object, source) { + if (isPrototype(source) || isArrayLike(source)) { + copyObject(source, keys(source), object); + return; + } + for (var key in source) { + if (hasOwnProperty.call(source, key)) { + assignValue(object, key, source[key]); + } + } + }); + + /** + * This method is like `_.assign` except that it iterates over own and + * inherited source properties. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @alias extend + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see _.assign + * @example + * + * function Foo() { + * this.a = 1; + * } + * + * function Bar() { + * this.c = 3; + * } + * + * Foo.prototype.b = 2; + * Bar.prototype.d = 4; + * + * _.assignIn({ 'a': 0 }, new Foo, new Bar); + * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } + */ + var assignIn = createAssigner(function(object, source) { + copyObject(source, keysIn(source), object); + }); + + /** + * This method is like `_.assignIn` except that it accepts `customizer` + * which is invoked to produce the assigned values. If `customizer` returns + * `undefined`, assignment is handled by the method instead. The `customizer` + * is invoked with five arguments: (objValue, srcValue, key, object, source). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @alias extendWith + * @category Object + * @param {Object} object The destination object. + * @param {...Object} sources The source objects. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @see _.assignWith + * @example + * + * function customizer(objValue, srcValue) { + * return _.isUndefined(objValue) ? srcValue : objValue; + * } + * + * var defaults = _.partialRight(_.assignInWith, customizer); + * + * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); + * // => { 'a': 1, 'b': 2 } + */ + var assignInWith = createAssigner(function(object, source, srcIndex, customizer) { + copyObject(source, keysIn(source), object, customizer); + }); + + /** + * This method is like `_.assign` except that it accepts `customizer` + * which is invoked to produce the assigned values. If `customizer` returns + * `undefined`, assignment is handled by the method instead. The `customizer` + * is invoked with five arguments: (objValue, srcValue, key, object, source). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} sources The source objects. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @see _.assignInWith + * @example + * + * function customizer(objValue, srcValue) { + * return _.isUndefined(objValue) ? srcValue : objValue; + * } + * + * var defaults = _.partialRight(_.assignWith, customizer); + * + * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); + * // => { 'a': 1, 'b': 2 } + */ + var assignWith = createAssigner(function(object, source, srcIndex, customizer) { + copyObject(source, keys(source), object, customizer); + }); + + /** + * Creates an array of values corresponding to `paths` of `object`. + * + * @static + * @memberOf _ + * @since 1.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {...(string|string[])} [paths] The property paths to pick. + * @returns {Array} Returns the picked values. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; + * + * _.at(object, ['a[0].b.c', 'a[1]']); + * // => [3, 4] + */ + var at = flatRest(baseAt); + + /** + * Creates an object that inherits from the `prototype` object. If a + * `properties` object is given, its own enumerable string keyed properties + * are assigned to the created object. + * + * @static + * @memberOf _ + * @since 2.3.0 + * @category Object + * @param {Object} prototype The object to inherit from. + * @param {Object} [properties] The properties to assign to the object. + * @returns {Object} Returns the new object. + * @example + * + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * function Circle() { + * Shape.call(this); + * } + * + * Circle.prototype = _.create(Shape.prototype, { + * 'constructor': Circle + * }); + * + * var circle = new Circle; + * circle instanceof Circle; + * // => true + * + * circle instanceof Shape; + * // => true + */ + function create(prototype, properties) { + var result = baseCreate(prototype); + return properties == null ? result : baseAssign(result, properties); + } + + /** + * Assigns own and inherited enumerable string keyed properties of source + * objects to the destination object for all destination properties that + * resolve to `undefined`. Source objects are applied from left to right. + * Once a property is set, additional values of the same property are ignored. + * + * **Note:** This method mutates `object`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see _.defaultsDeep + * @example + * + * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); + * // => { 'a': 1, 'b': 2 } + */ + var defaults = baseRest(function(object, sources) { + object = Object(object); + + var index = -1; + var length = sources.length; + var guard = length > 2 ? sources[2] : undefined; + + if (guard && isIterateeCall(sources[0], sources[1], guard)) { + length = 1; + } + + while (++index < length) { + var source = sources[index]; + var props = keysIn(source); + var propsIndex = -1; + var propsLength = props.length; + + while (++propsIndex < propsLength) { + var key = props[propsIndex]; + var value = object[key]; + + if (value === undefined || + (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { + object[key] = source[key]; + } + } + } + + return object; + }); + + /** + * This method is like `_.defaults` except that it recursively assigns + * default properties. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 3.10.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see _.defaults + * @example + * + * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }); + * // => { 'a': { 'b': 2, 'c': 3 } } + */ + var defaultsDeep = baseRest(function(args) { + args.push(undefined, customDefaultsMerge); + return apply(mergeWith, undefined, args); + }); + + /** + * This method is like `_.find` except that it returns the key of the first + * element `predicate` returns truthy for instead of the element itself. + * + * @static + * @memberOf _ + * @since 1.1.0 + * @category Object + * @param {Object} object The object to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. + * @example + * + * var users = { + * 'barney': { 'age': 36, 'active': true }, + * 'fred': { 'age': 40, 'active': false }, + * 'pebbles': { 'age': 1, 'active': true } + * }; + * + * _.findKey(users, function(o) { return o.age < 40; }); + * // => 'barney' (iteration order is not guaranteed) + * + * // The `_.matches` iteratee shorthand. + * _.findKey(users, { 'age': 1, 'active': true }); + * // => 'pebbles' + * + * // The `_.matchesProperty` iteratee shorthand. + * _.findKey(users, ['active', false]); + * // => 'fred' + * + * // The `_.property` iteratee shorthand. + * _.findKey(users, 'active'); + * // => 'barney' + */ + function findKey(object, predicate) { + return baseFindKey(object, getIteratee(predicate, 3), baseForOwn); + } + + /** + * This method is like `_.findKey` except that it iterates over elements of + * a collection in the opposite order. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Object + * @param {Object} object The object to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. + * @example + * + * var users = { + * 'barney': { 'age': 36, 'active': true }, + * 'fred': { 'age': 40, 'active': false }, + * 'pebbles': { 'age': 1, 'active': true } + * }; + * + * _.findLastKey(users, function(o) { return o.age < 40; }); + * // => returns 'pebbles' assuming `_.findKey` returns 'barney' + * + * // The `_.matches` iteratee shorthand. + * _.findLastKey(users, { 'age': 36, 'active': true }); + * // => 'barney' + * + * // The `_.matchesProperty` iteratee shorthand. + * _.findLastKey(users, ['active', false]); + * // => 'fred' + * + * // The `_.property` iteratee shorthand. + * _.findLastKey(users, 'active'); + * // => 'pebbles' + */ + function findLastKey(object, predicate) { + return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight); + } + + /** + * Iterates over own and inherited enumerable string keyed properties of an + * object and invokes `iteratee` for each property. The iteratee is invoked + * with three arguments: (value, key, object). Iteratee functions may exit + * iteration early by explicitly returning `false`. + * + * @static + * @memberOf _ + * @since 0.3.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns `object`. + * @see _.forInRight + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forIn(new Foo, function(value, key) { + * console.log(key); + * }); + * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed). + */ + function forIn(object, iteratee) { + return object == null + ? object + : baseFor(object, getIteratee(iteratee, 3), keysIn); + } + + /** + * This method is like `_.forIn` except that it iterates over properties of + * `object` in the opposite order. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns `object`. + * @see _.forIn + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forInRight(new Foo, function(value, key) { + * console.log(key); + * }); + * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'. + */ + function forInRight(object, iteratee) { + return object == null + ? object + : baseForRight(object, getIteratee(iteratee, 3), keysIn); + } + + /** + * Iterates over own enumerable string keyed properties of an object and + * invokes `iteratee` for each property. The iteratee is invoked with three + * arguments: (value, key, object). Iteratee functions may exit iteration + * early by explicitly returning `false`. + * + * @static + * @memberOf _ + * @since 0.3.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns `object`. + * @see _.forOwnRight + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forOwn(new Foo, function(value, key) { + * console.log(key); + * }); + * // => Logs 'a' then 'b' (iteration order is not guaranteed). + */ + function forOwn(object, iteratee) { + return object && baseForOwn(object, getIteratee(iteratee, 3)); + } + + /** + * This method is like `_.forOwn` except that it iterates over properties of + * `object` in the opposite order. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns `object`. + * @see _.forOwn + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forOwnRight(new Foo, function(value, key) { + * console.log(key); + * }); + * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. + */ + function forOwnRight(object, iteratee) { + return object && baseForOwnRight(object, getIteratee(iteratee, 3)); + } + + /** + * Creates an array of function property names from own enumerable properties + * of `object`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to inspect. + * @returns {Array} Returns the function names. + * @see _.functionsIn + * @example + * + * function Foo() { + * this.a = _.constant('a'); + * this.b = _.constant('b'); + * } + * + * Foo.prototype.c = _.constant('c'); + * + * _.functions(new Foo); + * // => ['a', 'b'] + */ + function functions(object) { + return object == null ? [] : baseFunctions(object, keys(object)); + } + + /** + * Creates an array of function property names from own and inherited + * enumerable properties of `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to inspect. + * @returns {Array} Returns the function names. + * @see _.functions + * @example + * + * function Foo() { + * this.a = _.constant('a'); + * this.b = _.constant('b'); + * } + * + * Foo.prototype.c = _.constant('c'); + * + * _.functionsIn(new Foo); + * // => ['a', 'b', 'c'] + */ + function functionsIn(object) { + return object == null ? [] : baseFunctions(object, keysIn(object)); + } + + /** + * Gets the value at `path` of `object`. If the resolved value is + * `undefined`, the `defaultValue` is returned in its place. + * + * @static + * @memberOf _ + * @since 3.7.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to get. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. + * @returns {*} Returns the resolved value. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }] }; + * + * _.get(object, 'a[0].b.c'); + * // => 3 + * + * _.get(object, ['a', '0', 'b', 'c']); + * // => 3 + * + * _.get(object, 'a.b.c', 'default'); + * // => 'default' + */ + function get(object, path, defaultValue) { + var result = object == null ? undefined : baseGet(object, path); + return result === undefined ? defaultValue : result; + } + + /** + * Checks if `path` is a direct property of `object`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + * @example + * + * var object = { 'a': { 'b': 2 } }; + * var other = _.create({ 'a': _.create({ 'b': 2 }) }); + * + * _.has(object, 'a'); + * // => true + * + * _.has(object, 'a.b'); + * // => true + * + * _.has(object, ['a', 'b']); + * // => true + * + * _.has(other, 'a'); + * // => false + */ + function has(object, path) { + return object != null && hasPath(object, path, baseHas); + } + + /** + * Checks if `path` is a direct or inherited property of `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + * @example + * + * var object = _.create({ 'a': _.create({ 'b': 2 }) }); + * + * _.hasIn(object, 'a'); + * // => true + * + * _.hasIn(object, 'a.b'); + * // => true + * + * _.hasIn(object, ['a', 'b']); + * // => true + * + * _.hasIn(object, 'b'); + * // => false + */ + function hasIn(object, path) { + return object != null && hasPath(object, path, baseHasIn); + } + + /** + * Creates an object composed of the inverted keys and values of `object`. + * If `object` contains duplicate values, subsequent values overwrite + * property assignments of previous values. + * + * @static + * @memberOf _ + * @since 0.7.0 + * @category Object + * @param {Object} object The object to invert. + * @returns {Object} Returns the new inverted object. + * @example + * + * var object = { 'a': 1, 'b': 2, 'c': 1 }; + * + * _.invert(object); + * // => { '1': 'c', '2': 'b' } + */ + var invert = createInverter(function(result, value, key) { + if (value != null && + typeof value.toString != 'function') { + value = nativeObjectToString.call(value); + } + + result[value] = key; + }, constant(identity)); + + /** + * This method is like `_.invert` except that the inverted object is generated + * from the results of running each element of `object` thru `iteratee`. The + * corresponding inverted value of each inverted key is an array of keys + * responsible for generating the inverted value. The iteratee is invoked + * with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.1.0 + * @category Object + * @param {Object} object The object to invert. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Object} Returns the new inverted object. + * @example + * + * var object = { 'a': 1, 'b': 2, 'c': 1 }; + * + * _.invertBy(object); + * // => { '1': ['a', 'c'], '2': ['b'] } + * + * _.invertBy(object, function(value) { + * return 'group' + value; + * }); + * // => { 'group1': ['a', 'c'], 'group2': ['b'] } + */ + var invertBy = createInverter(function(result, value, key) { + if (value != null && + typeof value.toString != 'function') { + value = nativeObjectToString.call(value); + } + + if (hasOwnProperty.call(result, value)) { + result[value].push(key); + } else { + result[value] = [key]; + } + }, getIteratee); + + /** + * Invokes the method at `path` of `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path of the method to invoke. + * @param {...*} [args] The arguments to invoke the method with. + * @returns {*} Returns the result of the invoked method. + * @example + * + * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] }; + * + * _.invoke(object, 'a[0].b.c.slice', 1, 3); + * // => [2, 3] + */ + var invoke = baseRest(baseInvoke); + + /** + * Creates an array of the own enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. See the + * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) + * for more details. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keys(new Foo); + * // => ['a', 'b'] (iteration order is not guaranteed) + * + * _.keys('hi'); + * // => ['0', '1'] + */ + function keys(object) { + return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object); + } + + /** + * Creates an array of the own and inherited enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keysIn(new Foo); + * // => ['a', 'b', 'c'] (iteration order is not guaranteed) + */ + function keysIn(object) { + return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object); + } + + /** + * The opposite of `_.mapValues`; this method creates an object with the + * same values as `object` and keys generated by running each own enumerable + * string keyed property of `object` thru `iteratee`. The iteratee is invoked + * with three arguments: (value, key, object). + * + * @static + * @memberOf _ + * @since 3.8.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns the new mapped object. + * @see _.mapValues + * @example + * + * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { + * return key + value; + * }); + * // => { 'a1': 1, 'b2': 2 } + */ + function mapKeys(object, iteratee) { + var result = {}; + iteratee = getIteratee(iteratee, 3); + + baseForOwn(object, function(value, key, object) { + baseAssignValue(result, iteratee(value, key, object), value); + }); + return result; + } + + /** + * Creates an object with the same keys as `object` and values generated + * by running each own enumerable string keyed property of `object` thru + * `iteratee`. The iteratee is invoked with three arguments: + * (value, key, object). + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns the new mapped object. + * @see _.mapKeys + * @example + * + * var users = { + * 'fred': { 'user': 'fred', 'age': 40 }, + * 'pebbles': { 'user': 'pebbles', 'age': 1 } + * }; + * + * _.mapValues(users, function(o) { return o.age; }); + * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) + * + * // The `_.property` iteratee shorthand. + * _.mapValues(users, 'age'); + * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) + */ + function mapValues(object, iteratee) { + var result = {}; + iteratee = getIteratee(iteratee, 3); + + baseForOwn(object, function(value, key, object) { + baseAssignValue(result, key, iteratee(value, key, object)); + }); + return result; + } + + /** + * This method is like `_.assign` except that it recursively merges own and + * inherited enumerable string keyed properties of source objects into the + * destination object. Source properties that resolve to `undefined` are + * skipped if a destination value exists. Array and plain object properties + * are merged recursively. Other objects and value types are overridden by + * assignment. Source objects are applied from left to right. Subsequent + * sources overwrite property assignments of previous sources. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @example + * + * var object = { + * 'a': [{ 'b': 2 }, { 'd': 4 }] + * }; + * + * var other = { + * 'a': [{ 'c': 3 }, { 'e': 5 }] + * }; + * + * _.merge(object, other); + * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } + */ + var merge = createAssigner(function(object, source, srcIndex) { + baseMerge(object, source, srcIndex); + }); + + /** + * This method is like `_.merge` except that it accepts `customizer` which + * is invoked to produce the merged values of the destination and source + * properties. If `customizer` returns `undefined`, merging is handled by the + * method instead. The `customizer` is invoked with six arguments: + * (objValue, srcValue, key, object, source, stack). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} sources The source objects. + * @param {Function} customizer The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * function customizer(objValue, srcValue) { + * if (_.isArray(objValue)) { + * return objValue.concat(srcValue); + * } + * } + * + * var object = { 'a': [1], 'b': [2] }; + * var other = { 'a': [3], 'b': [4] }; + * + * _.mergeWith(object, other, customizer); + * // => { 'a': [1, 3], 'b': [2, 4] } + */ + var mergeWith = createAssigner(function(object, source, srcIndex, customizer) { + baseMerge(object, source, srcIndex, customizer); + }); + + /** + * The opposite of `_.pick`; this method creates an object composed of the + * own and inherited enumerable property paths of `object` that are not omitted. + * + * **Note:** This method is considerably slower than `_.pick`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {...(string|string[])} [paths] The property paths to omit. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.omit(object, ['a', 'c']); + * // => { 'b': '2' } + */ + var omit = flatRest(function(object, paths) { + var result = {}; + if (object == null) { + return result; + } + var isDeep = false; + paths = arrayMap(paths, function(path) { + path = castPath(path, object); + isDeep || (isDeep = path.length > 1); + return path; + }); + copyObject(object, getAllKeysIn(object), result); + if (isDeep) { + result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone); + } + var length = paths.length; + while (length--) { + baseUnset(result, paths[length]); + } + return result; + }); + + /** + * The opposite of `_.pickBy`; this method creates an object composed of + * the own and inherited enumerable string keyed properties of `object` that + * `predicate` doesn't return truthy for. The predicate is invoked with two + * arguments: (value, key). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The source object. + * @param {Function} [predicate=_.identity] The function invoked per property. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.omitBy(object, _.isNumber); + * // => { 'b': '2' } + */ + function omitBy(object, predicate) { + return pickBy(object, negate(getIteratee(predicate))); + } + + /** + * Creates an object composed of the picked `object` properties. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {...(string|string[])} [paths] The property paths to pick. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.pick(object, ['a', 'c']); + * // => { 'a': 1, 'c': 3 } + */ + var pick = flatRest(function(object, paths) { + return object == null ? {} : basePick(object, paths); + }); + + /** + * Creates an object composed of the `object` properties `predicate` returns + * truthy for. The predicate is invoked with two arguments: (value, key). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The source object. + * @param {Function} [predicate=_.identity] The function invoked per property. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.pickBy(object, _.isNumber); + * // => { 'a': 1, 'c': 3 } + */ + function pickBy(object, predicate) { + if (object == null) { + return {}; + } + var props = arrayMap(getAllKeysIn(object), function(prop) { + return [prop]; + }); + predicate = getIteratee(predicate); + return basePickBy(object, props, function(value, path) { + return predicate(value, path[0]); + }); + } + + /** + * This method is like `_.get` except that if the resolved value is a + * function it's invoked with the `this` binding of its parent object and + * its result is returned. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to resolve. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. + * @returns {*} Returns the resolved value. + * @example + * + * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] }; + * + * _.result(object, 'a[0].b.c1'); + * // => 3 + * + * _.result(object, 'a[0].b.c2'); + * // => 4 + * + * _.result(object, 'a[0].b.c3', 'default'); + * // => 'default' + * + * _.result(object, 'a[0].b.c3', _.constant('default')); + * // => 'default' + */ + function result(object, path, defaultValue) { + path = castPath(path, object); + + var index = -1, + length = path.length; + + // Ensure the loop is entered when path is empty. + if (!length) { + length = 1; + object = undefined; + } + while (++index < length) { + var value = object == null ? undefined : object[toKey(path[index])]; + if (value === undefined) { + index = length; + value = defaultValue; + } + object = isFunction(value) ? value.call(object) : value; + } + return object; + } + + /** + * Sets the value at `path` of `object`. If a portion of `path` doesn't exist, + * it's created. Arrays are created for missing index properties while objects + * are created for all other missing properties. Use `_.setWith` to customize + * `path` creation. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 3.7.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @returns {Object} Returns `object`. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }] }; + * + * _.set(object, 'a[0].b.c', 4); + * console.log(object.a[0].b.c); + * // => 4 + * + * _.set(object, ['x', '0', 'y', 'z'], 5); + * console.log(object.x[0].y.z); + * // => 5 + */ + function set(object, path, value) { + return object == null ? object : baseSet(object, path, value); + } + + /** + * This method is like `_.set` except that it accepts `customizer` which is + * invoked to produce the objects of `path`. If `customizer` returns `undefined` + * path creation is handled by the method instead. The `customizer` is invoked + * with three arguments: (nsValue, key, nsObject). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * var object = {}; + * + * _.setWith(object, '[0][1]', 'a', Object); + * // => { '0': { '1': 'a' } } + */ + function setWith(object, path, value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; + return object == null ? object : baseSet(object, path, value, customizer); + } + + /** + * Creates an array of own enumerable string keyed-value pairs for `object` + * which can be consumed by `_.fromPairs`. If `object` is a map or set, its + * entries are returned. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @alias entries + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the key-value pairs. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.toPairs(new Foo); + * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed) + */ + var toPairs = createToPairs(keys); + + /** + * Creates an array of own and inherited enumerable string keyed-value pairs + * for `object` which can be consumed by `_.fromPairs`. If `object` is a map + * or set, its entries are returned. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @alias entriesIn + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the key-value pairs. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.toPairsIn(new Foo); + * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed) + */ + var toPairsIn = createToPairs(keysIn); + + /** + * An alternative to `_.reduce`; this method transforms `object` to a new + * `accumulator` object which is the result of running each of its own + * enumerable string keyed properties thru `iteratee`, with each invocation + * potentially mutating the `accumulator` object. If `accumulator` is not + * provided, a new object with the same `[[Prototype]]` will be used. The + * iteratee is invoked with four arguments: (accumulator, value, key, object). + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * @static + * @memberOf _ + * @since 1.3.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {*} [accumulator] The custom accumulator value. + * @returns {*} Returns the accumulated value. + * @example + * + * _.transform([2, 3, 4], function(result, n) { + * result.push(n *= n); + * return n % 2 == 0; + * }, []); + * // => [4, 9] + * + * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { + * (result[value] || (result[value] = [])).push(key); + * }, {}); + * // => { '1': ['a', 'c'], '2': ['b'] } + */ + function transform(object, iteratee, accumulator) { + var isArr = isArray(object), + isArrLike = isArr || isBuffer(object) || isTypedArray(object); + + iteratee = getIteratee(iteratee, 4); + if (accumulator == null) { + var Ctor = object && object.constructor; + if (isArrLike) { + accumulator = isArr ? new Ctor : []; + } + else if (isObject(object)) { + accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {}; + } + else { + accumulator = {}; + } + } + (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) { + return iteratee(accumulator, value, index, object); + }); + return accumulator; + } + + /** + * Removes the property at `path` of `object`. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to unset. + * @returns {boolean} Returns `true` if the property is deleted, else `false`. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 7 } }] }; + * _.unset(object, 'a[0].b.c'); + * // => true + * + * console.log(object); + * // => { 'a': [{ 'b': {} }] }; + * + * _.unset(object, ['a', '0', 'b', 'c']); + * // => true + * + * console.log(object); + * // => { 'a': [{ 'b': {} }] }; + */ + function unset(object, path) { + return object == null ? true : baseUnset(object, path); + } + + /** + * This method is like `_.set` except that accepts `updater` to produce the + * value to set. Use `_.updateWith` to customize `path` creation. The `updater` + * is invoked with one argument: (value). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.6.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {Function} updater The function to produce the updated value. + * @returns {Object} Returns `object`. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }] }; + * + * _.update(object, 'a[0].b.c', function(n) { return n * n; }); + * console.log(object.a[0].b.c); + * // => 9 + * + * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; }); + * console.log(object.x[0].y.z); + * // => 0 + */ + function update(object, path, updater) { + return object == null ? object : baseUpdate(object, path, castFunction(updater)); + } + + /** + * This method is like `_.update` except that it accepts `customizer` which is + * invoked to produce the objects of `path`. If `customizer` returns `undefined` + * path creation is handled by the method instead. The `customizer` is invoked + * with three arguments: (nsValue, key, nsObject). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.6.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {Function} updater The function to produce the updated value. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * var object = {}; + * + * _.updateWith(object, '[0][1]', _.constant('a'), Object); + * // => { '0': { '1': 'a' } } + */ + function updateWith(object, path, updater, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined; + return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer); + } + + /** + * Creates an array of the own enumerable string keyed property values of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property values. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.values(new Foo); + * // => [1, 2] (iteration order is not guaranteed) + * + * _.values('hi'); + * // => ['h', 'i'] + */ + function values(object) { + return object == null ? [] : baseValues(object, keys(object)); + } + + /** + * Creates an array of the own and inherited enumerable string keyed property + * values of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property values. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.valuesIn(new Foo); + * // => [1, 2, 3] (iteration order is not guaranteed) + */ + function valuesIn(object) { + return object == null ? [] : baseValues(object, keysIn(object)); + } + + /*------------------------------------------------------------------------*/ + + /** + * Clamps `number` within the inclusive `lower` and `upper` bounds. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Number + * @param {number} number The number to clamp. + * @param {number} [lower] The lower bound. + * @param {number} upper The upper bound. + * @returns {number} Returns the clamped number. + * @example + * + * _.clamp(-10, -5, 5); + * // => -5 + * + * _.clamp(10, -5, 5); + * // => 5 + */ + function clamp(number, lower, upper) { + if (upper === undefined) { + upper = lower; + lower = undefined; + } + if (upper !== undefined) { + upper = toNumber(upper); + upper = upper === upper ? upper : 0; + } + if (lower !== undefined) { + lower = toNumber(lower); + lower = lower === lower ? lower : 0; + } + return baseClamp(toNumber(number), lower, upper); + } + + /** + * Checks if `n` is between `start` and up to, but not including, `end`. If + * `end` is not specified, it's set to `start` with `start` then set to `0`. + * If `start` is greater than `end` the params are swapped to support + * negative ranges. + * + * @static + * @memberOf _ + * @since 3.3.0 + * @category Number + * @param {number} number The number to check. + * @param {number} [start=0] The start of the range. + * @param {number} end The end of the range. + * @returns {boolean} Returns `true` if `number` is in the range, else `false`. + * @see _.range, _.rangeRight + * @example + * + * _.inRange(3, 2, 4); + * // => true + * + * _.inRange(4, 8); + * // => true + * + * _.inRange(4, 2); + * // => false + * + * _.inRange(2, 2); + * // => false + * + * _.inRange(1.2, 2); + * // => true + * + * _.inRange(5.2, 4); + * // => false + * + * _.inRange(-3, -2, -6); + * // => true + */ + function inRange(number, start, end) { + start = toFinite(start); + if (end === undefined) { + end = start; + start = 0; + } else { + end = toFinite(end); + } + number = toNumber(number); + return baseInRange(number, start, end); + } + + /** + * Produces a random number between the inclusive `lower` and `upper` bounds. + * If only one argument is provided a number between `0` and the given number + * is returned. If `floating` is `true`, or either `lower` or `upper` are + * floats, a floating-point number is returned instead of an integer. + * + * **Note:** JavaScript follows the IEEE-754 standard for resolving + * floating-point values which can produce unexpected results. + * + * @static + * @memberOf _ + * @since 0.7.0 + * @category Number + * @param {number} [lower=0] The lower bound. + * @param {number} [upper=1] The upper bound. + * @param {boolean} [floating] Specify returning a floating-point number. + * @returns {number} Returns the random number. + * @example + * + * _.random(0, 5); + * // => an integer between 0 and 5 + * + * _.random(5); + * // => also an integer between 0 and 5 + * + * _.random(5, true); + * // => a floating-point number between 0 and 5 + * + * _.random(1.2, 5.2); + * // => a floating-point number between 1.2 and 5.2 + */ + function random(lower, upper, floating) { + if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) { + upper = floating = undefined; + } + if (floating === undefined) { + if (typeof upper == 'boolean') { + floating = upper; + upper = undefined; + } + else if (typeof lower == 'boolean') { + floating = lower; + lower = undefined; + } + } + if (lower === undefined && upper === undefined) { + lower = 0; + upper = 1; + } + else { + lower = toFinite(lower); + if (upper === undefined) { + upper = lower; + lower = 0; + } else { + upper = toFinite(upper); + } + } + if (lower > upper) { + var temp = lower; + lower = upper; + upper = temp; + } + if (floating || lower % 1 || upper % 1) { + var rand = nativeRandom(); + return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper); + } + return baseRandom(lower, upper); + } + + /*------------------------------------------------------------------------*/ + + /** + * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the camel cased string. + * @example + * + * _.camelCase('Foo Bar'); + * // => 'fooBar' + * + * _.camelCase('--foo-bar--'); + * // => 'fooBar' + * + * _.camelCase('__FOO_BAR__'); + * // => 'fooBar' + */ + var camelCase = createCompounder(function(result, word, index) { + word = word.toLowerCase(); + return result + (index ? capitalize(word) : word); + }); + + /** + * Converts the first character of `string` to upper case and the remaining + * to lower case. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to capitalize. + * @returns {string} Returns the capitalized string. + * @example + * + * _.capitalize('FRED'); + * // => 'Fred' + */ + function capitalize(string) { + return upperFirst(toString(string).toLowerCase()); + } + + /** + * Deburrs `string` by converting + * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) + * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) + * letters to basic Latin letters and removing + * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to deburr. + * @returns {string} Returns the deburred string. + * @example + * + * _.deburr('déjà vu'); + * // => 'deja vu' + */ + function deburr(string) { + string = toString(string); + return string && string.replace(reLatin, deburrLetter).replace(reComboMark, ''); + } + + /** + * Checks if `string` ends with the given target string. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to inspect. + * @param {string} [target] The string to search for. + * @param {number} [position=string.length] The position to search up to. + * @returns {boolean} Returns `true` if `string` ends with `target`, + * else `false`. + * @example + * + * _.endsWith('abc', 'c'); + * // => true + * + * _.endsWith('abc', 'b'); + * // => false + * + * _.endsWith('abc', 'b', 2); + * // => true + */ + function endsWith(string, target, position) { + string = toString(string); + target = baseToString(target); + + var length = string.length; + position = position === undefined + ? length + : baseClamp(toInteger(position), 0, length); + + var end = position; + position -= target.length; + return position >= 0 && string.slice(position, end) == target; + } + + /** + * Converts the characters "&", "<", ">", '"', and "'" in `string` to their + * corresponding HTML entities. + * + * **Note:** No other characters are escaped. To escape additional + * characters use a third-party library like [_he_](https://mths.be/he). + * + * Though the ">" character is escaped for symmetry, characters like + * ">" and "/" don't need escaping in HTML and have no special meaning + * unless they're part of a tag or unquoted attribute value. See + * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) + * (under "semi-related fun fact") for more details. + * + * When working with HTML you should always + * [quote attribute values](http://wonko.com/post/html-escaping) to reduce + * XSS vectors. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category String + * @param {string} [string=''] The string to escape. + * @returns {string} Returns the escaped string. + * @example + * + * _.escape('fred, barney, & pebbles'); + * // => 'fred, barney, & pebbles' + */ + function escape(string) { + string = toString(string); + return (string && reHasUnescapedHtml.test(string)) + ? string.replace(reUnescapedHtml, escapeHtmlChar) + : string; + } + + /** + * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+", + * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to escape. + * @returns {string} Returns the escaped string. + * @example + * + * _.escapeRegExp('[lodash](https://lodash.com/)'); + * // => '\[lodash\]\(https://lodash\.com/\)' + */ + function escapeRegExp(string) { + string = toString(string); + return (string && reHasRegExpChar.test(string)) + ? string.replace(reRegExpChar, '\\$&') + : string; + } + + /** + * Converts `string` to + * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the kebab cased string. + * @example + * + * _.kebabCase('Foo Bar'); + * // => 'foo-bar' + * + * _.kebabCase('fooBar'); + * // => 'foo-bar' + * + * _.kebabCase('__FOO_BAR__'); + * // => 'foo-bar' + */ + var kebabCase = createCompounder(function(result, word, index) { + return result + (index ? '-' : '') + word.toLowerCase(); + }); + + /** + * Converts `string`, as space separated words, to lower case. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the lower cased string. + * @example + * + * _.lowerCase('--Foo-Bar--'); + * // => 'foo bar' + * + * _.lowerCase('fooBar'); + * // => 'foo bar' + * + * _.lowerCase('__FOO_BAR__'); + * // => 'foo bar' + */ + var lowerCase = createCompounder(function(result, word, index) { + return result + (index ? ' ' : '') + word.toLowerCase(); + }); + + /** + * Converts the first character of `string` to lower case. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the converted string. + * @example + * + * _.lowerFirst('Fred'); + * // => 'fred' + * + * _.lowerFirst('FRED'); + * // => 'fRED' + */ + var lowerFirst = createCaseFirst('toLowerCase'); + + /** + * Pads `string` on the left and right sides if it's shorter than `length`. + * Padding characters are truncated if they can't be evenly divided by `length`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to pad. + * @param {number} [length=0] The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padded string. + * @example + * + * _.pad('abc', 8); + * // => ' abc ' + * + * _.pad('abc', 8, '_-'); + * // => '_-abc_-_' + * + * _.pad('abc', 3); + * // => 'abc' + */ + function pad(string, length, chars) { + string = toString(string); + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + if (!length || strLength >= length) { + return string; + } + var mid = (length - strLength) / 2; + return ( + createPadding(nativeFloor(mid), chars) + + string + + createPadding(nativeCeil(mid), chars) + ); + } + + /** + * Pads `string` on the right side if it's shorter than `length`. Padding + * characters are truncated if they exceed `length`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to pad. + * @param {number} [length=0] The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padded string. + * @example + * + * _.padEnd('abc', 6); + * // => 'abc ' + * + * _.padEnd('abc', 6, '_-'); + * // => 'abc_-_' + * + * _.padEnd('abc', 3); + * // => 'abc' + */ + function padEnd(string, length, chars) { + string = toString(string); + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + return (length && strLength < length) + ? (string + createPadding(length - strLength, chars)) + : string; + } + + /** + * Pads `string` on the left side if it's shorter than `length`. Padding + * characters are truncated if they exceed `length`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to pad. + * @param {number} [length=0] The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padded string. + * @example + * + * _.padStart('abc', 6); + * // => ' abc' + * + * _.padStart('abc', 6, '_-'); + * // => '_-_abc' + * + * _.padStart('abc', 3); + * // => 'abc' + */ + function padStart(string, length, chars) { + string = toString(string); + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + return (length && strLength < length) + ? (createPadding(length - strLength, chars) + string) + : string; + } + + /** + * Converts `string` to an integer of the specified radix. If `radix` is + * `undefined` or `0`, a `radix` of `10` is used unless `value` is a + * hexadecimal, in which case a `radix` of `16` is used. + * + * **Note:** This method aligns with the + * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`. + * + * @static + * @memberOf _ + * @since 1.1.0 + * @category String + * @param {string} string The string to convert. + * @param {number} [radix=10] The radix to interpret `value` by. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {number} Returns the converted integer. + * @example + * + * _.parseInt('08'); + * // => 8 + * + * _.map(['6', '08', '10'], _.parseInt); + * // => [6, 8, 10] + */ + function parseInt(string, radix, guard) { + if (guard || radix == null) { + radix = 0; + } else if (radix) { + radix = +radix; + } + return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0); + } + + /** + * Repeats the given string `n` times. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to repeat. + * @param {number} [n=1] The number of times to repeat the string. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {string} Returns the repeated string. + * @example + * + * _.repeat('*', 3); + * // => '***' + * + * _.repeat('abc', 2); + * // => 'abcabc' + * + * _.repeat('abc', 0); + * // => '' + */ + function repeat(string, n, guard) { + if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) { + n = 1; + } else { + n = toInteger(n); + } + return baseRepeat(toString(string), n); + } + + /** + * Replaces matches for `pattern` in `string` with `replacement`. + * + * **Note:** This method is based on + * [`String#replace`](https://mdn.io/String/replace). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to modify. + * @param {RegExp|string} pattern The pattern to replace. + * @param {Function|string} replacement The match replacement. + * @returns {string} Returns the modified string. + * @example + * + * _.replace('Hi Fred', 'Fred', 'Barney'); + * // => 'Hi Barney' + */ + function replace() { + var args = arguments, + string = toString(args[0]); + + return args.length < 3 ? string : string.replace(args[1], args[2]); + } + + /** + * Converts `string` to + * [snake case](https://en.wikipedia.org/wiki/Snake_case). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the snake cased string. + * @example + * + * _.snakeCase('Foo Bar'); + * // => 'foo_bar' + * + * _.snakeCase('fooBar'); + * // => 'foo_bar' + * + * _.snakeCase('--FOO-BAR--'); + * // => 'foo_bar' + */ + var snakeCase = createCompounder(function(result, word, index) { + return result + (index ? '_' : '') + word.toLowerCase(); + }); + + /** + * Splits `string` by `separator`. + * + * **Note:** This method is based on + * [`String#split`](https://mdn.io/String/split). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to split. + * @param {RegExp|string} separator The separator pattern to split by. + * @param {number} [limit] The length to truncate results to. + * @returns {Array} Returns the string segments. + * @example + * + * _.split('a-b-c', '-', 2); + * // => ['a', 'b'] + */ + function split(string, separator, limit) { + if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) { + separator = limit = undefined; + } + limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0; + if (!limit) { + return []; + } + string = toString(string); + if (string && ( + typeof separator == 'string' || + (separator != null && !isRegExp(separator)) + )) { + separator = baseToString(separator); + if (!separator && hasUnicode(string)) { + return castSlice(stringToArray(string), 0, limit); + } + } + return string.split(separator, limit); + } + + /** + * Converts `string` to + * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). + * + * @static + * @memberOf _ + * @since 3.1.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the start cased string. + * @example + * + * _.startCase('--foo-bar--'); + * // => 'Foo Bar' + * + * _.startCase('fooBar'); + * // => 'Foo Bar' + * + * _.startCase('__FOO_BAR__'); + * // => 'FOO BAR' + */ + var startCase = createCompounder(function(result, word, index) { + return result + (index ? ' ' : '') + upperFirst(word); + }); + + /** + * Checks if `string` starts with the given target string. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to inspect. + * @param {string} [target] The string to search for. + * @param {number} [position=0] The position to search from. + * @returns {boolean} Returns `true` if `string` starts with `target`, + * else `false`. + * @example + * + * _.startsWith('abc', 'a'); + * // => true + * + * _.startsWith('abc', 'b'); + * // => false + * + * _.startsWith('abc', 'b', 1); + * // => true + */ + function startsWith(string, target, position) { + string = toString(string); + position = position == null + ? 0 + : baseClamp(toInteger(position), 0, string.length); + + target = baseToString(target); + return string.slice(position, position + target.length) == target; + } + + /** + * Creates a compiled template function that can interpolate data properties + * in "interpolate" delimiters, HTML-escape interpolated data properties in + * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data + * properties may be accessed as free variables in the template. If a setting + * object is given, it takes precedence over `_.templateSettings` values. + * + * **Note:** In the development build `_.template` utilizes + * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) + * for easier debugging. + * + * For more information on precompiling templates see + * [lodash's custom builds documentation](https://lodash.com/custom-builds). + * + * For more information on Chrome extension sandboxes see + * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category String + * @param {string} [string=''] The template string. + * @param {Object} [options={}] The options object. + * @param {RegExp} [options.escape=_.templateSettings.escape] + * The HTML "escape" delimiter. + * @param {RegExp} [options.evaluate=_.templateSettings.evaluate] + * The "evaluate" delimiter. + * @param {Object} [options.imports=_.templateSettings.imports] + * An object to import into the template as free variables. + * @param {RegExp} [options.interpolate=_.templateSettings.interpolate] + * The "interpolate" delimiter. + * @param {string} [options.sourceURL='lodash.templateSources[n]'] + * The sourceURL of the compiled template. + * @param {string} [options.variable='obj'] + * The data object variable name. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Function} Returns the compiled template function. + * @example + * + * // Use the "interpolate" delimiter to create a compiled template. + * var compiled = _.template('hello <%= user %>!'); + * compiled({ 'user': 'fred' }); + * // => 'hello fred!' + * + * // Use the HTML "escape" delimiter to escape data property values. + * var compiled = _.template('<%- value %>'); + * compiled({ 'value': ' + + + {{content-for "body-footer"}} + + diff --git a/tests/dummy/app/models/.gitkeep b/tests/dummy/app/models/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/dummy/app/resolver.ts b/tests/dummy/app/resolver.ts new file mode 100644 index 00000000000..2fb563d6c04 --- /dev/null +++ b/tests/dummy/app/resolver.ts @@ -0,0 +1,3 @@ +import Resolver from 'ember-resolver'; + +export default Resolver; diff --git a/tests/dummy/app/router.ts b/tests/dummy/app/router.ts new file mode 100644 index 00000000000..8f6f4598916 --- /dev/null +++ b/tests/dummy/app/router.ts @@ -0,0 +1,11 @@ +import EmberRouter from '@ember/routing/router'; +import config from './config/environment'; + +const Router = EmberRouter.extend({ + location: config.locationType, + rootURL: config.rootURL, +}); + +Router.map(function() {}); + +export default Router; diff --git a/tests/dummy/app/routes/.gitkeep b/tests/dummy/app/routes/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/dummy/app/routes/application/route.ts b/tests/dummy/app/routes/application/route.ts new file mode 100644 index 00000000000..d09f667b240 --- /dev/null +++ b/tests/dummy/app/routes/application/route.ts @@ -0,0 +1,3 @@ +import Route from '@ember/routing/route'; + +export default Route.extend({}); diff --git a/tests/dummy/app/routes/application/template.hbs b/tests/dummy/app/routes/application/template.hbs new file mode 100644 index 00000000000..1c967ea89c3 --- /dev/null +++ b/tests/dummy/app/routes/application/template.hbs @@ -0,0 +1,6 @@ + +{{outlet}} diff --git a/tests/dummy/app/routes/components/.gitkeep b/tests/dummy/app/routes/components/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.css new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/dummy/app/templates/.gitkeep b/tests/dummy/app/templates/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js new file mode 100644 index 00000000000..8f6ea148349 --- /dev/null +++ b/tests/dummy/config/environment.js @@ -0,0 +1,51 @@ +'use strict'; + +var fs = require('fs'); +var path = require('path'); +var featuresJsonPath = path.join(__dirname, '../../../config/features.json'); +var featuresJson = fs.readFileSync(featuresJsonPath, { encoding: 'utf8' }); +var featureFlags = JSON.parse(featuresJson); + +module.exports = function(environment) { + var ENV = { + modulePrefix: 'dummy', + podModulePrefix: 'dummy/routes', + environment: environment, + rootURL: '/', + locationType: 'auto', + EmberENV: { + FEATURES: featureFlags, + RAISE_ON_DEPRECATION: false, + }, + + APP: { + // Here you can pass flags/options to your application instance + // when it is created + }, + }; + + if (environment === 'test-optional-features') { + ENV.EmberENV.ENABLE_OPTIONAL_FEATURES = true; + } + + if (environment === 'development') { + // ENV.APP.LOG_RESOLVER = true; + // ENV.APP.LOG_ACTIVE_GENERATION = true; + // ENV.APP.LOG_TRANSITIONS = true; + // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; + // ENV.APP.LOG_VIEW_LOOKUPS = true; + } + + if (environment === 'test') { + // Testem prefers this... + ENV.locationType = 'none'; + + // keep test console output quieter + ENV.APP.LOG_ACTIVE_GENERATION = false; + ENV.APP.LOG_VIEW_LOOKUPS = false; + + ENV.APP.rootElement = '#ember-testing'; + } + + return ENV; +}; diff --git a/tests/dummy/config/targets.js b/tests/dummy/config/targets.js new file mode 100644 index 00000000000..2e8b5f14f4a --- /dev/null +++ b/tests/dummy/config/targets.js @@ -0,0 +1,13 @@ +'use strict'; + +const browsers = ['last 1 Chrome versions', 'last 1 Firefox versions', 'last 1 Safari versions']; + +const needsIE11 = !!process.env.TARGET_IE11; + +if (needsIE11) { + browsers.push('ie 11'); +} + +module.exports = { + browsers, +}; diff --git a/tests/dummy/public/crossdomain.xml b/tests/dummy/public/crossdomain.xml new file mode 100644 index 00000000000..0c16a7a07b3 --- /dev/null +++ b/tests/dummy/public/crossdomain.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/tests/dummy/public/robots.txt b/tests/dummy/public/robots.txt new file mode 100644 index 00000000000..f5916452e5f --- /dev/null +++ b/tests/dummy/public/robots.txt @@ -0,0 +1,3 @@ +# http://www.robotstxt.org +User-agent: * +Disallow: diff --git a/tests/ember_configuration.js b/tests/ember_configuration.js deleted file mode 100644 index bee739c60eb..00000000000 --- a/tests/ember_configuration.js +++ /dev/null @@ -1,208 +0,0 @@ -/*globals EmberDev ENV QUnit */ - -(function() { - window.Ember = window.Ember || {}; - - Ember.config = {}; - Ember.testing = true; - - window.ENV = { TESTING: true }; - - var extendPrototypes = QUnit.urlParams.extendprototypes; - ENV['EXTEND_PROTOTYPES'] = !!extendPrototypes; - - if (EmberDev.jsHint) { - // jsHint makes its own Object.create stub, we don't want to use this - ENV['STUB_OBJECT_CREATE'] = !Object.create; - } - - window.async = function(callback, timeout) { - stop(); - - timeout = setTimeout(function() { - start(); - ok(false, "Timeout was reached"); - }, timeout || 200); - - return function() { - clearTimeout(timeout); - - start(); - - var args = arguments; - return Ember.run(function() { - return callback.apply(this, args); - }); - }; - }; - - window.asyncEqual = function(a, b, message) { - Ember.RSVP.all([ Ember.RSVP.resolve(a), Ember.RSVP.resolve(b) ]).then(async(function(array) { - /*globals QUnit*/ - QUnit.push(array[0] === array[1], array[0], array[1], message); - })); - }; - - window.invokeAsync = function(callback, timeout) { - timeout = timeout || 1; - - setTimeout(async(callback, timeout+100), timeout); - }; - - window.setupStore = function(options) { - var env = {}; - options = options || {}; - - var container = env.container = new Ember.Container(); - - var adapter = env.adapter = (options.adapter || DS.Adapter); - delete options.adapter; - - for (var prop in options) { - container.register('model:' + prop, options[prop]); - } - - container.register('store:main', DS.Store.extend({ - adapter: adapter - })); - - container.register('serializer:-default', DS.JSONSerializer); - container.register('serializer:-rest', DS.RESTSerializer); - container.register('adapter:-rest', DS.RESTAdapter); - - container.injection('serializer', 'store', 'store:main'); - - env.serializer = container.lookup('serializer:-default'); - env.restSerializer = container.lookup('serializer:-rest'); - env.store = container.lookup('store:main'); - env.adapter = env.store.get('defaultAdapter'); - - return env; - }; - - window.createStore = function(options) { - return setupStore(options).store; - }; - - var syncForTest = function(fn) { - var callSuper; - - if (typeof fn !== "function") { callSuper = true; } - - return function() { - var override = false, ret; - - if (Ember.run && !Ember.run.currentRunLoop) { - Ember.run.begin(); - override = true; - } - - try { - if (callSuper) { - ret = this._super.apply(this, arguments); - } else { - ret = fn.apply(this, arguments); - } - } finally { - if (override) { - Ember.run.end(); - } - } - - return ret; - }; - }; - - Ember.config.overrideAccessors = function() { - Ember.set = syncForTest(Ember.set); - Ember.get = syncForTest(Ember.get); - }; - - Ember.config.overrideClassMixin = function(ClassMixin) { - ClassMixin.reopen({ - create: syncForTest() - }); - }; - - Ember.config.overridePrototypeMixin = function(PrototypeMixin) { - PrototypeMixin.reopen({ - destroy: syncForTest() - }); - }; - - minispade.register('ember-data/~test-setup', function() { - Ember.RSVP.configure('onerror', function(reason) { - // only print error messages if they're exceptions; - // otherwise, let a future turn of the event loop - // handle the error. - if (reason && reason instanceof Error) { - Ember.Logger.log(reason, reason.stack) - throw reason; - } - }); - - Ember.RSVP.resolve = syncForTest(Ember.RSVP.resolve); - - Ember.View.reopen({ - _insertElementLater: syncForTest() - }); - - DS.Store.reopen({ - save: syncForTest(), - createRecord: syncForTest(), - deleteRecord: syncForTest(), - push: syncForTest(), - pushMany: syncForTest(), - filter: syncForTest(), - find: syncForTest(), - findMany: syncForTest(), - findByIds: syncForTest(), - didSaveRecord: syncForTest(), - didSaveRecords: syncForTest(), - didUpdateAttribute: syncForTest(), - didUpdateAttributes: syncForTest(), - didUpdateRelationship: syncForTest(), - didUpdateRelationships: syncForTest() - }); - - DS.Model.reopen({ - save: syncForTest(), - reload: syncForTest(), - deleteRecord: syncForTest(), - dataDidChange: Ember.observer(syncForTest(), 'data'), - updateRecordArraysLater: syncForTest() - }); - - DS.Errors.reopen({ - add: syncForTest(), - remove: syncForTest(), - clear: syncForTest() - }); - - var transforms = { - 'boolean': DS.BooleanTransform.create(), - 'date': DS.DateTransform.create(), - 'number': DS.NumberTransform.create(), - 'string': DS.StringTransform.create() - }; - - // Prevent all tests involving serialization to require a container - DS.JSONSerializer.reopen({ - transformFor: function(attributeType) { - return this._super(attributeType, true) || transforms[attributeType]; - } - }); - - Ember.RSVP.Promise.prototype.then = syncForTest(Ember.RSVP.Promise.prototype.then); - }); - - EmberDev.distros = { - spade: 'ember-data-spade.js', - build: 'ember-data.js' - }; - - // Generate the jQuery expando on window ahead of time - // to make the QUnit global check run clean - jQuery(window).data('testing', true); - -})(); diff --git a/tests/helpers/async.js b/tests/helpers/async.js new file mode 100644 index 00000000000..40a5e12c93d --- /dev/null +++ b/tests/helpers/async.js @@ -0,0 +1,36 @@ +import { all, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; + +export function wait(callback, timeout) { + let done = this.async(); + + let timer = setTimeout(() => { + this.ok(false, 'Timeout was reached'); + done(); + }, timeout || 200); + + return function() { + window.clearTimeout(timer); + + let args = arguments; + let result; + try { + result = run(() => callback.apply(this, args)); + } finally { + done(); + } + return result; + }; +} + +export function asyncEqual(a, b, message) { + return all([resolve(a), resolve(b)]).then( + this.wait(array => { + this.push(array[0] === array[1], array[0], array[1], message); + }) + ); +} + +export function invokeAsync(callback, timeout = 1) { + setTimeout(this.wait(callback, timeout + 100), timeout); +} diff --git a/tests/helpers/custom-adapter.js b/tests/helpers/custom-adapter.js new file mode 100644 index 00000000000..7e174c1520b --- /dev/null +++ b/tests/helpers/custom-adapter.js @@ -0,0 +1,12 @@ +import { run } from '@ember/runloop'; +import DS from 'ember-data'; + +export default function(env, adapterDefinition) { + let adapter = adapterDefinition; + if (!DS.Adapter.detect(adapterDefinition)) { + adapter = DS.Adapter.extend(adapterDefinition); + } + let store = env.store; + env.owner.register('adapter:-custom', adapter); + run(() => store.set('adapter', '-custom')); +} diff --git a/tests/helpers/deep-copy.js b/tests/helpers/deep-copy.js new file mode 100644 index 00000000000..143c31d3dbc --- /dev/null +++ b/tests/helpers/deep-copy.js @@ -0,0 +1,54 @@ +/* global WeakMap */ +export default function deepCopy(obj) { + return _deepCopy(obj, new WeakMap()); +} + +function isPrimitive(value) { + return typeof value !== 'object' || value === null; +} + +function _deepCopy(oldObject, seen) { + if (Array.isArray(oldObject)) { + return copyArray(oldObject, seen); + } else if (!isPrimitive(oldObject)) { + return copyObject(oldObject, seen); + } else { + return oldObject; + } +} + +function copyObject(oldObject, seen) { + let newObject = {}; + + Object.keys(oldObject).forEach(key => { + let value = oldObject[key]; + let newValue = isPrimitive(value) ? value : seen.get(value); + + if (value && newValue === undefined) { + newValue = newObject[key] = _deepCopy(value, seen); + seen.set(value, newValue); + } + + newObject[key] = newValue; + }); + + return newObject; +} + +function copyArray(oldArray, seen) { + let newArray = []; + + for (let i = 0; i < oldArray.length; i++) { + let value = oldArray[i]; + let newValue = isPrimitive(value) ? value : seen.get(value); + + if (value && newValue === undefined) { + newValue = newArray[i] = _deepCopy(value, seen); + seen.set(value, newValue); + } + + newArray[i] = newValue; + } + + return newArray; +} diff --git a/tests/helpers/destroy-app.js b/tests/helpers/destroy-app.js new file mode 100644 index 00000000000..e7f983bd14b --- /dev/null +++ b/tests/helpers/destroy-app.js @@ -0,0 +1,5 @@ +import { run } from '@ember/runloop'; + +export default function destroyApp(application) { + run(application, 'destroy'); +} diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js new file mode 100644 index 00000000000..53ef0cfac24 --- /dev/null +++ b/tests/helpers/module-for-acceptance.js @@ -0,0 +1,21 @@ +import { Promise } from 'rsvp'; +import { module } from 'qunit'; +import startApp from '../helpers/start-app'; +import destroyApp from '../helpers/destroy-app'; + +export default function(name, options = {}) { + module(name, { + beforeEach() { + this.application = startApp(); + + if (options.beforeEach) { + return options.beforeEach.apply(this, arguments); + } + }, + + afterEach() { + let afterEach = options.afterEach && options.afterEach.apply(this, arguments); + return Promise.resolve(afterEach).then(() => destroyApp(this.application)); + }, + }); +} diff --git a/tests/helpers/owner.js b/tests/helpers/owner.js new file mode 100644 index 00000000000..8b8e3abee97 --- /dev/null +++ b/tests/helpers/owner.js @@ -0,0 +1,12 @@ +import EmberObject from '@ember/object'; +import Ember from 'ember'; + +let Owner; + +if (Ember._RegistryProxyMixin && Ember._ContainerProxyMixin) { + Owner = EmberObject.extend(Ember._RegistryProxyMixin, Ember._ContainerProxyMixin); +} else { + Owner = EmberObject.extend(); +} + +export default Owner; diff --git a/tests/helpers/resolver.js b/tests/helpers/resolver.js new file mode 100644 index 00000000000..fa5d4579739 --- /dev/null +++ b/tests/helpers/resolver.js @@ -0,0 +1,9 @@ +import Resolver from '../../resolver'; +import config from '../../config/environment'; + +export default Resolver.create({ + namespace: { + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix, + }, +}); diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js new file mode 100644 index 00000000000..37db37f585e --- /dev/null +++ b/tests/helpers/start-app.js @@ -0,0 +1,19 @@ +import { run } from '@ember/runloop'; +import { merge } from '@ember/polyfills'; +import Application from '../../app'; +import config from '../../config/environment'; + +export default function startApp(attrs) { + let application; + + let attributes = merge({}, config.APP); + attributes = merge(attributes, attrs); // use defaults, but you can override; + + run(() => { + application = Application.create(attributes); + application.setupForTesting(); + application.injectTestHelpers(); + }); + + return application; +} diff --git a/tests/helpers/store.js b/tests/helpers/store.js new file mode 100644 index 00000000000..f0ca5a9a8e3 --- /dev/null +++ b/tests/helpers/store.js @@ -0,0 +1,112 @@ +import { dasherize } from '@ember/string'; +import { setResolver } from '@ember/test-helpers'; +import EmberObject from '@ember/object'; +import Ember from 'ember'; +import Store from 'ember-data/store'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import RESTAdapter from 'ember-data/adapters/rest'; +import Adapter from 'ember-data/adapter'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import RESTSerializer from 'ember-data/serializers/rest'; +import JSONSerializer from 'ember-data/serializers/json'; +import config from '../../config/environment'; +import Resolver from '../../resolver'; + +const { _RegistryProxyMixin, _ContainerProxyMixin, Registry } = Ember; + +const Owner = EmberObject.extend(_RegistryProxyMixin, _ContainerProxyMixin); +const resolver = Resolver.create({ + namespace: { + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix, + }, +}); + +// TODO get us to a setApplication world instead +// seems to require killing off createStore +setResolver(resolver); + +export default function setupStore(options) { + let container, registry, owner; + let env = {}; + options = options || {}; + + registry = new Registry(); + registry.optionsForType('serializer', { singleton: false }); + registry.optionsForType('adapter', { singleton: false }); + + owner = Owner.create({ __registry__: registry }); + container = registry.container({ owner }); + owner.__container__ = container; + + env.owner = owner; + env.container = container; + env.registry = registry; + + env.replaceContainerNormalize = function replaceContainerNormalize(fn) { + if (env.registry) { + env.registry.normalize = fn; + } else { + env.container.normalize = fn; + } + }; + + let adapter = (env.adapter = options.adapter || '-default'); + delete options.adapter; + + if (typeof adapter !== 'string') { + env.registry.register('adapter:-ember-data-test-custom', adapter); + adapter = '-ember-data-test-custom'; + } + + for (let prop in options) { + registry.register('model:' + dasherize(prop), options[prop]); + } + + registry.optionsForType('serializer', { singleton: false }); + registry.optionsForType('adapter', { singleton: false }); + + owner.register('service:store', Store.extend({ adapter })); + owner.register('serializer:-default', JSONAPISerializer); + owner.register('serializer:-json', JSONSerializer); + owner.register('serializer:-rest', RESTSerializer); + owner.register('adapter:-default', Adapter); + owner.register('adapter:-rest', RESTAdapter); + owner.register('adapter:-json-api', JSONAPIAdapter); + + owner.inject('serializer', 'store', 'service:store'); + + owner.inject('serializer', 'store', 'service:store'); + + registry.injection('serializer', 'store', 'service:store'); + + env.store = container.lookup('service:store'); + env.restSerializer = container.lookup('serializer:-rest'); + env.restSerializer.store = env.store; + env.serializer = env.store.serializerFor('-default'); + env.serializer.store = env.store; + // lazily create the adapter method because some tests depend on + // modifiying the adapter in the container after setupStore is + // called + Object.defineProperty(env, 'adapter', { + get() { + if (!this._adapter) { + this._adapter = this.store.adapterFor('application'); + } + return this._adapter; + }, + set(adapter) { + this._adapter = adapter; + }, + enumerable: true, + configurable: true, + }); + + return env; +} + +export { setupStore }; + +export function createStore(options) { + return setupStore(options).store; +} diff --git a/tests/helpers/test-in-debug.js b/tests/helpers/test-in-debug.js new file mode 100644 index 00000000000..949b64daac2 --- /dev/null +++ b/tests/helpers/test-in-debug.js @@ -0,0 +1,10 @@ +import { DEBUG } from '@glimmer/env'; +import { test, skip } from 'qunit'; + +export default function testInDebug() { + if (DEBUG) { + test(...arguments); + } else { + skip(...arguments); + } +} diff --git a/tests/helpers/todo.js b/tests/helpers/todo.js new file mode 100644 index 00000000000..41a570184cd --- /dev/null +++ b/tests/helpers/todo.js @@ -0,0 +1,95 @@ +/* global Proxy */ +import QUnit, { test } from 'qunit'; + +export default function todo(description, callback) { + test(`[TODO] ${description}`, async function todoTest(assert) { + let todos = []; + hijackAssert(assert, todos); + + await callback.call(this, assert); + + assertTestStatus(assert, todos); + }); +} + +function hijackAssert(assert, todos) { + const pushResult = assert.pushResult; + + assert.pushResult = function hijackedPushResult(assertion) { + let result = assertion.result; + if (!assertion.isTodo && result === false) { + assertion.message = `[REGRESSION ENCOUNTERED] ${assertion.message}`; + } + + return pushResult.call(assert, assertion); + }; + let handler = { + get(target, propKey /*, receiver*/) { + const origMethod = target[propKey]; + + if (typeof origMethod === 'function' && propKey === 'pushResult') { + return function captureResult(assertion) { + let result = assertion.result; + assertion.isTodo = true; + assertion.message = `[TODO ${result === true ? 'COMPLETED' : 'INCOMPLETE'}] ${ + assertion.message + }`; + + todos.push(assertion); + origMethod.call(target, assertion); + }; + } else { + return origMethod; + } + }, + }; + + assert.todo = new Proxy(assert, handler); +} + +function assertTestStatus(assert, todos) { + assert.todo = false; + const totalTodoFailures = todos.reduce((c, r) => { + return r.result === false ? c + 1 : c; + }, 0); + const results = QUnit.config.current.assertions; + const totalFailures = results.reduce((c, r) => { + return r.result === false ? c + 1 : c; + }, 0); + const hasNonTodoFailures = totalFailures > totalTodoFailures; + const hasSomeCompletedTodos = totalTodoFailures < todos.length; + const totalWasMet = assert.test.expected === null || assert.test.expected === results.length; + const todoIsComplete = totalWasMet && totalTodoFailures === 0; + + if (todoIsComplete) { + assert.pushResult({ + isTodo: true, + actual: true, + expected: false, + message: + '[TODO COMPLETED] This TODO is now complete (all "todo" assertions pass) and MUST be converted from todo() to test()', + result: false, + }); + } else if (hasNonTodoFailures) { + assert.pushResult({ + isTodo: true, + actual: false, + expected: true, + message: + '[REGRESSION MUST-FIX] This TODO is has regressed (a non "todo" assertion has failed) and MUST be fixed', + result: false, + }); + } else if (hasSomeCompletedTodos) { + assert.pushResult({ + isTodo: true, + actual: false, + expected: true, + message: + '[TODOS COMPLETED] Some assert.todos assertions have been completed and MUST now be converted from assert.todo to assert.', + result: false, + }); + } else { + assert.test.skip = true; + assert.test.testReport.skipped = true; + } +} diff --git a/tests/helpers/watch-property.js b/tests/helpers/watch-property.js new file mode 100644 index 00000000000..8a210b9a4d0 --- /dev/null +++ b/tests/helpers/watch-property.js @@ -0,0 +1,157 @@ +import { removeObserver, addObserver } from '@ember/object/observers'; +import QUnit from 'qunit'; + +function makeCounter() { + let count = 0; + const counter = Object.create(null); + counter.reset = function resetCounter() { + count = 0; + }; + + Object.defineProperty(counter, 'count', { + get() { + return count; + }, + set() {}, + configurable: false, + enumerable: true, + }); + + Object.freeze(counter); + + function increment() { + count++; + } + + return { counter, increment }; +} + +export function watchProperty(obj, propertyName) { + let { counter, increment } = makeCounter(); + + function observe() { + increment(); + } + + addObserver(obj, propertyName, observe); + + function unwatch() { + removeObserver(obj, propertyName, observe); + } + + return { counter, unwatch }; +} + +export function watchProperties(obj, propertyNames) { + let watched = {}; + let counters = {}; + + if (!Array.isArray(propertyNames)) { + throw new Error( + `Must call watchProperties with an array of propertyNames to watch, received ${propertyNames}` + ); + } + + for (let i = 0; i < propertyNames.length; i++) { + let propertyName = propertyNames[i]; + + if (watched[propertyName] !== undefined) { + throw new Error(`Cannot watch the same property ${propertyName} more than once`); + } + + let { counter, increment } = makeCounter(); + watched[propertyName] = increment; + counters[propertyName] = counter; + + addObserver(obj, propertyName, increment); + } + + function unwatch() { + Object.keys(watched).forEach(propertyName => { + removeObserver(obj, propertyName, watched[propertyName]); + }); + } + + return { counters, unwatch }; +} + +QUnit.assert.watchedPropertyCounts = function assertWatchedPropertyCount( + watchedObject, + expectedCounts, + label = '' +) { + if (!watchedObject || !watchedObject.counters) { + throw new Error( + 'Expected to receive the return value of watchProperties: an object containing counters' + ); + } + + let counters = watchedObject.counters; + + Object.keys(expectedCounts).forEach(propertyName => { + let counter = counters[propertyName]; + let expectedCount = expectedCounts[propertyName]; + let assertionText = label; + + if (Array.isArray(expectedCount)) { + label = expectedCount[1]; + expectedCount = expectedCount[0]; + } + + assertionText += ` | Expected ${expectedCount} change notifications for ${propertyName} but recieved ${ + counter.count + }`; + + if (counter === undefined) { + throw new Error( + `Cannot assert expected count for ${propertyName} as there is no watcher for that property` + ); + } + + this.pushResult({ + result: counter.count === expectedCount, + actual: counter.count, + expected: expectedCount, + message: assertionText, + }); + }); +}; + +QUnit.assert.watchedPropertyCount = function assertWatchedPropertyCount( + watcher, + expectedCount, + label +) { + let counter; + if (!watcher) { + throw new Error(`Expected to receive a watcher`); + } + + // this allows us to handle watchers passed in from a watchProperties return hash + if (!watcher.counter && watcher.count !== undefined) { + counter = watcher; + } else { + counter = watcher.counter; + } + + this.pushResult({ + result: counter.count === expectedCount, + actual: counter.count, + expected: expectedCount, + message: label, + }); +}; + +QUnit.assert.dirties = function assertDirties(options, updateMethodCallback, label) { + let { object: obj, property, count } = options; + count = typeof count === 'number' ? count : 1; + let { counter, unwatch } = watchProperty(obj, property); + updateMethodCallback(); + this.pushResult({ + result: counter.count === count, + actual: counter.count, + expected: count, + message: label, + }); + unwatch(); +}; diff --git a/tests/index.html b/tests/index.html new file mode 100644 index 00000000000..5209b852321 --- /dev/null +++ b/tests/index.html @@ -0,0 +1,33 @@ + + + + + + Dummy Tests + + + + {{content-for "head"}} + {{content-for "test-head"}} + + + + + + {{content-for "head-footer"}} + {{content-for "test-head-footer"}} + + + {{content-for "body"}} + {{content-for "test-body"}} + + + + + + + + {{content-for "body-footer"}} + {{content-for "test-body-footer"}} + + diff --git a/tests/integration/adapter/build-url-mixin-test.js b/tests/integration/adapter/build-url-mixin-test.js new file mode 100644 index 00000000000..04ac25e974a --- /dev/null +++ b/tests/integration/adapter/build-url-mixin-test.js @@ -0,0 +1,337 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import { decamelize, underscore } from '@ember/string'; +import { resolve } from 'rsvp'; +import deepCopy from 'dummy/tests/helpers/deep-copy'; +import { pluralize } from 'ember-inflector'; +import RESTAdapter from 'ember-data/adapters/rest'; +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +import { belongsTo, hasMany } from 'ember-data/relationships'; + +module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', function(hooks) { + setupTest(hooks); + + let store, adapter, Post, Comment, passedUrl; + + function ajaxResponse(value) { + adapter.ajax = function(url, verb, hash) { + passedUrl = url; + + return resolve(deepCopy(value)); + }; + } + + hooks.beforeEach(function() { + let { owner } = this; + const PostModel = Model.extend({ + name: attr('string'), + }); + const CommentModel = Model.extend({ + name: attr('string'), + }); + const SuperUser = Model.extend({}); + + owner.register('adapter:application', RESTAdapter); + owner.register('model:comment', CommentModel); + owner.register('model:post', PostModel); + owner.register('model:super-user', SuperUser); + + store = owner.lookup('service:store'); + adapter = store.adapterFor('application'); + + Post = store.modelFor('post'); + Comment = store.modelFor('comment'); + + passedUrl = null; + }); + + test('buildURL - with host and namespace', async function(assert) { + adapter.setProperties({ + host: 'http://example.com', + namespace: 'api/v1', + }); + + ajaxResponse({ posts: [{ id: 1 }] }); + + await store.findRecord('post', 1); + + assert.equal(passedUrl, 'http://example.com/api/v1/posts/1'); + }); + + test('buildURL - with relative paths in links', async function(assert) { + adapter.setProperties({ + host: 'http://example.com', + namespace: 'api/v1', + }); + + Post.reopen({ comments: hasMany('comment', { async: true }) }); + Comment.reopen({ post: belongsTo('post', { async: false }) }); + + ajaxResponse({ posts: [{ id: 1, links: { comments: 'comments' } }] }); + + let post = await store.findRecord('post', 1); + ajaxResponse({ comments: [{ id: 1 }] }); + + await post.get('comments'); + assert.equal(passedUrl, 'http://example.com/api/v1/posts/1/comments'); + }); + + test('buildURL - with absolute paths in links', async function(assert) { + adapter.setProperties({ + host: 'http://example.com', + namespace: 'api/v1', + }); + + Post.reopen({ comments: hasMany('comment', { async: true }) }); + Comment.reopen({ post: belongsTo('post', { async: false }) }); + + ajaxResponse({ posts: [{ id: 1, links: { comments: '/api/v1/posts/1/comments' } }] }); + + let post = await store.findRecord('post', 1); + + ajaxResponse({ comments: [{ id: 1 }] }); + await post.get('comments'); + assert.equal(passedUrl, 'http://example.com/api/v1/posts/1/comments'); + }); + + test('buildURL - with absolute paths in links and protocol relative host', async function(assert) { + adapter.setProperties({ + host: '//example.com', + namespace: 'api/v1', + }); + Post.reopen({ comments: hasMany('comment', { async: true }) }); + Comment.reopen({ post: belongsTo('post', { async: false }) }); + + ajaxResponse({ posts: [{ id: 1, links: { comments: '/api/v1/posts/1/comments' } }] }); + + let post = await store.findRecord('post', 1); + ajaxResponse({ comments: [{ id: 1 }] }); + + await post.get('comments'); + assert.equal(passedUrl, '//example.com/api/v1/posts/1/comments'); + }); + + test('buildURL - with absolute paths in links and host is /', async function(assert) { + adapter.setProperties({ + host: '/', + namespace: 'api/v1', + }); + Post.reopen({ comments: hasMany('comment', { async: true }) }); + Comment.reopen({ post: belongsTo('post', { async: false }) }); + + ajaxResponse({ posts: [{ id: 1, links: { comments: '/api/v1/posts/1/comments' } }] }); + + let post = await store.findRecord('post', 1); + ajaxResponse({ comments: [{ id: 1 }] }); + + await post.get('comments'); + assert.equal(passedUrl, '/api/v1/posts/1/comments', 'host stripped out properly'); + }); + + test('buildURL - with full URLs in links', async function(assert) { + adapter.setProperties({ + host: 'http://example.com', + namespace: 'api/v1', + }); + Post.reopen({ comments: hasMany('comment', { async: true }) }); + Comment.reopen({ post: belongsTo('post', { async: false }) }); + + ajaxResponse({ + posts: [ + { + id: 1, + links: { comments: 'http://example.com/api/v1/posts/1/comments' }, + }, + ], + }); + + let post = await store.findRecord('post', 1); + ajaxResponse({ comments: [{ id: 1 }] }); + + await post.get('comments'); + assert.equal(passedUrl, 'http://example.com/api/v1/posts/1/comments'); + }); + + test('buildURL - with camelized names', async function(assert) { + adapter.setProperties({ + pathForType(type) { + let decamelized = decamelize(type); + return underscore(pluralize(decamelized)); + }, + }); + + ajaxResponse({ superUsers: [{ id: 1 }] }); + + await store.findRecord('super-user', 1); + assert.equal(passedUrl, '/super_users/1'); + }); + + test('buildURL - buildURL takes a record from find', async function(assert) { + Comment.reopen({ post: belongsTo('post', { async: false }) }); + + adapter.buildURL = function(type, id, snapshot) { + return '/posts/' + snapshot.belongsTo('post', { id: true }) + '/comments/' + snapshot.id; + }; + + ajaxResponse({ comments: [{ id: 1 }] }); + + let post = store.push({ + data: { + type: 'post', + id: '2', + }, + }); + + await store.findRecord('comment', 1, { preload: { post } }); + + assert.equal(passedUrl, '/posts/2/comments/1'); + }); + + test('buildURL - buildURL takes the records from findMany', async function(assert) { + Comment.reopen({ post: belongsTo('post', { async: false }) }); + Post.reopen({ comments: hasMany('comment', { async: true }) }); + + adapter.buildURL = function(type, ids, snapshots) { + if (Array.isArray(snapshots)) { + return ( + '/posts/' + snapshots.get('firstObject').belongsTo('post', { id: true }) + '/comments/' + ); + } + return ''; + }; + adapter.coalesceFindRequests = true; + + ajaxResponse({ comments: [{ id: 1 }, { id: 2 }, { id: 3 }] }); + let post = store.push({ + data: { + type: 'post', + id: '2', + relationships: { + comments: { + data: [ + { id: '1', type: 'comment' }, + { id: '2', type: 'comment' }, + { id: '3', type: 'comment' }, + ], + }, + }, + }, + }); + + await post.get('comments'); + assert.equal(passedUrl, '/posts/2/comments/'); + }); + + test('buildURL - buildURL takes a record from create', async function(assert) { + Comment.reopen({ post: belongsTo('post', { async: false }) }); + adapter.buildURL = function(type, id, snapshot) { + return '/posts/' + snapshot.belongsTo('post', { id: true }) + '/comments/'; + }; + + ajaxResponse({ comments: [{ id: 1 }] }); + + let post = store.push({ + data: { + type: 'post', + id: '2', + }, + }); + let comment = store.createRecord('comment'); + comment.set('post', post); + await comment.save(); + assert.equal(passedUrl, '/posts/2/comments/'); + }); + + test('buildURL - buildURL takes a record from create to query a resolved async belongsTo relationship', async function(assert) { + Comment.reopen({ post: belongsTo('post', { async: true }) }); + adapter.buildURL = function(type, id, snapshot) { + return '/posts/' + snapshot.belongsTo('post', { id: true }) + '/comments/'; + }; + + let post = store.push({ + data: { + id: '2', + type: 'post', + attributes: { + name: 'foo', + }, + }, + }); + + ajaxResponse({ comments: [{ id: 1 }] }); + + let comment = store.createRecord('comment'); + comment.set('post', post); + + await comment.save(); + + assert.equal(passedUrl, '/posts/2/comments/'); + }); + + test('buildURL - buildURL takes a record from update', async function(assert) { + Comment.reopen({ post: belongsTo('post', { async: false }) }); + adapter.buildURL = function(type, id, snapshot) { + return '/posts/' + snapshot.belongsTo('post', { id: true }) + '/comments/' + snapshot.id; + }; + + ajaxResponse({ comments: [{ id: 1 }] }); + + let post = store.push({ + data: { + type: 'post', + id: '2', + }, + }); + let comment = store.push({ + data: { + type: 'comment', + id: '1', + }, + }); + comment.set('post', post); + + await comment.save(); + assert.equal(passedUrl, '/posts/2/comments/1'); + }); + + test('buildURL - buildURL takes a record from delete', async function(assert) { + Comment.reopen({ post: belongsTo('post', { async: false }) }); + Post.reopen({ comments: hasMany('comment', { async: false }) }); + adapter.buildURL = function(type, id, snapshot) { + return 'posts/' + snapshot.belongsTo('post', { id: true }) + '/comments/' + snapshot.id; + }; + + ajaxResponse({ comments: [{ id: 1 }] }); + + let post = store.push({ + data: { + type: 'post', + id: '2', + }, + }); + let comment = store.push({ + data: { + type: 'comment', + id: '1', + }, + }); + + comment.set('post', post); + comment.deleteRecord(); + + await comment.save(); + assert.equal(passedUrl, 'posts/2/comments/1'); + }); + + test('buildURL - with absolute namespace', async function(assert) { + adapter.setProperties({ + namespace: '/api/v1', + }); + + ajaxResponse({ posts: [{ id: 1 }] }); + + await store.findRecord('post', 1); + assert.equal(passedUrl, '/api/v1/posts/1'); + }); +}); diff --git a/tests/integration/adapter/client-side-delete-test.js b/tests/integration/adapter/client-side-delete-test.js new file mode 100644 index 00000000000..e8bf2c6609b --- /dev/null +++ b/tests/integration/adapter/client-side-delete-test.js @@ -0,0 +1,105 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; +import { settled } from '@ember/test-helpers'; + +module('integration/adapter/store-adapter - client-side delete', { + beforeEach() { + this.Bookstore = DS.Model.extend({ + books: DS.hasMany('book', { async: false, inverse: 'bookstore' }), + }); + this.Book = DS.Model.extend({ + bookstore: DS.belongsTo('bookstore', { inverse: 'books' }), + }); + + this.env = setupStore({ + bookstore: this.Bookstore, + book: this.Book, + }); + this.store = this.env.store; + this.adapter = this.env.adapter; + }, + + afterEach() { + run(this.env.container, 'destroy'); + }, +}); + +test('client-side deleted records can be added back from an inverse', async function(assert) { + this.adapter.deleteRecord = function(store, modelClass, snapshot) { + if (snapshot.adapterOptions.clientSideDelete) { + return resolve(); + } + + assert.ok(false, 'unreachable'); + }; + + let bookstore = this.store.push({ + data: { + id: '1', + type: 'bookstore', + relationships: { + books: { + data: [ + { + id: '1', + type: 'book', + }, + { + id: '2', + type: 'book', + }, + ], + }, + }, + }, + included: [ + { + id: '1', + type: 'book', + }, + { + id: '2', + type: 'book', + }, + ], + }); + + assert.deepEqual(bookstore.get('books').mapBy('id'), ['1', '2'], 'initial hasmany loaded'); + + let book2 = this.store.peekRecord('book', '2'); + + await book2.destroyRecord({ adapterOptions: { clientSideDelete: true } }); + + run(() => book2.unloadRecord()); + + await settled(); + + assert.equal(this.store.hasRecordForId('book', '2'), false, 'book 2 unloaded'); + assert.deepEqual(bookstore.get('books').mapBy('id'), ['1'], 'one book client-side deleted'); + + this.store.push({ + data: { + id: '2', + type: 'book', + relationships: { + bookstore: { + data: { + id: '1', + type: 'bookstore', + }, + }, + }, + }, + }); + + assert.deepEqual( + bookstore.get('books').mapBy('id'), + ['1', '2'], + 'the deleted book (with same id) is pushed back into the store' + ); +}); diff --git a/tests/integration/adapter/find-all-test.js b/tests/integration/adapter/find-all-test.js new file mode 100644 index 00000000000..f3b63421267 --- /dev/null +++ b/tests/integration/adapter/find-all-test.js @@ -0,0 +1,282 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import { reject, resolve, defer, Promise } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import Model from 'ember-data/model'; +import { attr } from '@ember-decorators/data'; +import { settled } from '@ember/test-helpers'; + +class Person extends Model { + @attr + updatedAt; + + @attr + name; + + @attr + firstName; + + @attr + lastName; + + toString() { + return 'Person'; + } +} + +module('integration/adapter/find-all - Finding All Records of a Type', function(hooks) { + setupTest(hooks); + let store; + + hooks.beforeEach(function() { + let { owner } = this; + + owner.register('model:person', Person); + store = owner.lookup('service:store'); + }); + + test("When all records for a type are requested, the store should call the adapter's `findAll` method.", async function(assert) { + assert.expect(5); + let adapter = store.adapterFor('person'); + + adapter.findAll = () => { + // this will get called twice + assert.ok(true, "the adapter's findAll method should be invoked"); + + return resolve({ + data: [ + { + id: 1, + type: 'person', + attributes: { + name: 'Braaaahm Dale', + }, + }, + ], + }); + }; + + let allRecords = await store.findAll('person'); + assert.equal( + get(allRecords, 'length'), + 1, + "the record array's length is 1 after a record is loaded into it" + ); + assert.equal( + allRecords.objectAt(0).get('name'), + 'Braaaahm Dale', + 'the first item in the record array is Braaaahm Dale' + ); + + let all = await store.findAll('person'); + // Only one record array per type should ever be created (identity map) + assert.strictEqual( + allRecords, + all, + 'the same record array is returned every time all records of a type are requested' + ); + }); + + test('When all records for a type are requested, a rejection should reject the promise', async function(assert) { + assert.expect(5); + let adapter = store.adapterFor('person'); + + let count = 0; + adapter.findAll = () => { + // this will get called twice + assert.ok(true, "the adapter's findAll method should be invoked"); + + if (count++ === 0) { + return reject(); + } else { + return resolve({ + data: [ + { + id: 1, + type: 'person', + attributes: { + name: 'Braaaahm Dale', + }, + }, + ], + }); + } + }; + + let all = await store.findAll('person').catch(() => { + assert.ok(true, 'The rejection should get here'); + return store.findAll('person'); + }); + assert.equal( + get(all, 'length'), + 1, + "the record array's length is 1 after a record is loaded into it" + ); + assert.equal( + all.objectAt(0).get('name'), + 'Braaaahm Dale', + 'the first item in the record array is Braaaahm Dale' + ); + }); + + test('When all records for a type are requested, records that are already loaded should be returned immediately.', async assert => { + assert.expect(3); + + // Load a record from the server + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Jeremy Ashkenas', + }, + }, + }); + + // Create a new, unsaved record in the store + store.createRecord('person', { name: 'Alex MacCaw' }); + + let allRecords = store.peekAll('person'); + + assert.equal(get(allRecords, 'length'), 2, "the record array's length is 2"); + assert.equal( + allRecords.objectAt(0).get('name'), + 'Jeremy Ashkenas', + 'the first item in the record array is Jeremy Ashkenas' + ); + assert.equal( + allRecords.objectAt(1).get('name'), + 'Alex MacCaw', + 'the second item in the record array is Alex MacCaw' + ); + }); + + test('When all records for a type are requested, records that are created on the client should be added to the record array.', assert => { + assert.expect(3); + + let allRecords = store.peekAll('person'); + + assert.equal( + get(allRecords, 'length'), + 0, + "precond - the record array's length is zero before any records are loaded" + ); + + store.createRecord('person', { name: 'Carsten Nielsen' }); + + assert.equal(get(allRecords, 'length'), 1, "the record array's length is 1"); + assert.equal( + allRecords.objectAt(0).get('name'), + 'Carsten Nielsen', + 'the first item in the record array is Carsten Nielsen' + ); + }); + + testInDebug('When all records are requested, assert the payload is not blank', async function( + assert + ) { + let adapter = store.adapterFor('person'); + adapter.findAll = () => resolve({}); + + assert.expectAssertion(() => { + run(() => store.findAll('person')); + }, /You made a 'findAll' request for 'person' records, but the adapter's response did not have any data/); + }); + + test('isUpdating is true while records are fetched', async function(assert) { + let findAllDeferred = defer(); + let adapter = store.adapterFor('person'); + adapter.findAll = () => findAllDeferred.promise; + adapter.shouldReloadAll = () => true; + + store.push({ + data: [ + { + type: 'person', + id: 1, + }, + ], + }); + + let persons = store.peekAll('person'); + assert.equal(persons.get('length'), 1); + + let promise = new Promise(async resolve => { + let persons = await store.findAll('person'); + + assert.equal(persons.get('isUpdating'), false); + assert.equal(persons.get('length'), 2); + resolve(); + }); + + assert.equal(persons.get('isUpdating'), true); + + findAllDeferred.resolve({ data: [{ id: 2, type: 'person' }] }); + + await promise; + }); + + test('isUpdating is true while records are fetched in the background', async function(assert) { + let findAllDeferred = defer(); + let adapter = store.adapterFor('person'); + adapter.findAll = () => { + return findAllDeferred.promise; + }; + adapter.shouldReloadAll = () => false; + adapter.shouldBackgroundReloadAll = () => true; + + store.push({ + data: [ + { + type: 'person', + id: 1, + }, + ], + }); + + let persons = store.peekAll('person'); + assert.equal(persons.get('length'), 1); + + persons = await store.findAll('person'); + assert.equal(persons.get('isUpdating'), true); + assert.equal(persons.get('length'), 1, 'persons are updated in the background'); + + assert.equal(persons.get('isUpdating'), true); + + findAllDeferred.resolve({ data: [{ id: 2, type: 'person' }] }); + + await settled(); + + await findAllDeferred.promise; + + assert.equal(persons.get('isUpdating'), false); + assert.equal(persons.get('length'), 2); + }); + + test('isUpdating is false if records are not fetched in the background', async function(assert) { + let findAllDeferred = defer(); + let adapter = store.adapterFor('person'); + adapter.findAll = () => { + return findAllDeferred.promise; + }; + adapter.shouldReloadAll = () => false; + adapter.shouldBackgroundReloadAll = () => false; + + store.push({ + data: [ + { + type: 'person', + id: 1, + }, + ], + }); + + let persons = store.peekAll('person'); + assert.equal(persons.get('length'), 1); + + persons = await store.findAll('person'); + assert.equal(persons.get('isUpdating'), false); + }); +}); diff --git a/tests/integration/adapter/find-test.js b/tests/integration/adapter/find-test.js new file mode 100644 index 00000000000..397b5e568af --- /dev/null +++ b/tests/integration/adapter/find-test.js @@ -0,0 +1,244 @@ +import { Promise, reject, defer, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; + +const { attr } = DS; + +let Person, store, env; + +module('integration/adapter/find - Finding Records', { + beforeEach() { + Person = DS.Model.extend({ + updatedAt: attr('string'), + name: attr('string'), + firstName: attr('string'), + lastName: attr('string'), + }); + + env = setupStore({ + person: Person, + }); + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +testInDebug('It raises an assertion when `undefined` is passed as id (#1705)', function(assert) { + assert.expectAssertion(() => { + store.find('person', undefined); + }, `You cannot pass 'undefined' as id to the store's find method`); + + assert.expectAssertion(() => { + store.find('person', null); + }, `You cannot pass 'null' as id to the store's find method`); +}); + +test("When a single record is requested, the adapter's find method should be called unless it's loaded.", function(assert) { + assert.expect(2); + + let count = 0; + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord(_, type) { + assert.equal(type, Person, 'the find method is called with the correct type'); + assert.equal(count, 0, 'the find method is only called once'); + + count++; + return { + data: { + id: 1, + type: 'person', + attributes: { + name: 'Braaaahm Dale', + }, + }, + }; + }, + }) + ); + + run(() => { + store.findRecord('person', 1); + store.findRecord('person', 1); + }); +}); + +test('When a single record is requested multiple times, all .findRecord() calls are resolved after the promise is resolved', function(assert) { + let deferred = defer(); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return deferred.promise; + }, + }) + ); + + let requestOne = run(() => { + return store.findRecord('person', 1).then(person => { + assert.equal(person.get('id'), '1'); + assert.equal(person.get('name'), 'Braaaahm Dale'); + }); + }); + + let requestTwo = run(() => { + return store.findRecord('person', 1).then(post => { + assert.equal(post.get('id'), '1'); + assert.equal(post.get('name'), 'Braaaahm Dale'); + }); + }); + + run(() => { + deferred.resolve({ + data: { + id: 1, + type: 'person', + attributes: { + name: 'Braaaahm Dale', + }, + }, + }); + }); + + return Promise.all([requestOne, requestTwo]); +}); + +test('When a single record is requested, and the promise is rejected, .findRecord() is rejected.', function(assert) { + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return reject(); + }, + }) + ); + + return run(() => { + return store.findRecord('person', 1).catch(() => { + assert.ok(true, 'The rejection handler was called'); + }); + }); +}); + +test('When a single record is requested, and the promise is rejected, the record should be unloaded.', function(assert) { + assert.expect(2); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return reject(); + }, + }) + ); + + return run(() => { + return store.findRecord('person', 1).catch(reason => { + assert.ok(true, 'The rejection handler was called'); + assert.ok(!store.hasRecordForId('person', 1), 'The record has been unloaded'); + }); + }); +}); + +testInDebug('When a single record is requested, and the payload is blank', function(assert) { + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord: () => resolve({}), + }) + ); + + assert.expectAssertion(() => { + run(() => store.findRecord('person', 'the-id')); + }, /You made a 'findRecord' request for a 'person' with id 'the-id', but the adapter's response did not have any data/); +}); + +testInDebug('When multiple records are requested, and the payload is blank', function(assert) { + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + coalesceFindRequests: true, + findMany: () => resolve({}), + }) + ); + + assert.expectAssertion(() => { + run(() => { + store.findRecord('person', '1'); + store.findRecord('person', '2'); + }); + }, /You made a 'findMany' request for 'person' records with ids '\[1,2\]', but the adapter's response did not have any data/); +}); + +testInDebug('warns when returned record has different id', function(assert) { + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return { + data: { + id: 1, + type: 'person', + attributes: { + name: 'Braaaahm Dale', + }, + }, + }; + }, + }) + ); + + assert.expectWarning( + () => run(() => env.store.findRecord('person', 'me')), + /You requested a record of type 'person' with id 'me' but the adapter returned a payload with primary data having an id of '1'/ + ); +}); + +testInDebug('coerces ids before warning when returned record has different id', async function( + assert +) { + env.owner.register( + 'serializer:application', + JSONAPISerializer.extend({ + normalizeResponse(_, __, payload) { + return payload; + }, + }) + ); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return { + data: { + id: 1, + type: 'person', + attributes: { + name: 'Braaaahm Dale', + }, + }, + }; + }, + }) + ); + + assert.expectNoWarning( + () => run(() => env.store.findRecord('person', 1)), + /You requested a record of type 'person' with id '1' but the adapter returned a payload with primary data having an id of '1'/ + ); + assert.expectNoWarning( + () => run(() => env.store.findRecord('person', '1')), + /You requested a record of type 'person' with id '1' but the adapter returned a payload with primary data having an id of '1'/ + ); +}); diff --git a/tests/integration/adapter/json-api-adapter-test.js b/tests/integration/adapter/json-api-adapter-test.js new file mode 100644 index 00000000000..5d092798117 --- /dev/null +++ b/tests/integration/adapter/json-api-adapter-test.js @@ -0,0 +1,1063 @@ +import RSVP from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; + +import DS from 'ember-data'; + +let env, store, adapter; +let passedUrl, passedVerb, passedHash; + +let User, + Post, + Comment, + Handle, + GithubHandle, + TwitterHandle, + Company, + DevelopmentShop, + DesignStudio; + +module('integration/adapter/json-api-adapter - JSONAPIAdapter', { + beforeEach() { + User = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + posts: DS.hasMany('post', { async: true }), + handles: DS.hasMany('handle', { async: true, polymorphic: true }), + company: DS.belongsTo('company', { async: true, polymorphic: true }), + }); + + Post = DS.Model.extend({ + title: DS.attr('string'), + author: DS.belongsTo('user', { async: true }), + comments: DS.hasMany('comment', { async: true }), + }); + + Comment = DS.Model.extend({ + text: DS.attr('string'), + post: DS.belongsTo('post', { async: true }), + }); + + Handle = DS.Model.extend({ + user: DS.belongsTo('user', { async: true }), + }); + + GithubHandle = Handle.extend({ + username: DS.attr('string'), + }); + + TwitterHandle = Handle.extend({ + nickname: DS.attr('string'), + }); + + Company = DS.Model.extend({ + name: DS.attr('string'), + employees: DS.hasMany('user', { async: true }), + }); + + DevelopmentShop = Company.extend({ + coffee: DS.attr('boolean'), + }); + + DesignStudio = Company.extend({ + hipsters: DS.attr('number'), + }); + + env = setupStore({ + adapter: DS.JSONAPIAdapter.extend(), + + user: User, + post: Post, + comment: Comment, + handle: Handle, + 'github-handle': GithubHandle, + 'twitter-handle': TwitterHandle, + company: Company, + 'development-shop': DevelopmentShop, + 'design-studio': DesignStudio, + }); + + store = env.store; + adapter = env.adapter; + }, + + afterEach() { + run(env.store, 'destroy'); + }, +}); + +function ajaxResponse(responses) { + let counter = 0; + let index; + + passedUrl = []; + passedVerb = []; + passedHash = []; + + adapter.ajax = function(url, verb, hash) { + index = counter++; + + passedUrl[index] = url; + passedVerb[index] = verb; + passedHash[index] = hash; + + return run(RSVP, 'resolve', responses[index]); + }; +} + +test('find a single record', function(assert) { + assert.expect(3); + + ajaxResponse([ + { + data: { + type: 'post', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + }, + }, + ]); + + return run(() => { + return store.findRecord('post', 1).then(post => { + assert.equal(passedUrl[0], '/posts/1'); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('title'), 'Ember.js rocks'); + }); + }); +}); + +test('find all records with sideloaded relationships', function(assert) { + assert.expect(9); + + ajaxResponse([ + { + data: [ + { + type: 'posts', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + relationships: { + author: { + data: { type: 'users', id: '3' }, + }, + }, + }, + { + type: 'posts', + id: '2', + attributes: { + title: 'Tomster rules', + }, + relationships: { + author: { + data: { type: 'users', id: '3' }, + }, + comments: { + data: [{ type: 'comments', id: '4' }, { type: 'comments', id: '5' }], + }, + }, + }, + ], + included: [ + { + type: 'users', + id: '3', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + }, + { + type: 'comments', + id: '4', + attributes: { + text: 'This is the first comment', + }, + }, + { + type: 'comments', + id: '5', + attributes: { + text: 'This is the second comment', + }, + }, + ], + }, + ]); + + return run(() => { + return store.findAll('post').then(posts => { + assert.equal(passedUrl[0], '/posts'); + + assert.equal(posts.get('length'), '2'); + assert.equal(posts.get('firstObject.title'), 'Ember.js rocks'); + assert.equal(posts.get('lastObject.title'), 'Tomster rules'); + + assert.equal(posts.get('firstObject.author.firstName'), 'Yehuda'); + assert.equal(posts.get('lastObject.author.lastName'), 'Katz'); + + assert.equal(posts.get('firstObject.comments.length'), 0); + + assert.equal(posts.get('lastObject.comments.firstObject.text'), 'This is the first comment'); + assert.equal(posts.get('lastObject.comments.lastObject.text'), 'This is the second comment'); + }); + }); +}); + +test('find many records', function(assert) { + assert.expect(4); + + ajaxResponse([ + { + data: [ + { + type: 'posts', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + }, + ], + }, + ]); + + return run(() => { + return store.query('post', { filter: { id: 1 } }).then(posts => { + assert.equal(passedUrl[0], '/posts'); + assert.deepEqual(passedHash[0], { data: { filter: { id: 1 } } }); + + assert.equal(posts.get('length'), '1'); + assert.equal(posts.get('firstObject.title'), 'Ember.js rocks'); + }); + }); +}); + +test('queryRecord - primary data being a single record', function(assert) { + ajaxResponse([ + { + data: { + type: 'posts', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + }, + }, + ]); + + return run(() => { + return store.queryRecord('post', {}).then(post => { + assert.equal(passedUrl[0], '/posts'); + + assert.equal(post.get('title'), 'Ember.js rocks'); + }); + }); +}); + +test('queryRecord - primary data being null', function(assert) { + ajaxResponse([ + { + data: null, + }, + ]); + + return run(() => { + return store.queryRecord('post', {}).then(post => { + assert.equal(passedUrl[0], '/posts'); + + assert.strictEqual(post, null); + }); + }); +}); + +testInDebug('queryRecord - primary data being an array throws an assertion', function(assert) { + ajaxResponse([ + { + data: [ + { + type: 'posts', + id: '1', + }, + ], + }, + ]); + + assert.expectAssertion(() => { + run(() => store.queryRecord('post', {})); + }, 'Expected the primary data returned by the serializer for a `queryRecord` response to be a single object but instead it was an array.'); +}); + +test('find a single record with belongsTo link as object { related }', function(assert) { + assert.expect(7); + + ajaxResponse([ + { + data: { + type: 'posts', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + relationships: { + author: { + links: { + related: 'http://example.com/user/2', + }, + }, + }, + }, + }, + { + data: { + type: 'users', + id: '2', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + }, + }, + ]); + + return run(() => { + return store.findRecord('post', 1).then(post => { + assert.equal( + passedUrl[0], + '/posts/1', + 'The primary record post:1 was fetched by the correct url' + ); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('title'), 'Ember.js rocks'); + + return post.get('author').then(author => { + assert.equal( + passedUrl[1], + 'http://example.com/user/2', + 'The relationship user:2 was fetched by the correct url' + ); + + assert.equal(author.get('id'), '2'); + assert.equal(author.get('firstName'), 'Yehuda'); + assert.equal(author.get('lastName'), 'Katz'); + }); + }); + }); +}); + +test('find a single record with belongsTo link as object { data }', function(assert) { + assert.expect(7); + + ajaxResponse([ + { + data: { + type: 'posts', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + relationships: { + author: { + data: { type: 'users', id: '2' }, + }, + }, + }, + }, + { + data: { + type: 'users', + id: '2', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + }, + }, + ]); + + return run(() => { + return store.findRecord('post', 1).then(post => { + assert.equal( + passedUrl[0], + '/posts/1', + 'The primary record post:1 was fetched by the correct url' + ); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('title'), 'Ember.js rocks'); + + return post.get('author').then(author => { + assert.equal( + passedUrl[1], + '/users/2', + 'The relationship user:2 was fetched by the correct url' + ); + + assert.equal(author.get('id'), '2'); + assert.equal(author.get('firstName'), 'Yehuda'); + assert.equal(author.get('lastName'), 'Katz'); + }); + }); + }); +}); + +test('find a single record with belongsTo link as object { data } (polymorphic)', function(assert) { + assert.expect(8); + + ajaxResponse([ + { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + relationships: { + company: { + data: { type: 'development-shops', id: '2' }, + }, + }, + }, + }, + { + data: { + type: 'development-shop', + id: '2', + attributes: { + name: 'Tilde', + coffee: true, + }, + }, + }, + ]); + + return run(() => { + return store.findRecord('user', 1).then(user => { + assert.equal(passedUrl[0], '/users/1'); + + assert.equal(user.get('id'), '1'); + assert.equal(user.get('firstName'), 'Yehuda'); + assert.equal(user.get('lastName'), 'Katz'); + + return user.get('company').then(company => { + assert.equal(passedUrl[1], '/development-shops/2'); + + assert.equal(company.get('id'), '2'); + assert.equal(company.get('name'), 'Tilde'); + assert.equal(company.get('coffee'), true); + }); + }); + }); +}); + +test('find a single record with sideloaded belongsTo link as object { data }', function(assert) { + assert.expect(7); + + ajaxResponse([ + { + data: { + type: 'post', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + relationships: { + author: { + data: { type: 'user', id: '2' }, + }, + }, + }, + included: [ + { + type: 'user', + id: '2', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + }, + ], + }, + ]); + + return run(() => { + return store.findRecord('post', 1).then(post => { + assert.equal( + passedUrl[0], + '/posts/1', + 'The primary record post:1 was fetched by the correct url' + ); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('title'), 'Ember.js rocks'); + + return post.get('author').then(author => { + assert.equal(passedUrl.length, 1); + + assert.equal(author.get('id'), '2'); + assert.equal(author.get('firstName'), 'Yehuda'); + assert.equal(author.get('lastName'), 'Katz'); + }); + }); + }); +}); + +test('find a single record with hasMany link as object { related }', function(assert) { + assert.expect(7); + + ajaxResponse([ + { + data: { + type: 'post', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + relationships: { + comments: { + links: { + related: 'http://example.com/post/1/comments', + }, + }, + }, + }, + }, + { + data: [ + { + type: 'comment', + id: '2', + attributes: { + text: 'This is the first comment', + }, + }, + { + type: 'comment', + id: '3', + attributes: { + text: 'This is the second comment', + }, + }, + ], + }, + ]); + + return run(() => { + return store.findRecord('post', 1).then(post => { + assert.equal(passedUrl[0], '/posts/1'); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('title'), 'Ember.js rocks'); + + return post.get('comments').then(comments => { + assert.equal(passedUrl[1], 'http://example.com/post/1/comments'); + + assert.equal(comments.get('length'), 2); + assert.equal(comments.get('firstObject.text'), 'This is the first comment'); + assert.equal(comments.get('lastObject.text'), 'This is the second comment'); + }); + }); + }); +}); + +test('find a single record with hasMany link as object { data }', function(assert) { + assert.expect(8); + + ajaxResponse([ + { + data: { + type: 'post', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '2' }, { type: 'comment', id: '3' }], + }, + }, + }, + }, + { + data: { + type: 'comment', + id: '2', + attributes: { + text: 'This is the first comment', + }, + }, + }, + { + data: { + type: 'comment', + id: '3', + attributes: { + text: 'This is the second comment', + }, + }, + }, + ]); + + return run(() => { + return store.findRecord('post', 1).then(post => { + assert.equal(passedUrl[0], '/posts/1'); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('title'), 'Ember.js rocks'); + + return post.get('comments').then(comments => { + assert.equal(passedUrl[1], '/comments/2'); + assert.equal(passedUrl[2], '/comments/3'); + + assert.equal(comments.get('length'), 2); + assert.equal(comments.get('firstObject.text'), 'This is the first comment'); + assert.equal(comments.get('lastObject.text'), 'This is the second comment'); + }); + }); + }); +}); + +test('find a single record with hasMany link as object { data } (polymorphic)', function(assert) { + assert.expect(9); + + ajaxResponse([ + { + data: { + type: 'user', + id: '1', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + relationships: { + handles: { + data: [{ type: 'github-handle', id: '2' }, { type: 'twitter-handle', id: '3' }], + }, + }, + }, + }, + { + data: { + type: 'github-handle', + id: '2', + attributes: { + username: 'wycats', + }, + }, + }, + { + data: { + type: 'twitter-handle', + id: '3', + attributes: { + nickname: '@wycats', + }, + }, + }, + ]); + + return run(() => { + return store.findRecord('user', 1).then(user => { + assert.equal(passedUrl[0], '/users/1'); + + assert.equal(user.get('id'), '1'); + assert.equal(user.get('firstName'), 'Yehuda'); + assert.equal(user.get('lastName'), 'Katz'); + + return user.get('handles').then(handles => { + assert.equal(passedUrl[1], '/github-handles/2'); + assert.equal(passedUrl[2], '/twitter-handles/3'); + + assert.equal(handles.get('length'), 2); + assert.equal(handles.get('firstObject.username'), 'wycats'); + assert.equal(handles.get('lastObject.nickname'), '@wycats'); + }); + }); + }); +}); + +test('find a single record with sideloaded hasMany link as object { data }', function(assert) { + assert.expect(7); + + ajaxResponse([ + { + data: { + type: 'post', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '2' }, { type: 'comment', id: '3' }], + }, + }, + }, + included: [ + { + type: 'comment', + id: '2', + attributes: { + text: 'This is the first comment', + }, + }, + { + type: 'comment', + id: '3', + attributes: { + text: 'This is the second comment', + }, + }, + ], + }, + ]); + + return run(() => { + return store.findRecord('post', 1).then(post => { + assert.equal(passedUrl[0], '/posts/1'); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('title'), 'Ember.js rocks'); + + return post.get('comments').then(comments => { + assert.equal(passedUrl.length, 1); + + assert.equal(comments.get('length'), 2); + assert.equal(comments.get('firstObject.text'), 'This is the first comment'); + assert.equal(comments.get('lastObject.text'), 'This is the second comment'); + }); + }); + }); +}); + +test('find a single record with sideloaded hasMany link as object { data } (polymorphic)', function(assert) { + assert.expect(8); + + ajaxResponse([ + { + data: { + type: 'user', + id: '1', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + relationships: { + handles: { + data: [{ type: 'github-handle', id: '2' }, { type: 'twitter-handle', id: '3' }], + }, + }, + }, + included: [ + { + type: 'github-handle', + id: '2', + attributes: { + username: 'wycats', + }, + }, + { + type: 'twitter-handle', + id: '3', + attributes: { + nickname: '@wycats', + }, + }, + ], + }, + ]); + + return run(() => { + return store.findRecord('user', 1).then(user => { + assert.equal(passedUrl[0], '/users/1'); + + assert.equal(user.get('id'), '1'); + assert.equal(user.get('firstName'), 'Yehuda'); + assert.equal(user.get('lastName'), 'Katz'); + + return user.get('handles').then(handles => { + assert.equal(passedUrl.length, 1); + + assert.equal(handles.get('length'), 2); + assert.equal(handles.get('firstObject.username'), 'wycats'); + assert.equal(handles.get('lastObject.nickname'), '@wycats'); + }); + }); + }); +}); + +test('create record', function(assert) { + assert.expect(3); + + ajaxResponse([ + { + data: { + type: 'users', + id: '3', + }, + }, + ]); + + return run(() => { + let company = store.push({ + data: { + type: 'company', + id: '1', + attributes: { + name: 'Tilde Inc.', + }, + }, + }); + + let githubHandle = store.push({ + data: { + type: 'github-handle', + id: '2', + attributes: { + username: 'wycats', + }, + }, + }); + + let user = store.createRecord('user', { + firstName: 'Yehuda', + lastName: 'Katz', + company: company, + }); + + return user.get('handles').then(handles => { + handles.addObject(githubHandle); + + return user.save().then(() => { + assert.equal(passedUrl[0], '/users'); + assert.equal(passedVerb[0], 'POST'); + + // TODO @runspired seems mega-bad that we expect an extra `data` key + assert.deepEqual(passedHash[0], { + data: { + data: { + type: 'users', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + relationships: { + company: { + data: { type: 'companies', id: '1' }, + }, + }, + }, + }, + }); + }); + }); + }); +}); + +test('update record', async function(assert) { + assert.expect(3); + + ajaxResponse([ + { + data: { + type: 'users', + id: '1', + }, + }, + ]); + + let user = store.push({ + data: { + type: 'user', + id: '1', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + + let company = store.push({ + data: { + type: 'company', + id: '2', + attributes: { + name: 'Tilde Inc.', + }, + }, + }); + + let githubHandle = store.push({ + data: { + type: 'github-handle', + id: '3', + attributes: { + username: 'wycats', + }, + }, + }); + + user.set('firstName', 'Yehuda!'); + user.set('company', company); + + let handles = await user.get('handles'); + + handles.addObject(githubHandle); + + await user.save(); + + assert.equal(passedUrl[0], '/users/1'); + assert.equal(passedVerb[0], 'PATCH'); + // TODO @runspired seems mega-bad that we expect an extra `data` key + assert.deepEqual(passedHash[0], { + data: { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': 'Yehuda!', + 'last-name': 'Katz', + }, + relationships: { + company: { + data: { type: 'companies', id: '2' }, + }, + }, + }, + }, + }); +}); + +test('update record - serialize hasMany', function(assert) { + assert.expect(3); + + ajaxResponse([ + { + data: { + type: 'users', + id: '1', + }, + }, + ]); + + env.owner.register( + 'serializer:user', + DS.JSONAPISerializer.extend({ + attrs: { + handles: { serialize: true }, + }, + }) + ); + + return run(() => { + let user = store.push({ + data: { + type: 'user', + id: '1', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + + let githubHandle = store.push({ + data: { + type: 'github-handle', + id: '2', + attributes: { + username: 'wycats', + }, + }, + }); + + let twitterHandle = store.push({ + data: { + type: 'twitter-handle', + id: '3', + attributes: { + nickname: '@wycats', + }, + }, + }); + + user.set('firstName', 'Yehuda!'); + + return user.get('handles').then(handles => { + handles.addObject(githubHandle); + handles.addObject(twitterHandle); + + return user.save().then(() => { + assert.equal(passedUrl[0], '/users/1'); + assert.equal(passedVerb[0], 'PATCH'); + // TODO @runspired seems mega-bad that we expect an extra `data` key + assert.deepEqual(passedHash[0], { + data: { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': 'Yehuda!', + 'last-name': 'Katz', + }, + relationships: { + handles: { + data: [{ type: 'github-handles', id: '2' }, { type: 'twitter-handles', id: '3' }], + }, + }, + }, + }, + }); + }); + }); + }); +}); + +test('fetching a belongsTo relationship link that returns null', function(assert) { + assert.expect(3); + + ajaxResponse([ + { + data: { + type: 'post', + id: '1', + attributes: { + title: 'Ember.js rocks', + }, + relationships: { + author: { + links: { + related: 'http://example.com/post/1/author', + }, + }, + }, + }, + }, + { + data: null, + }, + ]); + + return run(() => { + return store + .findRecord('post', 1) + .then(post => { + assert.equal(passedUrl[0], '/posts/1'); + return post.get('author'); + }) + .then(author => { + assert.equal(passedUrl[1], 'http://example.com/post/1/author'); + assert.strictEqual(author, null); + }); + }); +}); diff --git a/tests/integration/adapter/queries-test.js b/tests/integration/adapter/queries-test.js new file mode 100644 index 00000000000..7ae4e1f7250 --- /dev/null +++ b/tests/integration/adapter/queries-test.js @@ -0,0 +1,143 @@ +import { Promise as EmberPromise, resolve } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let Person, env, store, adapter; + +module('integration/adapter/queries - Queries', { + beforeEach() { + Person = DS.Model.extend({ + updatedAt: DS.attr('string'), + name: DS.attr('string'), + firstName: DS.attr('string'), + lastName: DS.attr('string'), + }); + + env = setupStore({ person: Person }); + store = env.store; + adapter = env.adapter; + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +testInDebug('It raises an assertion when no type is passed', function(assert) { + assert.expectAssertion(() => { + store.query(); + }, "You need to pass a model name to the store's query method"); +}); + +testInDebug('It raises an assertion when no query hash is passed', function(assert) { + assert.expectAssertion(() => { + store.query('person'); + }, "You need to pass a query hash to the store's query method"); +}); + +test('When a query is made, the adapter should receive a record array it can populate with the results of the query.', function(assert) { + adapter.query = function(store, type, query, recordArray) { + assert.equal(type, Person, 'the query method is called with the correct type'); + + return EmberPromise.resolve({ + data: [ + { + id: 1, + type: 'person', + attributes: { + name: 'Peter Wagenet', + }, + }, + { + id: 2, + type: 'person', + attributes: { + name: 'Brohuda Katz', + }, + }, + ], + }); + }; + + return store.query('person', { page: 1 }).then(queryResults => { + assert.equal( + get(queryResults, 'length'), + 2, + 'the record array has a length of 2 after the results are loaded' + ); + assert.equal( + get(queryResults, 'isLoaded'), + true, + "the record array's `isLoaded` property should be true" + ); + + assert.equal( + queryResults.objectAt(0).get('name'), + 'Peter Wagenet', + "the first record is 'Peter Wagenet'" + ); + assert.equal( + queryResults.objectAt(1).get('name'), + 'Brohuda Katz', + "the second record is 'Brohuda Katz'" + ); + }); +}); + +test('a query can be updated via `update()`', function(assert) { + adapter.query = function() { + return resolve({ data: [{ id: 'first', type: 'person' }] }); + }; + + return run(() => { + return store + .query('person', {}) + .then(query => { + assert.equal(query.get('length'), 1); + assert.equal(query.get('firstObject.id'), 'first'); + assert.equal(query.get('isUpdating'), false); + + adapter.query = function() { + assert.ok('query is called a second time'); + return resolve({ data: [{ id: 'second', type: 'person' }] }); + }; + + let updateQuery = query.update(); + + assert.equal(query.get('isUpdating'), true); + + return updateQuery; + }) + .then(query => { + assert.equal(query.get('length'), 1); + assert.equal(query.get('firstObject.id'), 'second'); + + assert.equal(query.get('isUpdating'), false); + }); + }); +}); + +testInDebug( + 'The store asserts when query is made and the adapter responses with a single record.', + function(assert) { + env = setupStore({ person: Person, adapter: DS.RESTAdapter }); + store = env.store; + adapter = env.adapter; + + adapter.query = function(store, type, query, recordArray) { + assert.equal(type, Person, 'the query method is called with the correct type'); + + return resolve({ data: [{ id: 1, type: 'person', attributes: { name: 'Peter Wagenet' } }] }); + }; + + assert.expectAssertion(() => { + run(() => store.query('person', { page: 1 })); + }, /The response to store.query is expected to be an array but it was a single record/); + } +); diff --git a/tests/integration/adapter/record-persistence-test.js b/tests/integration/adapter/record-persistence-test.js new file mode 100644 index 00000000000..1ce033654ca --- /dev/null +++ b/tests/integration/adapter/record-persistence-test.js @@ -0,0 +1,403 @@ +import { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; +import RSVP, { resolve } from 'rsvp'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; +import DS from 'ember-data'; + +const { all, hash } = RSVP; +const { attr } = DS; + +let Person, env, store; + +module('integration/adapter/record_persistence - Persisting Records', { + beforeEach() { + Person = DS.Model.extend({ + updatedAt: attr('string'), + name: attr('string'), + firstName: attr('string'), + lastName: attr('string'), + }); + + env = setupStore({ + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false, + }), + person: Person, + }); + store = env.store; + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test("When a store is committed, the adapter's `commit` method should be called with records that have been changed.", function(assert) { + assert.expect(2); + + env.adapter.updateRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + assert.equal(snapshot.record, tom, 'the record is correct'); + + return run(RSVP, 'resolve'); + }; + + run(() => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Braaaahm Dale', + }, + }, + }); + }); + + let tom; + + return run(() => { + return env.store.findRecord('person', 1).then(person => { + tom = person; + set(tom, 'name', 'Tom Dale'); + return tom.save(); + }); + }); +}); + +test("When a store is committed, the adapter's `commit` method should be called with records that have been created.", function(assert) { + assert.expect(2); + let tom; + + env.adapter.createRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + assert.equal(snapshot.record, tom, 'the record is correct'); + + return resolve({ data: { id: 1, type: 'person', attributes: { name: 'Tom Dale' } } }); + }; + + return run(() => { + tom = env.store.createRecord('person', { name: 'Tom Dale' }); + return tom.save(); + }); +}); + +test('After a created record has been assigned an ID, finding a record by that ID returns the original record.', function(assert) { + assert.expect(1); + let tom; + + env.adapter.createRecord = function(store, type, snapshot) { + return resolve({ data: { id: 1, type: 'person', attributes: { name: 'Tom Dale' } } }); + }; + + return run(() => { + tom = env.store.createRecord('person', { name: 'Tom Dale' }); + return tom.save(); + }).then(tom => { + return env.store.find('person', 1).then(nextTom => { + assert.equal(tom, nextTom, 'the retrieved record is the same as the created record'); + }); + }); +}); + +test("when a store is committed, the adapter's `commit` method should be called with records that have been deleted.", function(assert) { + env.adapter.deleteRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + assert.equal(snapshot.record, tom, 'the record is correct'); + + return run(RSVP, 'resolve'); + }; + + let tom; + + run(() => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }); + }); + + return env.store + .findRecord('person', 1) + .then(person => { + tom = person; + tom.deleteRecord(); + return tom.save(); + }) + .then(tom => { + assert.equal(get(tom, 'isDeleted'), true, 'record is marked as deleted'); + }); +}); + +test('An adapter can notify the store that records were updated by calling `didSaveRecords`.', function(assert) { + assert.expect(6); + + let tom, yehuda; + + env.adapter.updateRecord = function(store, type, snapshot) { + return resolve(); + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + }, + { + type: 'person', + id: '2', + }, + ], + }); + }); + + return all([env.store.findRecord('person', 1), env.store.findRecord('person', 2)]).then(array => { + tom = array[0]; + yehuda = array[1]; + + tom.set('name', 'Michael Phelps'); + yehuda.set('name', 'Usain Bolt'); + + assert.ok(tom.get('hasDirtyAttributes'), 'tom is dirty'); + assert.ok(yehuda.get('hasDirtyAttributes'), 'yehuda is dirty'); + + let savedTom = assert.assertClean(tom.save()).then(record => { + assert.equal(record, tom, 'The record is correct'); + }); + + let savedYehuda = assert.assertClean(yehuda.save()).then(record => { + assert.equal(record, yehuda, 'The record is correct'); + }); + + return all([savedTom, savedYehuda]); + }); +}); + +test('An adapter can notify the store that records were updated and provide new data by calling `didSaveRecords`.', function(assert) { + env.adapter.updateRecord = function(store, type, snapshot) { + if (snapshot.id === '1') { + return resolve({ + data: { id: 1, type: 'person', attributes: { name: 'Tom Dale', 'updated-at': 'now' } }, + }); + } else if (snapshot.id === '2') { + return resolve({ + data: { id: 2, type: 'person', attributes: { name: 'Yehuda Katz', 'updated-at': 'now!' } }, + }); + } + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Braaaahm Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Gentile Katz', + }, + }, + ], + }); + }); + + return hash({ + tom: env.store.findRecord('person', 1), + yehuda: env.store.findRecord('person', 2), + }) + .then(people => { + people.tom.set('name', 'Draaaaaahm Dale'); + people.yehuda.set('name', 'Goy Katz'); + + return hash({ + tom: people.tom.save(), + yehuda: people.yehuda.save(), + }); + }) + .then(people => { + assert.equal( + people.tom.get('name'), + 'Tom Dale', + 'name attribute should reflect value of hash passed to didSaveRecords' + ); + assert.equal( + people.tom.get('updatedAt'), + 'now', + 'updatedAt attribute should reflect value of hash passed to didSaveRecords' + ); + assert.equal( + people.yehuda.get('name'), + 'Yehuda Katz', + 'name attribute should reflect value of hash passed to didSaveRecords' + ); + assert.equal( + people.yehuda.get('updatedAt'), + 'now!', + 'updatedAt attribute should reflect value of hash passed to didSaveRecords' + ); + }); +}); + +test('An adapter can notify the store that a record was updated by calling `didSaveRecord`.', function(assert) { + env.adapter.updateRecord = function(store, type, snapshot) { + return resolve(); + }; + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: '1', + }, + { + type: 'person', + id: '2', + }, + ], + }); + }); + + return hash({ + tom: store.findRecord('person', 1), + yehuda: store.findRecord('person', 2), + }).then(people => { + people.tom.set('name', 'Tom Dale'); + people.yehuda.set('name', 'Yehuda Katz'); + + assert.ok(people.tom.get('hasDirtyAttributes'), 'tom is dirty'); + assert.ok(people.yehuda.get('hasDirtyAttributes'), 'yehuda is dirty'); + + assert.assertClean(people.tom.save()); + assert.assertClean(people.yehuda.save()); + }); +}); + +test('An adapter can notify the store that a record was updated and provide new data by calling `didSaveRecord`.', function(assert) { + env.adapter.updateRecord = function(store, type, snapshot) { + switch (snapshot.id) { + case '1': + return resolve({ + data: { id: 1, type: 'person', attributes: { name: 'Tom Dale', 'updated-at': 'now' } }, + }); + case '2': + return resolve({ + data: { + id: 2, + type: 'person', + attributes: { name: 'Yehuda Katz', 'updated-at': 'now!' }, + }, + }); + } + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Braaaahm Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Gentile Katz', + }, + }, + ], + }); + }); + + return hash({ + tom: store.findRecord('person', 1), + yehuda: store.findRecord('person', 2), + }) + .then(people => { + people.tom.set('name', 'Draaaaaahm Dale'); + people.yehuda.set('name', 'Goy Katz'); + + return hash({ + tom: people.tom.save(), + yehuda: people.yehuda.save(), + }); + }) + .then(people => { + assert.equal( + people.tom.get('name'), + 'Tom Dale', + 'name attribute should reflect value of hash passed to didSaveRecords' + ); + assert.equal( + people.tom.get('updatedAt'), + 'now', + 'updatedAt attribute should reflect value of hash passed to didSaveRecords' + ); + assert.equal( + people.yehuda.get('name'), + 'Yehuda Katz', + 'name attribute should reflect value of hash passed to didSaveRecords' + ); + assert.equal( + people.yehuda.get('updatedAt'), + 'now!', + 'updatedAt attribute should reflect value of hash passed to didSaveRecords' + ); + }); +}); + +test('An adapter can notify the store that records were deleted by calling `didSaveRecords`.', function(assert) { + env.adapter.deleteRecord = function(store, type, snapshot) { + return resolve(); + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Braaaahm Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Gentile Katz', + }, + }, + ], + }); + }); + + return hash({ + tom: store.findRecord('person', 1), + yehuda: store.findRecord('person', 2), + }).then(people => { + people.tom.deleteRecord(); + people.yehuda.deleteRecord(); + + assert.assertClean(people.tom.save()); + assert.assertClean(people.yehuda.save()); + }); +}); diff --git a/tests/integration/adapter/rest-adapter-test.js b/tests/integration/adapter/rest-adapter-test.js new file mode 100644 index 00000000000..82e8a45c23b --- /dev/null +++ b/tests/integration/adapter/rest-adapter-test.js @@ -0,0 +1,2830 @@ +import { underscore } from '@ember/string'; +import RSVP, { resolve, reject } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import setupStore from 'dummy/tests/helpers/store'; +import { singularize } from 'ember-inflector'; +import deepCopy from 'dummy/tests/helpers/deep-copy'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import Pretender from 'pretender'; + +import DS from 'ember-data'; + +let env, store, adapter, Post, Comment, SuperUser; +let passedUrl, passedVerb, passedHash; +let server; + +module('integration/adapter/rest_adapter - REST Adapter', { + beforeEach() { + Post = DS.Model.extend({ + name: DS.attr('string'), + }); + + Comment = DS.Model.extend({ + name: DS.attr('string'), + }); + + SuperUser = DS.Model.extend(); + + env = setupStore({ + post: Post, + comment: Comment, + superUser: SuperUser, + adapter: DS.RESTAdapter, + }); + + server = new Pretender(); + store = env.store; + adapter = env.adapter; + + passedUrl = passedVerb = passedHash = null; + }, + afterEach() { + if (server) { + server.shutdown(); + server = null; + } + }, +}); + +function ajaxResponse(value) { + adapter.ajax = function(url, verb, hash) { + passedUrl = url; + passedVerb = verb; + passedHash = hash; + + return run(RSVP, 'resolve', deepCopy(value)); + }; +} + +function ajaxError(responseText, status = 400, headers = '') { + adapter._ajaxRequest = function(hash) { + let jqXHR = { + status, + responseText, + getAllResponseHeaders() { + return headers; + }, + }; + hash.error(jqXHR, responseText); + }; +} + +test('findRecord - basic payload', function(assert) { + ajaxResponse({ posts: [{ id: 1, name: 'Rails is omakase' }] }); + + return run(() => + store.findRecord('post', 1).then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'GET'); + assert.deepEqual(passedHash.data, {}); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('name'), 'Rails is omakase'); + }) + ); +}); + +test('findRecord - passes buildURL a requestType', function(assert) { + adapter.buildURL = function(type, id, snapshot, requestType) { + return '/' + requestType + '/post/' + id; + }; + + ajaxResponse({ posts: [{ id: 1, name: 'Rails is omakase' }] }); + + return run(() => + store.findRecord('post', 1).then(post => { + assert.equal(passedUrl, '/findRecord/post/1'); + }) + ); +}); + +test('findRecord - basic payload (with legacy singular name)', function(assert) { + ajaxResponse({ post: { id: 1, name: 'Rails is omakase' } }); + + return run(() => + store.findRecord('post', 1).then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'GET'); + assert.deepEqual(passedHash.data, {}); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('name'), 'Rails is omakase'); + }) + ); +}); + +test('findRecord - payload with sideloaded records of the same type', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is omakase' }, { id: 2, name: 'The Parley Letter' }], + }); + + return run(() => + store.findRecord('post', 1).then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'GET'); + assert.deepEqual(passedHash.data, {}); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('name'), 'Rails is omakase'); + + let post2 = store.peekRecord('post', 2); + assert.equal(post2.get('id'), '2'); + assert.equal(post2.get('name'), 'The Parley Letter'); + }) + ); +}); + +test('findRecord - payload with sideloaded records of a different type', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is omakase' }], + comments: [{ id: 1, name: 'FIRST' }], + }); + + return run(() => + store.findRecord('post', 1).then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'GET'); + assert.deepEqual(passedHash.data, {}); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('name'), 'Rails is omakase'); + + let comment = store.peekRecord('comment', 1); + assert.equal(comment.get('id'), '1'); + assert.equal(comment.get('name'), 'FIRST'); + }) + ); +}); + +test('findRecord - payload with an serializer-specified primary key', function(assert) { + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + primaryKey: '_ID_', + }) + ); + + ajaxResponse({ posts: [{ _ID_: 1, name: 'Rails is omakase' }] }); + + return run(() => + store.findRecord('post', 1).then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'GET'); + assert.deepEqual(passedHash.data, {}); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('name'), 'Rails is omakase'); + }) + ); +}); + +test('findRecord - payload with a serializer-specified attribute mapping', function(assert) { + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + attrs: { + name: '_NAME_', + createdAt: { key: '_CREATED_AT_', someOtherOption: 'option' }, + }, + }) + ); + + Post.reopen({ + createdAt: DS.attr('number'), + }); + + ajaxResponse({ posts: [{ id: 1, _NAME_: 'Rails is omakase', _CREATED_AT_: 2013 }] }); + + return run(() => + store.findRecord('post', 1).then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'GET'); + assert.deepEqual(passedHash.data, {}); + + assert.equal(post.get('id'), '1'); + assert.equal(post.get('name'), 'Rails is omakase'); + assert.equal(post.get('createdAt'), 2013); + }) + ); +}); + +test('findRecord - passes `include` as a query parameter to ajax', function(assert) { + ajaxResponse({ + post: { id: 1, name: 'Rails is very expensive sushi' }, + }); + + return run(() => + store.findRecord('post', 1, { include: 'comments' }).then(() => { + assert.deepEqual( + passedHash.data, + { include: 'comments' }, + '`include` parameter sent to adapter.ajax' + ); + }) + ); +}); + +test('createRecord - an empty payload is a basic success if an id was specified', function(assert) { + ajaxResponse(); + + return run(() => { + let post = store.createRecord('post', { id: 'some-uuid', name: 'The Parley Letter' }); + return post.save().then(post => { + assert.equal(passedUrl, '/posts'); + assert.equal(passedVerb, 'POST'); + assert.deepEqual(passedHash.data, { post: { id: 'some-uuid', name: 'The Parley Letter' } }); + + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('name'), 'The Parley Letter', 'the post was updated'); + }); + }); +}); + +test('createRecord - passes buildURL the requestType', function(assert) { + adapter.buildURL = function(type, id, snapshot, requestType) { + return '/post/' + requestType; + }; + + ajaxResponse(); + + return run(() => { + let post = store.createRecord('post', { id: 'some-uuid', name: 'The Parley Letter' }); + return post.save().then(post => { + assert.equal(passedUrl, '/post/createRecord'); + }); + }); +}); + +test('createRecord - a payload with a new ID and data applies the updates', function(assert) { + ajaxResponse({ posts: [{ id: '1', name: 'Dat Parley Letter' }] }); + + return run(() => { + let post = store.createRecord('post', { name: 'The Parley Letter' }); + + return post.save().then(post => { + assert.equal(passedUrl, '/posts'); + assert.equal(passedVerb, 'POST'); + assert.deepEqual(passedHash.data, { post: { name: 'The Parley Letter' } }); + + assert.equal(post.get('id'), '1', 'the post has the updated ID'); + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('name'), 'Dat Parley Letter', 'the post was updated'); + }); + }); +}); + +test('createRecord - a payload with a new ID and data applies the updates (with legacy singular name)', function(assert) { + ajaxResponse({ post: { id: '1', name: 'Dat Parley Letter' } }); + let post = store.createRecord('post', { name: 'The Parley Letter' }); + + return run(post, 'save').then(post => { + assert.equal(passedUrl, '/posts'); + assert.equal(passedVerb, 'POST'); + assert.deepEqual(passedHash.data, { post: { name: 'The Parley Letter' } }); + + assert.equal(post.get('id'), '1', 'the post has the updated ID'); + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('name'), 'Dat Parley Letter', 'the post was updated'); + }); +}); + +test("createRecord - findMany doesn't overwrite owner", function(assert) { + ajaxResponse({ comment: { id: '1', name: 'Dat Parley Letter', post: 1 } }); + + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + data: [], + }, + }, + }, + }); + }); + let post = store.peekRecord('post', 1); + + let comment = store.createRecord('comment', { name: 'The Parley Letter' }); + + run(() => { + post.get('comments').pushObject(comment); + + assert.equal(comment.get('post'), post, 'the post has been set correctly'); + }); + + return run(() => { + return comment.save().then(comment => { + assert.equal(comment.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(comment.get('name'), 'Dat Parley Letter', 'the post was updated'); + assert.equal(comment.get('post'), post, 'the post is still set'); + }); + }); +}); + +test("createRecord - a serializer's primary key and attributes are consulted when building the payload", function(assert) { + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + primaryKey: '_id_', + + attrs: { + name: '_name_', + }, + }) + ); + + ajaxResponse(); + + let post = store.createRecord('post', { id: 'some-uuid', name: 'The Parley Letter' }); + + return run(() => + post.save().then(post => { + assert.deepEqual(passedHash.data, { + post: { _id_: 'some-uuid', _name_: 'The Parley Letter' }, + }); + }) + ); +}); + +test("createRecord - a serializer's attributes are consulted when building the payload if no id is pre-defined", function(assert) { + let post; + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + attrs: { + name: '_name_', + }, + }) + ); + + ajaxResponse({ + post: { _name_: 'The Parley Letter', id: '1' }, + }); + + return run(() => { + post = store.createRecord('post', { name: 'The Parley Letter' }); + + return post.save().then(post => { + assert.deepEqual(passedHash.data, { post: { _name_: 'The Parley Letter' } }); + }); + }); +}); + +test("createRecord - a serializer's attribute mapping takes precedence over keyForAttribute when building the payload", function(assert) { + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + attrs: { + name: 'given_name', + }, + + keyForAttribute(attr) { + return attr.toUpperCase(); + }, + }) + ); + + ajaxResponse(); + + return run(() => { + let post = store.createRecord('post', { id: 'some-uuid', name: 'The Parley Letter' }); + + return post.save().then(post => { + assert.deepEqual(passedHash.data, { + post: { given_name: 'The Parley Letter', id: 'some-uuid' }, + }); + }); + }); +}); + +test("createRecord - a serializer's attribute mapping takes precedence over keyForRelationship (belongsTo) when building the payload", function(assert) { + env.owner.register( + 'serializer:comment', + DS.RESTSerializer.extend({ + attrs: { + post: 'article', + }, + + keyForRelationship(attr, kind) { + return attr.toUpperCase(); + }, + }) + ); + + ajaxResponse(); + + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + + return run(() => { + let post = store.createRecord('post', { id: 'a-post-id', name: 'The Parley Letter' }); + let comment = store.createRecord('comment', { + id: 'some-uuid', + name: 'Letters are fun', + post: post, + }); + + return comment.save().then(post => { + assert.deepEqual(passedHash.data, { + comment: { article: 'a-post-id', id: 'some-uuid', name: 'Letters are fun' }, + }); + }); + }); +}); + +test("createRecord - a serializer's attribute mapping takes precedence over keyForRelationship (hasMany) when building the payload", function(assert) { + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + attrs: { + comments: 'opinions', + }, + + keyForRelationship(attr, kind) { + return attr.toUpperCase(); + }, + }) + ); + + ajaxResponse(); + + Post.reopen({ comments: DS.hasMany('comment', { async: false }) }); + + return run(() => { + let comment = store.createRecord('comment', { id: 'a-comment-id', name: 'First!' }); + let post = store.createRecord('post', { + id: 'some-uuid', + name: 'The Parley Letter', + comments: [comment], + }); + + return post.save().then(post => { + assert.deepEqual(passedHash.data, { + post: { opinions: ['a-comment-id'], id: 'some-uuid', name: 'The Parley Letter' }, + }); + }); + }); +}); + +test('createRecord - a record on the many side of a hasMany relationship should update relationships when data is sideloaded', function(assert) { + assert.expect(3); + + ajaxResponse({ + posts: [ + { + id: '1', + name: 'Rails is omakase', + comments: [1, 2], + }, + ], + comments: [ + { + id: '2', + name: 'Another Comment', + post: 1, + }, + { + id: '1', + name: 'Dat Parley Letter', + post: 1, + }, + ], + // My API is returning a comment:{} as well as a comments:[{...},...] + //, comment: { + // id: "2", + // name: "Another Comment", + // post: 1 + // } + }); + + Post.reopen({ comments: DS.hasMany('comment', { async: false }) }); + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], + }, + }, + }, + }); + store.push({ + data: { + type: 'comment', + id: '1', + attributes: { + name: 'Dat Parlay Letter', + }, + relationships: { + post: { + data: { type: 'post', id: '1' }, + }, + }, + }, + }); + }); + + let post = store.peekRecord('post', 1); + let commentCount = run(() => post.get('comments.length')); + + assert.equal(commentCount, 1, 'the post starts life with a comment'); + + return run(() => { + let comment = store.createRecord('comment', { name: 'Another Comment', post: post }); + + return comment.save().then(comment => { + assert.equal(comment.get('post'), post, 'the comment is related to the post'); + return post.reload().then(post => { + assert.equal(post.get('comments.length'), 2, 'Post comment count has been updated'); + }); + }); + }); +}); + +test('createRecord - sideloaded belongsTo relationships are both marked as loaded', function(assert) { + assert.expect(4); + + Post.reopen({ comment: DS.belongsTo('comment', { async: false }) }); + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + + let post = store.createRecord('post', { name: 'man' }); + + ajaxResponse({ + posts: [{ id: 1, comment: 1, name: 'marked' }], + comments: [{ id: 1, post: 1, name: 'Comcast is a bargain' }], + }); + + return run(() => { + return post.save().then(record => { + assert.equal( + store.peekRecord('post', 1).get('comment.isLoaded'), + true, + "post's comment isLoaded (via store)" + ); + assert.equal( + store.peekRecord('comment', 1).get('post.isLoaded'), + true, + "comment's post isLoaded (via store)" + ); + assert.equal(record.get('comment.isLoaded'), true, "post's comment isLoaded (via record)"); + assert.equal( + record.get('comment.post.isLoaded'), + true, + "post's comment's post isLoaded (via record)" + ); + }); + }); +}); + +test("createRecord - response can contain relationships the client doesn't yet know about", function(assert) { + assert.expect(3); // while records.length is 2, we are getting 4 assertions + + ajaxResponse({ + posts: [ + { + id: '1', + name: 'Rails is omakase', + comments: [2], + }, + ], + comments: [ + { + id: '2', + name: 'Another Comment', + post: 1, + }, + ], + }); + + Post.reopen({ comments: DS.hasMany('comment', { async: false }) }); + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + + let post = store.createRecord('post', { name: 'Rails is omakase' }); + + return run(() => { + return post.save().then(post => { + assert.equal( + post.get('comments.firstObject.post'), + post, + 'the comments are related to the correct post model' + ); + assert.equal( + store._internalModelsFor('post').models.length, + 1, + 'There should only be one post record in the store' + ); + + let postRecords = store._internalModelsFor('post').models; + for (var i = 0; i < postRecords.length; i++) { + assert.equal( + post, + postRecords[i].getRecord(), + 'The object in the identity map is the same' + ); + } + }); + }); +}); + +test('createRecord - relationships are not duplicated', function(assert) { + Post.reopen({ comments: DS.hasMany('comment', { async: false }) }); + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + + let post = store.createRecord('post', { name: 'Tomtomhuda' }); + let comment = store.createRecord('comment', { id: 2, name: 'Comment title' }); + + ajaxResponse({ post: [{ id: 1, name: 'Rails is omakase', comments: [] }] }); + + return run(() => + post + .save() + .then(post => { + assert.equal(post.get('comments.length'), 0, 'post has 0 comments'); + post.get('comments').pushObject(comment); + assert.equal(post.get('comments.length'), 1, 'post has 1 comment'); + + ajaxResponse({ + post: [{ id: 1, name: 'Rails is omakase', comments: [2] }], + comments: [{ id: 2, name: 'Comment title' }], + }); + + return post.save(); + }) + .then(post => { + assert.equal(post.get('comments.length'), 1, 'post has 1 comment'); + }) + ); +}); + +test('updateRecord - an empty payload is a basic success', function(assert) { + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + }); + }); + + return run(() => { + let post = store.peekRecord('post', 1); + ajaxResponse(); + + post.set('name', 'The Parley Letter'); + return post.save().then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'PUT'); + assert.deepEqual(passedHash.data, { post: { name: 'The Parley Letter' } }); + + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('name'), 'The Parley Letter', 'the post was updated'); + }); + }); +}); + +test('updateRecord - passes the requestType to buildURL', function(assert) { + adapter.buildURL = function(type, id, snapshot, requestType) { + return '/posts/' + id + '/' + requestType; + }; + adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + }); + }); + + return run(() => { + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse(); + + post.set('name', 'The Parley Letter'); + return post.save(); + }) + .then(post => { + assert.equal(passedUrl, '/posts/1/updateRecord'); + }); + }); +}); + +test('updateRecord - a payload with updates applies the updates', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ posts: [{ id: 1, name: 'Dat Parley Letter' }] }); + + post.set('name', 'The Parley Letter'); + return post.save(); + }) + .then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'PUT'); + assert.deepEqual(passedHash.data, { post: { name: 'The Parley Letter' } }); + + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('name'), 'Dat Parley Letter', 'the post was updated'); + }); +}); + +test('updateRecord - a payload with updates applies the updates (with legacy singular name)', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ post: { id: 1, name: 'Dat Parley Letter' } }); + + post.set('name', 'The Parley Letter'); + return post.save(); + }) + .then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'PUT'); + assert.deepEqual(passedHash.data, { post: { name: 'The Parley Letter' } }); + + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('name'), 'Dat Parley Letter', 'the post was updated'); + }); +}); + +test('updateRecord - a payload with sideloaded updates pushes the updates', function(assert) { + let post; + ajaxResponse({ + posts: [{ id: 1, name: 'Dat Parley Letter' }], + comments: [{ id: 1, name: 'FIRST' }], + }); + + return run(() => { + post = store.createRecord('post', { name: 'The Parley Letter' }); + return post.save().then(post => { + assert.equal(passedUrl, '/posts'); + assert.equal(passedVerb, 'POST'); + assert.deepEqual(passedHash.data, { post: { name: 'The Parley Letter' } }); + + assert.equal(post.get('id'), '1', 'the post has the updated ID'); + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('name'), 'Dat Parley Letter', 'the post was updated'); + + let comment = store.peekRecord('comment', 1); + assert.equal(comment.get('name'), 'FIRST', 'The comment was sideloaded'); + }); + }); +}); + +test('updateRecord - a payload with sideloaded updates pushes the updates', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ + posts: [{ id: 1, name: 'Dat Parley Letter' }], + comments: [{ id: 1, name: 'FIRST' }], + }); + + post.set('name', 'The Parley Letter'); + return post.save(); + }) + .then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'PUT'); + assert.deepEqual(passedHash.data, { post: { name: 'The Parley Letter' } }); + + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('name'), 'Dat Parley Letter', 'the post was updated'); + + let comment = store.peekRecord('comment', 1); + assert.equal(comment.get('name'), 'FIRST', 'The comment was sideloaded'); + }); +}); + +test("updateRecord - a serializer's primary key and attributes are consulted when building the payload", function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + primaryKey: '_id_', + + attrs: { + name: '_name_', + }, + }) + ); + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + name: 'Rails is omakase', + }, + }); + }); + + ajaxResponse(); + + return store + .findRecord('post', 1) + .then(post => { + post.set('name', 'The Parley Letter'); + return post.save(); + }) + .then(post => { + assert.deepEqual(passedHash.data, { post: { _name_: 'The Parley Letter' } }); + }); +}); + +test('updateRecord - hasMany relationships faithfully reflect simultaneous adds and removes', function(assert) { + Post.reopen({ comments: DS.hasMany('comment', { async: false }) }); + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Not everyone uses Rails', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], + }, + }, + }, + included: [ + { + type: 'comment', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + name: 'Yes. Yes it is.', + }, + }, + ], + }); + }); + + ajaxResponse({ + posts: { id: 1, name: 'Not everyone uses Rails', comments: [2] }, + }); + + return store + .findRecord('comment', 2) + .then(() => { + return store.findRecord('post', 1); + }) + .then(post => { + let newComment = store.peekRecord('comment', 2); + let comments = post.get('comments'); + + // Replace the comment with a new one + comments.popObject(); + comments.pushObject(newComment); + + return post.save(); + }) + .then(post => { + assert.equal(post.get('comments.length'), 1, 'the post has the correct number of comments'); + assert.equal( + post.get('comments.firstObject.name'), + 'Yes. Yes it is.', + 'the post has the correct comment' + ); + }); +}); + +test('deleteRecord - an empty payload is a basic success', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse(); + + post.deleteRecord(); + return post.save(); + }) + .then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'DELETE'); + assert.strictEqual(passedHash, undefined); + + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('isDeleted'), true, 'the post is now deleted'); + }); +}); + +test('deleteRecord - passes the requestType to buildURL', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + adapter.buildURL = function(type, id, snapshot, requestType) { + return '/posts/' + id + '/' + requestType; + }; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse(); + + post.deleteRecord(); + return post.save(); + }) + .then(post => { + assert.equal(passedUrl, '/posts/1/deleteRecord'); + }); +}); + +test('deleteRecord - a payload with sideloaded updates pushes the updates', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ comments: [{ id: 1, name: 'FIRST' }] }); + + post.deleteRecord(); + return post.save(); + }) + .then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'DELETE'); + assert.strictEqual(passedHash, undefined); + + assert.equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + assert.equal(post.get('isDeleted'), true, 'the post is now deleted'); + + let comment = store.peekRecord('comment', 1); + assert.equal(comment.get('name'), 'FIRST', 'The comment was sideloaded'); + }); +}); + +test('deleteRecord - a payload with sidloaded updates pushes the updates when the original record is omitted', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ posts: [{ id: 2, name: 'The Parley Letter' }] }); + + post.deleteRecord(); + return post.save(); + }) + .then(post => { + assert.equal(passedUrl, '/posts/1'); + assert.equal(passedVerb, 'DELETE'); + assert.strictEqual(passedHash, undefined); + + assert.equal(post.get('hasDirtyAttributes'), false, "the original post isn't dirty anymore"); + assert.equal(post.get('isDeleted'), true, 'the original post is now deleted'); + + let newPost = store.peekRecord('post', 2); + assert.equal(newPost.get('name'), 'The Parley Letter', 'The new post was added to the store'); + }); +}); + +test('deleteRecord - deleting a newly created record should not throw an error', function(assert) { + let post = store.createRecord('post'); + + return run(() => { + post.deleteRecord(); + return post.save().then(post => { + assert.equal( + passedUrl, + null, + 'There is no ajax call to delete a record that has never been saved.' + ); + assert.equal( + passedVerb, + null, + 'There is no ajax call to delete a record that has never been saved.' + ); + assert.equal( + passedHash, + null, + 'There is no ajax call to delete a record that has never been saved.' + ); + + assert.equal(post.get('isDeleted'), true, 'the post is now deleted'); + assert.equal(post.get('isError'), false, 'the post is not an error'); + }); + }); +}); + +test('findAll - returning an array populates the array', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is omakase' }, { id: 2, name: 'The Parley Letter' }], + }); + + return store.findAll('post').then(posts => { + assert.equal(passedUrl, '/posts'); + assert.equal(passedVerb, 'GET'); + assert.deepEqual(passedHash.data, {}); + + let post1 = store.peekRecord('post', 1); + let post2 = store.peekRecord('post', 2); + + assert.deepEqual( + post1.getProperties('id', 'name'), + { id: '1', name: 'Rails is omakase' }, + 'Post 1 is loaded' + ); + + assert.deepEqual( + post2.getProperties('id', 'name'), + { id: '2', name: 'The Parley Letter' }, + 'Post 2 is loaded' + ); + + assert.equal(posts.get('length'), 2, 'The posts are in the array'); + assert.equal(posts.get('isLoaded'), true, 'The RecordArray is loaded'); + assert.deepEqual(posts.toArray(), [post1, post2], 'The correct records are in the array'); + }); +}); + +test('findAll - passes buildURL the requestType and snapshot', function(assert) { + assert.expect(2); + let adapterOptionsStub = { stub: true }; + adapter.buildURL = function(type, id, snapshot, requestType) { + assert.equal(snapshot.adapterOptions, adapterOptionsStub); + return '/' + requestType + '/posts'; + }; + + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is omakase' }, { id: 2, name: 'The Parley Letter' }], + }); + + return store.findAll('post', { adapterOptions: adapterOptionsStub }).then(posts => { + assert.equal(passedUrl, '/findAll/posts'); + }); +}); + +test('findAll - passed `include` as a query parameter to ajax', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is very expensive sushi' }], + }); + + return run(store, 'findAll', 'post', { include: 'comments' }).then(() => { + assert.deepEqual( + passedHash.data, + { include: 'comments' }, + '`include` params sent to adapter.ajax' + ); + }); +}); + +test('findAll - returning sideloaded data loads the data', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is omakase' }, { id: 2, name: 'The Parley Letter' }], + comments: [{ id: 1, name: 'FIRST' }], + }); + + return store.findAll('post').then(posts => { + let comment = store.peekRecord('comment', 1); + + assert.deepEqual(comment.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); + }); +}); + +test('findAll - data is normalized through custom serializers', function(assert) { + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + primaryKey: '_ID_', + attrs: { name: '_NAME_' }, + }) + ); + + ajaxResponse({ + posts: [{ _ID_: 1, _NAME_: 'Rails is omakase' }, { _ID_: 2, _NAME_: 'The Parley Letter' }], + }); + + return store.findAll('post').then(posts => { + let post1 = store.peekRecord('post', 1); + let post2 = store.peekRecord('post', 2); + + assert.deepEqual( + post1.getProperties('id', 'name'), + { id: '1', name: 'Rails is omakase' }, + 'Post 1 is loaded' + ); + assert.deepEqual( + post2.getProperties('id', 'name'), + { id: '2', name: 'The Parley Letter' }, + 'Post 2 is loaded' + ); + + assert.equal(posts.get('length'), 2, 'The posts are in the array'); + assert.equal(posts.get('isLoaded'), true, 'The RecordArray is loaded'); + assert.deepEqual(posts.toArray(), [post1, post2], 'The correct records are in the array'); + }); +}); + +test('query - if `sortQueryParams` option is not provided, query params are sorted alphabetically', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is very expensive sushi' }], + }); + + return store.query('post', { params: 1, in: 2, wrong: 3, order: 4 }).then(() => { + assert.deepEqual( + Object.keys(passedHash.data), + ['in', 'order', 'params', 'wrong'], + 'query params are received in alphabetical order' + ); + }); +}); + +test('query - passes buildURL the requestType', function(assert) { + adapter.buildURL = function(type, id, snapshot, requestType) { + return '/' + requestType + '/posts'; + }; + + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is very expensive sushi' }], + }); + + return store.query('post', { params: 1, in: 2, wrong: 3, order: 4 }).then(() => { + assert.equal(passedUrl, '/query/posts'); + }); +}); + +test('query - if `sortQueryParams` is falsey, query params are not sorted at all', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is very expensive sushi' }], + }); + + adapter.sortQueryParams = null; + + return store.query('post', { params: 1, in: 2, wrong: 3, order: 4 }).then(() => { + assert.deepEqual( + Object.keys(passedHash.data), + ['params', 'in', 'wrong', 'order'], + 'query params are received in their original order' + ); + }); +}); + +test('query - if `sortQueryParams` is a custom function, query params passed through that function', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is very expensive sushi' }], + }); + + adapter.sortQueryParams = function(obj) { + let sortedKeys = Object.keys(obj) + .sort() + .reverse(); + let len = sortedKeys.length; + let newQueryParams = {}; + + for (var i = 0; i < len; i++) { + newQueryParams[sortedKeys[i]] = obj[sortedKeys[i]]; + } + return newQueryParams; + }; + + return store.query('post', { params: 1, in: 2, wrong: 3, order: 4 }).then(() => { + assert.deepEqual( + Object.keys(passedHash.data), + ['wrong', 'params', 'order', 'in'], + 'query params are received in reverse alphabetical order' + ); + }); +}); + +test("query - payload 'meta' is accessible on the record array", function(assert) { + ajaxResponse({ + meta: { offset: 5 }, + posts: [{ id: 1, name: 'Rails is very expensive sushi' }], + }); + + return store.query('post', { page: 2 }).then(posts => { + assert.equal( + posts.get('meta.offset'), + 5, + 'Reponse metadata can be accessed with recordArray.meta' + ); + }); +}); + +test("query - each record array can have it's own meta object", function(assert) { + ajaxResponse({ + meta: { offset: 5 }, + posts: [{ id: 1, name: 'Rails is very expensive sushi' }], + }); + + return store.query('post', { page: 2 }).then(posts => { + assert.equal( + posts.get('meta.offset'), + 5, + 'Reponse metadata can be accessed with recordArray.meta' + ); + ajaxResponse({ + meta: { offset: 1 }, + posts: [{ id: 1, name: 'Rails is very expensive sushi' }], + }); + + return store.query('post', { page: 1 }).then(newPosts => { + assert.equal(newPosts.get('meta.offset'), 1, 'new array has correct metadata'); + assert.equal(posts.get('meta.offset'), 5, 'metadata on the old array hasnt been clobbered'); + }); + }); +}); + +test('query - returning an array populates the array', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is omakase' }, { id: 2, name: 'The Parley Letter' }], + }); + + return store.query('post', { page: 1 }).then(posts => { + assert.equal(passedUrl, '/posts'); + assert.equal(passedVerb, 'GET'); + assert.deepEqual(passedHash.data, { page: 1 }); + + let post1 = store.peekRecord('post', 1); + let post2 = store.peekRecord('post', 2); + + assert.deepEqual( + post1.getProperties('id', 'name'), + { id: '1', name: 'Rails is omakase' }, + 'Post 1 is loaded' + ); + assert.deepEqual( + post2.getProperties('id', 'name'), + { id: '2', name: 'The Parley Letter' }, + 'Post 2 is loaded' + ); + + assert.equal(posts.get('length'), 2, 'The posts are in the array'); + assert.equal(posts.get('isLoaded'), true, 'The RecordArray is loaded'); + assert.deepEqual(posts.toArray(), [post1, post2], 'The correct records are in the array'); + }); +}); + +test('query - returning sideloaded data loads the data', function(assert) { + ajaxResponse({ + posts: [{ id: 1, name: 'Rails is omakase' }, { id: 2, name: 'The Parley Letter' }], + comments: [{ id: 1, name: 'FIRST' }], + }); + + return store.query('post', { page: 1 }).then(posts => { + let comment = store.peekRecord('comment', 1); + + assert.deepEqual(comment.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); + }); +}); + +test('query - data is normalized through custom serializers', function(assert) { + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + primaryKey: '_ID_', + attrs: { name: '_NAME_' }, + }) + ); + + ajaxResponse({ + posts: [{ _ID_: 1, _NAME_: 'Rails is omakase' }, { _ID_: 2, _NAME_: 'The Parley Letter' }], + }); + + return store.query('post', { page: 1 }).then(posts => { + let post1 = store.peekRecord('post', 1); + let post2 = store.peekRecord('post', 2); + + assert.deepEqual( + post1.getProperties('id', 'name'), + { id: '1', name: 'Rails is omakase' }, + 'Post 1 is loaded' + ); + + assert.deepEqual( + post2.getProperties('id', 'name'), + { id: '2', name: 'The Parley Letter' }, + 'Post 2 is loaded' + ); + + assert.equal(posts.get('length'), 2, 'The posts are in the array'); + assert.equal(posts.get('isLoaded'), true, 'The RecordArray is loaded'); + assert.deepEqual(posts.toArray(), [post1, post2], 'The correct records are in the array'); + }); +}); + +test('queryRecord - empty response', function(assert) { + ajaxResponse({}); + + return store.queryRecord('post', { slug: 'ember-js-rocks' }).then(post => { + assert.strictEqual(post, null); + }); +}); + +test('queryRecord - primary data being null', function(assert) { + ajaxResponse({ + post: null, + }); + + return store.queryRecord('post', { slug: 'ember-js-rocks' }).then(post => { + assert.strictEqual(post, null); + }); +}); + +test('queryRecord - primary data being a single object', function(assert) { + ajaxResponse({ + post: { + id: '1', + name: 'Ember.js rocks', + }, + }); + + return store.queryRecord('post', { slug: 'ember-js-rocks' }).then(post => { + assert.deepEqual(post.get('name'), 'Ember.js rocks'); + }); +}); + +test('queryRecord - returning sideloaded data loads the data', function(assert) { + ajaxResponse({ + post: { id: 1, name: 'Rails is omakase' }, + comments: [{ id: 1, name: 'FIRST' }], + }); + + return store.queryRecord('post', { slug: 'rails-is-omakaze' }).then(post => { + let comment = store.peekRecord('comment', 1); + + assert.deepEqual(comment.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); + }); +}); + +testInDebug( + 'queryRecord - returning an array picks the first one but saves all records to the store', + function(assert) { + ajaxResponse({ + post: [{ id: 1, name: 'Rails is omakase' }, { id: 2, name: 'Ember is js' }], + }); + + assert.expectDeprecation( + () => + run(() => { + return store.queryRecord('post', { slug: 'rails-is-omakaze' }).then(post => { + let post2 = store.peekRecord('post', 2); + + assert.deepEqual(post.getProperties('id', 'name'), { + id: '1', + name: 'Rails is omakase', + }); + assert.deepEqual(post2.getProperties('id', 'name'), { id: '2', name: 'Ember is js' }); + }); + }), + + /The adapter returned an array for the primary data of a `queryRecord` response. This is deprecated as `queryRecord` should return a single record./ + ); + } +); + +testInDebug('queryRecord - returning an array is deprecated', function(assert) { + ajaxResponse({ + post: [{ id: 1, name: 'Rails is omakase' }, { id: 2, name: 'Ember is js' }], + }); + + assert.expectDeprecation( + () => run(() => store.queryRecord('post', { slug: 'rails-is-omakaze' })), + 'The adapter returned an array for the primary data of a `queryRecord` response. This is deprecated as `queryRecord` should return a single record.' + ); +}); + +testInDebug("queryRecord - returning an single object doesn't throw a deprecation", function( + assert +) { + ajaxResponse({ + post: { id: 1, name: 'Rails is omakase' }, + }); + + assert.expectNoDeprecation(); + + return run(() => store.queryRecord('post', { slug: 'rails-is-omakaze' })); +}); + +test('queryRecord - data is normalized through custom serializers', function(assert) { + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + primaryKey: '_ID_', + attrs: { name: '_NAME_' }, + }) + ); + + ajaxResponse({ + post: { _ID_: 1, _NAME_: 'Rails is omakase' }, + }); + + return store.queryRecord('post', { slug: 'rails-is-omakaze' }).then(post => { + assert.deepEqual( + post.getProperties('id', 'name'), + { id: '1', name: 'Rails is omakase' }, + 'Post 1 is loaded with correct data' + ); + }); +}); + +test('findMany - findMany uses a correct URL to access the records', function(assert) { + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + adapter.coalesceFindRequests = true; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }); + }); + + let post = store.peekRecord('post', 1); + ajaxResponse({ + comments: [ + { id: 1, name: 'FIRST' }, + { id: 2, name: 'Rails is unagi' }, + { id: 3, name: 'What is omakase?' }, + ], + }); + + return run(() => + post.get('comments').then(comments => { + assert.equal(passedUrl, '/comments'); + assert.deepEqual(passedHash, { data: { ids: ['1', '2', '3'] } }); + }) + ); +}); + +test('findMany - passes buildURL the requestType', function(assert) { + adapter.buildURL = function(type, id, snapshot, requestType) { + return '/' + requestType + '/' + type; + }; + + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + adapter.coalesceFindRequests = true; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }); + }); + + let post = store.peekRecord('post', 1); + ajaxResponse({ + comments: [ + { id: 1, name: 'FIRST' }, + { id: 2, name: 'Rails is unagi' }, + { id: 3, name: 'What is omakase?' }, + ], + }); + + return run(post, 'get', 'comments').then(comments => { + assert.equal(passedUrl, '/findMany/comment'); + }); +}); + +test('findMany - findMany does not coalesce by default', function(assert) { + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }); + }); + + let post = store.peekRecord('post', 1); + //It's still ok to return this even without coalescing because RESTSerializer supports sideloading + ajaxResponse({ + comments: [ + { id: 1, name: 'FIRST' }, + { id: 2, name: 'Rails is unagi' }, + { id: 3, name: 'What is omakase?' }, + ], + }); + + return run(() => + post.get('comments').then(comments => { + assert.equal(passedUrl, '/comments/3'); + assert.deepEqual(passedHash.data, {}); + }) + ); +}); + +test('findMany - returning an array populates the array', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + adapter.coalesceFindRequests = true; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ + comments: [ + { id: 1, name: 'FIRST' }, + { id: 2, name: 'Rails is unagi' }, + { id: 3, name: 'What is omakase?' }, + ], + }); + + return post.get('comments'); + }) + .then(comments => { + let comment1 = store.peekRecord('comment', 1); + let comment2 = store.peekRecord('comment', 2); + let comment3 = store.peekRecord('comment', 3); + + assert.deepEqual(comment1.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); + assert.deepEqual(comment2.getProperties('id', 'name'), { id: '2', name: 'Rails is unagi' }); + assert.deepEqual(comment3.getProperties('id', 'name'), { id: '3', name: 'What is omakase?' }); + + assert.deepEqual( + comments.toArray(), + [comment1, comment2, comment3], + 'The correct records are in the array' + ); + }); +}); + +test('findMany - returning sideloaded data loads the data', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + adapter.coalesceFindRequests = true; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ + comments: [ + { id: 1, name: 'FIRST' }, + { id: 2, name: 'Rails is unagi' }, + { id: 3, name: 'What is omakase?' }, + { id: 4, name: 'Unrelated comment' }, + ], + posts: [{ id: 2, name: 'The Parley Letter' }], + }); + + return post.get('comments'); + }) + .then(comments => { + let comment1 = store.peekRecord('comment', 1); + let comment2 = store.peekRecord('comment', 2); + let comment3 = store.peekRecord('comment', 3); + let comment4 = store.peekRecord('comment', 4); + let post2 = store.peekRecord('post', 2); + + assert.deepEqual( + comments.toArray(), + [comment1, comment2, comment3], + 'The correct records are in the array' + ); + + assert.deepEqual(comment4.getProperties('id', 'name'), { + id: '4', + name: 'Unrelated comment', + }); + assert.deepEqual(post2.getProperties('id', 'name'), { id: '2', name: 'The Parley Letter' }); + }); +}); + +test('findMany - a custom serializer is used if present', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + primaryKey: '_ID_', + attrs: { name: '_NAME_' }, + }) + ); + + env.owner.register( + 'serializer:comment', + DS.RESTSerializer.extend({ + primaryKey: '_ID_', + attrs: { name: '_NAME_' }, + }) + ); + + adapter.coalesceFindRequests = true; + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ + comments: [ + { _ID_: 1, _NAME_: 'FIRST' }, + { _ID_: 2, _NAME_: 'Rails is unagi' }, + { _ID_: 3, _NAME_: 'What is omakase?' }, + ], + }); + + return post.get('comments'); + }) + .then(comments => { + let comment1 = store.peekRecord('comment', 1); + let comment2 = store.peekRecord('comment', 2); + let comment3 = store.peekRecord('comment', 3); + + assert.deepEqual(comment1.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); + assert.deepEqual(comment2.getProperties('id', 'name'), { id: '2', name: 'Rails is unagi' }); + assert.deepEqual(comment3.getProperties('id', 'name'), { id: '3', name: 'What is omakase?' }); + + assert.deepEqual( + comments.toArray(), + [comment1, comment2, comment3], + 'The correct records are in the array' + ); + }); +}); + +test('findHasMany - returning an array populates the array', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + links: { + related: '/posts/1/comments', + }, + }, + }, + }, + }); + }); + + return run(() => + store + .findRecord('post', '1') + .then(post => { + ajaxResponse({ + comments: [ + { id: 1, name: 'FIRST' }, + { id: 2, name: 'Rails is unagi' }, + { id: 3, name: 'What is omakase?' }, + ], + }); + + return post.get('comments'); + }) + .then(comments => { + assert.equal(passedUrl, '/posts/1/comments'); + assert.equal(passedVerb, 'GET'); + assert.strictEqual(passedHash, undefined); + + let comment1 = store.peekRecord('comment', 1); + let comment2 = store.peekRecord('comment', 2); + let comment3 = store.peekRecord('comment', 3); + + assert.deepEqual(comment1.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); + assert.deepEqual(comment2.getProperties('id', 'name'), { id: '2', name: 'Rails is unagi' }); + assert.deepEqual(comment3.getProperties('id', 'name'), { + id: '3', + name: 'What is omakase?', + }); + + assert.deepEqual( + comments.toArray(), + [comment1, comment2, comment3], + 'The correct records are in the array' + ); + }) + ); +}); + +test('findHasMany - passes buildURL the requestType', function(assert) { + assert.expect(2); + adapter.shouldBackgroundReloadRecord = () => false; + adapter.buildURL = function(type, id, snapshot, requestType) { + assert.ok(snapshot instanceof DS.Snapshot); + assert.equal(requestType, 'findHasMany'); + }; + + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + links: { + related: '/posts/1/comments', + }, + }, + }, + }, + }); + }); + + return run(() => + store.findRecord('post', '1').then(post => { + ajaxResponse({ + comments: [ + { id: 1, name: 'FIRST' }, + { id: 2, name: 'Rails is unagi' }, + { id: 3, name: 'What is omakase?' }, + ], + }); + + return post.get('comments'); + }) + ); +}); + +test('findMany - returning sideloaded data loads the data (with JSONApi Links)', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + adapter.coalesceFindRequests = true; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + links: { + related: '/posts/1/comments', + }, + }, + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ + comments: [ + { id: 1, name: 'FIRST' }, + { id: 2, name: 'Rails is unagi' }, + { id: 3, name: 'What is omakase?' }, + ], + posts: [{ id: 2, name: 'The Parley Letter' }], + }); + + return post.get('comments'); + }) + .then(comments => { + let comment1 = store.peekRecord('comment', 1); + let comment2 = store.peekRecord('comment', 2); + let comment3 = store.peekRecord('comment', 3); + let post2 = store.peekRecord('post', 2); + + assert.deepEqual( + comments.toArray(), + [comment1, comment2, comment3], + 'The correct records are in the array' + ); + + assert.deepEqual(post2.getProperties('id', 'name'), { id: '2', name: 'The Parley Letter' }); + }); +}); + +test('findMany - a custom serializer is used if present', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + primaryKey: '_ID_', + attrs: { name: '_NAME_' }, + }) + ); + + env.owner.register( + 'serializer:comment', + DS.RESTSerializer.extend({ + primaryKey: '_ID_', + attrs: { name: '_NAME_' }, + }) + ); + + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + name: 'Rails is omakase', + }, + relationships: { + comments: { + links: { + related: '/posts/1/comments', + }, + }, + }, + }, + }); + }); + + return store + .findRecord('post', 1) + .then(post => { + ajaxResponse({ + comments: [ + { _ID_: 1, _NAME_: 'FIRST' }, + { _ID_: 2, _NAME_: 'Rails is unagi' }, + { _ID_: 3, _NAME_: 'What is omakase?' }, + ], + }); + return post.get('comments'); + }) + .then(comments => { + let comment1 = store.peekRecord('comment', 1); + let comment2 = store.peekRecord('comment', 2); + let comment3 = store.peekRecord('comment', 3); + + assert.deepEqual(comment1.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); + assert.deepEqual(comment2.getProperties('id', 'name'), { id: '2', name: 'Rails is unagi' }); + assert.deepEqual(comment3.getProperties('id', 'name'), { id: '3', name: 'What is omakase?' }); + + assert.deepEqual( + comments.toArray(), + [comment1, comment2, comment3], + 'The correct records are in the array' + ); + }); +}); + +test('findBelongsTo - passes buildURL the requestType', function(assert) { + assert.expect(2); + adapter.shouldBackgroundReloadRecord = () => false; + adapter.buildURL = function(type, id, snapshot, requestType) { + assert.ok(snapshot instanceof DS.Snapshot); + assert.equal(requestType, 'findBelongsTo'); + }; + + Comment.reopen({ post: DS.belongsTo('post', { async: true }) }); + + run(() => { + store.push({ + data: { + type: 'comment', + id: '1', + attributes: { + name: 'FIRST', + }, + relationships: { + post: { + links: { + related: '/posts/1', + }, + }, + }, + }, + }); + }); + + return run(() => + store.findRecord('comment', '1').then(comment => { + ajaxResponse({ post: { id: 1, name: 'Rails is omakase' } }); + return comment.get('post'); + }) + ); +}); + +testInDebug( + 'coalesceFindRequests assert.warns if the expected records are not returned in the coalesced request', + function(assert) { + assert.expect(2); + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + + adapter.coalesceFindRequests = true; + + ajaxResponse({ + comments: [{ id: '1', type: 'comment' }], + }); + + let post = run(() => + store.push({ + data: { + type: 'post', + id: '2', + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }) + ); + + assert.expectWarning(() => { + return run(() => { + return post.get('comments').catch(e => { + assert.equal( + e.message, + `Expected: '' to be present in the adapter provided payload, but it was not found.` + ); + }); + }); + }, /expected to find records with the following ids in the adapter response but they were missing: \[ "2", "3" \]/); + } +); + +test('groupRecordsForFindMany groups records based on their url', function(assert) { + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + adapter.coalesceFindRequests = true; + + adapter.buildURL = function(type, id, snapshot) { + if (id === '1') { + return '/comments/1'; + } else { + return '/other_comments/' + id; + } + }; + + adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(id, '1'); + return resolve({ comments: { id: 1 } }); + }; + + adapter.findMany = function(store, type, ids, snapshots) { + assert.deepEqual(ids, ['2', '3']); + return resolve({ comments: [{ id: 2 }, { id: 3 }] }); + }; + + let post; + run(() => { + store.push({ + data: { + type: 'post', + id: '2', + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }); + post = store.peekRecord('post', 2); + }); + + run(() => post.get('comments')); +}); + +test('groupRecordsForFindMany groups records correctly when singular URLs are encoded as query params', function(assert) { + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + adapter.coalesceFindRequests = true; + + adapter.buildURL = function(type, id, snapshot) { + if (id === '1') { + return '/comments?id=1'; + } else { + return '/other_comments?id=' + id; + } + }; + + adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(id, '1'); + return resolve({ comments: { id: 1 } }); + }; + + adapter.findMany = function(store, type, ids, snapshots) { + assert.deepEqual(ids, ['2', '3']); + return resolve({ comments: [{ id: 2 }, { id: 3 }] }); + }; + let post; + + run(() => { + store.push({ + data: { + type: 'post', + id: '2', + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }); + post = store.peekRecord('post', 2); + }); + + run(() => post.get('comments')); +}); + +test('normalizeKey - to set up _ids and _id', function(assert) { + env.owner.register( + 'serializer:application', + DS.RESTSerializer.extend({ + keyForAttribute(attr) { + return underscore(attr); + }, + + keyForBelongsTo(belongsTo) {}, + + keyForRelationship(rel, kind) { + if (kind === 'belongsTo') { + let underscored = underscore(rel); + return underscored + '_id'; + } else { + let singular = singularize(rel); + return underscore(singular) + '_ids'; + } + }, + }) + ); + + env.owner.register( + 'model:post', + DS.Model.extend({ + name: DS.attr(), + authorName: DS.attr(), + author: DS.belongsTo('user', { async: false }), + comments: DS.hasMany('comment', { async: false }), + }) + ); + + env.owner.register( + 'model:user', + DS.Model.extend({ + createdAt: DS.attr(), + name: DS.attr(), + }) + ); + + env.owner.register( + 'model:comment', + DS.Model.extend({ + body: DS.attr(), + }) + ); + + ajaxResponse({ + posts: [ + { + id: '1', + name: 'Rails is omakase', + author_name: '@d2h', + author_id: '1', + comment_ids: ['1', '2'], + }, + ], + + users: [ + { + id: '1', + name: 'D2H', + }, + ], + + comments: [ + { + id: '1', + body: 'Rails is unagi', + }, + { + id: '2', + body: 'What is omakase?', + }, + ], + }); + + return run(() => { + return store.findRecord('post', 1).then(post => { + assert.equal(post.get('authorName'), '@d2h'); + assert.equal(post.get('author.name'), 'D2H'); + assert.deepEqual(post.get('comments').mapBy('body'), ['Rails is unagi', 'What is omakase?']); + }); + }); +}); + +test('groupRecordsForFindMany splits up calls for large ids', function(assert) { + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + + assert.expect(2); + + function repeatChar(character, n) { + return new Array(n + 1).join(character); + } + + let a2000 = repeatChar('a', 2000); + let b2000 = repeatChar('b', 2000); + let post; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: a2000 }, { type: 'comment', id: b2000 }], + }, + }, + }, + }); + post = store.peekRecord('post', 1); + }); + + adapter.coalesceFindRequests = true; + + adapter.findRecord = function(store, type, id, snapshot) { + if (id === a2000 || id === b2000) { + assert.ok(true, 'Found ' + id); + } + + return resolve({ comments: { id: id } }); + }; + + adapter.findMany = function(store, type, ids, snapshots) { + assert.ok( + false, + 'findMany should not be called - we expect 2 calls to find for a2000 and b2000' + ); + return reject(); + }; + + run(() => post.get('comments')); +}); + +test('groupRecordsForFindMany groups calls for small ids', function(assert) { + Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); + + assert.expect(1); + + function repeatChar(character, n) { + return new Array(n + 1).join(character); + } + + let a100 = repeatChar('a', 100); + let b100 = repeatChar('b', 100); + let post; + + run(() => { + store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: a100 }, { type: 'comment', id: b100 }], + }, + }, + }, + }); + post = store.peekRecord('post', 1); + }); + + adapter.coalesceFindRequests = true; + + adapter.findRecord = function(store, type, id, snapshot) { + assert.ok( + false, + 'findRecord should not be called - we expect 1 call to findMany for a100 and b100' + ); + return reject(); + }; + + adapter.findMany = function(store, type, ids, snapshots) { + assert.deepEqual(ids, [a100, b100]); + return resolve({ comments: [{ id: a100 }, { id: b100 }] }); + }; + + run(() => post.get('comments')); +}); + +test('calls adapter.handleResponse with the jqXHR and json', function(assert) { + assert.expect(2); + + let data = { + post: { + id: '1', + name: 'Docker is amazing', + }, + }; + + server.get('/posts/1', function() { + return [200, { 'Content-Type': 'application/json' }, JSON.stringify(data)]; + }); + + adapter.handleResponse = function(status, headers, json) { + assert.deepEqual(status, 200); + assert.deepEqual(json, data); + return json; + }; + + return run(() => store.findRecord('post', '1')); +}); + +test('calls handleResponse with jqXHR, jqXHR.responseText, and requestData', function(assert) { + assert.expect(4); + + let responseText = 'Nope lol'; + + let expectedRequestData = { + method: 'GET', + url: '/posts/1', + }; + + server.get('/posts/1', function() { + return [400, {}, responseText]; + }); + + adapter.handleResponse = function(status, headers, json, requestData) { + assert.deepEqual(status, 400); + assert.deepEqual(json, responseText); + assert.deepEqual(requestData, expectedRequestData); + return new DS.AdapterError('nope!'); + }; + + return run(() => { + return store.findRecord('post', '1').catch(err => assert.ok(err, 'promise rejected')); + }); +}); + +test('rejects promise if DS.AdapterError is returned from adapter.handleResponse', function(assert) { + assert.expect(3); + + let data = { + something: 'is invalid', + }; + + server.get('/posts/1', function() { + return [200, { 'Content-Type': 'application/json' }, JSON.stringify(data)]; + }); + + adapter.handleResponse = function(status, headers, json) { + assert.ok(true, 'handleResponse should be called'); + return new DS.AdapterError(json); + }; + + return run(() => { + return store.findRecord('post', '1').catch(reason => { + assert.ok(true, 'promise should be rejected'); + assert.ok( + reason instanceof DS.AdapterError, + 'reason should be an instance of DS.AdapterError' + ); + }); + }); +}); + +test('gracefully handles exceptions in handleResponse', function(assert) { + assert.expect(1); + + server.post('/posts/1', function() { + return [200, { 'Content-Type': 'application/json' }, 'ok']; + }); + + adapter.handleResponse = function(status, headers, json) { + throw new Error('Unexpected error'); + }; + + return run(() => { + return store.findRecord('post', '1').catch(error => { + assert.ok(true, 'Unexpected error is captured by the promise chain'); + }); + }); +}); + +test('gracefully handles exceptions in handleResponse where the ajax request errors', function(assert) { + assert.expect(1); + + server.get('/posts/1', function() { + return [500, { 'Content-Type': 'application/json' }, 'Internal Server Error']; + }); + + adapter.handleResponse = function(status, headers, json) { + throw new Error('Unexpected error'); + }; + + return run(() => { + return store.findRecord('post', '1').catch(error => { + assert.ok(true, 'Unexpected error is captured by the promise chain'); + }); + }); +}); + +test('treats status code 0 as an abort', function(assert) { + assert.expect(3); + + adapter._ajaxRequest = function(hash) { + hash.error({ + status: 0, + getAllResponseHeaders() { + return ''; + }, + }); + }; + adapter.handleResponse = function(status, headers, payload) { + assert.ok(false); + }; + + return run(() => { + return store.findRecord('post', '1').catch(err => { + assert.ok(err instanceof DS.AbortError, 'reason should be an instance of DS.AbortError'); + assert.equal( + err.errors.length, + 1, + 'AbortError includes errors with request/response details' + ); + let expectedError = { + title: 'Adapter Error', + detail: 'Request failed: GET /posts/1', + status: 0, + }; + assert.deepEqual( + err.errors[0], + expectedError, + 'method, url and, status are captured as details' + ); + }); + }); +}); + +test('on error appends errorThrown for sanity', function(assert) { + assert.expect(2); + + let jqXHR = { + responseText: 'Nope lol', + getAllResponseHeaders() { + return ''; + }, + }; + + let errorThrown = new Error('nope!'); + + adapter._ajaxRequest = function(hash) { + hash.error(jqXHR, jqXHR.responseText, errorThrown); + }; + + adapter.handleResponse = function(status, headers, payload) { + assert.ok(false); + }; + + return run(() => { + return store.findRecord('post', '1').catch(err => { + assert.equal(err, errorThrown); + assert.ok(err, 'promise rejected'); + }); + }); +}); + +test('rejects promise with a specialized subclass of DS.AdapterError if ajax responds with http error codes', function(assert) { + assert.expect(10); + + ajaxError('error', 401); + + run(() => { + store.find('post', '1').catch(reason => { + assert.ok(true, 'promise should be rejected'); + assert.ok( + reason instanceof DS.UnauthorizedError, + 'reason should be an instance of DS.UnauthorizedError' + ); + }); + }); + + ajaxError('error', 403); + + run(() => { + store.find('post', '1').catch(reason => { + assert.ok(true, 'promise should be rejected'); + assert.ok( + reason instanceof DS.ForbiddenError, + 'reason should be an instance of DS.ForbiddenError' + ); + }); + }); + + ajaxError('error', 404); + + run(() => { + store.find('post', '1').catch(reason => { + assert.ok(true, 'promise should be rejected'); + assert.ok( + reason instanceof DS.NotFoundError, + 'reason should be an instance of DS.NotFoundError' + ); + }); + }); + + ajaxError('error', 409); + + run(() => { + store.find('post', '1').catch(reason => { + assert.ok(true, 'promise should be rejected'); + assert.ok( + reason instanceof DS.ConflictError, + 'reason should be an instance of DS.ConflictError' + ); + }); + }); + + ajaxError('error', 500); + + run(() => { + store.find('post', '1').catch(reason => { + assert.ok(true, 'promise should be rejected'); + assert.ok(reason instanceof DS.ServerError, 'reason should be an instance of DS.ServerError'); + }); + }); +}); + +test('on error wraps the error string in an DS.AdapterError object', function(assert) { + assert.expect(2); + + let jqXHR = { + responseText: '', + getAllResponseHeaders() { + return ''; + }, + }; + + let errorThrown = 'nope!'; + + adapter._ajaxRequest = function(hash) { + hash.error(jqXHR, 'error', errorThrown); + }; + + run(() => { + store.findRecord('post', '1').catch(err => { + assert.equal(err.errors[0].detail, errorThrown); + assert.ok(err, 'promise rejected'); + }); + }); +}); + +test('error handling includes a detailed message from the server', assert => { + assert.expect(2); + + ajaxError( + 'An error message, perhaps generated from a backend server!', + 500, + 'Content-Type: text/plain' + ); + + run(() => { + store.findRecord('post', '1').catch(err => { + assert.equal( + err.message, + 'Ember Data Request GET /posts/1 returned a 500\nPayload (text/plain)\nAn error message, perhaps generated from a backend server!' + ); + assert.ok(err, 'promise rejected'); + }); + }); +}); + +test('error handling with a very long HTML-formatted payload truncates the friendly message', assert => { + assert.expect(2); + + ajaxError(new Array(100).join(''), 500, 'Content-Type: text/html'); + + run(() => { + store.findRecord('post', '1').catch(err => { + assert.equal( + err.message, + 'Ember Data Request GET /posts/1 returned a 500\nPayload (text/html)\n[Omitted Lengthy HTML]' + ); + assert.ok(err, 'promise rejected'); + }); + }); +}); + +test('findAll resolves with a collection of DS.Models, not DS.InternalModels', assert => { + assert.expect(4); + + ajaxResponse({ + posts: [ + { + id: 1, + name: 'dhh lol', + }, + { + id: 2, + name: 'james mickens is rad', + }, + { + id: 3, + name: 'in the name of love', + }, + ], + }); + + return run(() => { + return store.findAll('post').then(posts => { + assert.equal(get(posts, 'length'), 3); + posts.forEach(post => assert.ok(post instanceof DS.Model)); + }); + }); +}); + +test('createRecord - sideloaded records are pushed to the store', function(assert) { + Post.reopen({ + comments: DS.hasMany('comment'), + }); + + ajaxResponse({ + post: { + id: 1, + name: 'The Parley Letter', + comments: [2, 3], + }, + comments: [ + { + id: 2, + name: 'First comment', + }, + { + id: 3, + name: 'Second comment', + }, + ], + }); + let post; + + return run(() => { + post = store.createRecord('post', { name: 'The Parley Letter' }); + + return post.save().then(post => { + let comments = store.peekAll('comment'); + + assert.equal(get(comments, 'length'), 2, 'comments.length is correct'); + assert.equal( + get(comments, 'firstObject.name'), + 'First comment', + 'comments.firstObject.name is correct' + ); + assert.equal( + get(comments, 'lastObject.name'), + 'Second comment', + 'comments.lastObject.name is correct' + ); + }); + }); +}); + +testInDebug( + 'warns when an empty response is returned, though a valid stringified JSON is expected', + function(assert) { + server.post('/posts', function() { + return [201, { 'Content-Type': 'application/json' }, '']; + }); + + return run(() => { + return store.createRecord('post').save(); + }).then( + () => { + assert.equal(true, false, 'should not have fulfilled'); + }, + reason => { + assert.ok(/JSON/.test(reason.message)); + } + ); + } +); diff --git a/tests/integration/adapter/serialize-test.js b/tests/integration/adapter/serialize-test.js new file mode 100644 index 00000000000..f5ced5ec0b6 --- /dev/null +++ b/tests/integration/adapter/serialize-test.js @@ -0,0 +1,36 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let env, store, adapter, serializer; + +module('integration/adapter/serialize - DS.Adapter integration test', { + beforeEach() { + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + env = setupStore({ person: Person }); + store = env.store; + adapter = env.adapter; + serializer = store.serializerFor('person'); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('serialize() is delegated to the serializer', function(assert) { + assert.expect(1); + + serializer.serialize = function(snapshot, options) { + assert.deepEqual(options, { foo: 'bar' }); + }; + + let person = store.createRecord('person'); + adapter.serialize(person._createSnapshot(), { foo: 'bar' }); +}); diff --git a/tests/integration/adapter/store-adapter-test.js b/tests/integration/adapter/store-adapter-test.js new file mode 100644 index 00000000000..655f5df7d45 --- /dev/null +++ b/tests/integration/adapter/store-adapter-test.js @@ -0,0 +1,1606 @@ +import { resolve, hash, Promise as EmberPromise, reject } from 'rsvp'; +import { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; + +import DS from 'ember-data'; + +let Person, Dog, env, store, adapter; + +function moveRecordOutOfInFlight(record) { + run(() => { + // move record out of the inflight state so the tests can clean up + // correctly + let { store, _internalModel } = record; + store.recordWasError(_internalModel, new Error()); + }); +} + +module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test', { + beforeEach() { + Person = DS.Model.extend({ + updatedAt: DS.attr('string'), + name: DS.attr('string'), + firstName: DS.attr('string'), + lastName: DS.attr('string'), + }); + + Dog = DS.Model.extend({ + name: DS.attr('string'), + }); + + env = setupStore({ + serializer: DS.JSONAPISerializer, + adapter: DS.JSONAPIAdapter, + person: Person, + dog: Dog, + }); + store = env.store; + adapter = env.adapter; + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('Records loaded multiple times and retrieved in recordArray are ready to send state events', function(assert) { + adapter.query = function(store, type, query, recordArray) { + return resolve({ + data: [ + { + id: 1, + type: 'person', + attributes: { + name: 'Mickael Ramírez', + }, + }, + { + id: 2, + type: 'person', + attributes: { + name: 'Johny Fontana', + }, + }, + ], + }); + }; + + return run(() => + store + .query('person', { q: 'bla' }) + .then(people => { + let people2 = store.query('person', { q: 'bla2' }); + + return hash({ people: people, people2: people2 }); + }) + .then(results => { + assert.equal(results.people2.get('length'), 2, 'return the elements'); + assert.ok(results.people2.get('isLoaded'), 'array is loaded'); + + var person = results.people.objectAt(0); + assert.ok(person.get('isLoaded'), 'record is loaded'); + + // delete record will not throw exception + person.deleteRecord(); + }) + ); +}); + +test('by default, createRecords calls createRecord once per record', function(assert) { + let count = 1; + adapter.shouldBackgroundReloadRecord = () => false; + adapter.createRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + + if (count === 1) { + assert.equal(snapshot.attr('name'), 'Tom Dale'); + } else if (count === 2) { + assert.equal(snapshot.attr('name'), 'Yehuda Katz'); + } else { + assert.ok(false, 'should not have invoked more than 2 times'); + } + + let hash = snapshot.attributes(); + let recordId = count; + hash['updated-at'] = 'now'; + + count++; + return resolve({ + data: { + id: recordId, + type: 'person', + attributes: hash, + }, + }); + }; + + let tom = store.createRecord('person', { name: 'Tom Dale' }); + let yehuda = store.createRecord('person', { name: 'Yehuda Katz' }); + + let promise = run(() => { + return hash({ + tom: tom.save(), + yehuda: yehuda.save(), + }); + }); + + return promise.then(records => { + tom = records.tom; + yehuda = records.yehuda; + + assert.asyncEqual( + tom, + store.findRecord('person', 1), + 'Once an ID is in, findRecord returns the same object' + ); + assert.asyncEqual( + yehuda, + store.findRecord('person', 2), + 'Once an ID is in, findRecord returns the same object' + ); + assert.equal(get(tom, 'updatedAt'), 'now', 'The new information is received'); + assert.equal(get(yehuda, 'updatedAt'), 'now', 'The new information is received'); + }); +}); + +test('by default, updateRecords calls updateRecord once per record', function(assert) { + let count = 0; + adapter.shouldBackgroundReloadRecord = () => false; + adapter.updateRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + + if (count === 0) { + assert.equal(snapshot.attr('name'), 'Tom Dale'); + } else if (count === 1) { + assert.equal(snapshot.attr('name'), 'Yehuda Katz'); + } else { + assert.ok(false, 'should not get here'); + } + + count++; + + assert.equal(snapshot.record.get('isSaving'), true, 'record is saving'); + + return resolve(); + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Braaaahm Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Brohuda Katz', + }, + }, + ], + }); + }); + + let promise = run(() => { + return hash({ + tom: store.findRecord('person', 1), + yehuda: store.findRecord('person', 2), + }); + }); + + return promise + .then(records => { + let tom = records.tom; + let yehuda = records.yehuda; + + set(tom, 'name', 'Tom Dale'); + set(yehuda, 'name', 'Yehuda Katz'); + + return hash({ + tom: tom.save(), + yehuda: yehuda.save(), + }); + }) + .then(records => { + let tom = records.tom; + let yehuda = records.yehuda; + + assert.equal(tom.get('isSaving'), false, 'record is no longer saving'); + assert.equal(tom.get('isLoaded'), true, 'record is loaded'); + + assert.equal(yehuda.get('isSaving'), false, 'record is no longer saving'); + assert.equal(yehuda.get('isLoaded'), true, 'record is loaded'); + }); +}); + +test('calling store.didSaveRecord can provide an optional hash', function(assert) { + let count = 0; + adapter.shouldBackgroundReloadRecord = () => false; + adapter.updateRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + + count++; + if (count === 1) { + assert.equal(snapshot.attr('name'), 'Tom Dale'); + return resolve({ + data: { id: 1, type: 'person', attributes: { name: 'Tom Dale', 'updated-at': 'now' } }, + }); + } else if (count === 2) { + assert.equal(snapshot.attr('name'), 'Yehuda Katz'); + return resolve({ + data: { id: 2, type: 'person', attributes: { name: 'Yehuda Katz', 'updated-at': 'now!' } }, + }); + } else { + assert.ok(false, 'should not get here'); + } + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Braaaahm Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Brohuda Katz', + }, + }, + ], + }); + }); + + let promise = run(() => { + return hash({ + tom: store.findRecord('person', 1), + yehuda: store.findRecord('person', 2), + }); + }); + + return promise + .then(records => { + let tom = records.tom; + let yehuda = records.yehuda; + + set(tom, 'name', 'Tom Dale'); + set(yehuda, 'name', 'Yehuda Katz'); + + return hash({ + tom: tom.save(), + yehuda: yehuda.save(), + }); + }) + .then(records => { + let tom = records.tom; + let yehuda = records.yehuda; + + assert.equal(get(tom, 'hasDirtyAttributes'), false, 'the record should not be dirty'); + assert.equal(get(tom, 'updatedAt'), 'now', 'the hash was updated'); + + assert.equal(get(yehuda, 'hasDirtyAttributes'), false, 'the record should not be dirty'); + assert.equal(get(yehuda, 'updatedAt'), 'now!', 'the hash was updated'); + }); +}); + +test('by default, deleteRecord calls deleteRecord once per record', function(assert) { + assert.expect(4); + + let count = 0; + adapter.shouldBackgroundReloadRecord = () => false; + adapter.deleteRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + + if (count === 0) { + assert.equal(snapshot.attr('name'), 'Tom Dale'); + } else if (count === 1) { + assert.equal(snapshot.attr('name'), 'Yehuda Katz'); + } else { + assert.ok(false, 'should not get here'); + } + + count++; + + return resolve(); + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Yehuda Katz', + }, + }, + ], + }); + }); + + let promise = run(() => { + return hash({ + tom: store.findRecord('person', 1), + yehuda: store.findRecord('person', 2), + }); + }); + + return promise.then(records => { + let tom = records.tom; + let yehuda = records.yehuda; + + tom.deleteRecord(); + yehuda.deleteRecord(); + + return EmberPromise.all([tom.save(), yehuda.save()]); + }); +}); + +test('by default, destroyRecord calls deleteRecord once per record without requiring .save', function(assert) { + assert.expect(4); + + let count = 0; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.deleteRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + + if (count === 0) { + assert.equal(snapshot.attr('name'), 'Tom Dale'); + } else if (count === 1) { + assert.equal(snapshot.attr('name'), 'Yehuda Katz'); + } else { + assert.ok(false, 'should not get here'); + } + + count++; + + return resolve(); + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Yehuda Katz', + }, + }, + ], + }); + }); + + let promise = run(() => { + return hash({ + tom: store.findRecord('person', 1), + yehuda: store.findRecord('person', 2), + }); + }); + + return promise.then(records => { + let tom = records.tom; + let yehuda = records.yehuda; + + return EmberPromise.all([tom.destroyRecord(), yehuda.destroyRecord()]); + }); +}); + +test('if an existing model is edited then deleted, deleteRecord is called on the adapter', function(assert) { + assert.expect(5); + + let count = 0; + adapter.shouldBackgroundReloadRecord = () => false; + adapter.deleteRecord = function(store, type, snapshot) { + count++; + assert.equal(snapshot.id, 'deleted-record', 'should pass correct record to deleteRecord'); + assert.equal(count, 1, 'should only call deleteRecord method of adapter once'); + + return resolve(); + }; + + adapter.updateRecord = function() { + assert.ok(false, 'should not have called updateRecord method of adapter'); + }; + + // Load data for a record into the store. + run(() => { + env.store.push({ + data: { + type: 'person', + id: 'deleted-record', + attributes: { + name: 'Tom Dale', + }, + }, + }); + }); + + // Retrieve that loaded record and edit it so it becomes dirty + return run(() => + store + .findRecord('person', 'deleted-record') + .then(tom => { + tom.set('name', "Tom Mothereffin' Dale"); + + assert.equal( + get(tom, 'hasDirtyAttributes'), + true, + 'precond - record should be dirty after editing' + ); + + tom.deleteRecord(); + return tom.save(); + }) + .then(tom => { + assert.equal(get(tom, 'hasDirtyAttributes'), false, 'record should not be dirty'); + assert.equal(get(tom, 'isDeleted'), true, 'record should be considered deleted'); + }) + ); +}); + +test('if a deleted record errors, it enters the error state', function(assert) { + let count = 0; + let error = new DS.AdapterError(); + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.deleteRecord = function(store, type, snapshot) { + if (count++ === 0) { + return reject(error); + } else { + return resolve(); + } + }; + + run(() => { + env.store.push({ + data: { + type: 'person', + id: 'deleted-record', + attributes: { + name: 'Tom Dale', + }, + }, + }); + }); + + return run(() => { + let tom; + store + .findRecord('person', 'deleted-record') + .then(person => { + tom = person; + person.deleteRecord(); + return person.save(); + }) + .catch(() => { + assert.equal(tom.get('isError'), true, 'Tom is now errored'); + assert.equal(tom.get('adapterError'), error, 'error object is exposed'); + + // this time it succeeds + return tom.save(); + }) + .then(() => { + assert.equal(tom.get('isError'), false, 'Tom is not errored anymore'); + assert.equal(tom.get('adapterError'), null, 'error object is discarded'); + }); + }); +}); + +test('if a created record is marked as invalid by the server, it enters an error state', function(assert) { + adapter.createRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + + if (snapshot.attr('name').indexOf('Bro') === -1) { + return reject( + new DS.InvalidError([ + { + title: 'Invalid Attribute', + detail: 'common... name requires a "bro"', + source: { + pointer: '/data/attributes/name', + }, + }, + ]) + ); + } else { + return resolve(); + } + }; + + let yehuda = store.createRecord('person', { id: 1, name: 'Yehuda Katz' }); + // Wrap this in an Ember.run so that all chained async behavior is set up + // before flushing any scheduled behavior. + return run(function() { + return yehuda + .save() + .catch(error => { + assert.equal(get(yehuda, 'isValid'), false, 'the record is invalid'); + assert.ok(get(yehuda, 'errors.name'), 'The errors.name property exists'); + + set(yehuda, 'updatedAt', true); + assert.equal(get(yehuda, 'isValid'), false, 'the record is still invalid'); + + set(yehuda, 'name', 'Brohuda Brokatz'); + + assert.equal( + get(yehuda, 'isValid'), + true, + 'the record is no longer invalid after changing' + ); + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record has outstanding changes'); + + assert.equal(get(yehuda, 'isNew'), true, 'precond - record is still new'); + + return yehuda.save(); + }) + .then(person => { + assert.strictEqual(person, yehuda, 'The promise resolves with the saved record'); + + assert.equal(get(yehuda, 'isValid'), true, 'record remains valid after committing'); + assert.equal(get(yehuda, 'isNew'), false, 'record is no longer new'); + }); + }); +}); + +test('allows errors on arbitrary properties on create', function(assert) { + adapter.createRecord = function(store, type, snapshot) { + if (snapshot.attr('name').indexOf('Bro') === -1) { + return reject( + new DS.InvalidError([ + { + title: 'Invalid Attribute', + detail: 'is a generally unsavoury character', + source: { + pointer: '/data/attributes/base', + }, + }, + ]) + ); + } else { + return resolve(); + } + }; + + let yehuda = store.createRecord('person', { id: 1, name: 'Yehuda Katz' }); + + // Wrap this in an Ember.run so that all chained async behavior is set up + // before flushing any scheduled behavior. + return run(() => { + return yehuda + .save() + .catch(error => { + assert.equal(get(yehuda, 'isValid'), false, 'the record is invalid'); + assert.ok(get(yehuda, 'errors.base'), 'The errors.base property exists'); + assert.deepEqual(get(yehuda, 'errors').errorsFor('base'), [ + { attribute: 'base', message: 'is a generally unsavoury character' }, + ]); + + set(yehuda, 'updatedAt', true); + assert.equal(get(yehuda, 'isValid'), false, 'the record is still invalid'); + + set(yehuda, 'name', 'Brohuda Brokatz'); + + assert.equal( + get(yehuda, 'isValid'), + false, + 'the record is still invalid as far as we know' + ); + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record has outstanding changes'); + + assert.equal(get(yehuda, 'isNew'), true, 'precond - record is still new'); + + return yehuda.save(); + }) + .then(person => { + assert.strictEqual(person, yehuda, 'The promise resolves with the saved record'); + assert.ok(!get(yehuda, 'errors.base'), 'The errors.base property does not exist'); + assert.deepEqual(get(yehuda, 'errors').errorsFor('base'), []); + assert.equal(get(yehuda, 'isValid'), true, 'record remains valid after committing'); + assert.equal(get(yehuda, 'isNew'), false, 'record is no longer new'); + }); + }); +}); + +test('if a created record is marked as invalid by the server, you can attempt the save again', function(assert) { + let saveCount = 0; + adapter.createRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + saveCount++; + + if (snapshot.attr('name').indexOf('Bro') === -1) { + return reject( + new DS.InvalidError([ + { + title: 'Invalid Attribute', + detail: 'common... name requires a "bro"', + source: { + pointer: '/data/attributes/name', + }, + }, + ]) + ); + } else { + return resolve(); + } + }; + + let yehuda = store.createRecord('person', { id: 1, name: 'Yehuda Katz' }); + + // Wrap this in an Ember.run so that all chained async behavior is set up + // before flushing any scheduled behavior. + return run(() => { + return yehuda + .save() + .catch(reason => { + assert.equal(saveCount, 1, 'The record has been saved once'); + assert.ok( + reason.message.match('The adapter rejected the commit because it was invalid'), + 'It should fail due to being invalid' + ); + assert.equal(get(yehuda, 'isValid'), false, 'the record is invalid'); + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record has outstanding changes'); + assert.ok(get(yehuda, 'errors.name'), 'The errors.name property exists'); + assert.equal(get(yehuda, 'isNew'), true, 'precond - record is still new'); + return yehuda.save(); + }) + .catch(reason => { + assert.equal(saveCount, 2, 'The record has been saved twice'); + assert.ok( + reason.message.match('The adapter rejected the commit because it was invalid'), + 'It should fail due to being invalid' + ); + assert.equal(get(yehuda, 'isValid'), false, 'the record is still invalid'); + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record has outstanding changes'); + assert.ok(get(yehuda, 'errors.name'), 'The errors.name property exists'); + assert.equal(get(yehuda, 'isNew'), true, 'precond - record is still new'); + set(yehuda, 'name', 'Brohuda Brokatz'); + return yehuda.save(); + }) + .then(person => { + assert.equal(saveCount, 3, 'The record has been saved thrice'); + assert.equal(get(yehuda, 'isValid'), true, 'record is valid'); + assert.equal(get(yehuda, 'hasDirtyAttributes'), false, 'record is not dirty'); + assert.equal(get(yehuda, 'errors.isEmpty'), true, 'record has no errors'); + }); + }); +}); + +test('if a created record is marked as erred by the server, it enters an error state', function(assert) { + let error = new DS.AdapterError(); + + adapter.createRecord = function(store, type, snapshot) { + return reject(error); + }; + + return run(() => { + let person = store.createRecord('person', { id: 1, name: 'John Doe' }); + + return person.save().catch(() => { + assert.ok(get(person, 'isError'), 'the record is in the error state'); + assert.equal(get(person, 'adapterError'), error, 'error object is exposed'); + }); + }); +}); + +test('if an updated record is marked as invalid by the server, it enters an error state', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + adapter.updateRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + + if (snapshot.attr('name').indexOf('Bro') === -1) { + return reject( + new DS.InvalidError([ + { + title: 'Invalid Attribute', + detail: 'common... name requires a "bro"', + source: { + pointer: '/data/attributes/name', + }, + }, + ]) + ); + } else { + return resolve(); + } + }; + + let yehuda = run(() => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Brohuda Brokatz', + }, + }, + }); + + return store.peekRecord('person', 1); + }); + + return run(() => { + return store + .findRecord('person', 1) + .then(person => { + assert.equal(person, yehuda, 'The same object is passed through'); + + assert.equal(get(yehuda, 'isValid'), true, 'precond - the record is valid'); + set(yehuda, 'name', 'Yehuda Katz'); + assert.equal( + get(yehuda, 'isValid'), + true, + 'precond - the record is still valid as far as we know' + ); + + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record is dirty'); + + return yehuda.save(); + }) + .catch(reason => { + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record is still dirty'); + assert.equal(get(yehuda, 'isValid'), false, 'the record is invalid'); + + set(yehuda, 'updatedAt', true); + assert.equal(get(yehuda, 'isValid'), false, 'the record is still invalid'); + + set(yehuda, 'name', 'Brohuda Brokatz'); + assert.equal( + get(yehuda, 'isValid'), + true, + 'the record is no longer invalid after changing' + ); + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record has outstanding changes'); + + return yehuda.save(); + }) + .then(yehuda => { + assert.equal(get(yehuda, 'isValid'), true, 'record remains valid after committing'); + assert.equal(get(yehuda, 'hasDirtyAttributes'), false, 'record is no longer new'); + }); + }); +}); + +test('records can have errors on arbitrary properties after update', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + adapter.updateRecord = function(store, type, snapshot) { + if (snapshot.attr('name').indexOf('Bro') === -1) { + return reject( + new DS.InvalidError([ + { + title: 'Invalid Attribute', + detail: 'is a generally unsavoury character', + source: { + pointer: '/data/attributes/base', + }, + }, + ]) + ); + } else { + return resolve(); + } + }; + + let yehuda = run(() => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Brohuda Brokatz', + }, + }, + }); + return store.peekRecord('person', 1); + }); + + return run(() => { + return store + .findRecord('person', 1) + .then(person => { + assert.equal(person, yehuda, 'The same object is passed through'); + + assert.equal(get(yehuda, 'isValid'), true, 'precond - the record is valid'); + set(yehuda, 'name', 'Yehuda Katz'); + assert.equal( + get(yehuda, 'isValid'), + true, + 'precond - the record is still valid as far as we know' + ); + + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record is dirty'); + + return yehuda.save(); + }) + .catch(reason => { + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record is still dirty'); + assert.equal(get(yehuda, 'isValid'), false, 'the record is invalid'); + assert.ok(get(yehuda, 'errors.base'), 'The errors.base property exists'); + assert.deepEqual(get(yehuda, 'errors').errorsFor('base'), [ + { attribute: 'base', message: 'is a generally unsavoury character' }, + ]); + + set(yehuda, 'updatedAt', true); + assert.equal(get(yehuda, 'isValid'), false, 'the record is still invalid'); + + set(yehuda, 'name', 'Brohuda Brokatz'); + assert.equal( + get(yehuda, 'isValid'), + false, + "the record is still invalid after changing (only server can know if it's now valid)" + ); + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record has outstanding changes'); + + return yehuda.save(); + }) + .then(yehuda => { + assert.equal(get(yehuda, 'isValid'), true, 'record remains valid after committing'); + assert.equal(get(yehuda, 'hasDirtyAttributes'), false, 'record is no longer new'); + assert.ok(!get(yehuda, 'errors.base'), 'The errors.base property does not exist'); + assert.deepEqual(get(yehuda, 'errors').errorsFor('base'), []); + }); + }); +}); + +test('if an updated record is marked as invalid by the server, you can attempt the save again', function(assert) { + let saveCount = 0; + adapter.shouldBackgroundReloadRecord = () => false; + adapter.updateRecord = function(store, type, snapshot) { + assert.equal(type, Person, 'the type is correct'); + saveCount++; + if (snapshot.attr('name').indexOf('Bro') === -1) { + return reject( + new DS.InvalidError([ + { + title: 'Invalid Attribute', + detail: 'common... name requires a "bro"', + source: { + pointer: '/data/attributes/name', + }, + }, + ]) + ); + } else { + return resolve(); + } + }; + + let yehuda = run(() => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Brohuda Brokatz', + }, + }, + }); + return store.peekRecord('person', 1); + }); + + return run(() => { + return store + .findRecord('person', 1) + .then(person => { + assert.equal(person, yehuda, 'The same object is passed through'); + + assert.equal(get(yehuda, 'isValid'), true, 'precond - the record is valid'); + set(yehuda, 'name', 'Yehuda Katz'); + assert.equal( + get(yehuda, 'isValid'), + true, + 'precond - the record is still valid as far as we know' + ); + + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record is dirty'); + + return yehuda.save(); + }) + .catch(reason => { + assert.equal(saveCount, 1, 'The record has been saved once'); + assert.ok( + reason.message.match('The adapter rejected the commit because it was invalid'), + 'It should fail due to being invalid' + ); + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'the record is still dirty'); + assert.equal(get(yehuda, 'isValid'), false, 'the record is invalid'); + return yehuda.save(); + }) + .catch(reason => { + assert.equal(saveCount, 2, 'The record has been saved twice'); + assert.ok( + reason.message.match('The adapter rejected the commit because it was invalid'), + 'It should fail due to being invalid' + ); + assert.equal(get(yehuda, 'isValid'), false, 'record is still invalid'); + assert.equal(get(yehuda, 'hasDirtyAttributes'), true, 'record is still dirty'); + set(yehuda, 'name', 'Brohuda Brokatz'); + return yehuda.save(); + }) + .then(person => { + assert.equal(saveCount, 3, 'The record has been saved thrice'); + assert.equal(get(yehuda, 'isValid'), true, 'record is valid'); + assert.equal(get(yehuda, 'hasDirtyAttributes'), false, 'record is not dirty'); + assert.equal(get(yehuda, 'errors.isEmpty'), true, 'record has no errors'); + }); + }); +}); + +test('if a updated record is marked as erred by the server, it enters an error state', function(assert) { + let error = new DS.AdapterError(); + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.updateRecord = function(store, type, snapshot) { + return reject(error); + }; + + let person = run(() => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Doe', + }, + }, + }); + return store.peekRecord('person', 1); + }); + + return run(() => + store + .findRecord('person', 1) + .then(record => { + assert.equal(record, person, 'The person was resolved'); + person.set('name', 'Jonathan Doe'); + return person.save(); + }) + .catch(reason => { + assert.ok(get(person, 'isError'), 'the record is in the error state'); + assert.equal(get(person, 'adapterError'), error, 'error object is exposed'); + }) + ); +}); + +test('can be created after the DS.Store', function(assert) { + assert.expect(1); + + adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(type, Person, 'the type is correct'); + return resolve({ data: { id: 1, type: 'person' } }); + }; + + run(() => store.findRecord('person', 1)); +}); + +test('relationships returned via `commit` do not trigger additional findManys', function(assert) { + Person.reopen({ + dogs: DS.hasMany('dog', { async: false }), + }); + + run(() => { + env.store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'Scruffy', + }, + }, + }); + }); + + adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'person', + attributes: { name: 'Tom Dale' }, + relationships: { + dogs: { + data: [{ id: 1, type: 'dog' }], + }, + }, + }, + }); + }; + + adapter.updateRecord = function(store, type, snapshot) { + return new EmberPromise((resolve, reject) => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + dogs: { + data: [{ type: 'dog', id: '1' }, { type: 'dog', id: '2' }], + }, + }, + }, + included: [ + { + type: 'dog', + id: '2', + attributes: { + name: 'Scruffles', + }, + }, + ], + }); + + resolve({ data: { id: 1, type: 'dog', attributes: { name: 'Scruffy' } } }); + }); + }; + + adapter.findMany = function(store, type, ids, snapshots) { + assert.ok(false, 'Should not get here'); + }; + + return run(() => { + store + .findRecord('person', 1) + .then(person => { + return hash({ tom: person, dog: store.findRecord('dog', 1) }); + }) + .then(records => { + records.tom.get('dogs'); + return records.dog.save(); + }) + .then(tom => { + assert.ok(true, 'Tom was saved'); + }); + }); +}); + +test("relationships don't get reset if the links is the same", function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + Person.reopen({ + dogs: DS.hasMany({ async: true }), + }); + + let count = 0; + + adapter.findHasMany = function(store, snapshot, link, relationship) { + assert.ok(count++ === 0, 'findHasMany is only called once'); + + return resolve({ data: [{ id: 1, type: 'dog', attributes: { name: 'Scruffy' } }] }); + }; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + dogs: { + links: { + related: '/dogs', + }, + }, + }, + }, + }); + }); + + let tom, dogs; + + return run(() => + store + .findRecord('person', 1) + .then(person => { + tom = person; + dogs = tom.get('dogs'); + return dogs; + }) + .then(dogs => { + assert.equal(dogs.get('length'), 1, 'The dogs are loaded'); + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + dogs: { + links: { + related: '/dogs', + }, + }, + }, + }, + }); + assert.ok(tom.get('dogs') instanceof DS.PromiseArray, 'dogs is a promise'); + return tom.get('dogs'); + }) + .then(dogs => { + assert.equal(dogs.get('length'), 1, 'The same dogs are loaded'); + }) + ); +}); + +test('async hasMany always returns a promise', function(assert) { + Person.reopen({ + dogs: DS.hasMany({ async: true }), + }); + + adapter.createRecord = function(store, type, snapshot) { + return resolve({ + data: { + id: 1, + type: 'person', + attributes: { + name: 'Tom Dale', + }, + relationships: { + dogs: [], + }, + }, + }); + }; + + let tom = store.createRecord('person', { name: 'Tom Dale' }); + + run(() => { + assert.ok(tom.get('dogs') instanceof DS.PromiseArray, 'dogs is a promise before save'); + }); + + return run(() => { + return tom.save().then(() => { + assert.ok(tom.get('dogs') instanceof DS.PromiseArray, 'dogs is a promise after save'); + }); + }); +}); + +test('createRecord receives a snapshot', function(assert) { + assert.expect(1); + + adapter.createRecord = function(store, type, snapshot) { + assert.ok(snapshot instanceof DS.Snapshot, 'snapshot is an instance of DS.Snapshot'); + return resolve(); + }; + + let record = store.createRecord('person', { name: 'Tom Dale', id: 1 }); + + run(() => record.save()); +}); + +test('updateRecord receives a snapshot', function(assert) { + assert.expect(1); + + adapter.updateRecord = function(store, type, snapshot) { + assert.ok(snapshot instanceof DS.Snapshot, 'snapshot is an instance of DS.Snapshot'); + return resolve(); + }; + + let person; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }); + person = store.peekRecord('person', 1); + }); + + run(() => { + set(person, 'name', 'Tomster'); + person.save(); + }); +}); + +test('deleteRecord receives a snapshot', function(assert) { + assert.expect(1); + + adapter.deleteRecord = function(store, type, snapshot) { + assert.ok(snapshot instanceof DS.Snapshot, 'snapshot is an instance of DS.Snapshot'); + return resolve(); + }; + + let person; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }); + person = store.peekRecord('person', 1); + }); + + return run(() => { + person.deleteRecord(); + return person.save(); + }); +}); + +test('findRecord receives a snapshot', function(assert) { + assert.expect(1); + + adapter.findRecord = function(store, type, id, snapshot) { + assert.ok(snapshot instanceof DS.Snapshot, 'snapshot is an instance of DS.Snapshot'); + return resolve({ data: { id: 1, type: 'person' } }); + }; + + return run(() => store.findRecord('person', 1)); +}); + +test('findMany receives an array of snapshots', function(assert) { + assert.expect(2); + + Person.reopen({ + dogs: DS.hasMany({ async: true }), + }); + + adapter.coalesceFindRequests = true; + adapter.findMany = function(store, type, ids, snapshots) { + assert.ok(snapshots[0] instanceof DS.Snapshot, 'snapshots[0] is an instance of DS.Snapshot'); + assert.ok(snapshots[1] instanceof DS.Snapshot, 'snapshots[1] is an instance of DS.Snapshot'); + return resolve({ data: [{ id: 2, type: 'dog' }, { id: 3, type: 'dog' }] }); + }; + + let person; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + dogs: { + data: [{ type: 'dog', id: '2' }, { type: 'dog', id: '3' }], + }, + }, + }, + }); + person = store.peekRecord('person', 1); + }); + + run(() => person.get('dogs')); +}); + +test('findHasMany receives a snapshot', function(assert) { + assert.expect(1); + + Person.reopen({ + dogs: DS.hasMany({ async: true }), + }); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + assert.ok(snapshot instanceof DS.Snapshot, 'snapshot is an instance of DS.Snapshot'); + return resolve({ data: [{ id: 2, type: 'dog' }, { id: 3, type: 'dog' }] }); + }; + + let person; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + dogs: { + links: { + related: 'dogs', + }, + }, + }, + }, + }); + person = store.peekRecord('person', 1); + }); + + return run(() => person.get('dogs')); +}); + +test('findBelongsTo receives a snapshot', function(assert) { + assert.expect(1); + + Person.reopen({ + dog: DS.belongsTo({ async: true }), + }); + + env.adapter.findBelongsTo = function(store, snapshot, link, relationship) { + assert.ok(snapshot instanceof DS.Snapshot, 'snapshot is an instance of DS.Snapshot'); + return resolve({ data: { id: 2, type: 'dog' } }); + }; + + let person; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + dog: { + links: { + related: 'dog', + }, + }, + }, + }, + }); + person = store.peekRecord('person', 1); + }); + + return run(() => person.get('dog')); +}); + +test('record.save should pass adapterOptions to the updateRecord method', function(assert) { + assert.expect(1); + + env.adapter.updateRecord = function(store, type, snapshot) { + assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); + return resolve({ data: { id: 1, type: 'person' } }); + }; + + return run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom', + }, + }, + }); + let person = store.peekRecord('person', 1); + return person.save({ adapterOptions: { subscribe: true } }); + }); +}); + +test('record.save should pass adapterOptions to the createRecord method', function(assert) { + assert.expect(1); + + env.adapter.createRecord = function(store, type, snapshot) { + assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); + return resolve({ data: { id: 1, type: 'person' } }); + }; + + return run(() => { + store.createRecord('person', { name: 'Tom' }).save({ adapterOptions: { subscribe: true } }); + }); +}); + +test('record.save should pass adapterOptions to the deleteRecord method', function(assert) { + assert.expect(1); + + env.adapter.deleteRecord = function(store, type, snapshot) { + assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); + return resolve({ data: { id: 1, type: 'person' } }); + }; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom', + }, + }, + }); + let person = store.peekRecord('person', 1); + person.destroyRecord({ adapterOptions: { subscribe: true } }); + }); +}); + +test('store.findRecord should pass adapterOptions to adapter.findRecord', function(assert) { + assert.expect(1); + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.deepEqual(snapshot.adapterOptions, { query: { embed: true } }); + return resolve({ data: { id: 1, type: 'person' } }); + }; + + return run(() => { + return store.findRecord('person', 1, { adapterOptions: { query: { embed: true } } }); + }); +}); + +test('store.query should pass adapterOptions to adapter.query ', function(assert) { + assert.expect(2); + + env.adapter.query = function(store, type, query, array, options) { + assert.ok(!('adapterOptions' in query)); + assert.deepEqual(options.adapterOptions, { query: { embed: true } }); + return { data: [] }; + }; + + return run(() => { + return store.query('person', {}, { adapterOptions: { query: { embed: true } } }); + }); +}); + +test('store.queryRecord should pass adapterOptions to adapter.queryRecord', function(assert) { + assert.expect(2); + + env.adapter.queryRecord = function(store, type, query, snapshot) { + assert.ok(!('adapterOptions' in query)); + assert.deepEqual(snapshot.adapterOptions, { query: { embed: true } }); + return { data: { type: 'person', id: 1, attributes: {} } }; + }; + + return run(() => { + return store.queryRecord('person', {}, { adapterOptions: { query: { embed: true } } }); + }); +}); + +test("store.findRecord should pass 'include' to adapter.findRecord", function(assert) { + assert.expect(1); + + env.adapter.findRecord = (store, type, id, snapshot) => { + assert.equal(snapshot.include, 'books', 'include passed to adapter.findRecord'); + return resolve({ data: { id: 1, type: 'person' } }); + }; + + run(() => store.findRecord('person', 1, { include: 'books' })); +}); + +test('store.findAll should pass adapterOptions to the adapter.findAll method', function(assert) { + assert.expect(1); + + env.adapter.findAll = function(store, type, sinceToken, arraySnapshot) { + let adapterOptions = arraySnapshot.adapterOptions; + assert.deepEqual(adapterOptions, { query: { embed: true } }); + return resolve({ data: [{ id: 1, type: 'person' }] }); + }; + + return run(() => { + return store.findAll('person', { adapterOptions: { query: { embed: true } } }); + }); +}); + +test("store.findAll should pass 'include' to adapter.findAll", function(assert) { + assert.expect(1); + + env.adapter.findAll = function(store, type, sinceToken, arraySnapshot) { + assert.equal(arraySnapshot.include, 'books', 'include passed to adapter.findAll'); + return resolve({ data: [{ id: 1, type: 'person' }] }); + }; + + run(() => store.findAll('person', { include: 'books' })); +}); + +test('An async hasMany relationship with links should not trigger shouldBackgroundReloadRecord', function(assert) { + const Post = DS.Model.extend({ + name: DS.attr('string'), + comments: DS.hasMany('comment', { async: true }), + }); + + const Comment = DS.Model.extend({ + name: DS.attr('string'), + }); + + env = setupStore({ + post: Post, + comment: Comment, + adapter: DS.RESTAdapter.extend({ + findRecord() { + return { + posts: { + id: 1, + name: 'Rails is omakase', + links: { comments: '/posts/1/comments' }, + }, + }; + }, + findHasMany() { + return resolve({ + comments: [ + { id: 1, name: 'FIRST' }, + { id: 2, name: 'Rails is unagi' }, + { id: 3, name: 'What is omakase?' }, + ], + }); + }, + shouldBackgroundReloadRecord() { + assert.ok(false, 'shouldBackgroundReloadRecord should not be called'); + }, + }), + }); + + store = env.store; + + return run(() => + store + .findRecord('post', '1') + .then(post => { + return post.get('comments'); + }) + .then(comments => { + assert.equal(comments.get('length'), 3); + }) + ); +}); + +testInDebug( + 'There should be a friendly error for if the adapter does not implement createRecord', + function(assert) { + adapter.createRecord = null; + + let tom = run(() => store.createRecord('person', { name: 'Tom Dale' })); + + assert.expectAssertion(() => { + run(() => tom.save()); + }, /does not implement 'createRecord'/); + + moveRecordOutOfInFlight(tom); + } +); + +testInDebug( + 'There should be a friendly error for if the adapter does not implement updateRecord', + function(assert) { + adapter.updateRecord = null; + + let tom = run(() => store.push({ data: { type: 'person', id: 1 } })); + assert.expectAssertion(() => { + run(() => tom.save()); + }, /does not implement 'updateRecord'/); + + moveRecordOutOfInFlight(tom); + } +); + +testInDebug( + 'There should be a friendly error for if the adapter does not implement deleteRecord', + function(assert) { + adapter.deleteRecord = null; + + let tom = run(() => store.push({ data: { type: 'person', id: 1 } })); + + assert.expectAssertion(() => { + run(() => { + tom.deleteRecord(); + return tom.save(); + }); + }, /does not implement 'deleteRecord'/); + + moveRecordOutOfInFlight(tom); + } +); diff --git a/tests/integration/application-test.js b/tests/integration/application-test.js new file mode 100644 index 00000000000..1c965b679ff --- /dev/null +++ b/tests/integration/application-test.js @@ -0,0 +1,166 @@ +import Namespace from '@ember/application/namespace'; +import Service, { inject as service } from '@ember/service'; +import Controller from '@ember/controller'; +import Application from '@ember/application'; +import { run } from '@ember/runloop'; +import Store from 'ember-data/store'; +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import initializeEmberData from 'ember-data/setup-container'; +import initializeStoreService from 'ember-data/initialize-store-service'; + +/* + These tests ensure that Ember Data works with Ember's application + initialization and dependency injection APIs. +*/ +module('integration/application - Injecting a Custom Store', function(hooks) { + setupTest(hooks); + + hooks.beforeEach(function() { + let { owner } = this; + + owner.register('service:store', Store.extend({ isCustom: true })); + owner.register('controller:foo', Controller.extend()); + owner.register('controller:baz', {}); + owner.register('controller:application', Controller.extend()); + }); + + test('If a Store property exists on an Application, it should be instantiated.', async function(assert) { + let store = this.owner.lookup('service:store'); + assert.ok(store.isCustom === true, 'the custom store was instantiated'); + }); + + test('If a store is instantiated, it should be made available to each controller.', async function(assert) { + let fooController = this.owner.lookup('controller:foo'); + let isCustom = fooController.get('store.isCustom'); + assert.ok(isCustom, 'the custom store was injected'); + }); + + test('The JSONAPIAdapter is the default adapter when no custom adapter is provided', async function(assert) { + let store = this.owner.lookup('service:store'); + let adapter = store.adapterFor('application'); + + assert.ok(adapter instanceof JSONAPIAdapter, 'default adapter should be the JSONAPIAdapter'); + }); +}); + +module('integration/application - Injecting the Default Store', function(hooks) { + setupTest(hooks); + + hooks.beforeEach(function() { + let { owner } = this; + + owner.register('controller:foo', Controller.extend()); + owner.register('controller:baz', {}); + owner.register('controller:application', Controller.extend()); + }); + + test('If a Store property exists on an Application, it should be instantiated.', async function(assert) { + let store = this.owner.lookup('service:store'); + assert.ok(store instanceof Store, 'the store was instantiated'); + }); + + test('If a store is instantiated, it should be made available to each controller.', async function(assert) { + let fooController = this.owner.lookup('controller:foo'); + assert.ok(fooController.get('store') instanceof Store, 'the store was injected'); + }); + + test('the DS namespace should be accessible', async function(assert) { + assert.ok(Namespace.byName('DS') instanceof Namespace, 'the DS namespace is accessible'); + }); +}); + +module('integration/application - Using the store as a service', function(hooks) { + setupTest(hooks); + + hooks.beforeEach(function() { + let { owner } = this; + + owner.register('controller:foo', Controller.extend()); + owner.register('controller:baz', {}); + owner.register('controller:application', Controller.extend()); + owner.register('service:doodle', Service.extend({ store: service() })); + owner.register('service:second-store', Store); + }); + + test('The store can be injected as a service', async function(assert) { + let doodleService = this.owner.lookup('service:doodle'); + assert.ok(doodleService.get('store') instanceof Store, 'the store can be used as a service'); + }); + + test('There can be multiple store services', function(assert) { + let doodleService = this.owner.lookup('service:doodle'); + let store = doodleService.get('store'); + let secondService = this.owner.lookup('service:second-store'); + + assert.ok(secondService instanceof Store, 'the store can be used as a service'); + assert.ok(store !== secondService, 'the store can be used as a service'); + }); +}); + +module('integration/application - Attaching initializer', function(hooks) { + hooks.beforeEach(function() { + this.TestApplication = Application.extend(); + this.TestApplication.initializer({ + name: 'ember-data', + initialize: initializeEmberData, + }); + this.TestApplication.instanceInitializer({ + name: 'ember-data', + initialize: initializeStoreService, + }); + this.application = null; + this.owner = null; + }); + + hooks.afterEach(function() { + if (this.application !== null) { + run(this.application, 'destroy'); + } + }); + + test('ember-data initializer is run', async function(assert) { + let ran = false; + + this.TestApplication.initializer({ + name: 'after-ember-data', + after: 'ember-data', + initialize() { + ran = true; + }, + }); + + this.application = this.TestApplication.create({ autoboot: false }); + + await run(() => this.application.boot()); + + assert.ok(ran, 'ember-data initializer was found'); + }); + + test('ember-data initializer does not register the store service when it was already registered', async function(assert) { + let AppStore = Store.extend({ + isCustomStore: true, + }); + + this.TestApplication.initializer({ + name: 'before-ember-data', + before: 'ember-data', + initialize(registry) { + registry.register('service:store', AppStore); + }, + }); + + this.application = this.TestApplication.create({ autoboot: false }); + + await run(() => + this.application.boot().then(() => (this.owner = this.application.buildInstance())) + ); + + let store = this.owner.lookup('service:store'); + assert.ok( + store && store.get('isCustomStore'), + 'ember-data initializer does not overwrite the previous registered service store' + ); + }); +}); diff --git a/tests/integration/backwards-compat/non-dasherized-lookups-test.js b/tests/integration/backwards-compat/non-dasherized-lookups-test.js new file mode 100644 index 00000000000..bfbb18379a2 --- /dev/null +++ b/tests/integration/backwards-compat/non-dasherized-lookups-test.js @@ -0,0 +1,196 @@ +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +const { JSONAPIAdapter, Model, attr, belongsTo, hasMany } = DS; + +let store; + +module( + 'integration/backwards-compat/non-dasherized-lookups - non dasherized lookups in application code finders', + { + beforeEach() { + const PostNote = Model.extend({ + name: attr('string'), + }); + + const ApplicationAdapter = JSONAPIAdapter.extend({ + shouldBackgroundReloadRecord() { + return false; + }, + }); + + const env = setupStore({ + postNote: PostNote, + adapter: ApplicationAdapter, + }); + + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, + } +); + +test('can lookup records using camelCase strings', function(assert) { + assert.expect(1); + + run(() => { + store.pushPayload('post-note', { + data: { + type: 'post-notes', + id: '1', + attributes: { + name: 'Ember Data', + }, + }, + }); + }); + + run(() => { + store.findRecord('postNote', 1).then(postNote => { + assert.equal(get(postNote, 'name'), 'Ember Data', 'record found'); + }); + }); +}); + +test('can lookup records using under_scored strings', function(assert) { + assert.expect(1); + + run(() => { + store.pushPayload('post-note', { + data: { + type: 'post-notes', + id: '1', + attributes: { + name: 'Ember Data', + }, + }, + }); + }); + + run(() => { + store.findRecord('post_note', 1).then(postNote => { + assert.equal(get(postNote, 'name'), 'Ember Data', 'record found'); + }); + }); +}); + +module( + 'integration/backwards-compat/non-dasherized-lookups - non dasherized lookups in application code relationship macros', + { + beforeEach() { + const PostNote = Model.extend({ + notePost: belongsTo('note-post', { async: false }), + + name: attr('string'), + }); + + const NotePost = Model.extend({ + name: attr('string'), + }); + + const LongModelName = Model.extend({ + postNotes: hasMany('post_note'), + }); + + const ApplicationAdapter = JSONAPIAdapter.extend({ + shouldBackgroundReloadRecord() { + return false; + }, + }); + + const env = setupStore({ + longModelName: LongModelName, + notePost: NotePost, + postNote: PostNote, + adapter: ApplicationAdapter, + }); + + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, + } +); + +test('looks up belongsTo using camelCase strings', function(assert) { + assert.expect(1); + + run(() => { + store.pushPayload('post-note', { + data: { + type: 'post-notes', + id: '1', + attributes: { + name: 'Ember Data', + }, + relationships: { + 'note-post': { + data: { type: 'note-post', id: '1' }, + }, + }, + }, + }); + store.pushPayload('notePost', { + data: { + type: 'note-posts', + id: '1', + attributes: { + name: 'Inverse', + }, + }, + }); + }); + + run(() => { + store.findRecord('post-note', 1).then(postNote => { + assert.equal(get(postNote, 'notePost.name'), 'Inverse', 'inverse record found'); + }); + }); +}); + +test('looks up belongsTo using under_scored strings', function(assert) { + assert.expect(1); + + run(() => { + store.pushPayload('long_model_name', { + data: { + type: 'long-model-names', + id: '1', + attributes: {}, + relationships: { + 'post-notes': { + data: [{ type: 'post-note', id: '1' }], + }, + }, + }, + }); + + store.pushPayload('post-note', { + data: { + type: 'post-notes', + id: '1', + attributes: { + name: 'Ember Data', + }, + }, + }); + }); + + run(() => { + store.findRecord('long_model_name', 1).then(longModelName => { + const postNotes = get(longModelName, 'postNotes').toArray(); + + assert.deepEqual(postNotes, [store.peekRecord('postNote', 1)], 'inverse records found'); + }); + }); +}); diff --git a/tests/integration/client-id-generation-test.js b/tests/integration/client-id-generation-test.js new file mode 100644 index 00000000000..af9d97e23a2 --- /dev/null +++ b/tests/integration/client-id-generation-test.js @@ -0,0 +1,116 @@ +import { resolve } from 'rsvp'; +import { get } from '@ember/object'; +import { setupTest } from 'ember-qunit'; +import { module, test } from 'qunit'; +import Model from 'ember-data/model'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import { attr, belongsTo, hasMany } from '@ember-decorators/data'; + +module('integration - Client Id Generation', function(hooks) { + setupTest(hooks); + let store; + let adapter; + + hooks.beforeEach(function() { + let { owner } = this; + + class Comment extends Model { + @attr + text; + @belongsTo('post', { async: false, inverse: 'comments' }) + post; + } + class Post extends Model { + @attr + title; + @hasMany('comment', { async: false, inverse: 'post' }) + comments; + } + class Misc extends Model { + @attr('string') + foo; + } + + owner.register('model:comment', Comment); + owner.register('model:post', Post); + owner.register('model:misc', Misc); + owner.register('adapter:application', JSONAPIAdapter); + + store = owner.lookup('service:store'); + adapter = store.adapterFor('application'); + }); + + test('If an adapter implements the `generateIdForRecord` method, the store should be able to assign IDs without saving to the persistence layer.', async function(assert) { + assert.expect(6); + + let idCount = 1; + + adapter.generateIdForRecord = function(passedStore, record) { + assert.ok(store === passedStore, 'store is the first parameter'); + + return 'id-' + idCount++; + }; + + adapter.createRecord = function(store, modelClass, snapshot) { + let type = modelClass.modelName; + + if (type === 'comment') { + assert.equal(snapshot.id, 'id-1', "Comment passed to `createRecord` has 'id-1' assigned"); + return resolve({ + data: { + type, + id: snapshot.id, + }, + }); + } else { + assert.equal(snapshot.id, 'id-2', "Post passed to `createRecord` has 'id-2' assigned"); + return resolve({ + data: { + type, + id: snapshot.id, + }, + }); + } + }; + + let comment = store.createRecord('comment'); + let post = store.createRecord('post'); + + assert.equal(get(comment, 'id'), 'id-1', "comment is assigned id 'id-1'"); + assert.equal(get(post, 'id'), 'id-2', "post is assigned id 'id-2'"); + + // Despite client-generated IDs, calling save() on the store should still + // invoke the adapter's `createRecord` method. + await comment.save(); + await post.save(); + }); + + test('empty string and undefined ids should coerce to null', async function(assert) { + assert.expect(6); + let idCount = 0; + let id = 1; + let ids = [undefined, '']; + + adapter.generateIdForRecord = function(passedStore, record) { + assert.ok(store === passedStore, 'store is the first parameter'); + + return ids[idCount++]; + }; + + adapter.createRecord = function(store, type, record) { + assert.equal(typeof get(record, 'id'), 'object', 'correct type'); + return resolve({ data: { id: id++, type: type.modelName } }); + }; + + let comment = store.createRecord('misc'); + let post = store.createRecord('misc'); + + assert.equal(get(comment, 'id'), null, "comment is assigned id 'null'"); + assert.equal(get(post, 'id'), null, "post is assigned id 'null'"); + + // Despite client-generated IDs, calling commit() on the store should still + // invoke the adapter's `createRecord` method. + await comment.save(); + await post.save(); + }); +}); diff --git a/tests/integration/debug-adapter-test.js b/tests/integration/debug-adapter-test.js new file mode 100644 index 00000000000..43e999ac09e --- /dev/null +++ b/tests/integration/debug-adapter-test.js @@ -0,0 +1,149 @@ +import { setupTest } from 'ember-qunit'; +import { A } from '@ember/array'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import Model from 'ember-data/model'; +import { attr } from '@ember-decorators/data'; +import Adapter from 'ember-data/adapter'; +import { module, test } from 'qunit'; +import { settled } from '@ember/test-helpers'; + +class Post extends Model { + @attr + title; +} + +module('integration/debug-adapter - DS.DebugAdapter', function(hooks) { + setupTest(hooks); + + let store, debugAdapter; + + hooks.beforeEach(function() { + let { owner } = this; + + owner.register('model:post', Post); + store = owner.lookup('service:store'); + debugAdapter = owner.lookup('data-adapter:main'); + + debugAdapter.reopen({ + getModelTypes() { + return A([{ klass: Post, name: 'post' }]); + }, + }); + }); + + test('Watching Model Types', async function(assert) { + assert.expect(5); + + function added(types) { + assert.equal(types.length, 1); + assert.equal(types[0].name, 'post'); + assert.equal(types[0].count, 0); + assert.strictEqual(types[0].object, store.modelFor('post')); + } + + function updated(types) { + assert.equal(types[0].count, 1); + } + + debugAdapter.watchModelTypes(added, updated); + + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Post Title', + }, + }, + }); + }); + + test('Watching Records', async function(assert) { + let addedRecords, updatedRecords, removedIndex, removedCount; + + this.owner.register( + 'adapter:application', + Adapter.extend({ + shouldBackgroundReloadRecord() { + return false; + }, + }) + ); + + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Clean Post', + }, + }, + }); + + var recordsAdded = function(wrappedRecords) { + addedRecords = wrappedRecords; + }; + var recordsUpdated = function(wrappedRecords) { + updatedRecords = wrappedRecords; + }; + var recordsRemoved = function(index, count) { + removedIndex = index; + removedCount = count; + }; + + debugAdapter.watchRecords('post', recordsAdded, recordsUpdated, recordsRemoved); + + assert.equal(get(addedRecords, 'length'), 1); + let record = addedRecords[0]; + assert.deepEqual(record.columnValues, { id: '1', title: 'Clean Post' }); + assert.deepEqual(record.filterValues, { isNew: false, isModified: false, isClean: true }); + assert.deepEqual(record.searchKeywords, ['1', 'Clean Post']); + assert.deepEqual(record.color, 'black'); + + let post = await store.findRecord('post', 1); + + post.set('title', 'Modified Post'); + + assert.equal(get(updatedRecords, 'length'), 1); + record = updatedRecords[0]; + assert.deepEqual(record.columnValues, { id: '1', title: 'Modified Post' }); + assert.deepEqual(record.filterValues, { isNew: false, isModified: true, isClean: false }); + assert.deepEqual(record.searchKeywords, ['1', 'Modified Post']); + assert.deepEqual(record.color, 'blue'); + + post = store.createRecord('post', { id: '2', title: 'New Post' }); + + await settled(); + + assert.equal(get(addedRecords, 'length'), 1); + record = addedRecords[0]; + assert.deepEqual(record.columnValues, { id: '2', title: 'New Post' }); + assert.deepEqual(record.filterValues, { isNew: true, isModified: false, isClean: false }); + assert.deepEqual(record.searchKeywords, ['2', 'New Post']); + assert.deepEqual(record.color, 'green'); + + run(() => post.unloadRecord()); + + await settled(); + + assert.equal(removedIndex, 1); + assert.equal(removedCount, 1); + }); + + test('Column names', function(assert) { + class Person extends Model { + @attr + title; + + @attr + firstOrLastName; + } + + const columns = debugAdapter.columnsForType(Person); + + assert.equal(columns[0].desc, 'Id'); + assert.equal(columns[1].desc, 'Title'); + assert.equal(columns[2].desc, 'First or last name'); + }); +}); diff --git a/tests/integration/injection-test.js b/tests/integration/injection-test.js new file mode 100644 index 00000000000..908cb738a2d --- /dev/null +++ b/tests/integration/injection-test.js @@ -0,0 +1,65 @@ +import Model from 'ember-data/model'; +import Service from '@ember/service'; +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('integration/injection factoryFor enabled', function(hooks) { + setupTest(hooks); + let store; + let Model; + + hooks.beforeEach(function() { + let { owner } = this; + Model = { + isModel: true, + }; + owner.register('model:super-villain', Model); + store = owner.lookup('service:store'); + }); + + test('modelFactoryFor', function(assert) { + let { owner } = this; + const trueFactory = owner.factoryFor('model:super-villain'); + const modelFactory = store._modelFactoryFor('super-villain'); + + assert.strictEqual(modelFactory, trueFactory, 'expected the factory itself to be returned'); + }); + + test('modelFor', function(assert) { + const modelClass = store.modelFor('super-villain'); + + assert.strictEqual(modelClass, Model, 'expected the factory itself to be returned'); + + assert.equal( + modelClass.modelName, + 'super-villain', + 'expected the factory itself to be returned' + ); + }); +}); + +module('integration/injection eager injections', function(hooks) { + setupTest(hooks); + let store; + let Apple = Service.extend(); + + hooks.beforeEach(function() { + let { owner } = this; + + owner.register('model:foo', Model.extend()); + owner.register('service:apple', Apple); + owner.inject('model:foo', 'apple', 'service:apple'); + + store = this.owner.lookup('service:store'); + }); + + test('did inject', async function(assert) { + let foo = store.createRecord('foo'); + let apple = foo.get('apple'); + let appleService = this.owner.lookup('service:apple'); + + assert.ok(apple, `'model:foo' instance should have an 'apple' property`); + assert.ok(apple === appleService, `'model:foo.apple' should be the apple service`); + assert.ok(apple instanceof Apple, `'model:foo'.apple should be an instance of 'service:apple'`); + }); +}); diff --git a/tests/integration/inverse-test.js b/tests/integration/inverse-test.js new file mode 100644 index 00000000000..870f6139bab --- /dev/null +++ b/tests/integration/inverse-test.js @@ -0,0 +1,169 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let env, store, User, Job, ReflexiveModel; + +const { attr, belongsTo } = DS; + +function stringify(string) { + return function() { + return string; + }; +} + +module('integration/inverse_test - inverseFor', { + beforeEach() { + User = DS.Model.extend({ + name: attr('string'), + bestFriend: belongsTo('user', { async: true, inverse: null }), + job: belongsTo('job', { async: false }), + }); + + User.toString = stringify('user'); + + Job = DS.Model.extend({ + isGood: attr(), + user: belongsTo('user', { async: false }), + }); + + Job.toString = stringify('job'); + + ReflexiveModel = DS.Model.extend({ + reflexiveProp: belongsTo('reflexive-model', { async: false }), + }); + + ReflexiveModel.toString = stringify('reflexiveModel'); + + env = setupStore({ + user: User, + job: Job, + reflexiveModel: ReflexiveModel, + }); + + store = env.store; + + Job = store.modelFor('job'); + User = store.modelFor('user'); + ReflexiveModel = store.modelFor('reflexive-model'); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('Finds the inverse when there is only one possible available', function(assert) { + let inverseDefinition = Job.inverseFor('user', store); + + assert.deepEqual( + inverseDefinition, + { + type: User, + name: 'job', + kind: 'belongsTo', + options: { + async: false, + }, + }, + 'Gets correct type, name and kind' + ); +}); + +test('Finds the inverse when only one side has defined it manually', function(assert) { + Job.reopen({ + owner: belongsTo('user', { inverse: 'previousJob', async: false }), + }); + + User.reopen({ + previousJob: belongsTo('job', { async: false }), + }); + + assert.deepEqual( + Job.inverseFor('owner', store), + { + type: User, //the model's type + name: 'previousJob', //the models relationship key + kind: 'belongsTo', + options: { + async: false, + }, + }, + 'Gets correct type, name and kind' + ); + + assert.deepEqual( + User.inverseFor('previousJob', store), + { + type: Job, //the model's type + name: 'owner', //the models relationship key + kind: 'belongsTo', + options: { + inverse: 'previousJob', + async: false, + }, + }, + 'Gets correct type, name and kind' + ); +}); + +test('Returns null if inverse relationship it is manually set with a different relationship key', function(assert) { + Job.reopen({ + user: belongsTo('user', { inverse: 'previousJob', async: false }), + }); + + User.reopen({ + job: belongsTo('job', { async: false }), + }); + + assert.equal(User.inverseFor('job', store), null, 'There is no inverse'); +}); + +testInDebug('Errors out if you define 2 inverses to the same model', function(assert) { + Job.reopen({ + user: belongsTo('user', { inverse: 'job', async: false }), + owner: belongsTo('user', { inverse: 'job', async: false }), + }); + + User.reopen({ + job: belongsTo('job', { async: false }), + }); + + assert.expectAssertion(() => { + User.inverseFor('job', store); + }, /You defined the 'job' relationship on user, but you defined the inverse relationships of type job multiple times/i); +}); + +test('Caches findInverseFor return value', function(assert) { + assert.expect(1); + + var inverseForUser = Job.inverseFor('user', store); + Job.findInverseFor = function() { + assert.ok(false, 'Find is not called anymore'); + }; + + assert.equal(inverseForUser, Job.inverseFor('user', store), 'Inverse cached succesfully'); +}); + +testInDebug('Errors out if you do not define an inverse for a reflexive relationship', function( + assert +) { + //Maybe store is evaluated lazily, so we need this :( + assert.expectWarning(() => { + var reflexiveModel; + run(() => { + store.push({ + data: { + type: 'reflexive-model', + id: '1', + }, + }); + reflexiveModel = store.peekRecord('reflexive-model', 1); + reflexiveModel.get('reflexiveProp'); + }); + }, /Detected a reflexive relationship by the name of 'reflexiveProp'/); +}); diff --git a/tests/integration/lifecycle-hooks-test.js b/tests/integration/lifecycle-hooks-test.js new file mode 100644 index 00000000000..aaf85583e20 --- /dev/null +++ b/tests/integration/lifecycle-hooks-test.js @@ -0,0 +1,64 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let Person, env; +const { attr } = DS; + +module('integration/lifecycle_hooks - Lifecycle Hooks', { + beforeEach() { + Person = DS.Model.extend({ + name: attr('string'), + }); + + env = setupStore({ + person: Person, + }); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('When the adapter acknowledges that a record has been created, a `didCreate` event is triggered.', function(assert) { + let done = assert.async(); + assert.expect(3); + + env.adapter.createRecord = function(store, type, snapshot) { + return resolve({ data: { id: 99, type: 'person', attributes: { name: 'Yehuda Katz' } } }); + }; + + let person = env.store.createRecord('person', { name: 'Yehuda Katz' }); + + person.on('didCreate', function() { + assert.equal(this, person, 'this is bound to the record'); + assert.equal(this.get('id'), '99', 'the ID has been assigned'); + assert.equal(this.get('name'), 'Yehuda Katz', 'the attribute has been assigned'); + done(); + }); + + run(person, 'save'); +}); + +test('When the adapter acknowledges that a record has been created without a new data payload, a `didCreate` event is triggered.', function(assert) { + assert.expect(3); + + env.adapter.createRecord = function(store, type, snapshot) { + return resolve(); + }; + + let person = env.store.createRecord('person', { id: 99, name: 'Yehuda Katz' }); + + person.on('didCreate', function() { + assert.equal(this, person, 'this is bound to the record'); + assert.equal(this.get('id'), '99', 'the ID has been assigned'); + assert.equal(this.get('name'), 'Yehuda Katz', 'the attribute has been assigned'); + }); + + run(person, 'save'); +}); diff --git a/tests/integration/multiple-stores-test.js b/tests/integration/multiple-stores-test.js new file mode 100644 index 00000000000..81172b68617 --- /dev/null +++ b/tests/integration/multiple-stores-test.js @@ -0,0 +1,227 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; +import { get } from '@ember/object'; + +import Store from 'ember-data/store'; +import attr from 'ember-data/attr'; +import { belongsTo, hasMany } from 'ember-data/relationships'; +import Model from 'ember-data/model'; +import RESTSerializer from 'ember-data/serializers/rest'; +import RESTAdapter from 'ember-data/adapters/rest'; +import Adapter from 'ember-data/adapter'; +import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin'; + +let env; + +module('integration/multiple_stores - Multiple Stores Tests', { + beforeEach() { + const SuperVillain = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + const HomePlanet = Model.extend({ + name: attr('string'), + villains: hasMany('super-villain', { inverse: 'homePlanet', async: false }), + }); + const EvilMinion = Model.extend({ + superVillain: belongsTo('super-villain', { async: false }), + name: attr('string'), + }); + + env = setupStore({}); + + let { owner } = env; + + owner.register('model:super-villain', SuperVillain); + owner.register('model:home-planet', HomePlanet); + owner.register('model:evil-minion', EvilMinion); + + owner.register('adapter:application', RESTAdapter); + owner.register('serializer:application', RESTSerializer); + + owner.register('store:store-a', Store); + owner.register('store:store-b', Store); + + env.store_a = owner.lookup('store:store-a'); + env.store_b = owner.lookup('store:store-b'); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('should be able to push into multiple stores', function(assert) { + env.owner.register( + 'adapter:home-planet', + RESTAdapter.extend({ + shouldBackgroundReloadRecord: () => false, + }) + ); + + let home_planet_main = { id: '1', name: 'Earth' }; + let home_planet_a = { id: '1', name: 'Mars' }; + let home_planet_b = { id: '1', name: 'Saturn' }; + + run(() => { + env.store.push(env.store.normalize('home-planet', home_planet_main)); + env.store_a.push(env.store_a.normalize('home-planet', home_planet_a)); + env.store_b.push(env.store_b.normalize('home-planet', home_planet_b)); + }); + + return env.store + .findRecord('home-planet', 1) + .then(homePlanet => { + assert.equal(homePlanet.get('name'), 'Earth'); + + return env.store_a.findRecord('homePlanet', 1); + }) + .then(homePlanet => { + assert.equal(homePlanet.get('name'), 'Mars'); + return env.store_b.findRecord('homePlanet', 1); + }) + .then(homePlanet => { + assert.equal(homePlanet.get('name'), 'Saturn'); + }); +}); + +test('embedded records should be created in multiple stores', function(assert) { + env.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + }, + }) + ); + + let serializer_main = env.store.serializerFor('home-planet'); + let serializer_a = env.store_a.serializerFor('home-planet'); + let serializer_b = env.store_b.serializerFor('home-planet'); + + let json_hash_main = { + homePlanet: { + id: '1', + name: 'Earth', + villains: [ + { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + }, + ], + }, + }; + let json_hash_a = { + homePlanet: { + id: '1', + name: 'Mars', + villains: [ + { + id: '1', + firstName: 'James', + lastName: 'Murphy', + }, + ], + }, + }; + let json_hash_b = { + homePlanet: { + id: '1', + name: 'Saturn', + villains: [ + { + id: '1', + firstName: 'Jade', + lastName: 'John', + }, + ], + }, + }; + let json_main, json_a, json_b; + + run(() => { + json_main = serializer_main.normalizeResponse( + env.store, + env.store.modelFor('home-planet'), + json_hash_main, + 1, + 'findRecord' + ); + env.store.push(json_main); + assert.equal( + env.store.hasRecordForId('super-villain', '1'), + true, + 'superVillain should exist in service:store' + ); + }); + + run(() => { + json_a = serializer_a.normalizeResponse( + env.store_a, + env.store_a.modelFor('home-planet'), + json_hash_a, + 1, + 'findRecord' + ); + env.store_a.push(json_a); + assert.equal( + env.store_a.hasRecordForId('super-villain', '1'), + true, + 'superVillain should exist in store:store-a' + ); + }); + + run(() => { + json_b = serializer_b.normalizeResponse( + env.store_b, + env.store_a.modelFor('home-planet'), + json_hash_b, + 1, + 'findRecord' + ); + env.store_b.push(json_b); + assert.equal( + env.store_b.hasRecordForId('super-villain', '1'), + true, + 'superVillain should exist in store:store-b' + ); + }); +}); + +test('each store should have a unique instance of the serializers', function(assert) { + env.owner.register('serializer:home-planet', RESTSerializer.extend({})); + + let serializer_a = env.store_a.serializerFor('home-planet'); + let serializer_b = env.store_b.serializerFor('home-planet'); + + assert.equal( + get(serializer_a, 'store'), + env.store_a, + "serializer_a's store prop should be sotre_a" + ); + assert.equal( + get(serializer_b, 'store'), + env.store_b, + "serializer_b's store prop should be sotre_b" + ); + assert.notEqual( + serializer_a, + serializer_b, + 'serialier_a and serialier_b should be unique instances' + ); +}); + +test('each store should have a unique instance of the adapters', function(assert) { + env.owner.register('adapter:home-planet', Adapter.extend({})); + + let adapter_a = env.store_a.adapterFor('home-planet'); + let adapter_b = env.store_b.adapterFor('home-planet'); + + assert.equal(get(adapter_a, 'store'), env.store_a); + assert.equal(get(adapter_b, 'store'), env.store_b); + assert.notEqual(adapter_a, adapter_b); +}); diff --git a/tests/integration/peek-all-test.js b/tests/integration/peek-all-test.js new file mode 100644 index 00000000000..4290f4295f6 --- /dev/null +++ b/tests/integration/peek-all-test.js @@ -0,0 +1,89 @@ +import { get } from '@ember/object'; +import { setupTest } from 'ember-qunit'; +import Model from 'ember-data/model'; +import { attr } from '@ember-decorators/data'; +import { module, test } from 'qunit'; +import { settled } from '@ember/test-helpers'; + +class Person extends Model { + @attr + name; +} + +module('integration/peek-all - DS.Store#peekAll()', function(hooks) { + setupTest(hooks); + + let store; + + hooks.beforeEach(function() { + let { owner } = this; + + owner.register('model:person', Person); + store = owner.lookup('service:store'); + }); + + test("store.peekAll('person') should return all records and should update with new ones", async function(assert) { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + ], + }); + + let all = store.peekAll('person'); + assert.equal(get(all, 'length'), 2); + + store.push({ + data: [ + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn', + }, + }, + ], + }); + + await settled(); + + assert.equal(get(all, 'length'), 3); + }); + + test('Calling store.peekAll() multiple times should update immediately', async function(assert) { + assert.expect(3); + + assert.equal(get(store.peekAll('person'), 'length'), 0, 'should initially be empty'); + store.createRecord('person', { name: 'Tomster' }); + assert.equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person'); + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: "Tomster's friend", + }, + }, + }); + assert.equal(get(store.peekAll('person'), 'length'), 2, 'should contain two people'); + }); + + test('Calling store.peekAll() after creating a record should return correct data', async function(assert) { + assert.expect(1); + + store.createRecord('person', { name: 'Tomster' }); + assert.equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person'); + }); +}); diff --git a/tests/integration/polymorphic-belongs-to-test.js b/tests/integration/polymorphic-belongs-to-test.js new file mode 100644 index 00000000000..558f0419be2 --- /dev/null +++ b/tests/integration/polymorphic-belongs-to-test.js @@ -0,0 +1,141 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +const { attr, belongsTo } = DS; + +let store; + +const Book = DS.Model.extend({ + title: attr(), + author: belongsTo('person', { polymorphic: true, async: false }), +}); + +const Author = DS.Model.extend({ + name: attr(), +}); + +const AsyncBook = DS.Model.extend({ + author: belongsTo('person', { polymorphic: true }), +}); + +module('integration/polymorphic-belongs-to - Polymorphic BelongsTo', { + beforeEach() { + let env = setupStore({ + book: Book, + author: Author, + 'async-book': AsyncBook, + person: DS.Model.extend(), + }); + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +test('using store.push with a null value for a payload in relationships sets the Models relationship to null - sync relationship', assert => { + let payload = { + data: { + type: 'book', + id: 1, + title: 'Yes, Please', + relationships: { + author: { + data: { + type: 'author', + id: 1, + }, + }, + }, + }, + included: [ + { + id: 1, + name: 'Amy Poehler', + type: 'author', + }, + ], + }; + + let book = run(() => { + store.push(payload); + return store.peekRecord('book', 1); + }); + + assert.equal(book.get('author.id'), 1); + + let payloadThatResetsBelongToRelationship = { + data: { + type: 'book', + id: 1, + title: 'Yes, Please', + relationships: { + author: { + data: null, + }, + }, + }, + }; + + run(() => store.push(payloadThatResetsBelongToRelationship)); + assert.strictEqual(book.get('author'), null); +}); + +test('using store.push with a null value for a payload in relationships sets the Models relationship to null - async relationship', assert => { + let payload = { + data: { + type: 'async-book', + id: 1, + title: 'Yes, Please', + relationships: { + author: { + data: { + type: 'author', + id: 1, + }, + }, + }, + }, + included: [ + { + id: 1, + name: 'Amy Poehler', + type: 'author', + }, + ], + }; + + let book = run(() => { + store.push(payload); + return store.peekRecord('async-book', 1); + }); + + let payloadThatResetsBelongToRelationship = { + data: { + type: 'async-book', + id: 1, + title: 'Yes, Please', + relationships: { + author: { + data: null, + }, + }, + }, + }; + + return book + .get('author') + .then(author => { + assert.equal(author.get('id'), 1); + run(() => store.push(payloadThatResetsBelongToRelationship)); + return book.get('author'); + }) + .then(author => { + assert.strictEqual(author, null); + }); +}); diff --git a/tests/integration/record-array-manager-test.js b/tests/integration/record-array-manager-test.js new file mode 100644 index 00000000000..a2958639825 --- /dev/null +++ b/tests/integration/record-array-manager-test.js @@ -0,0 +1,416 @@ +import { A } from '@ember/array'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import OrderedSet from '@ember/ordered-set'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let store, env, manager; + +const Person = DS.Model.extend({ + name: DS.attr('string'), + cars: DS.hasMany('car', { async: false }), +}); + +const Car = DS.Model.extend({ + make: DS.attr('string'), + model: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), +}); + +module('integration/record_array_manager', { + beforeEach() { + env = setupStore({ + adapter: DS.RESTAdapter.extend(), + }); + store = env.store; + + manager = store.recordArrayManager; + + env.owner.register('model:car', Car); + env.owner.register('model:person', Person); + }, +}); + +function tap(obj, methodName, callback) { + let old = obj[methodName]; + + let summary = { called: [] }; + + obj[methodName] = function() { + let result = old.apply(obj, arguments); + if (callback) { + callback.apply(obj, arguments); + } + summary.called.push(arguments); + return result; + }; + + return summary; +} + +test('destroying the store correctly cleans everything up', function(assert) { + let query = {}; + let person; + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini Cooper', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, + }); + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + cars: { + data: [{ type: 'car', id: '1' }], + }, + }, + }, + }); + person = store.peekRecord('person', 1); + }); + + let all = store.peekAll('person'); + let adapterPopulated = manager.createAdapterPopulatedRecordArray('person', query); + let allSummary = tap(all, 'willDestroy'); + let adapterPopulatedSummary = tap(adapterPopulated, 'willDestroy'); + let internalPersonModel = person._internalModel; + + assert.equal(allSummary.called.length, 0); + assert.equal(adapterPopulatedSummary.called.length, 0); + assert.equal( + internalPersonModel._recordArrays.size, + 1, + 'expected the person to be a member of 1 recordArrays' + ); + assert.equal('person' in manager._liveRecordArrays, true); + + run(all, all.destroy); + + assert.equal( + internalPersonModel._recordArrays.size, + 0, + 'expected the person to be a member of 1 recordArrays' + ); + assert.equal(allSummary.called.length, 1); + assert.equal('person' in manager._liveRecordArrays, false); + + run(manager, manager.destroy); + + assert.equal( + internalPersonModel._recordArrays.size, + 0, + 'expected the person to be a member of no recordArrays' + ); + assert.equal(allSummary.called.length, 1); + assert.equal(adapterPopulatedSummary.called.length, 1); +}); + +test('batch liveRecordArray changes', function(assert) { + let cars = store.peekAll('car'); + let arrayContentWillChangeCount = 0; + + cars.arrayContentWillChange = function(startIndex, removeCount, addedCount) { + arrayContentWillChangeCount++; + assert.equal(startIndex, 0, 'expected 0 startIndex'); + assert.equal(removeCount, 0, 'expected 0 removed'); + assert.equal(addedCount, 2, 'expected 2 added'); + }; + + assert.deepEqual(cars.toArray(), []); + assert.equal(arrayContentWillChangeCount, 0, 'expected NO arrayChangeEvents yet'); + + run(() => { + store.push({ + data: [ + { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini Cooper', + }, + }, + { + type: 'car', + id: '2', + attributes: { + make: 'Jeep', + model: 'Wrangler', + }, + }, + ], + }); + }); + + assert.equal(arrayContentWillChangeCount, 1, 'expected ONE array change event'); + + assert.deepEqual(cars.toArray(), [store.peekRecord('car', 1), store.peekRecord('car', 2)]); + + run(() => store.peekRecord('car', 1).set('model', 'Mini')); + + assert.equal(arrayContentWillChangeCount, 1, 'expected ONE array change event'); + + cars.arrayContentWillChange = function(startIndex, removeCount, addedCount) { + arrayContentWillChangeCount++; + assert.equal(startIndex, 2, 'expected a start index of TWO'); + assert.equal(removeCount, 0, 'expected no removes'); + assert.equal(addedCount, 1, 'expected ONE add'); + }; + + arrayContentWillChangeCount = 0; + + run(() => { + store.push({ + data: [ + { + type: 'car', + id: 2, // this ID is already present, array wont need to change + attributes: { + make: 'Tesla', + model: 'S', + }, + }, + ], + }); + }); + + assert.equal(arrayContentWillChangeCount, 0, 'expected NO array change events'); + + run(() => { + store.push({ + data: [ + { + type: 'car', + id: 3, + attributes: { + make: 'Tesla', + model: 'S', + }, + }, + ], + }); + }); + + assert.equal(arrayContentWillChangeCount, 1, 'expected ONE array change event'); +}); + +test('#GH-4041 store#query AdapterPopulatedRecordArrays are removed from their managers instead of retained when #destroy is called', function(assert) { + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'Honda', + model: 'fit', + }, + }, + }); + }); + + const query = {}; + + let adapterPopulated = manager.createAdapterPopulatedRecordArray('car', query); + + run(() => adapterPopulated.destroy()); + + assert.equal(manager._adapterPopulatedRecordArrays.length, 0); +}); + +test('createRecordArray', function(assert) { + let recordArray = manager.createRecordArray('foo'); + + assert.equal(recordArray.modelName, 'foo'); + assert.equal(recordArray.isLoaded, true); + assert.equal(recordArray.manager, manager); + assert.deepEqual(recordArray.get('content'), []); + assert.deepEqual(recordArray.toArray(), []); +}); + +test('createRecordArray with optional content', function(assert) { + let record = {}; + let internalModel = { + _recordArrays: new OrderedSet(), + getRecord() { + return record; + }, + }; + let content = A([internalModel]); + let recordArray = manager.createRecordArray('foo', content); + + assert.equal(recordArray.modelName, 'foo'); + assert.equal(recordArray.isLoaded, true); + assert.equal(recordArray.manager, manager); + assert.equal(recordArray.get('content'), content); + assert.deepEqual(recordArray.toArray(), [record]); + + assert.deepEqual(internalModel._recordArrays.toArray(), [recordArray]); +}); + +test('liveRecordArrayFor always return the same array for a given type', function(assert) { + assert.equal(manager.liveRecordArrayFor('foo'), manager.liveRecordArrayFor('foo')); +}); + +test('liveRecordArrayFor create with content', function(assert) { + assert.expect(6); + + let createRecordArrayCalled = 0; + let superCreateRecordArray = manager.createRecordArray; + + manager.createRecordArray = function(modelName, internalModels) { + createRecordArrayCalled++; + assert.equal(modelName, 'car'); + assert.equal(internalModels.length, 1); + assert.equal(internalModels[0].id, 1); + return superCreateRecordArray.apply(this, arguments); + }; + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini Cooper', + }, + }, + }); + }); + + assert.equal(createRecordArrayCalled, 0, 'no record array has been created yet'); + manager.liveRecordArrayFor('car'); + assert.equal(createRecordArrayCalled, 1, 'one record array is created'); + manager.liveRecordArrayFor('car'); + assert.equal(createRecordArrayCalled, 1, 'no new record array is created'); +}); + +test('[DEPRECATED FILTER SUPPORT until 3.5]', function(assert) { + let cars = store.peekAll('car'); + let arrayContentWillChangeCount = 0; + let updatesWithoutLiveArrayChangeCount = 0; + let updatesSignaledCount = 0; + + let originalUpdate = store.recordArrayManager.updateLiveRecordArray; + store.recordArrayManager.updateLiveRecordArray = function(recordArray, internalModels) { + updatesSignaledCount++; + let didUpdate = originalUpdate.call(store.recordArrayManager, recordArray, internalModels); + + if (!didUpdate) { + updatesWithoutLiveArrayChangeCount++; + } + + return didUpdate; + }; + + cars.arrayContentWillChange = function() { + arrayContentWillChangeCount++; + }; + + assert.deepEqual(cars.toArray(), []); + assert.equal(arrayContentWillChangeCount, 0, 'expected NO arrayChangeEvents yet'); + assert.equal(updatesWithoutLiveArrayChangeCount, 0, 'expected NO silent updates yet'); + assert.equal(updatesSignaledCount, 0, 'expected NO signals yet'); + + let [car1, car2] = run(() => + store.push({ + data: [ + { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini Cooper', + }, + }, + { + type: 'car', + id: '2', + attributes: { + make: 'Jeep', + model: 'Wrangler', + }, + }, + ], + }) + ); + + assert.equal(arrayContentWillChangeCount, 1, 'expected ONE array change event'); + assert.equal(updatesWithoutLiveArrayChangeCount, 0, 'expected NO silent updates yet'); + assert.equal(updatesSignaledCount, 1, 'expected ONE signal'); + assert.deepEqual(cars.toArray(), [car1, car2]); + + arrayContentWillChangeCount = 0; + updatesWithoutLiveArrayChangeCount = 0; + updatesSignaledCount = 0; + + run(() => car1.set('model', 'Mini')); + + assert.equal(arrayContentWillChangeCount, 0, 'expected no array change events'); + assert.equal(updatesWithoutLiveArrayChangeCount, 1, 'expected ONE silent update'); + assert.equal(updatesSignaledCount, 1, 'expected ONE total signals'); + + arrayContentWillChangeCount = 0; + updatesWithoutLiveArrayChangeCount = 0; + updatesSignaledCount = 0; + + run(() => + store.push({ + data: { + type: 'car', + id: '2', // this ID is already present, array wont need to change + attributes: { + make: 'Tesla', + model: 'S', + }, + }, + }) + ); + + assert.equal(arrayContentWillChangeCount, 0, 'expected NO array change events'); + assert.equal(updatesWithoutLiveArrayChangeCount, 1, 'expected ONE silent update'); + assert.equal(updatesSignaledCount, 1, 'expected ONE total signals'); + + arrayContentWillChangeCount = 0; + updatesWithoutLiveArrayChangeCount = 0; + updatesSignaledCount = 0; + + run(() => + store.push({ + data: { + type: 'car', + id: '3', + attributes: { + make: 'Tesla', + model: 'S', + }, + }, + }) + ); + + assert.equal(arrayContentWillChangeCount, 1, 'expected ONE array change event'); + assert.equal(updatesWithoutLiveArrayChangeCount, 0, 'expected ONE silent update'); + assert.equal(updatesSignaledCount, 1, 'expected ONE total signals'); +}); diff --git a/tests/integration/record-array-test.js b/tests/integration/record-array-test.js new file mode 100644 index 00000000000..3c0a89f7630 --- /dev/null +++ b/tests/integration/record-array-test.js @@ -0,0 +1,523 @@ +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { resolve } from 'rsvp'; +import { setupTest } from 'ember-qunit'; +import { settled } from '@ember/test-helpers'; +import Model from 'ember-data/model'; +import { attr, belongsTo, hasMany } from '@ember-decorators/data'; +import { module, test } from 'qunit'; +import Adapter from 'ember-data/adapter'; + +class Person extends Model { + @attr + name; + @belongsTo('tag', { async: false, inverse: 'people' }) + tag; +} + +class Tag extends Model { + @hasMany('person', { async: false, inverse: 'tag' }) + people; +} + +class Tool extends Model { + @belongsTo('person', { async: false, inverse: null }) + person; +} + +module('unit/record-array - RecordArray', function(hooks) { + setupTest(hooks); + let store; + + hooks.beforeEach(function() { + let { owner } = this; + + owner.register('model:person', Person); + owner.register('model:tag', Tag); + owner.register('model:tool', Tool); + + store = owner.lookup('service:store'); + }); + + test('a record array is backed by records', async function(assert) { + assert.expect(3); + this.owner.register( + 'adapter:application', + Adapter.extend({ + shouldBackgroundReloadRecord() { + return false; + }, + }) + ); + + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn', + }, + }, + ], + }); + + let records = await store.findByIds('person', [1, 2, 3]); + let expectedResults = { + data: [ + { id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }, + { id: '2', type: 'person', attributes: { name: 'Scumbag Katz' } }, + { id: '3', type: 'person', attributes: { name: 'Scumbag Bryn' } }, + ], + }; + + for (let i = 0, l = expectedResults.data.length; i < l; i++) { + let { + id, + attributes: { name }, + } = expectedResults.data[i]; + + assert.deepEqual( + records[i].getProperties('id', 'name'), + { id, name }, + 'a record array materializes objects on demand' + ); + } + }); + + test('acts as a live query', async function(assert) { + let recordArray = store.peekAll('person'); + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'wycats', + }, + }, + }); + + await settled(); + + assert.equal(get(recordArray, 'lastObject.name'), 'wycats'); + + store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'brohuda', + }, + }, + }); + + await settled(); + + assert.equal(get(recordArray, 'lastObject.name'), 'brohuda'); + }); + + test('acts as a live query (normalized names)', async function(assert) { + this.owner.register('model:Person', Person); + + let recordArray = store.peekAll('Person'); + let otherRecordArray = store.peekAll('person'); + + assert.ok(recordArray === otherRecordArray, 'Person and person are the same record-array'); + + store.push({ + data: { + type: 'Person', + id: '1', + attributes: { + name: 'John Churchill', + }, + }, + }); + + await settled(); + + assert.deepEqual(recordArray.mapBy('name'), ['John Churchill']); + + store.push({ + data: { + type: 'Person', + id: '2', + attributes: { + name: 'Winston Churchill', + }, + }, + }); + + await settled(); + + assert.deepEqual(recordArray.mapBy('name'), ['John Churchill', 'Winston Churchill']); + }); + + test('stops updating when destroyed', async function(assert) { + assert.expect(3); + + let recordArray = store.peekAll('person'); + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'wycats', + }, + }, + }); + + await settled(); + + // Ember 2.18 requires wrapping destroy in a run. Once we drop support with 3.8 LTS + // we can remove this. + run(() => recordArray.destroy()); + + await settled(); + + assert.equal(recordArray.get('length'), 0, 'Has no more records'); + store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'brohuda', + }, + }, + }); + + await settled(); + + assert.equal(recordArray.get('length'), 0, 'Has not been updated'); + assert.equal(recordArray.get('content'), undefined, 'Has not been updated'); + }); + + test('a loaded record is removed from a record array when it is deleted', async function(assert) { + assert.expect(5); + this.owner.register( + 'adapter:application', + Adapter.extend({ + deleteRecord() { + return resolve({ data: null }); + }, + shouldBackgroundReloadRecord() { + return false; + }, + }) + ); + + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn', + }, + }, + { + type: 'tag', + id: '1', + attributes: {}, + }, + ], + }); + + let scumbag = await store.findRecord('person', 1); + let tag = await store.findRecord('tag', 1); + let recordArray = tag.get('people'); + + recordArray.addObject(scumbag); + + assert.ok(scumbag.get('tag') === tag, "precond - the scumbag's tag has been set"); + assert.equal(get(recordArray, 'length'), 1, 'precond - record array has one item'); + assert.equal( + get(recordArray.objectAt(0), 'name'), + 'Scumbag Dale', + 'item at index 0 is record with id 1' + ); + + scumbag.deleteRecord(); + + assert.equal( + get(recordArray, 'length'), + 1, + 'record is still in the record array until it is saved' + ); + + await scumbag.save(); + + assert.equal( + get(recordArray, 'length'), + 0, + 'record is removed from the array when it is saved' + ); + }); + + test("a loaded record is not removed from a record array when it is deleted even if the belongsTo side isn't defined", async function(assert) { + class Person extends Model { + @attr + name; + } + + class Tag extends Model { + @hasMany('person', { async: false, inverse: null }) + people; + } + + this.owner.unregister('model:person'); + this.owner.unregister('model:tag'); + this.owner.register('model:person', Person); + this.owner.register('model:tag', Tag); + this.owner.register( + 'adapter:application', + Adapter.extend({ + deleteRecord() { + return resolve({ data: null }); + }, + }) + ); + + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Tom', + }, + }, + { + type: 'tag', + id: '1', + relationships: { + people: { + data: [{ type: 'person', id: '1' }], + }, + }, + }, + ], + }); + + let scumbag = store.peekRecord('person', 1); + let tag = store.peekRecord('tag', 1); + + scumbag.deleteRecord(); + + assert.equal(tag.get('people.length'), 1, 'record is not removed from the record array'); + assert.equal(tag.get('people').objectAt(0), scumbag, 'tag still has the scumbag'); + }); + + test("a loaded record is not removed from both the record array and from the belongs to, even if the belongsTo side isn't defined", async function(assert) { + this.owner.register( + 'adapter:application', + Adapter.extend({ + deleteRecord() { + return resolve({ data: null }); + }, + }) + ); + + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Tom', + }, + }, + { + type: 'tag', + id: '1', + relationships: { + people: { + data: [{ type: 'person', id: '1' }], + }, + }, + }, + { + type: 'tool', + id: '1', + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, + ], + }); + + let scumbag = store.peekRecord('person', 1); + let tag = store.peekRecord('tag', 1); + let tool = store.peekRecord('tool', 1); + + assert.equal(tag.get('people.length'), 1, 'record is in the record array'); + assert.equal(tool.get('person'), scumbag, 'the tool belongs to the record'); + + scumbag.deleteRecord(); + + assert.equal(tag.get('people.length'), 1, 'record is stil in the record array'); + assert.equal(tool.get('person'), scumbag, 'the tool still belongs to the record'); + }); + + // GitHub Issue #168 + test('a newly created record is removed from a record array when it is deleted', async function(assert) { + let recordArray = store.peekAll('person'); + let scumbag = store.createRecord('person', { + name: 'Scumbag Dale', + }); + + assert.equal( + get(recordArray, 'length'), + 1, + 'precond - record array already has the first created item' + ); + + store.createRecord('person', { name: 'p1' }); + store.createRecord('person', { name: 'p2' }); + store.createRecord('person', { name: 'p3' }); + + assert.equal(get(recordArray, 'length'), 4, 'precond - record array has the created item'); + assert.equal(recordArray.objectAt(0), scumbag, 'item at index 0 is record with id 1'); + + scumbag.deleteRecord(); + assert.equal(get(recordArray, 'length'), 4, 'record array still has the created item'); + + await settled(); + + assert.equal(get(recordArray, 'length'), 3, 'record array no longer has the created item'); + }); + + test("a record array returns undefined when asking for a member outside of its content Array's range", async function(assert) { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn', + }, + }, + ], + }); + + let recordArray = store.peekAll('person'); + + assert.strictEqual( + recordArray.objectAt(20), + undefined, + 'objects outside of the range just return undefined' + ); + }); + + // This tests for a bug in the recordCache, where the records were being cached in the incorrect order. + test('a record array should be able to be enumerated in any order', async function(assert) { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn', + }, + }, + ], + }); + + let recordArray = store.peekAll('person'); + + assert.equal( + get(recordArray.objectAt(2), 'id'), + '3', + 'should retrieve correct record at index 2' + ); + assert.equal( + get(recordArray.objectAt(1), 'id'), + '2', + 'should retrieve correct record at index 1' + ); + assert.equal( + get(recordArray.objectAt(0), 'id'), + '1', + 'should retrieve correct record at index 0' + ); + }); + + test("an AdapterPopulatedRecordArray knows if it's loaded or not", async function(assert) { + assert.expect(1); + let adapter = store.adapterFor('person'); + + adapter.query = function(store, type, query, recordArray) { + return resolve({ + data: [ + { id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }, + { id: '2', type: 'person', attributes: { name: 'Scumbag Katz' } }, + { id: '3', type: 'person', attributes: { name: 'Scumbag Bryn' } }, + ], + }); + }; + + let people = await store.query('person', { page: 1 }); + + assert.equal(get(people, 'isLoaded'), true, 'The array is now loaded'); + }); +}); diff --git a/tests/integration/record-arrays/adapter-populated-record-array-test.js b/tests/integration/record-arrays/adapter-populated-record-array-test.js new file mode 100644 index 00000000000..6d376136442 --- /dev/null +++ b/tests/integration/record-arrays/adapter-populated-record-array-test.js @@ -0,0 +1,344 @@ +import { run } from '@ember/runloop'; +import { Promise } from 'rsvp'; +import { setupStore, createStore } from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let store; + +const Person = DS.Model.extend({ + name: DS.attr('string'), + toString() { + return ``; + }, +}); + +const adapter = DS.Adapter.extend({ + deleteRecord() { + return Promise.resolve(); + }, +}); + +module( + 'integration/record-arrays/adapter_populated_record_array - DS.AdapterPopulatedRecordArray', + { + beforeEach() { + store = createStore({ + adapter: adapter, + person: Person, + }); + }, + } +); + +test('when a record is deleted in an adapter populated record array, it should be removed', function(assert) { + let recordArray = store.recordArrayManager.createAdapterPopulatedRecordArray('person', null); + + let payload = { + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn', + }, + }, + ], + }; + + run(() => { + recordArray._setInternalModels(store._push(payload), payload); + }); + + assert.equal(recordArray.get('length'), 3, 'expected recordArray to contain exactly 3 records'); + + run(() => recordArray.get('firstObject').destroyRecord()); + + assert.equal(recordArray.get('length'), 2, 'expected recordArray to contain exactly 2 records'); +}); + +test('stores the metadata off the payload', function(assert) { + let recordArray = store.recordArrayManager.createAdapterPopulatedRecordArray('person', null); + + let payload = { + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn', + }, + }, + ], + meta: { + foo: 'bar', + }, + }; + + run(() => { + recordArray._setInternalModels(store._push(payload), payload); + }); + + assert.equal(recordArray.get('meta.foo'), 'bar', 'expected meta.foo to be bar from payload'); +}); + +test('stores the links off the payload', function(assert) { + let recordArray = store.recordArrayManager.createAdapterPopulatedRecordArray('person', null); + + let payload = { + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn', + }, + }, + ], + links: { + first: '/foo?page=1', + }, + }; + + run(() => { + recordArray._setInternalModels(store._push(payload), payload); + }); + + assert.equal( + recordArray.get('links.first'), + '/foo?page=1', + 'expected links.first to be "/foo?page=1" from payload' + ); +}); + +test('recordArray.replace() throws error', function(assert) { + let recordArray = store.recordArrayManager.createAdapterPopulatedRecordArray('person', null); + + assert.throws( + () => { + recordArray.replace(); + }, + Error('The result of a server query (on person) is immutable.'), + 'throws error' + ); +}); + +test('pass record array to adapter.query based on arity', function(assert) { + let env = setupStore({ person: Person }); + let store = env.store; + + let payload = { + data: [ + { id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }, + { id: '2', type: 'person', attributes: { name: 'Scumbag Katz' } }, + ], + }; + + env.adapter.query = function(store, type, query) { + assert.equal(arguments.length, 3); + return payload; + }; + + return store.query('person', {}).then(recordArray => { + env.adapter.query = function(store, type, query, _recordArray) { + assert.equal(arguments.length, 5); + return payload; + }; + return store.query('person', {}); + }); +}); + +test('pass record array to adapter.query based on arity', function(assert) { + let env = setupStore({ person: Person }); + let store = env.store; + + let payload = { + data: [ + { id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }, + { id: '2', type: 'person', attributes: { name: 'Scumbag Katz' } }, + ], + }; + + let actualQuery = {}; + + let superCreateAdapterPopulatedRecordArray = + store.recordArrayManager.createAdapterPopulatedRecordArray; + + store.recordArrayManager.createStore = function(modelName, query, internalModels, _payload) { + assert.equal(arguments.length === 4); + + assert.equal(modelName, 'person'); + assert.equal(query, actualQuery); + assert.equal(_payload, payload); + assert.equal(internalModels.length, 2); + return superCreateAdapterPopulatedRecordArray.apply(this, arguments); + }; + + env.adapter.query = function(store, type, query) { + assert.equal(arguments.length, 3); + return payload; + }; + + return store.query('person', actualQuery).then(recordArray => { + env.adapter.query = function(store, type, query, _recordArray) { + assert.equal(arguments.length, 5); + return payload; + }; + + store.recordArrayManager.createStore = function(modelName, query) { + assert.equal(arguments.length === 2); + + assert.equal(modelName, 'person'); + assert.equal(query, actualQuery); + return superCreateAdapterPopulatedRecordArray.apply(this, arguments); + }; + + return store.query('person', actualQuery); + }); +}); + +test('loadRecord re-syncs internalModels recordArrays', function(assert) { + let env = setupStore({ person: Person }); + let store = env.store; + + let payload = { + data: [ + { id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }, + { id: '2', type: 'person', attributes: { name: 'Scumbag Katz' } }, + ], + }; + + env.adapter.query = function(store, type, query, recordArray) { + return payload; + }; + + return store.query('person', {}).then(recordArray => { + return recordArray + .update() + .then(recordArray => { + assert.deepEqual( + recordArray.getEach('name'), + ['Scumbag Dale', 'Scumbag Katz'], + 'expected query to contain specific records' + ); + + payload = { + data: [ + { id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }, + { id: '3', type: 'person', attributes: { name: 'Scumbag Penner' } }, + ], + }; + + return recordArray.update(); + }) + .then(recordArray => { + assert.deepEqual(recordArray.getEach('name'), ['Scumbag Dale', 'Scumbag Penner']); + }); + }); +}); + +test('when an adapter populated record gets updated the array contents are also updated', function(assert) { + assert.expect(8); + + let queryPromise, queryArr, findPromise, findArray; + let env = setupStore({ person: Person }); + let store = env.store; + let array = [{ id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }]; + + // resemble server side filtering + env.adapter.query = function(store, type, query, recordArray) { + return { data: array.slice(query.slice) }; + }; + + // implement findAll to further test that query updates won't muddle + // with the non-query record arrays + env.adapter.findAll = function(store, type, sinceToken) { + return { data: array.slice(0) }; + }; + + run(() => { + queryPromise = store.query('person', { slice: 1 }); + findPromise = store.findAll('person'); + + // initialize adapter populated record array and assert initial state + queryPromise.then(_queryArr => { + queryArr = _queryArr; + assert.equal(queryArr.get('length'), 0, 'No records for this query'); + assert.equal(queryArr.get('isUpdating'), false, 'Record array isUpdating state updated'); + }); + + // initialize a record collection array and assert initial state + findPromise.then(_findArr => { + findArray = _findArr; + assert.equal(findArray.get('length'), 1, 'All records are included in collection array'); + }); + }); + + // a new element gets pushed in record array + run(() => { + array.push({ id: '2', type: 'person', attributes: { name: 'Scumbag Katz' } }); + queryArr.update().then(() => { + assert.equal( + queryArr.get('length'), + 1, + 'The new record is returned and added in adapter populated array' + ); + assert.equal(queryArr.get('isUpdating'), false, 'Record array isUpdating state updated'); + assert.equal(findArray.get('length'), 2); + }); + }); + + // element gets removed + run(() => { + array.pop(0); + queryArr.update().then(() => { + assert.equal(queryArr.get('length'), 0, 'Record removed from array'); + // record not removed from the model collection + assert.equal(findArray.get('length'), 2, 'Record still remains in collection array'); + }); + }); +}); diff --git a/tests/integration/record-arrays/peeked-records-test.js b/tests/integration/record-arrays/peeked-records-test.js new file mode 100644 index 00000000000..9ea46a67b98 --- /dev/null +++ b/tests/integration/record-arrays/peeked-records-test.js @@ -0,0 +1,382 @@ +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; +import { get } from '@ember/object'; +import { watchProperties } from '../../helpers/watch-property'; + +let store; + +const Person = DS.Model.extend({ + name: DS.attr('string'), + toString() { + return ``; + }, +}); + +module('integration/peeked-records', { + beforeEach() { + store = createStore({ + person: Person, + }); + }, +}); + +test('repeated calls to peekAll in separate run-loops works as expected', function(assert) { + let peekedRecordArray = run(() => store.peekAll('person')); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + + run(() => + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'John', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Joe', + }, + }, + ], + }) + ); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state after a single push with multiple records to add' + ); + + run(() => store.peekAll('person')); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state has not changed after another call to peek' + ); +}); + +test('peekAll in the same run-loop as push works as expected', function(assert) { + let peekedRecordArray = run(() => store.peekAll('person')); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'John', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Joe', + }, + }, + ], + }); + store.peekAll('person'); + }); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state after a single push with multiple records to add' + ); + + run(() => store.peekAll('person')); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state has not changed after another call to peek' + ); +}); + +test('newly created records notify the array as expected', function(assert) { + let peekedRecordArray = run(() => store.peekAll('person')); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + let aNewlyCreatedRecord = store.createRecord('person', { + name: 'James', + }); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state when a new record is created' + ); + + run(() => { + aNewlyCreatedRecord.unloadRecord(); + }); + + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state when a new record is unloaded' + ); +}); + +test('immediately peeking newly created records works as expected', function(assert) { + let peekedRecordArray = run(() => store.peekAll('person')); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + let aNewlyCreatedRecord = store.createRecord('person', { + name: 'James', + }); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state when a new record is created' + ); + + run(() => { + aNewlyCreatedRecord.unloadRecord(); + store.peekAll('person'); + }); + + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state when a new record is unloaded' + ); +}); + +test('unloading newly created records notify the array as expected', function(assert) { + let peekedRecordArray = run(() => store.peekAll('person')); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + let aNewlyCreatedRecord = store.createRecord('person', { + name: 'James', + }); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state when a new record is created' + ); + + run(() => { + aNewlyCreatedRecord.unloadRecord(); + }); + + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state when a new record is unloaded' + ); +}); + +test('immediately peeking after unloading newly created records works as expected', function(assert) { + let peekedRecordArray = run(() => store.peekAll('person')); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + let aNewlyCreatedRecord = store.createRecord('person', { + name: 'James', + }); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state when a new record is created' + ); + + run(() => { + aNewlyCreatedRecord.unloadRecord(); + store.peekAll('person'); + }); + + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state when a new record is unloaded' + ); +}); + +test('unloadAll followed by peekAll in the same run-loop works as expected', function(assert) { + let peekedRecordArray = run(() => store.peekAll('person')); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'John', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Joe', + }, + }, + ], + }); + }); + + run(() => { + store.peekAll('person'); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state after a single push with multiple records to add' + ); + + store.unloadAll('person'); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state after unloadAll has not changed yet' + ); + + assert.equal( + get(peekedRecordArray, 'length'), + 2, + 'Array length is unchanged before the next peek' + ); + + store.peekAll('person'); + + assert.equal(get(peekedRecordArray, 'length'), 0, 'We no longer have any array content'); + + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state after a follow up peekAll reflects unload changes' + ); + }); + + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state has not changed any further' + ); +}); + +test('push+materialize => unloadAll => push+materialize works as expected', function(assert) { + function push() { + run(() => { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'John', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Joe', + }, + }, + ], + }); + }); + } + function unload() { + run(() => store.unloadAll('person')); + } + function peek() { + return run(() => store.peekAll('person')); + } + + let peekedRecordArray = peek(); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + + push(); + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state after a single push with multiple records to add' + ); + + unload(); + assert.equal(get(peekedRecordArray, 'length'), 0, 'We no longer have any array content'); + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state has signaled the unload' + ); + + push(); + assert.equal(get(peekedRecordArray, 'length'), 2, 'We have array content'); + assert.watchedPropertyCounts( + watcher, + { length: 3, '[]': 3 }, + 'RecordArray state now has records again' + ); +}); + +test('push-without-materialize => unloadAll => push-without-materialize works as expected', function(assert) { + function _push() { + run(() => { + store._push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'John', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Joe', + }, + }, + ], + }); + }); + } + function unload() { + run(() => store.unloadAll('person')); + } + function peek() { + return run(() => store.peekAll('person')); + } + + let peekedRecordArray = peek(); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + + _push(); + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state after a single push with multiple records to add' + ); + + unload(); + assert.equal(get(peekedRecordArray, 'length'), 0, 'We no longer have any array content'); + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state has signaled the unload' + ); + + _push(); + assert.equal(get(peekedRecordArray, 'length'), 2, 'We have array content'); + assert.watchedPropertyCounts( + watcher, + { length: 3, '[]': 3 }, + 'RecordArray state now has records again' + ); +}); diff --git a/tests/integration/records/collection-save-test.js b/tests/integration/records/collection-save-test.js new file mode 100644 index 00000000000..c4f7b3bc900 --- /dev/null +++ b/tests/integration/records/collection-save-test.js @@ -0,0 +1,112 @@ +import { resolve, reject } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let Post, env; + +module('integration/records/collection_save - Save Collection of Records', { + beforeEach() { + Post = DS.Model.extend({ + title: DS.attr('string'), + }); + + env = setupStore({ post: Post }); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('Collection will resolve save on success', function(assert) { + assert.expect(1); + let id = 1; + + env.store.createRecord('post', { title: 'Hello' }); + env.store.createRecord('post', { title: 'World' }); + + let posts = env.store.peekAll('post'); + + env.adapter.createRecord = function(store, type, snapshot) { + return resolve({ data: { id: id++, type: 'post' } }); + }; + + return run(() => { + return posts.save().then(() => { + assert.ok(true, 'save operation was resolved'); + }); + }); +}); + +test('Collection will reject save on error', function(assert) { + env.store.createRecord('post', { title: 'Hello' }); + env.store.createRecord('post', { title: 'World' }); + + let posts = env.store.peekAll('post'); + + env.adapter.createRecord = function(store, type, snapshot) { + return reject(); + }; + + return run(() => { + return posts.save().catch(() => { + assert.ok(true, 'save operation was rejected'); + }); + }); +}); + +test('Retry is allowed in a failure handler', function(assert) { + env.store.createRecord('post', { title: 'Hello' }); + env.store.createRecord('post', { title: 'World' }); + + let posts = env.store.peekAll('post'); + + let count = 0; + let id = 1; + + env.adapter.createRecord = function(store, type, snapshot) { + if (count++ === 0) { + return reject(); + } else { + return resolve({ data: { id: id++, type: 'post' } }); + } + }; + + env.adapter.updateRecord = function(store, type, snapshot) { + return resolve({ data: { id: snapshot.id, type: 'post' } }); + }; + + return run(() => { + return posts + .save() + .catch(() => posts.save()) + .then(post => { + // the ID here is '2' because the second post saves on the first attempt, + // while the first post saves on the second attempt + assert.equal(posts.get('firstObject.id'), '2', 'The post ID made it through'); + }); + }); +}); + +test('Collection will reject save on invalid', function(assert) { + assert.expect(1); + + env.store.createRecord('post', { title: 'Hello' }); + env.store.createRecord('post', { title: 'World' }); + + let posts = env.store.peekAll('post'); + + env.adapter.createRecord = function(store, type, snapshot) { + return reject({ title: 'invalid' }); + }; + + return run(() => { + return posts.save().catch(() => { + assert.ok(true, 'save operation was rejected'); + }); + }); +}); diff --git a/tests/integration/records/create-record-test.js b/tests/integration/records/create-record-test.js new file mode 100644 index 00000000000..a063a7838c3 --- /dev/null +++ b/tests/integration/records/create-record-test.js @@ -0,0 +1,200 @@ +import { module, test } from 'qunit'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import { setupTest } from 'ember-qunit'; +import Store from 'ember-data/store'; +import Model from 'ember-data/model'; +import { resolve } from 'rsvp'; +import { attr, belongsTo, hasMany } from '@ember-decorators/data'; + +class Person extends Model { + @hasMany('pet', { inverse: 'owner', async: false }) + pets; + @belongsTo('pet', { inverse: 'bestHuman', async: true }) + bestDog; + @attr + name; +} + +class Pet extends Model { + @belongsTo('person', { inverse: 'pets', async: false }) + owner; + @belongsTo('person', { inverse: 'bestDog', async: false }) + bestHuman; + @attr + name; +} + +module('Store.createRecord() coverage', function(hooks) { + let store; + setupTest(hooks); + + hooks.beforeEach(function() { + let { owner } = this; + owner.register('service:store', Store); + owner.register('model:person', Person); + owner.register('model:pet', Pet); + store = owner.lookup('service:store'); + }); + + test('unloading a newly created a record with a sync belongsTo relationship', async function(assert) { + let chris = store.push({ + data: { + id: '1', + type: 'person', + attributes: { + name: 'Chris', + }, + relationships: { + pets: { + data: [], + }, + }, + }, + }); + + let pet = store.createRecord('pet', { + name: 'Shen', + owner: chris, + }); + + // check that we are properly configured + assert.ok(pet.get('owner') === chris, 'Precondition: Our owner is Chris'); + + let pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, ['Shen'], 'Precondition: Chris has Shen as a pet'); + + pet.unloadRecord(); + + assert.ok(pet.get('owner') === null, 'Shen no longer has an owner'); + + // check that the relationship has been dissolved + pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, [], 'Chris no longer has any pets'); + }); + + test('unloading a record with a sync hasMany relationship to a newly created record', async function(assert) { + let chris = store.push({ + data: { + id: '1', + type: 'person', + attributes: { + name: 'Chris', + }, + relationships: { + pets: { + data: [], + }, + }, + }, + }); + + let pet = store.createRecord('pet', { + name: 'Shen', + owner: chris, + }); + + // check that we are properly configured + assert.ok(pet.get('owner') === chris, 'Precondition: Our owner is Chris'); + + let pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, ['Shen'], 'Precondition: Chris has Shen as a pet'); + + chris.unloadRecord(); + + assert.ok(pet.get('owner') === null, 'Shen no longer has an owner'); + + // check that the relationship has been dissolved + pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, [], 'Chris no longer has any pets'); + }); + + test('creating and saving a record with relationships puts them into the correct state', async function(assert) { + this.owner.register( + 'serializer:application', + JSONAPISerializer.extend({ + normalizeResponse(_, __, data) { + return data; + }, + }) + ); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + shouldBackgroundReloadRecord() { + return false; + }, + findRecord() { + assert.ok(false, 'Adapter should not make any findRecord Requests'); + }, + findBelongsTo() { + assert.ok(false, 'Adapter should not make any findBelongsTo Requests'); + }, + createRecord() { + return resolve({ + data: { + type: 'pet', + id: '2', + attributes: { name: 'Shen' }, + relationships: { + bestHuman: { + data: { type: 'person', id: '1' }, + links: { self: './person', related: './person' }, + }, + }, + }, + }); + }, + }) + ); + + let chris = store.push({ + data: { + id: '1', + type: 'person', + attributes: { + name: 'Chris', + }, + relationships: { + bestDog: { + data: null, + links: { self: './dog', related: './dog' }, + }, + }, + }, + }); + + let shen = store.createRecord('pet', { + name: 'Shen', + bestHuman: chris, + }); + + let bestHuman = shen.get('bestHuman'); + let bestDog = await chris.get('bestDog'); + + // check that we are properly configured + assert.ok(bestHuman === chris, 'Precondition: Shen has bestHuman as Chris'); + assert.ok(bestDog === shen, 'Precondition: Chris has Shen as his bestDog'); + + await shen.save(); + + bestHuman = shen.get('bestHuman'); + bestDog = await chris.get('bestDog'); + + // check that the relationship has remained established + assert.ok(bestHuman === chris, 'Shen bestHuman is still Chris'); + assert.ok(bestDog === shen, 'Chris still has Shen as bestDog'); + }); +}); diff --git a/tests/integration/records/delete-record-test.js b/tests/integration/records/delete-record-test.js new file mode 100644 index 00000000000..026527b1c40 --- /dev/null +++ b/tests/integration/records/delete-record-test.js @@ -0,0 +1,304 @@ +/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(adam|dave|cersei)" }]*/ + +import { Promise as EmberPromise, all } from 'rsvp'; + +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; + +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var attr = DS.attr; +var Person, env; + +module('integration/deletedRecord - Deleting Records', { + beforeEach() { + Person = DS.Model.extend({ + name: attr('string'), + }); + Person.toString = () => { + return 'Person'; + }; + + env = setupStore({ + person: Person, + }); + }, + + afterEach() { + run(function() { + env.container.destroy(); + }); + }, +}); + +test('records should not be removed from record arrays just after deleting, but only after committing them', function(assert) { + var adam, dave; + + env.adapter.deleteRecord = function() { + return EmberPromise.resolve(); + }; + + var all; + run(function() { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Dave Sunderland', + }, + }, + ], + }); + adam = env.store.peekRecord('person', 1); + dave = env.store.peekRecord('person', 2); + all = env.store.peekAll('person'); + }); + + // pre-condition + assert.equal(all.get('length'), 2, 'pre-condition: 2 records in array'); + + run(adam, 'deleteRecord'); + + assert.equal(all.get('length'), 2, '2 records in array after deleteRecord'); + + run(adam, 'save'); + + assert.equal(all.get('length'), 1, '1 record in array after deleteRecord and save'); +}); + +test('deleting a record that is part of a hasMany removes it from the hasMany recordArray', function(assert) { + let group; + let person; + const Group = DS.Model.extend({ + people: DS.hasMany('person', { inverse: null, async: false }), + }); + Group.toString = () => { + return 'Group'; + }; + + env.adapter.deleteRecord = function() { + return EmberPromise.resolve(); + }; + + env.owner.register('model:group', Group); + + run(function() { + env.store.push({ + data: { + type: 'group', + id: '1', + relationships: { + people: { + data: [{ type: 'person', id: '1' }, { type: 'person', id: '2' }], + }, + }, + }, + included: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Dave Sunderland', + }, + }, + ], + }); + + group = env.store.peekRecord('group', '1'); + person = env.store.peekRecord('person', '1'); + }); + + // Sanity Check we are in the correct state. + assert.equal(group.get('people.length'), 2, 'expected 2 related records before delete'); + assert.equal(person.get('name'), 'Adam Sunderland', 'expected related records to be loaded'); + + run(function() { + person.destroyRecord(); + }); + + assert.equal(group.get('people.length'), 1, 'expected 1 related records after delete'); +}); + +test('records can be deleted during record array enumeration', function(assert) { + var adam, dave; + + env.adapter.deleteRecord = function() { + return EmberPromise.resolve(); + }; + + run(function() { + env.store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Dave Sunderland', + }, + }, + ], + }); + adam = env.store.peekRecord('person', 1); + dave = env.store.peekRecord('person', 2); + }); + var all = env.store.peekAll('person'); + + // pre-condition + assert.equal(all.get('length'), 2, 'expected 2 records'); + + run(function() { + all.forEach(function(record) { + record.destroyRecord(); + }); + }); + + assert.equal(all.get('length'), 0, 'expected 0 records'); + assert.equal(all.objectAt(0), null, "can't get any records"); +}); + +test('Deleting an invalid newly created record should remove it from the store', function(assert) { + var record; + var store = env.store; + + env.adapter.createRecord = function() { + return EmberPromise.reject( + new DS.InvalidError([ + { + title: 'Invalid Attribute', + detail: 'name is invalid', + source: { + pointer: '/data/attributes/name', + }, + }, + ]) + ); + }; + + run(function() { + record = store.createRecord('person', { name: 'pablobm' }); + // Invalidate the record to put it in the `root.loaded.created.invalid` state + record.save().catch(() => {}); + }); + + // Preconditions + assert.equal( + get(record, 'currentState.stateName'), + 'root.loaded.created.invalid', + 'records should start in the created.invalid state' + ); + assert.equal(get(store.peekAll('person'), 'length'), 1, 'The new person should be in the store'); + + run(function() { + record.deleteRecord(); + }); + + assert.equal(get(record, 'currentState.stateName'), 'root.deleted.saved'); + assert.equal( + get(store.peekAll('person'), 'length'), + 0, + 'The new person should be removed from the store' + ); +}); + +test('Destroying an invalid newly created record should remove it from the store', function(assert) { + var record; + var store = env.store; + + env.adapter.deleteRecord = function() { + assert.fail( + "The adapter's deletedRecord method should not be called when the record was created locally." + ); + }; + + env.adapter.createRecord = function() { + return EmberPromise.reject( + new DS.InvalidError([ + { + title: 'Invalid Attribute', + detail: 'name is invalid', + source: { + pointer: '/data/attributes/name', + }, + }, + ]) + ); + }; + + run(function() { + record = store.createRecord('person', { name: 'pablobm' }); + // Invalidate the record to put it in the `root.loaded.created.invalid` state + record.save().catch(() => {}); + }); + + // Preconditions + assert.equal( + get(record, 'currentState.stateName'), + 'root.loaded.created.invalid', + 'records should start in the created.invalid state' + ); + assert.equal(get(store.peekAll('person'), 'length'), 1, 'The new person should be in the store'); + + run(function() { + record.destroyRecord(); + }); + + assert.equal(get(record, 'currentState.stateName'), 'root.deleted.saved'); + assert.equal( + get(store.peekAll('person'), 'length'), + 0, + 'The new person should be removed from the store' + ); +}); + +test('Will resolve destroy and save in same loop', function(assert) { + let adam, dave; + let promises; + + assert.expect(1); + + env.adapter.createRecord = function() { + assert.ok(true, 'save operation resolves'); + return EmberPromise.resolve({ + data: { + id: 123, + type: 'person', + }, + }); + }; + + adam = env.store.createRecord('person', { name: 'Adam Sunderland' }); + dave = env.store.createRecord('person', { name: 'Dave Sunderland' }); + + run(function() { + promises = [adam.destroyRecord(), dave.save()]; + }); + + return all(promises); +}); diff --git a/tests/integration/records/edit-record-test.js b/tests/integration/records/edit-record-test.js new file mode 100644 index 00000000000..c407535a36a --- /dev/null +++ b/tests/integration/records/edit-record-test.js @@ -0,0 +1,346 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import Store from 'ember-data/store'; +import Model from 'ember-data/model'; +import { attr, belongsTo, hasMany } from '@ember-decorators/data'; + +class Person extends Model { + @hasMany('pet', { inverse: 'owner', async: false }) + pets; + @hasMany('person', { inverse: 'friends', async: true }) + friends; + @belongsTo('person', { inverse: 'bestFriend', async: true }) + bestFriend; + @attr + name; +} + +class Pet extends Model { + @belongsTo('person', { inverse: 'pets', async: false }) + owner; + @attr + name; +} + +module('Editing a Record', function(hooks) { + let store; + setupTest(hooks); + + hooks.beforeEach(function() { + let { owner } = this; + owner.register('service:store', Store); + owner.register('model:person', Person); + owner.register('model:pet', Pet); + store = owner.lookup('service:store'); + }); + + module('Simple relationship addition case', function() { + module('Adding a sync belongsTo relationship to a record', function() { + test('We can add to a record', async function(assert) { + let chris = store.push({ + data: { + id: '1', + type: 'person', + attributes: { name: 'Chris' }, + relationships: { + pets: { + data: [], + }, + }, + }, + }); + + let pet = store.push({ + data: { + id: '1', + type: 'pet', + attributes: { name: 'Shen' }, + relationships: { + owner: { + data: null, + }, + }, + }, + }); + + // check that we are properly configured + assert.ok(pet.get('owner') === null, 'Precondition: Our owner is null'); + + let pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, [], 'Precondition: Chris has no pets'); + + pet.set('owner', chris); + + assert.ok(pet.get('owner') === chris, 'Shen has Chris as an owner'); + + // check that the relationship has been established + pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, ['Shen'], 'Chris has Shen as a pet'); + }); + + test('We can add a new record to a record', async function(assert) { + let chris = store.createRecord('person', { + name: 'Chris', + pets: [], + }); + + let pet = store.push({ + data: { + id: '1', + type: 'pet', + attributes: { name: 'Shen' }, + relationships: { + owner: { + data: null, + }, + }, + }, + }); + + // check that we are properly configured + assert.ok(pet.get('owner') === null, 'Precondition: Our owner is null'); + + let pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, [], 'Precondition: Chris has no pets'); + + pet.set('owner', chris); + + assert.ok(pet.get('owner') === chris, 'Shen has Chris as an owner'); + + // check that the relationship has been established + pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, ['Shen'], 'Chris has Shen as a pet'); + }); + + test('We can add a new record to a new record', async function(assert) { + let chris = store.createRecord('person', { + name: 'Chris', + pets: [], + }); + + let pet = store.createRecord('pet', { + name: 'Shen', + owner: null, + }); + + // check that we are properly configured + assert.ok(pet.get('owner') === null, 'Precondition: Our owner is null'); + + let pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, [], 'Precondition: Chris has no pets'); + + pet.set('owner', chris); + + assert.ok(pet.get('owner') === chris, 'Shen has Chris as an owner'); + + // check that the relationship has been established + pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, ['Shen'], 'Chris has Shen as a pet'); + }); + + test('We can add to a new record', async function(assert) { + let chris = store.push({ + data: { + id: '1', + type: 'person', + attributes: { name: 'Chris' }, + relationships: { + pets: { + data: [], + }, + }, + }, + }); + + let pet = store.createRecord('pet', { + name: 'Shen', + owner: null, + }); + + // check that we are properly configured + assert.ok(pet.get('owner') === null, 'Precondition: Our owner is null'); + + let pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, [], 'Precondition: Chris has no pets'); + + pet.set('owner', chris); + + assert.ok(pet.get('owner') === chris, 'Shen has Chris as an owner'); + + // check that the relationship has been established + pets = chris + .get('pets') + .toArray() + .map(pet => pet.get('name')); + assert.deepEqual(pets, ['Shen'], 'Chris has Shen as a pet'); + }); + }); + + module('Adding an async belongsTo relationship to a record', function() { + test('We can add to a record', async function(assert) { + let chris = store.push({ + data: { + id: '1', + type: 'person', + attributes: { name: 'Chris' }, + relationships: { + bestFriend: { + data: null, + }, + }, + }, + }); + + let james = store.push({ + data: { + id: '1', + type: 'person', + attributes: { name: 'James' }, + relationships: { + bestFriend: { + data: null, + }, + }, + }, + }); + + // check that we are properly configured + let chrisBestFriend = await chris.get('bestFriend'); + let jamesBestFriend = await james.get('bestFriend'); + + assert.ok(chrisBestFriend === null, 'Precondition: Chris has no best friend'); + assert.ok(jamesBestFriend === null, 'Precondition: James has no best friend'); + + chris.set('bestFriend', james); + + // check that the relationship has been established + chrisBestFriend = await chris.get('bestFriend'); + jamesBestFriend = await james.get('bestFriend'); + + assert.ok(chrisBestFriend === james, 'Chris has James as a best friend'); + assert.ok(jamesBestFriend === chris, 'James has Chris as a best friend'); + }); + + test('We can add a new record to a record', async function(assert) { + let chris = store.push({ + data: { + id: '1', + type: 'person', + attributes: { name: 'Chris' }, + relationships: { + bestFriend: { + data: null, + }, + }, + }, + }); + + let james = store.createRecord('person', { + name: 'James', + bestFriend: null, + }); + + // check that we are properly configured + let chrisBestFriend = await chris.get('bestFriend'); + let jamesBestFriend = await james.get('bestFriend'); + + assert.ok(chrisBestFriend === null, 'Precondition: Chris has no best friend'); + assert.ok(jamesBestFriend === null, 'Precondition: James has no best friend'); + + chris.set('bestFriend', james); + + // check that the relationship has been established + chrisBestFriend = await chris.get('bestFriend'); + jamesBestFriend = await james.get('bestFriend'); + + assert.ok(chrisBestFriend === james, 'Chris has James as a best friend'); + assert.ok(jamesBestFriend === chris, 'James has Chris as a best friend'); + }); + + test('We can add a new record to a new record', async function(assert) { + let chris = store.createRecord('person', { + name: 'Chris', + bestFriend: null, + }); + + let james = store.createRecord('person', { + name: 'James', + bestFriend: null, + }); + + // check that we are properly configured + let chrisBestFriend = await chris.get('bestFriend'); + let jamesBestFriend = await james.get('bestFriend'); + + assert.ok(chrisBestFriend === null, 'Precondition: Chris has no best friend'); + assert.ok(jamesBestFriend === null, 'Precondition: James has no best friend'); + + chris.set('bestFriend', james); + + // check that the relationship has been established + chrisBestFriend = await chris.get('bestFriend'); + jamesBestFriend = await james.get('bestFriend'); + + assert.ok(chrisBestFriend === james, 'Chris has James as a best friend'); + assert.ok(jamesBestFriend === chris, 'James has Chris as a best friend'); + }); + + test('We can add to a new record', async function(assert) { + let chris = store.createRecord('person', { + name: 'Chris', + bestFriend: null, + }); + + let james = store.push({ + data: { + id: '1', + type: 'person', + attributes: { name: 'James' }, + relationships: { + bestFriend: { + data: null, + }, + }, + }, + }); + + // check that we are properly configured + let chrisBestFriend = await chris.get('bestFriend'); + let jamesBestFriend = await james.get('bestFriend'); + + assert.ok(chrisBestFriend === null, 'Precondition: Chris has no best friend'); + assert.ok(jamesBestFriend === null, 'Precondition: James has no best friend'); + + chris.set('bestFriend', james); + + // check that the relationship has been established + chrisBestFriend = await chris.get('bestFriend'); + jamesBestFriend = await james.get('bestFriend'); + + assert.ok(chrisBestFriend === james, 'Chris has James as a best friend'); + assert.ok(jamesBestFriend === chris, 'James has Chris as a best friend'); + }); + }); + }); +}); diff --git a/tests/integration/records/error-test.js b/tests/integration/records/error-test.js new file mode 100644 index 00000000000..354b2ca1ff9 --- /dev/null +++ b/tests/integration/records/error-test.js @@ -0,0 +1,189 @@ +import { run } from '@ember/runloop'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; +import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import RSVP from 'rsvp'; + +var env, store, Person; +var attr = DS.attr; + +module('integration/records/error', { + beforeEach: function() { + Person = DS.Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + }); + + env = setupStore({ + person: Person, + }); + + store = env.store; + }, + + afterEach: function() { + run(function() { + env.container.destroy(); + }); + }, +}); + +testInDebug('adding errors during root.loaded.created.invalid works', function(assert) { + var person = run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + return store.peekRecord('person', 'wat'); + }); + + run(() => { + person.set('firstName', null); + person.set('lastName', null); + }); + + assert.equal(person._internalModel.currentState.stateName, 'root.loaded.updated.uncommitted'); + + person.get('errors').add('firstName', 'is invalid'); + + assert.equal(person._internalModel.currentState.stateName, 'root.loaded.updated.invalid'); + + person.get('errors').add('lastName', 'is invalid'); + + assert.deepEqual(person.get('errors').toArray(), [ + { attribute: 'firstName', message: 'is invalid' }, + { attribute: 'lastName', message: 'is invalid' }, + ]); +}); + +testInDebug('adding errors root.loaded.created.invalid works', function(assert) { + let person = store.createRecord('person', { + id: 'wat', + firstName: 'Yehuda', + lastName: 'Katz', + }); + + run(() => { + person.set('firstName', null); + person.set('lastName', null); + }); + + assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.uncommitted'); + + person.get('errors').add('firstName', 'is invalid'); + + assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid'); + + person.get('errors').add('lastName', 'is invalid'); + + assert.deepEqual(person.get('errors').toArray(), [ + { attribute: 'firstName', message: 'is invalid' }, + { attribute: 'lastName', message: 'is invalid' }, + ]); +}); + +testInDebug('adding errors root.loaded.created.invalid works add + remove + add', function(assert) { + let person = store.createRecord('person', { + id: 'wat', + firstName: 'Yehuda', + }); + + run(() => { + person.set('firstName', null); + }); + + assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.uncommitted'); + + person.get('errors').add('firstName', 'is invalid'); + + assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid'); + + person.get('errors').remove('firstName'); + + assert.deepEqual(person.get('errors').toArray(), []); + + person.get('errors').add('firstName', 'is invalid'); + + assert.deepEqual(person.get('errors').toArray(), [ + { attribute: 'firstName', message: 'is invalid' }, + ]); +}); + +testInDebug('adding errors root.loaded.created.invalid works add + (remove, add)', function( + assert +) { + let person = store.createRecord('person', { + id: 'wat', + firstName: 'Yehuda', + }); + + run(() => { + person.set('firstName', null); + }); + + assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.uncommitted'); + + { + person.get('errors').add('firstName', 'is invalid'); + } + + assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid'); + + { + person.get('errors').remove('firstName'); + person.get('errors').add('firstName', 'is invalid'); + } + + assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid'); + + assert.deepEqual(person.get('errors').toArray(), [ + { attribute: 'firstName', message: 'is invalid' }, + ]); +}); + +test('using setProperties to clear errors', function(assert) { + env.adapter.reopen({ + createRecord() { + return RSVP.reject( + new DS.InvalidError([ + { + detail: 'Must be unique', + source: { pointer: '/data/attributes/first-name' }, + }, + { + detail: 'Must not be blank', + source: { pointer: '/data/attributes/last-name' }, + }, + ]) + ); + }, + }); + + return run(() => { + let person = store.createRecord('person'); + + return person.save().then(null, function() { + let errors = person.get('errors'); + + assert.equal(errors.get('length'), 2); + assert.ok(errors.has('firstName')); + assert.ok(errors.has('lastName')); + + person.setProperties({ + firstName: 'updated', + lastName: 'updated', + }); + + assert.equal(errors.get('length'), 0); + assert.notOk(errors.has('firstName')); + assert.notOk(errors.has('lastName')); + }); + }); +}); diff --git a/tests/integration/records/load-test.js b/tests/integration/records/load-test.js new file mode 100644 index 00000000000..95aa84775a4 --- /dev/null +++ b/tests/integration/records/load-test.js @@ -0,0 +1,199 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import { reject, resolve } from 'rsvp'; +import Store from 'ember-data/store'; +import Model from 'ember-data/model'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import { attr, belongsTo } from '@ember-decorators/data'; +import { run } from '@ember/runloop'; +import todo from '../../helpers/todo'; + +class Person extends Model { + @attr + name; + + @belongsTo('person', { async: true, inverse: 'bestFriend' }) + bestFriend; +} + +module('integration/load - Loading Records', function(hooks) { + let store; + setupTest(hooks); + + hooks.beforeEach(function() { + let { owner } = this; + owner.register('service:store', Store); + owner.register('model:person', Person); + store = owner.lookup('service:store'); + }); + + test('When loading a record fails, the record is not left behind', async function(assert) { + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + return reject(); + }, + }) + ); + + await store.findRecord('person', '1').catch(() => { + assert.equal(store.hasRecordForId('person', '1'), false); + }); + }); + + todo('Empty records remain in the empty state while data is being fetched', async function( + assert + ) { + let payloads = [ + { + data: { + type: 'person', + id: '1', + attributes: { name: 'Chris' }, + relationships: { + bestFriend: { + data: { type: 'person', id: '2' }, + }, + }, + }, + included: [ + { + type: 'person', + id: '2', + attributes: { name: 'Shen' }, + relationships: { + bestFriend: { + data: { type: 'person', id: '1' }, + }, + }, + }, + ], + }, + { + data: { + type: 'person', + id: '1', + attributes: { name: 'Chris' }, + relationships: { + bestFriend: { + data: { type: 'person', id: '2' }, + }, + }, + }, + }, + { + data: { + type: 'person', + id: '1', + attributes: { name: 'Chris' }, + relationships: { + bestFriend: { + data: { type: 'person', id: '2' }, + }, + }, + }, + }, + ]; + + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + let payload = payloads.shift(); + + if (payload === undefined) { + return reject(new Error('Invalid Request')); + } + + return resolve(payload); + }, + }) + ); + this.owner.register( + 'serializer:application', + JSONAPISerializer.extend({ + normalizeResponse(_, __, data) { + return data; + }, + }) + ); + + let internalModel = store._internalModelForId('person', '1'); + + // test that our initial state is correct + assert.equal(internalModel.isEmpty(), true, 'We begin in the empty state'); + assert.equal(internalModel.isLoading(), false, 'We have not triggered a load'); + assert.equal(internalModel.isReloading, false, 'We are not reloading'); + + let recordPromise = store.findRecord('person', '1'); + + // test that during the initial load our state is correct + assert.todo.equal( + internalModel.isEmpty(), + true, + 'awaiting first fetch: We remain in the empty state' + ); + assert.equal( + internalModel.isLoading(), + true, + 'awaiting first fetch: We have now triggered a load' + ); + assert.equal(internalModel.isReloading, false, 'awaiting first fetch: We are not reloading'); + + let record = await recordPromise; + + // test that after the initial load our state is correct + assert.equal(internalModel.isEmpty(), false, 'after first fetch: We are no longer empty'); + assert.equal(internalModel.isLoading(), false, 'after first fetch: We have loaded'); + assert.equal(internalModel.isReloading, false, 'after first fetch: We are not reloading'); + + let bestFriend = await record.get('bestFriend'); + let trueBestFriend = await bestFriend.get('bestFriend'); + + // shen is our retainer for the record we are testing + // that ensures unloadRecord later in this test does not fully + // discard the internalModel + let shen = store.peekRecord('person', '2'); + + assert.ok(bestFriend === shen, 'Precond: bestFriend is correct'); + assert.ok(trueBestFriend === record, 'Precond: bestFriend of bestFriend is correct'); + + recordPromise = record.reload(); + + // test that during a reload our state is correct + assert.equal(internalModel.isEmpty(), false, 'awaiting reload: We remain non-empty'); + assert.equal(internalModel.isLoading(), false, 'awaiting reload: We are not loading again'); + assert.equal(internalModel.isReloading, true, 'awaiting reload: We are reloading'); + + await recordPromise; + + // test that after a reload our state is correct + assert.equal(internalModel.isEmpty(), false, 'after reload: We remain non-empty'); + assert.equal(internalModel.isLoading(), false, 'after reload: We have loaded'); + assert.equal(internalModel.isReloading, false, 'after reload:: We are not reloading'); + + run(() => record.unloadRecord()); + + // test that after an unload our state is correct + assert.equal(internalModel.isEmpty(), true, 'after unload: We are empty again'); + assert.equal(internalModel.isLoading(), false, 'after unload: We are not loading'); + assert.equal(internalModel.isReloading, false, 'after unload:: We are not reloading'); + + recordPromise = store.findRecord('person', '1'); + + // test that during a reload-due-to-unload our state is correct + // This requires a retainer (the async bestFriend relationship) + assert.todo.equal(internalModel.isEmpty(), true, 'awaiting second find: We remain empty'); + assert.equal(internalModel.isLoading(), true, 'awaiting second find: We are loading again'); + assert.equal(internalModel.isReloading, false, 'awaiting second find: We are not reloading'); + + await recordPromise; + + // test that after the reload-due-to-unload our state is correct + assert.equal(internalModel.isEmpty(), false, 'after second find: We are no longer empty'); + assert.equal(internalModel.isLoading(), false, 'after second find: We have loaded'); + assert.equal(internalModel.isReloading, false, 'after second find: We are not reloading'); + }); +}); diff --git a/tests/integration/records/property-changes-test.js b/tests/integration/records/property-changes-test.js new file mode 100644 index 00000000000..c1a2ffbe1d6 --- /dev/null +++ b/tests/integration/records/property-changes-test.js @@ -0,0 +1,188 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var env, store, Person; +var attr = DS.attr; + +module('integration/records/property-changes - Property changes', { + beforeEach() { + Person = DS.Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + }); + + env = setupStore({ + person: Person, + }); + store = env.store; + }, + + afterEach() { + run(function() { + env.container.destroy(); + }); + }, +}); + +test('Calling push with partial records trigger observers for just those attributes that changed', function(assert) { + assert.expect(1); + var person; + + run(function() { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + person = store.peekRecord('person', 'wat'); + }); + + person.addObserver('firstName', function() { + assert.ok(false, 'firstName observer should not be triggered'); + }); + + person.addObserver('lastName', function() { + assert.ok(true, 'lastName observer should be triggered'); + }); + + run(function() { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz!', + }, + }, + }); + }); +}); + +test('Calling push does not trigger observers for locally changed attributes with the same value', function(assert) { + assert.expect(0); + var person; + + run(function() { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + person = store.peekRecord('person', 'wat'); + person.set('lastName', 'Katz!'); + }); + + person.addObserver('firstName', function() { + assert.ok(false, 'firstName observer should not be triggered'); + }); + + person.addObserver('lastName', function() { + assert.ok(false, 'lastName observer should not be triggered'); + }); + + run(function() { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz!', + }, + }, + }); + }); +}); + +test('Saving a record trigger observers for locally changed attributes with the same canonical value', function(assert) { + assert.expect(1); + var person; + + env.adapter.updateRecord = function(store, type, snapshot) { + return resolve({ data: { id: 'wat', type: 'person', attributes: { 'last-name': 'Katz' } } }); + }; + + run(function() { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + person = store.peekRecord('person', 'wat'); + person.set('lastName', 'Katz!'); + }); + + person.addObserver('firstName', function() { + assert.ok(false, 'firstName observer should not be triggered'); + }); + + person.addObserver('lastName', function() { + assert.ok(true, 'lastName observer should be triggered'); + }); + + run(function() { + person.save(); + }); +}); + +test('store.push should not override a modified attribute', function(assert) { + assert.expect(1); + var person; + + run(function() { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + person = store.peekRecord('person', 'wat'); + person.set('lastName', 'Katz!'); + }); + + person.addObserver('firstName', function() { + assert.ok(true, 'firstName observer should be triggered'); + }); + + person.addObserver('lastName', function() { + assert.ok(false, 'lastName observer should not be triggered'); + }); + + run(function() { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + }, + }); + }); +}); diff --git a/tests/integration/records/record-data-test.js b/tests/integration/records/record-data-test.js new file mode 100644 index 00000000000..780db925daa --- /dev/null +++ b/tests/integration/records/record-data-test.js @@ -0,0 +1,278 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import Model from 'ember-data/model'; +import { run } from '@ember/runloop'; +import { attr, belongsTo, hasMany } from '@ember-decorators/data'; +import { assign } from '@ember/polyfills'; +import { RecordData, recordDataFor } from 'ember-data/-private'; +import { resolve } from 'rsvp'; + +class Person extends Model { + @hasMany('pet', { inverse: null, async: false }) + pets; + @attr + name; +} + +class Pet extends Model { + @belongsTo('person', { inverse: null, async: false }) + owner; + @attr + name; +} + +module('RecordData Compatibility', function(hooks) { + let store; + setupTest(hooks); + + hooks.beforeEach(function() { + let { owner } = this; + owner.register('model:person', Person); + owner.register('model:pet', Pet); + store = owner.lookup('service:store'); + }); + + class CustomRecordData { + constructor(modelName, id, clientId, storeWrapper) { + this.type = modelName; + this.id = id || null; + this.clientId = clientId; + this.storeWrapper = storeWrapper; + this.attributes = null; + this.relationships = null; + } + + pushData(jsonApiResource, shouldCalculateChanges) { + let oldAttrs = this.attributes; + let changedKeys; + + this.attributes = jsonApiResource.attributes || null; + + if (shouldCalculateChanges) { + changedKeys = Object.keys(assign({}, oldAttrs, this.attributes)); + } + + return changedKeys || []; + } + + getAttr(member) { + return this.attributes !== null ? this.attributes[member] : undefined; + } + + hasAttr(key) { + return key in this.attributes; + } + + // TODO missing from RFC but required to implement + _initRecordCreateOptions(options) { + return options !== undefined ? options : {}; + } + // TODO missing from RFC but required to implement + getResourceIdentifier() { + return { + id: this.id, + type: this.type, + clientId: this.clientId, + }; + } + // TODO missing from RFC but required to implement + unloadRecord() { + this.attributes = null; + this.relationships = null; + } + // TODO missing from RFC but required to implement + isNew() { + return this.id === null; + } + + adapterDidCommit() {} + didCreateLocally() {} + adapterWillCommit() {} + saveWasRejected() {} + adapterDidDelete() {} + recordUnloaded() {} + rollbackAttributes() {} + rollbackAttribute() {} + changedAttributes() {} + hasChangedAttributes() {} + setAttr() {} + setHasMany() {} + getHasMany() {} + addToHasMany() {} + removeFromHasMany() {} + setBelongsTo() {} + getBelongsTo() {} + } + + test(`store.unloadRecord on a record with default RecordData with relationship to a record with custom RecordData does not error`, async function(assert) { + const originalCreateRecordDataFor = store.createRecordDataFor; + store.createRecordDataFor = function provideCustomRecordData(modelName, id, lid, storeWrapper) { + if (modelName === 'pet') { + return new CustomRecordData(modelName, id, lid, storeWrapper); + } else { + return originalCreateRecordDataFor.call(this, modelName, id, lid, storeWrapper); + } + }; + + let chris = store.push({ + data: { + type: 'person', + id: '1', + attributes: { name: 'Chris' }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }, { type: 'pet', id: '2' }], + }, + }, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owner: { data: { type: 'person', id: '1' } }, + }, + }, + { + type: 'pet', + id: '2', + attributes: { name: 'Prince' }, + relationships: { + owner: { data: { type: 'person', id: '1' } }, + }, + }, + ], + }); + let pets = chris.get('pets'); + let shen = pets.objectAt(0); + + assert.equal(shen.get('name'), 'Shen', 'We found Shen'); + assert.ok( + recordDataFor(chris) instanceof RecordData, + 'We used the default record-data for person' + ); + assert.ok( + recordDataFor(shen) instanceof CustomRecordData, + 'We used the custom record-data for pets' + ); + + try { + run(() => chris.unloadRecord()); + assert.ok(true, 'expected `unloadRecord()` not to throw'); + } catch (e) { + assert.ok(false, 'expected `unloadRecord()` not to throw'); + } + }); + + test(`store.unloadRecord on a record with custom RecordData with relationship to a record with default RecordData does not error`, async function(assert) { + const originalCreateRecordDataFor = store.createModelDataFor; + store.createModelDataFor = function provideCustomRecordData(modelName, id, lid, storeWrapper) { + if (modelName === 'pet') { + return new CustomRecordData(modelName, id, lid, storeWrapper); + } else { + return originalCreateRecordDataFor.call(this, modelName, id, lid, storeWrapper); + } + }; + + let chris = store.push({ + data: { + type: 'person', + id: '1', + attributes: { name: 'Chris' }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }, { type: 'pet', id: '2' }], + }, + }, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owner: { data: { type: 'person', id: '1' } }, + }, + }, + { + type: 'pet', + id: '2', + attributes: { name: 'Prince' }, + relationships: { + owner: { data: { type: 'person', id: '1' } }, + }, + }, + ], + }); + let pets = chris.get('pets'); + let shen = pets.objectAt(0); + + assert.equal(shen.get('name'), 'Shen', 'We found Shen'); + + try { + run(() => shen.unloadRecord()); + assert.ok(true, 'expected `unloadRecord()` not to throw'); + } catch (e) { + assert.ok(false, 'expected `unloadRecord()` not to throw'); + } + }); + + test(`store.findRecord does not eagerly instantiate record data`, async function(assert) { + let recordDataInstances = 0; + class TestRecordData extends CustomRecordData { + constructor() { + super(...arguments); + ++recordDataInstances; + } + } + + store.createRecordDataFor = function(modelName, id, lid, storeWrapper) { + return new TestRecordData(modelName, id, lid, storeWrapper); + }; + this.owner.register( + 'adapter:pet', + class TestAdapter { + static create() { + return new TestAdapter(...arguments); + } + + findRecord() { + assert.equal( + recordDataInstances, + 0, + 'no instance created from findRecord before adapter promise resolves' + ); + + return resolve({ + data: { + id: '1', + type: 'pet', + attributes: { + name: 'Loki', + }, + }, + }); + } + } + ); + this.owner.register( + 'serializer:pet', + class TestSerializer { + static create() { + return new TestSerializer(...arguments); + } + + normalizeResponse(store, modelClass, payload) { + return payload; + } + } + ); + + assert.equal(recordDataInstances, 0, 'initially no instances'); + + await store.findRecord('pet', '1'); + + assert.equal(recordDataInstances, 1, 'record data created after promise fulfills'); + }); +}); diff --git a/tests/integration/records/relationship-changes-test.js b/tests/integration/records/relationship-changes-test.js new file mode 100644 index 00000000000..d6b38002966 --- /dev/null +++ b/tests/integration/records/relationship-changes-test.js @@ -0,0 +1,894 @@ +import { alias } from '@ember/object/computed'; +import { run } from '@ember/runloop'; +import EmberObject, { set, get } from '@ember/object'; +import setupStore from 'dummy/tests/helpers/store'; + +import DS from 'ember-data'; +import { module, test } from 'qunit'; + +const { attr, belongsTo, hasMany, Model } = DS; + +let env, store; + +const Author = Model.extend({ + name: attr('string'), +}); + +const Post = Model.extend({ + author: belongsTo(), +}); + +const Person = DS.Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + siblings: hasMany('person'), +}); + +const sibling1 = { + type: 'person', + id: '1', + attributes: { + firstName: 'Dogzn', + lastName: 'Katz', + }, +}; + +const sibling1Ref = { + type: 'person', + id: '1', +}; + +const sibling2 = { + type: 'person', + id: '2', + attributes: { + firstName: 'Katzn', + lastName: 'Dogz', + }, +}; + +const sibling2Ref = { + type: 'person', + id: '2', +}; + +const sibling3 = { + type: 'person', + id: '3', + attributes: { + firstName: 'Snakezn', + lastName: 'Ladderz', + }, +}; + +const sibling3Ref = { + type: 'person', + id: '3', +}; + +const sibling4 = { + type: 'person', + id: '4', + attributes: { + firstName: 'Hamsterzn', + lastName: 'Gerbilz', + }, +}; + +const sibling4Ref = { + type: 'person', + id: '4', +}; + +const sibling5 = { + type: 'person', + id: '5', + attributes: { + firstName: 'Donkeyzn', + lastName: 'Llamaz', + }, +}; + +const sibling5Ref = { + type: 'person', + id: '5', +}; + +module('integration/records/relationship-changes - Relationship changes', { + beforeEach() { + env = setupStore({ + person: Person, + author: Author, + post: Post, + }); + store = env.store; + }, + + afterEach() { + run(() => { + env.container.destroy(); + }); + }, +}); + +test('Calling push with relationship triggers observers once if the relationship was empty and is added to', function(assert) { + assert.expect(1); + let person = null; + let observerCount = 0; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [], + }, + }, + }, + }); + person = store.peekRecord('person', 'wat'); + }); + + run(() => { + person.addObserver('siblings.[]', function() { + observerCount++; + }); + // prime the pump + person.get('siblings'); + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref], + }, + }, + }, + included: [sibling1], + }); + }); + + run(() => { + assert.ok(observerCount >= 1, 'siblings observer should be triggered at least once'); + }); +}); + +test('Calling push with relationship recalculates computed alias property if the relationship was empty and is added to', function(assert) { + assert.expect(1); + + let Obj = EmberObject.extend({ + person: null, + siblings: alias('person.siblings'), + }); + + const obj = Obj.create(); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [], + }, + }, + }, + }); + set(obj, 'person', store.peekRecord('person', 'wat')); + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref], + }, + }, + }, + included: [sibling1], + }); + }); + + run(() => { + let cpResult = get(obj, 'siblings').toArray(); + assert.equal(cpResult.length, 1, 'siblings cp should have recalculated'); + obj.destroy(); + }); +}); + +test('Calling push with relationship recalculates computed alias property to firstObject if the relationship was empty and is added to', function(assert) { + assert.expect(1); + + let Obj = EmberObject.extend({ + person: null, + firstSibling: alias('person.siblings.firstObject'), + }); + + const obj = Obj.create(); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [], + }, + }, + }, + }); + set(obj, 'person', store.peekRecord('person', 'wat')); + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref], + }, + }, + }, + included: [sibling1], + }); + }); + + run(() => { + let cpResult = get(obj, 'firstSibling'); + assert.equal(get(cpResult, 'id'), 1, 'siblings cp should have recalculated'); + obj.destroy(); + }); +}); + +test('Calling push with relationship triggers observers once if the relationship was not empty and was added to', function(assert) { + assert.expect(1); + let person = null; + let observerCount = 0; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling1Ref], + }, + }, + }, + included: [sibling1], + }); + person = store.peekRecord('person', 'wat'); + }); + + run(() => { + person.addObserver('siblings.[]', function() { + observerCount++; + }); + // prime the pump + person.get('siblings'); + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref, sibling2Ref], + }, + }, + }, + included: [sibling2], + }); + }); + + run(() => { + assert.ok(observerCount >= 1, 'siblings observer should be triggered at least once'); + }); +}); + +test('Calling push with relationship triggers observers once if the relationship was made shorter', function(assert) { + assert.expect(1); + let person = null; + let observerCount = 0; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling1Ref], + }, + }, + }, + included: [sibling1], + }); + person = store.peekRecord('person', 'wat'); + }); + + run(() => { + person.addObserver('siblings.[]', function() { + observerCount++; + }); + // prime the pump + person.get('siblings'); + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [], + }, + }, + }, + included: [], + }); + }); + + run(() => { + assert.ok(observerCount >= 1, 'siblings observer should be triggered at least once'); + }); +}); + +test('Calling push with relationship triggers observers once if the relationship was reordered', function(assert) { + assert.expect(1); + let person = null; + let observerCount = 0; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling1Ref, sibling2Ref], + }, + }, + }, + included: [sibling1, sibling2], + }); + person = store.peekRecord('person', 'wat'); + }); + + run(() => { + person.addObserver('siblings.[]', function() { + observerCount++; + }); + // prime the pump + person.get('siblings'); + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling2Ref, sibling1Ref], + }, + }, + }, + included: [], + }); + }); + + run(() => { + assert.ok(observerCount >= 1, 'siblings observer should be triggered at least once'); + }); +}); + +test('Calling push with relationship does not trigger observers if the relationship was not changed', function(assert) { + assert.expect(1); + let person = null; + let observerCount = 0; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling1Ref], + }, + }, + }, + included: [sibling1], + }); + person = store.peekRecord('person', 'wat'); + }); + + run(() => { + // prime the pump + person.get('siblings'); + person.addObserver('siblings.[]', function() { + observerCount++; + }); + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref], + }, + }, + }, + included: [], + }); + }); + + run(() => { + assert.equal(observerCount, 0, 'siblings observer should not be triggered'); + }); +}); + +test('Calling push with relationship triggers willChange and didChange with detail when appending', function(assert) { + let willChangeCount = 0; + let didChangeCount = 0; + + let observer = { + arrayWillChange(array, start, removing, adding) { + willChangeCount++; + assert.equal(start, 1, 'willChange.start'); + assert.equal(removing, 0, 'willChange.removing'); + assert.equal(adding, 1, 'willChange.adding'); + }, + + arrayDidChange(array, start, removed, added) { + didChangeCount++; + assert.equal(start, 1, 'didChange.start'); + assert.equal(removed, 0, 'didChange.removed'); + assert.equal(added, 1, 'didChange.added'); + }, + }; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling1Ref], + }, + }, + }, + included: [sibling1], + }); + }); + + let person = store.peekRecord('person', 'wat'); + let siblings = run(() => person.get('siblings')); + + siblings.addArrayObserver(observer); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref, sibling2Ref], + }, + }, + }, + included: [sibling2], + }); + }); + + assert.equal(willChangeCount, 1, 'willChange observer should be triggered once'); + assert.equal(didChangeCount, 1, 'didChange observer should be triggered once'); + + siblings.removeArrayObserver(observer); +}); + +test('Calling push with relationship triggers willChange and didChange with detail when truncating', function(assert) { + let willChangeCount = 0; + let didChangeCount = 0; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling1Ref, sibling2Ref], + }, + }, + }, + included: [sibling1, sibling2], + }); + }); + + let person = store.peekRecord('person', 'wat'); + let siblings = run(() => person.get('siblings')); + + let observer = { + arrayWillChange(array, start, removing, adding) { + willChangeCount++; + assert.equal(start, 1); + assert.equal(removing, 1); + assert.equal(adding, 0); + }, + + arrayDidChange(array, start, removed, added) { + didChangeCount++; + assert.equal(start, 1); + assert.equal(removed, 1); + assert.equal(added, 0); + }, + }; + + siblings.addArrayObserver(observer); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref], + }, + }, + }, + included: [], + }); + }); + + assert.equal(willChangeCount, 1, 'willChange observer should be triggered once'); + assert.equal(didChangeCount, 1, 'didChange observer should be triggered once'); + + siblings.removeArrayObserver(observer); +}); + +test('Calling push with relationship triggers willChange and didChange with detail when inserting at front', function(assert) { + let willChangeCount = 0; + let didChangeCount = 0; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling2Ref], + }, + }, + }, + included: [sibling2], + }); + }); + let person = store.peekRecord('person', 'wat'); + + let observer = { + arrayWillChange(array, start, removing, adding) { + willChangeCount++; + assert.equal(start, 0, 'change will start at the beginning'); + assert.equal(removing, 0, 'we have no removals'); + assert.equal(adding, 1, 'we have one insertion'); + }, + + arrayDidChange(array, start, removed, added) { + didChangeCount++; + assert.equal(start, 0, 'change did start at the beginning'); + assert.equal(removed, 0, 'change had no removals'); + assert.equal(added, 1, 'change had one insertion'); + }, + }; + + let siblings = run(() => person.get('siblings')); + siblings.addArrayObserver(observer); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref, sibling2Ref], + }, + }, + }, + included: [sibling2], + }); + }); + + assert.equal(willChangeCount, 1, 'willChange observer should be triggered once'); + assert.equal(didChangeCount, 1, 'didChange observer should be triggered once'); + + siblings.removeArrayObserver(observer); +}); + +test('Calling push with relationship triggers willChange and didChange with detail when inserting in middle', function(assert) { + let willChangeCount = 0; + let didChangeCount = 0; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling1Ref, sibling3Ref], + }, + }, + }, + included: [sibling1, sibling3], + }); + }); + let person = store.peekRecord('person', 'wat'); + let observer = { + arrayWillChange(array, start, removing, adding) { + willChangeCount++; + assert.equal(start, 1); + assert.equal(removing, 0); + assert.equal(adding, 1); + }, + arrayDidChange(array, start, removed, added) { + didChangeCount++; + assert.equal(start, 1); + assert.equal(removed, 0); + assert.equal(added, 1); + }, + }; + + let siblings = run(() => person.get('siblings')); + siblings.addArrayObserver(observer); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref, sibling2Ref, sibling3Ref], + }, + }, + }, + included: [sibling2], + }); + }); + + assert.equal(willChangeCount, 1, 'willChange observer should be triggered once'); + assert.equal(didChangeCount, 1, 'didChange observer should be triggered once'); + + siblings.removeArrayObserver(observer); +}); + +test('Calling push with relationship triggers willChange and didChange with detail when replacing different length in middle', function(assert) { + let willChangeCount = 0; + let didChangeCount = 0; + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling1Ref, sibling2Ref, sibling3Ref], + }, + }, + }, + included: [sibling1, sibling2, sibling3], + }); + }); + + let person = store.peekRecord('person', 'wat'); + let observer = { + arrayWillChange(array, start, removing, adding) { + willChangeCount++; + assert.equal(start, 1); + assert.equal(removing, 1); + assert.equal(adding, 2); + }, + + arrayDidChange(array, start, removed, added) { + didChangeCount++; + assert.equal(start, 1); + assert.equal(removed, 1); + assert.equal(added, 2); + }, + }; + + let siblings = run(() => person.get('siblings')); + siblings.addArrayObserver(observer); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref, sibling4Ref, sibling5Ref, sibling3Ref], + }, + }, + }, + included: [sibling4, sibling5], + }); + }); + + assert.equal(willChangeCount, 1, 'willChange observer should be triggered once'); + assert.equal(didChangeCount, 1, 'didChange observer should be triggered once'); + + siblings.removeArrayObserver(observer); +}); + +test('Calling push with updated belongsTo relationship trigger observer', function(assert) { + assert.expect(1); + + let observerCount = 0; + + run(() => { + let post = env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + author: { + data: { type: 'author', id: '2' }, + }, + }, + }, + included: [ + { + id: 2, + type: 'author', + }, + ], + }); + + post.get('author'); + + post.addObserver('author', function() { + observerCount++; + }); + + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + author: { + data: { type: 'author', id: '3' }, + }, + }, + }, + }); + }); + + assert.equal(observerCount, 1, 'author observer should be triggered once'); +}); + +test('Calling push with same belongsTo relationship does not trigger observer', function(assert) { + assert.expect(1); + + let observerCount = 0; + + run(() => { + let post = env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + author: { + data: { type: 'author', id: '2' }, + }, + }, + }, + }); + + post.addObserver('author', function() { + observerCount++; + }); + + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + author: { + data: { type: 'author', id: '2' }, + }, + }, + }, + }); + }); + + assert.equal(observerCount, 0, 'author observer should not be triggered'); +}); diff --git a/tests/integration/records/reload-test.js b/tests/integration/records/reload-test.js new file mode 100644 index 00000000000..29318234f97 --- /dev/null +++ b/tests/integration/records/reload-test.js @@ -0,0 +1,712 @@ +import { resolve, reject } from 'rsvp'; +import { get } from '@ember/object'; +import { setupTest } from 'ember-qunit'; +import { module, test } from 'qunit'; +import Store from 'ember-data/store'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import Model from 'ember-data/model'; +import { attr, belongsTo, hasMany } from '@ember-decorators/data'; + +module('integration/reload - Reloading Records', function(hooks) { + let store; + setupTest(hooks); + + hooks.beforeEach(function() { + class Person extends Model { + @attr + updatedAt; + @attr + name; + @attr + firstName; + @attr + lastName; + } + + let { owner } = this; + owner.register('service:store', Store); + owner.register('model:person', Person); + owner.register( + 'serializer:application', + JSONAPISerializer.extend({ + normalizeResponse(_, __, jsonApiPayload) { + return jsonApiPayload; + }, + }) + ); + store = owner.lookup('service:store'); + }); + + test("When a single record is requested, the adapter's find method should be called unless it's loaded.", async function(assert) { + let count = 0; + let reloadOptions = { + adapterOptions: { + makeSnazzy: true, + }, + }; + + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + shouldBackgroundReloadRecord() { + return false; + }, + + findRecord(store, type, id, snapshot) { + if (count === 0) { + count++; + return resolve({ data: { id: id, type: 'person', attributes: { name: 'Tom Dale' } } }); + } else if (count === 1) { + assert.equal( + snapshot.adapterOptions, + reloadOptions.adapterOptions, + 'We passed adapterOptions via reload' + ); + count++; + return resolve({ + data: { id: id, type: 'person', attributes: { name: 'Braaaahm Dale' } }, + }); + } else { + assert.ok(false, 'Should not get here'); + } + }, + }) + ); + + let person = await store.findRecord('person', '1'); + + assert.equal(get(person, 'name'), 'Tom Dale', 'The person is loaded with the right name'); + assert.equal(get(person, 'isLoaded'), true, 'The person is now loaded'); + + let promise = person.reload(reloadOptions); + + assert.equal(get(person, 'isReloading'), true, 'The person is now reloading'); + + await promise; + + assert.equal(get(person, 'isReloading'), false, 'The person is no longer reloading'); + assert.equal( + get(person, 'name'), + 'Braaaahm Dale', + 'The person is now updated with the right name' + ); + + // ensure we won't call adapter.findRecord again + await store.findRecord('person', '1'); + }); + + test('When a record is reloaded and fails, it can try again', async function(assert) { + let tom = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }); + let count = 0; + + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + shouldBackgroundReloadRecord() { + return true; + }, + + findRecord() { + assert.equal(tom.get('isReloading'), true, 'Tom is reloading'); + if (count++ === 0) { + return reject(); + } else { + return resolve({ + data: { id: 1, type: 'person', attributes: { name: 'Thomas Dale' } }, + }); + } + }, + }) + ); + + await tom.reload().catch(() => { + assert.ok(true, 'we throw an error'); + }); + + assert.equal(tom.get('isError'), true, 'Tom is now errored'); + assert.equal(tom.get('isReloading'), false, 'Tom is no longer reloading'); + + let person = await tom.reload(); + + assert.equal(person, tom, 'The resolved value is the record'); + assert.equal(tom.get('isError'), false, 'Tom is no longer errored'); + assert.equal(tom.get('isReloading'), false, 'Tom is no longer reloading'); + assert.equal(tom.get('name'), 'Thomas Dale', 'the updates apply'); + }); + + test('When a record is loaded a second time, isLoaded stays true', async function(assert) { + assert.expect(3); + function getTomDale() { + return { + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }; + } + + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + shouldBackgroundReloadRecord() { + return true; + }, + + findRecord(store, type, id, snapshot) { + assert.ok(true, 'We should call findRecord'); + return resolve(getTomDale()); + }, + }) + ); + + function isLoadedDidChange() { + // This observer should never fire + assert.ok(false, 'We should not trigger the isLoaded observer'); + // but if it does we should still have the same isLoaded state + assert.equal(get(this, 'isLoaded'), true, 'The person is still loaded after change'); + } + + store.push(getTomDale()); + + let person = await store.findRecord('person', '1'); + + person.addObserver('isLoaded', isLoadedDidChange); + assert.equal(get(person, 'isLoaded'), true, 'The person is loaded'); + + // Reload the record + store.push(getTomDale()); + + assert.equal(get(person, 'isLoaded'), true, 'The person is still loaded after load'); + + person.removeObserver('isLoaded', isLoadedDidChange); + }); + + test('When a record is reloaded, its async hasMany relationships still work', async function(assert) { + class Person extends Model { + @attr + name; + @hasMany('tag', { async: true, inverse: null }) + tags; + } + class Tag extends Model { + @attr + name; + } + + this.owner.unregister('model:person'); + this.owner.register('model:person', Person); + this.owner.register('model:tag', Tag); + + let tagsById = { 1: 'hipster', 2: 'hair' }; + + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + shouldBackgroundReloadRecord() { + return false; + }, + + findRecord(store, type, id, snapshot) { + switch (type.modelName) { + case 'person': + return resolve({ + data: { + id: '1', + type: 'person', + attributes: { name: 'Tom' }, + relationships: { + tags: { + data: [{ id: '1', type: 'tag' }, { id: '2', type: 'tag' }], + }, + }, + }, + }); + case 'tag': + return resolve({ data: { id: id, type: 'tag', attributes: { name: tagsById[id] } } }); + } + }, + }) + ); + + let tom; + let person = await store.findRecord('person', '1'); + + tom = person; + assert.equal(person.get('name'), 'Tom', 'precond'); + + let tags = await person.get('tags'); + + assert.deepEqual(tags.mapBy('name'), ['hipster', 'hair']); + + person = await tom.reload(); + assert.equal(person.get('name'), 'Tom', 'precond'); + + tags = await person.get('tags'); + + assert.deepEqual(tags.mapBy('name'), ['hipster', 'hair'], 'The tags are still there'); + }); + + module('Reloading via relationship reference and { type, id }', function() { + test('When a sync belongsTo relationship has been loaded, it can still be reloaded via the reference', async function(assert) { + assert.expect(2); + class Pet extends Model { + @belongsTo('person', { async: false, inverse: null }) + owner; + @attr + name; + } + + this.owner.register('model:pet', Pet); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + assert.ok('We called findRecord'); + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + }); + }, + }) + ); + + let shen = store.push({ + data: { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owner: { + data: { type: 'person', id: '1' }, + }, + }, + }, + included: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + ], + }); + + let ownerRef = shen.belongsTo('owner'); + let owner = shen.get('owner'); + let ownerViaRef = await ownerRef.reload(); + + assert.ok(owner === ownerViaRef, 'We received the same reference via reload'); + }); + + test('When a sync belongsTo relationship has not been loaded, it can still be reloaded via the reference', async function(assert) { + assert.expect(2); + class Pet extends Model { + @belongsTo('person', { async: false, inverse: null }) + owner; + @attr + name; + } + + this.owner.register('model:pet', Pet); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + assert.ok('We called findRecord'); + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + }); + }, + }) + ); + + let shen = store.push({ + data: { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owner: { + data: { type: 'person', id: '1' }, + }, + }, + }, + }); + + let ownerRef = shen.belongsTo('owner'); + let ownerViaRef = await ownerRef.reload(); + let owner = shen.get('owner'); + + assert.ok(owner === ownerViaRef, 'We received the same reference via reload'); + }); + + test('When a sync hasMany relationship has been loaded, it can still be reloaded via the reference', async function(assert) { + assert.expect(2); + class Pet extends Model { + @hasMany('person', { async: false, inverse: null }) + owners; + @attr + name; + } + + this.owner.register('model:pet', Pet); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + assert.ok('We called findRecord'); + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + }); + }, + }) + ); + + let shen = store.push({ + data: { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owners: { + data: [{ type: 'person', id: '1' }], + }, + }, + }, + included: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + ], + }); + + let ownersRef = shen.hasMany('owners'); + let owners = shen.get('owners'); + let ownersViaRef = await ownersRef.reload(); + + assert.ok( + owners.objectAt(0) === ownersViaRef.objectAt(0), + 'We received the same reference via reload' + ); + }); + + test('When a sync hasMany relationship has not been loaded, it can still be reloaded via the reference', async function(assert) { + assert.expect(2); + class Pet extends Model { + @hasMany('person', { async: false, inverse: null }) + owners; + @attr + name; + } + + this.owner.register('model:pet', Pet); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + assert.ok('We called findRecord'); + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + }); + }, + }) + ); + + let shen = store.push({ + data: { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owners: { + data: [{ type: 'person', id: '1' }], + }, + }, + }, + }); + + let ownersRef = shen.hasMany('owners'); + let ownersViaRef = await ownersRef.reload(); + let owners = shen.get('owners'); + + assert.ok( + owners.objectAt(0) === ownersViaRef.objectAt(0), + 'We received the same reference via reload' + ); + }); + }); + + module('Reloading via relationship reference and links', function() { + test('When a sync belongsTo relationship has been loaded, it can still be reloaded via the reference', async function(assert) { + assert.expect(2); + class Pet extends Model { + @belongsTo('person', { async: false, inverse: null }) + owner; + @attr + name; + } + + this.owner.register('model:pet', Pet); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findBelongsTo() { + assert.ok('We called findRecord'); + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + }); + }, + }) + ); + + let shen = store.push({ + data: { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owner: { + data: { type: 'person', id: '1' }, + links: { + related: './owner', + }, + }, + }, + }, + included: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + ], + }); + + let ownerRef = shen.belongsTo('owner'); + let owner = shen.get('owner'); + let ownerViaRef = await ownerRef.reload(); + + assert.ok(owner === ownerViaRef, 'We received the same reference via reload'); + }); + + test('When a sync belongsTo relationship has not been loaded, it can still be reloaded via the reference', async function(assert) { + assert.expect(2); + class Pet extends Model { + @belongsTo('person', { async: false, inverse: null }) + owner; + @attr + name; + } + + this.owner.register('model:pet', Pet); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findBelongsTo() { + assert.ok('We called findRecord'); + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + }); + }, + }) + ); + + let shen = store.push({ + data: { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owner: { + data: { type: 'person', id: '1' }, + links: { + related: './owner', + }, + }, + }, + }, + }); + + let ownerRef = shen.belongsTo('owner'); + let ownerViaRef = await ownerRef.reload(); + let owner = shen.get('owner'); + + assert.ok(owner === ownerViaRef, 'We received the same reference via reload'); + }); + + test('When a sync hasMany relationship has been loaded, it can still be reloaded via the reference', async function(assert) { + assert.expect(2); + class Pet extends Model { + @hasMany('person', { async: false, inverse: null }) + owners; + @attr + name; + } + + this.owner.register('model:pet', Pet); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findHasMany() { + assert.ok('We called findRecord'); + return resolve({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + ], + }); + }, + }) + ); + + let shen = store.push({ + data: { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owners: { + data: [{ type: 'person', id: '1' }], + links: { + related: './owners', + }, + }, + }, + }, + included: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + ], + }); + + let ownersRef = shen.hasMany('owners'); + let owners = shen.get('owners'); + let ownersViaRef = await ownersRef.reload(); + + assert.ok( + owners.objectAt(0) === ownersViaRef.objectAt(0), + 'We received the same reference via reload' + ); + }); + + test('When a sync hasMany relationship has not been loaded, it can still be reloaded via the reference', async function(assert) { + assert.expect(2); + class Pet extends Model { + @hasMany('person', { async: false, inverse: null }) + owners; + @attr + name; + } + + this.owner.register('model:pet', Pet); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findHasMany() { + assert.ok('We called findRecord'); + return resolve({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Chris', + }, + }, + ], + }); + }, + }) + ); + + let shen = store.push({ + data: { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + owners: { + data: [{ type: 'person', id: '1' }], + links: { + related: './owners', + }, + }, + }, + }, + }); + + let ownersRef = shen.hasMany('owners'); + let ownersViaRef = await ownersRef.reload(); + let owners = shen.get('owners'); + + assert.ok( + owners.objectAt(0) === ownersViaRef.objectAt(0), + 'We received the same reference via reload' + ); + }); + }); +}); diff --git a/tests/integration/records/rematerialize-test.js b/tests/integration/records/rematerialize-test.js new file mode 100644 index 00000000000..c55e59c4c94 --- /dev/null +++ b/tests/integration/records/rematerialize-test.js @@ -0,0 +1,280 @@ +/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(adam|bob|dudu)" }]*/ + +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import deepCopy from 'dummy/tests/helpers/deep-copy'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; + +const { attr, belongsTo, hasMany, Model } = DS; + +let env; + +let Person = Model.extend({ + name: attr('string'), + cars: hasMany('car', { async: false }), + boats: hasMany('boat', { async: true }), +}); +Person.reopenClass({ + toString() { + return 'Person'; + }, +}); + +let Group = Model.extend({ + people: hasMany('person', { async: false }), +}); +Group.reopenClass({ + toString() { + return 'Group'; + }, +}); + +let Car = Model.extend({ + make: attr('string'), + model: attr('string'), + person: belongsTo('person', { async: false }), +}); +Car.reopenClass({ + toString() { + return 'Car'; + }, +}); + +let Boat = Model.extend({ + name: attr('string'), + person: belongsTo('person', { async: false }), +}); +Boat.toString = function() { + return 'Boat'; +}; + +module('integration/unload - Rematerializing Unloaded Records', { + beforeEach() { + env = setupStore({ + adapter: DS.JSONAPIAdapter, + person: Person, + car: Car, + group: Group, + boat: Boat, + }); + }, + + afterEach() { + run(function() { + env.container.destroy(); + }); + }, +}); + +test('a sync belongs to relationship to an unloaded record can restore that record', function(assert) { + // disable background reloading so we do not re-create the relationship. + env.adapter.shouldBackgroundReloadRecord = () => false; + + let adam = run(() => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + relationships: { + cars: { + data: [{ type: 'car', id: '1' }], + }, + }, + }, + }); + + return env.store.peekRecord('person', 1); + }); + + let bob = run(() => { + env.store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'Lotus', + model: 'Exige', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, + }); + + return env.store.peekRecord('car', 1); + }); + + let person = env.store.peekRecord('person', 1); + assert.equal(person.get('cars.length'), 1, 'The inital length of cars is correct'); + + assert.equal(env.store.hasRecordForId('person', 1), true, 'The person is in the store'); + assert.equal( + env.store._internalModelsFor('person').has(1), + true, + 'The person internalModel is loaded' + ); + + run(() => person.unloadRecord()); + + assert.equal(env.store.hasRecordForId('person', 1), false, 'The person is unloaded'); + assert.equal( + env.store._internalModelsFor('person').has(1), + false, + 'The person internalModel is freed' + ); + + run(() => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + relationships: { + cars: { + data: [{ type: 'car', id: '1' }], + }, + }, + }, + }); + }); + + let rematerializedPerson = bob.get('person'); + assert.equal(rematerializedPerson.get('id'), '1'); + assert.equal(rematerializedPerson.get('name'), 'Adam Sunderland'); + // the person is rematerialized; the previous person is *not* re-used + assert.notEqual(rematerializedPerson, adam, 'the person is rematerialized, not recycled'); +}); + +test('an async has many relationship to an unloaded record can restore that record', function(assert) { + assert.expect(16); + + // disable background reloading so we do not re-create the relationship. + env.adapter.shouldBackgroundReloadRecord = () => false; + + const BOAT_ONE = { + type: 'boat', + id: '1', + attributes: { + name: 'Boaty McBoatface', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }; + + const BOAT_TWO = { + type: 'boat', + id: '2', + attributes: { + name: 'Some other boat', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }; + + let adapterCalls = 0; + env.adapter.findRecord = function(store, model, param) { + assert.ok(true, `adapter called ${++adapterCalls}x`); + + let data; + if (param === '1') { + data = deepCopy(BOAT_ONE); + } else if (param === '2') { + data = deepCopy(BOAT_TWO); + } else { + throw new Error(`404: no such boat with id=${param}`); + } + + return { + data, + }; + }; + + run(() => { + env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + relationships: { + boats: { + data: [{ type: 'boat', id: '2' }, { type: 'boat', id: '1' }], + }, + }, + }, + }); + }); + + run(() => { + env.store.push({ + data: [deepCopy(BOAT_ONE), deepCopy(BOAT_TWO)], + }); + }); + + let adam = env.store.peekRecord('person', '1'); + let boaty = env.store.peekRecord('boat', '1'); + + // assert our initial cache state + assert.equal(env.store.hasRecordForId('person', '1'), true, 'The person is in the store'); + assert.equal( + env.store._internalModelsFor('person').has('1'), + true, + 'The person internalModel is loaded' + ); + assert.equal(env.store.hasRecordForId('boat', '1'), true, 'The boat is in the store'); + assert.equal( + env.store._internalModelsFor('boat').has('1'), + true, + 'The boat internalModel is loaded' + ); + + let boats = run(() => adam.get('boats')); + assert.equal(boats.get('length'), 2, 'Before unloading boats.length is correct'); + + run(() => boaty.unloadRecord()); + assert.equal(boats.get('length'), 1, 'after unloading boats.length is correct'); + + // assert our new cache state + assert.equal(env.store.hasRecordForId('boat', '1'), false, 'The boat is unloaded'); + assert.equal( + env.store._internalModelsFor('boat').has('1'), + true, + 'The boat internalModel is retained' + ); + + // cause a rematerialization, this should also cause us to fetch boat '1' again + boats = run(() => adam.get('boats')); + let rematerializedBoaty = boats.objectAt(1); + + assert.ok(!!rematerializedBoaty, 'We have a boat!'); + assert.equal(adam.get('boats.length'), 2, 'boats.length correct after rematerialization'); + assert.equal(rematerializedBoaty.get('id'), '1', 'Rematerialized boat has the right id'); + assert.equal( + rematerializedBoaty.get('name'), + 'Boaty McBoatface', + 'Rematerialized boat has the right name' + ); + assert.ok(rematerializedBoaty !== boaty, 'the boat is rematerialized, not recycled'); + + assert.equal(env.store.hasRecordForId('boat', '1'), true, 'The boat is loaded'); + assert.equal( + env.store._internalModelsFor('boat').has('1'), + true, + 'The boat internalModel is retained' + ); +}); diff --git a/tests/integration/records/save-test.js b/tests/integration/records/save-test.js new file mode 100644 index 00000000000..58164fd38ac --- /dev/null +++ b/tests/integration/records/save-test.js @@ -0,0 +1,206 @@ +import { defer, reject, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var Post, env; + +module('integration/records/save - Save Record', { + beforeEach() { + Post = DS.Model.extend({ + title: DS.attr('string'), + }); + + env = setupStore({ post: Post }); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('Will resolve save on success', function(assert) { + assert.expect(4); + let post = env.store.createRecord('post', { title: 'toto' }); + + var deferred = defer(); + env.adapter.createRecord = function(store, type, snapshot) { + return deferred.promise; + }; + + run(function() { + var saved = post.save(); + + // `save` returns a PromiseObject which allows to call get on it + assert.strictEqual(saved.get('id'), undefined); + + deferred.resolve({ data: { id: 123, type: 'post' } }); + saved.then(function(model) { + assert.ok(true, 'save operation was resolved'); + assert.equal(saved.get('id'), 123); + assert.equal(model, post, 'resolves with the model'); + }); + }); +}); + +test('Will reject save on error', function(assert) { + let post = env.store.createRecord('post', { title: 'toto' }); + + env.adapter.createRecord = function(store, type, snapshot) { + var error = new DS.InvalidError([{ title: 'not valid' }]); + + return reject(error); + }; + + run(function() { + post.save().then( + function() {}, + function() { + assert.ok(true, 'save operation was rejected'); + } + ); + }); +}); + +test('Retry is allowed in a failure handler', function(assert) { + let post = env.store.createRecord('post', { title: 'toto' }); + + var count = 0; + + env.adapter.createRecord = function(store, type, snapshot) { + var error = new DS.InvalidError([{ title: 'not valid' }]); + + if (count++ === 0) { + return reject(error); + } else { + return resolve({ data: { id: 123, type: 'post' } }); + } + }; + + run(function() { + post + .save() + .then( + function() {}, + function() { + return post.save(); + } + ) + .then(function(post) { + assert.equal(post.get('id'), '123', 'The post ID made it through'); + }); + }); +}); + +test('Repeated failed saves keeps the record in uncommited state', function(assert) { + assert.expect(4); + let post = env.store.createRecord('post', { title: 'toto' }); + + env.adapter.createRecord = function(store, type, snapshot) { + return reject(); + }; + + run(function() { + post.save().then(null, function() { + assert.ok(post.get('isError')); + assert.equal(post.get('currentState.stateName'), 'root.loaded.created.uncommitted'); + + post.save().then(null, function() { + assert.ok(post.get('isError')); + assert.equal(post.get('currentState.stateName'), 'root.loaded.created.uncommitted'); + }); + }); + }); +}); + +test('Repeated failed saves with invalid error marks the record as invalid', function(assert) { + assert.expect(2); + let post = env.store.createRecord('post', { title: 'toto' }); + + env.adapter.createRecord = function(store, type, snapshot) { + var error = new DS.InvalidError([ + { + detail: 'is invalid', + source: { pointer: 'data/attributes/title' }, + }, + ]); + + return reject(error); + }; + + run(function() { + post.save().then(null, function() { + assert.equal(post.get('isValid'), false); + + post.save().then(null, function() { + assert.equal(post.get('isValid'), false); + }); + }); + }); +}); + +test('Repeated failed saves with invalid error without payload marks the record as invalid', function(assert) { + assert.expect(2); + let post = env.store.createRecord('post', { title: 'toto' }); + + env.adapter.createRecord = function(store, type, snapshot) { + var error = new DS.InvalidError(); + + return reject(error); + }; + + run(function() { + post.save().then(null, function() { + assert.equal(post.get('isValid'), false); + + post.save().then(null, function() { + assert.equal(post.get('isValid'), false); + }); + }); + }); +}); + +test('Will reject save on invalid', function(assert) { + assert.expect(1); + let post = env.store.createRecord('post', { title: 'toto' }); + + env.adapter.createRecord = function(store, type, snapshot) { + var error = new DS.InvalidError([{ title: 'not valid' }]); + + return reject(error); + }; + + run(function() { + post.save().then( + function() {}, + function() { + assert.ok(true, 'save operation was rejected'); + } + ); + }); +}); + +test('Will error when saving after unloading record via the store', function(assert) { + assert.expect(1); + let post = env.store.createRecord('post', { title: 'toto' }); + run(function() { + env.store.unloadAll('post'); + assert.throws(function() { + post.save(); + }, 'Attempting to save the unloaded record threw an error'); + }); +}); + +test('Will error when saving after unloading record', function(assert) { + assert.expect(1); + let post = env.store.createRecord('post', { title: 'toto' }); + run(function() { + post.unloadRecord(); + assert.throws(function() { + post.save(); + }, 'Attempting to save the unloaded record threw an error'); + }); +}); diff --git a/tests/integration/records/unload-test.js b/tests/integration/records/unload-test.js new file mode 100644 index 00000000000..0b5f1d5bcd1 --- /dev/null +++ b/tests/integration/records/unload-test.js @@ -0,0 +1,3005 @@ +/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(adam|bob|dudu)" }]*/ + +import { resolve, Promise as EmberPromise } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; +import { setupTest } from 'ember-qunit'; +import { recordDataFor } from 'ember-data/-private'; + +function idsFromOrderedSet(set) { + return set.list.map(i => i.id); +} + +const { attr, belongsTo, hasMany, Model } = DS; + +const Person = Model.extend({ + name: attr('string'), + // 1:many sync + cars: hasMany('car', { async: false }), + // 1:many async + boats: hasMany('boat', { async: true }), + // many:many sync + groups: hasMany('group', { async: false }), + // many:many async + friends: hasMany('people', { async: true }), + // 1:1 sync inverse null + bike: belongsTo('bike', { async: false, inverse: null }), + // 1:1 sync + house: belongsTo('house', { async: false }), + // 1:1 async + mortgage: belongsTo('mortgage', { async: true }), + // 1 async : 1 sync + favoriteBook: belongsTo('book', { async: false }), + // 1 async : many sync + favoriteSpoons: hasMany('spoon', { async: false }), + // 1 sync: many async + favoriteShows: hasMany('show', { async: true }), + // many sync : many async + favoriteFriends: hasMany('people', { async: true, inverse: 'favoriteAsyncFriends' }), + // many async : many sync + favoriteAsyncFriends: hasMany('people', { async: false, inverse: 'favoriteFriends' }), +}); +Person.reopenClass({ + toString() { + return 'Person'; + }, +}); + +const House = Model.extend({ + person: belongsTo('person', { async: false }), +}); +House.reopenClass({ + toString() { + return 'House'; + }, +}); + +const Mortgage = Model.extend({ + person: belongsTo('person', { async: true }), +}); +Mortgage.reopenClass({ + toString() { + return 'Mortgage'; + }, +}); + +const Group = Model.extend({ + people: hasMany('person', { async: false }), +}); +Group.reopenClass({ + toString() { + return 'Group'; + }, +}); + +const Car = Model.extend({ + make: attr('string'), + model: attr('string'), + person: belongsTo('person', { async: false }), +}); +Car.reopenClass({ + toString() { + return 'Car'; + }, +}); + +const Boat = Model.extend({ + name: attr('string'), + person: belongsTo('person', { async: true }), +}); +Boat.toString = function() { + return 'Boat'; +}; + +const Bike = Model.extend({ + name: DS.attr(), +}); +Bike.toString = function() { + return 'Bike'; +}; + +const Book = Model.extend({ + person: belongsTo('person', { async: true }), +}); +Book.toString = function() { + return 'Book'; +}; + +const Spoon = Model.extend({ + person: belongsTo('person', { async: true }), +}); +Spoon.toString = function() { + return 'Spoon'; +}; + +const Show = Model.extend({ + person: belongsTo('person', { async: false }), +}); +Show.toString = function() { + return 'Show'; +}; + +module('integration/unload - Unloading Records', function(hooks) { + setupTest(hooks); + let store, adapter; + + hooks.beforeEach(function() { + let { owner } = this; + + owner.register(`model:person`, Person); + owner.register(`model:car`, Car); + owner.register(`model:group`, Group); + owner.register(`model:house`, House); + owner.register(`model:mortgage`, Mortgage); + owner.register(`model:boat`, Boat); + owner.register(`model:bike`, Bike); + owner.register(`model:book`, Book); + owner.register(`model:spoon`, Spoon); + owner.register(`model:show`, Show); + + store = owner.lookup('service:store'); + adapter = store.adapterFor('application'); + }); + + test('can unload a single record', function(assert) { + let adam; + run(function() { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + relationships: { + cars: { + data: [ + { + id: 1, + type: 'car', + }, + ], + }, + boats: { + data: [ + { + id: 2, + type: 'boat', + }, + ], + }, + }, + }, + }); + adam = store.peekRecord('person', 1); + }); + + assert.equal(store.peekAll('person').get('length'), 1, 'one person record loaded'); + assert.equal(store._internalModelsFor('person').length, 1, 'one person internalModel loaded'); + + run(function() { + adam.unloadRecord(); + }); + + assert.equal(store.peekAll('person').get('length'), 0, 'no person records'); + assert.equal(store._internalModelsFor('person').length, 0, 'no person internalModels'); + }); + + test('can unload all records for a given type', function(assert) { + assert.expect(10); + + let adam, bob, dudu, car; + run(function() { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Bob Bobson', + }, + }, + ], + }); + adam = store.peekRecord('person', 1); + bob = store.peekRecord('person', 2); + + car = store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'VW', + model: 'Beetle', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, + }); + dudu = bob = store.peekRecord('car', 1); + }); + + assert.equal(store.peekAll('person').get('length'), 2, 'two person records loaded'); + assert.equal(store._internalModelsFor('person').length, 2, 'two person internalModels loaded'); + assert.equal(store.peekAll('car').get('length'), 1, 'one car record loaded'); + assert.equal(store._internalModelsFor('car').length, 1, 'one car internalModel loaded'); + + run(function() { + car.get('person'); + store.unloadAll('person'); + }); + + assert.equal(store.peekAll('person').get('length'), 0); + assert.equal(store.peekAll('car').get('length'), 1); + assert.equal(store._internalModelsFor('person').length, 0, 'zero person internalModels loaded'); + assert.equal(store._internalModelsFor('car').length, 1, 'one car internalModel loaded'); + + run(function() { + store.push({ + data: { + id: 1, + type: 'person', + attributes: { + name: 'Richard II', + }, + }, + }); + }); + + car = store.peekRecord('car', 1); + let person = car.get('person'); + + assert.ok(!!car, 'We have a car'); + assert.ok(!person, 'We dont have a person'); + + /* + @runspired believes these asserts were incorrect on master. + Basically, we intentionally treat unload on a sync belongsTo as client-side + delete bc "bad reason" of legacy support for the mis-use of unloadRecord. + Because of this, there should be no way to resurrect the relationship without + receiving new relationship info which does not occur in this test. + He checked how master manages to do this, and discovered bad things. TL;DR + because the `person` relationship is never materialized, it's state was + not cleared on unload, and thus the client-side delete never happened as intended. + */ + // assert.equal(person.get('id'), '1', 'Inverse can load relationship after the record is unloaded'); + // assert.equal(person.get('name'), 'Richard II', 'Inverse can load relationship after the record is unloaded'); + }); + + test('can unload all records', function(assert) { + assert.expect(8); + + let adam, bob, dudu; + run(function() { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Bob Bobson', + }, + }, + ], + }); + adam = store.peekRecord('person', 1); + bob = store.peekRecord('person', 2); + + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'VW', + model: 'Beetle', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, + }); + dudu = bob = store.peekRecord('car', 1); + }); + + assert.equal(store.peekAll('person').get('length'), 2, 'two person records loaded'); + assert.equal(store._internalModelsFor('person').length, 2, 'two person internalModels loaded'); + assert.equal(store.peekAll('car').get('length'), 1, 'one car record loaded'); + assert.equal(store._internalModelsFor('car').length, 1, 'one car internalModel loaded'); + + run(function() { + store.unloadAll(); + }); + + assert.equal(store.peekAll('person').get('length'), 0); + assert.equal(store.peekAll('car').get('length'), 0); + assert.equal(store._internalModelsFor('person').length, 0, 'zero person internalModels loaded'); + assert.equal(store._internalModelsFor('car').length, 0, 'zero car internalModels loaded'); + }); + + test('removes findAllCache after unloading all records', function(assert) { + assert.expect(4); + + let adam, bob; + run(function() { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Bob Bobson', + }, + }, + ], + }); + adam = store.peekRecord('person', 1); + bob = store.peekRecord('person', 2); + }); + + assert.equal(store.peekAll('person').get('length'), 2, 'two person records loaded'); + assert.equal(store._internalModelsFor('person').length, 2, 'two person internalModels loaded'); + + run(function() { + store.peekAll('person'); + store.unloadAll('person'); + }); + + assert.equal(store.peekAll('person').get('length'), 0, 'zero person records loaded'); + assert.equal(store._internalModelsFor('person').length, 0, 'zero person internalModels loaded'); + }); + + test('unloading all records also updates record array from peekAll()', function(assert) { + let adam, bob; + run(function() { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Bob Bobson', + }, + }, + ], + }); + adam = store.peekRecord('person', 1); + bob = store.peekRecord('person', 2); + }); + let all = store.peekAll('person'); + + assert.equal(all.get('length'), 2); + + run(function() { + store.unloadAll('person'); + }); + assert.equal(all.get('length'), 0); + }); + + function makeBoatOneForPersonOne() { + return { + type: 'boat', + id: '1', + attributes: { + name: 'Boaty McBoatface', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }; + } + + test('unloadAll(type) does not leave stranded internalModels in relationships (rediscover via store.push)', function(assert) { + assert.expect(15); + + let person = run(() => + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Could be Anybody', + }, + relationships: { + boats: { + data: [{ type: 'boat', id: '1' }], + }, + }, + }, + included: [makeBoatOneForPersonOne()], + }) + ); + + let boat = store.peekRecord('boat', '1'); + let initialBoatInternalModel = boat._internalModel; + let relationshipState = person.hasMany('boats').hasManyRelationship; + let knownPeople = store._internalModelsFor('person'); + let knownBoats = store._internalModelsFor('boat'); + + // ensure we loaded the people and boats + assert.equal(knownPeople.models.length, 1, 'one person record is loaded'); + assert.equal(knownBoats.models.length, 1, 'one boat record is loaded'); + assert.equal(store.hasRecordForId('person', '1'), true); + assert.equal(store.hasRecordForId('boat', '1'), true); + + // ensure the relationship was established (we reach through the async proxy here) + let peopleBoats = run(() => person.get('boats.content')); + let boatPerson = run(() => boat.get('person.content')); + + assert.equal(relationshipState.canonicalMembers.size, 1, 'canonical member size should be 1'); + assert.equal(relationshipState.members.size, 1, 'members size should be 1'); + assert.ok(get(peopleBoats, 'length') === 1, 'Our person has a boat'); + assert.ok(peopleBoats.objectAt(0) === boat, 'Our person has the right boat'); + assert.ok(boatPerson === person, 'Our boat has the right person'); + + run(() => { + store.unloadAll('boat'); + }); + + // ensure that our new state is correct + assert.equal(knownPeople.models.length, 1, 'one person record is loaded'); + assert.equal(knownBoats.models.length, 0, 'no boat records are loaded'); + assert.equal( + relationshipState.canonicalMembers.size, + 1, + 'canonical member size should still be 1' + ); + assert.equal(relationshipState.members.size, 1, 'members size should still be 1'); + assert.ok(get(peopleBoats, 'length') === 0, 'Our person thinks they have no boats'); + + run(() => + store.push({ + data: makeBoatOneForPersonOne(), + }) + ); + + let reloadedBoat = store.peekRecord('boat', '1'); + let reloadedBoatInternalModel = reloadedBoat._internalModel; + + assert.ok( + reloadedBoatInternalModel === initialBoatInternalModel, + 'after an unloadAll, subsequent fetch results in the same InternalModel' + ); + }); + + test('unloadAll(type) does not leave stranded internalModels in relationships (rediscover via relationship reload)', function(assert) { + assert.expect(17); + + adapter.findRecord = (store, type, id) => { + assert.ok(type.modelName === 'boat', 'We refetch the boat'); + assert.ok(id === '1', 'We refetch the right boat'); + return resolve({ + data: makeBoatOneForPersonOne(), + }); + }; + + let person = run(() => + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Could be Anybody', + }, + relationships: { + boats: { + data: [{ type: 'boat', id: '1' }], + }, + }, + }, + included: [makeBoatOneForPersonOne()], + }) + ); + + let boat = store.peekRecord('boat', '1'); + let initialBoatInternalModel = boat._internalModel; + let relationshipState = person.hasMany('boats').hasManyRelationship; + let knownPeople = store._internalModelsFor('person'); + let knownBoats = store._internalModelsFor('boat'); + + // ensure we loaded the people and boats + assert.equal(knownPeople.models.length, 1, 'one person record is loaded'); + assert.equal(knownBoats.models.length, 1, 'one boat record is loaded'); + assert.equal(store.hasRecordForId('person', '1'), true); + assert.equal(store.hasRecordForId('boat', '1'), true); + + // ensure the relationship was established (we reach through the async proxy here) + let peopleBoats = run(() => person.get('boats.content')); + let boatPerson = run(() => boat.get('person.content')); + + assert.equal(relationshipState.canonicalMembers.size, 1, 'canonical member size should be 1'); + assert.equal(relationshipState.members.size, 1, 'members size should be 1'); + assert.ok(get(peopleBoats, 'length') === 1, 'Our person has a boat'); + assert.ok(peopleBoats.objectAt(0) === boat, 'Our person has the right boat'); + assert.ok(boatPerson === person, 'Our boat has the right person'); + + run(() => { + store.unloadAll('boat'); + }); + + // ensure that our new state is correct + assert.equal(knownPeople.models.length, 1, 'one person record is loaded'); + assert.equal(knownBoats.models.length, 0, 'no boat records are loaded'); + assert.equal( + relationshipState.canonicalMembers.size, + 1, + 'canonical member size should still be 1' + ); + assert.equal(relationshipState.members.size, 1, 'members size should still be 1'); + assert.ok(get(peopleBoats, 'length') === 0, 'Our person thinks they have no boats'); + + run(() => person.get('boats')); + + let reloadedBoat = store.peekRecord('boat', '1'); + let reloadedBoatInternalModel = reloadedBoat._internalModel; + + assert.ok( + reloadedBoatInternalModel === initialBoatInternalModel, + 'after an unloadAll, subsequent fetch results in the same InternalModel' + ); + }); + + test('(regression) unloadRecord followed by push in the same run-loop', function(assert) { + let person = run(() => + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Could be Anybody', + }, + relationships: { + boats: { + data: [{ type: 'boat', id: '1' }], + }, + }, + }, + included: [makeBoatOneForPersonOne()], + }) + ); + + let boat = store.peekRecord('boat', '1'); + let initialBoatInternalModel = boat._internalModel; + let relationshipState = person.hasMany('boats').hasManyRelationship; + let knownPeople = store._internalModelsFor('person'); + let knownBoats = store._internalModelsFor('boat'); + + // ensure we loaded the people and boats + assert.deepEqual(knownPeople.models.map(m => m.id), ['1'], 'one person record is loaded'); + assert.deepEqual(knownBoats.models.map(m => m.id), ['1'], 'one boat record is loaded'); + assert.equal(store.hasRecordForId('person', '1'), true); + assert.equal(store.hasRecordForId('boat', '1'), true); + + // ensure the relationship was established (we reach through the async proxy here) + let peopleBoats = run(() => person.get('boats.content')); + let boatPerson = run(() => boat.get('person.content')); + + assert.deepEqual( + idsFromOrderedSet(relationshipState.canonicalMembers), + ['1'], + 'canonical member size should be 1' + ); + assert.deepEqual( + idsFromOrderedSet(relationshipState.members), + ['1'], + 'members size should be 1' + ); + assert.ok(get(peopleBoats, 'length') === 1, 'Our person has a boat'); + assert.ok(peopleBoats.objectAt(0) === boat, 'Our person has the right boat'); + assert.ok(boatPerson === person, 'Our boat has the right person'); + + run(() => boat.unloadRecord()); + + // ensure that our new state is correct + assert.deepEqual(knownPeople.models.map(m => m.id), ['1'], 'one person record is loaded'); + assert.deepEqual(knownBoats.models.map(m => m.id), ['1'], 'one boat record is known'); + assert.ok(knownBoats.models[0] === initialBoatInternalModel, 'We still have our boat'); + assert.equal(initialBoatInternalModel.isEmpty(), true, 'Model is in the empty state'); + assert.deepEqual( + idsFromOrderedSet(relationshipState.canonicalMembers), + ['1'], + 'canonical member size should still be 1' + ); + assert.deepEqual( + idsFromOrderedSet(relationshipState.members), + ['1'], + 'members size should still be 1' + ); + assert.ok(get(peopleBoats, 'length') === 0, 'Our person thinks they have no boats'); + + run(() => + store.push({ + data: makeBoatOneForPersonOne(), + }) + ); + + let reloadedBoat = store.peekRecord('boat', '1'); + let reloadedBoatInternalModel = reloadedBoat._internalModel; + + assert.deepEqual( + idsFromOrderedSet(relationshipState.canonicalMembers), + ['1'], + 'canonical member size should be 1' + ); + assert.deepEqual( + idsFromOrderedSet(relationshipState.members), + ['1'], + 'members size should be 1' + ); + assert.ok( + reloadedBoatInternalModel === initialBoatInternalModel, + 'after an unloadRecord, subsequent fetch results in the same InternalModel' + ); + + // and now the kicker, run-loop fun! + // here, we will dematerialize the record, but push it back into the store + // all in the same run-loop! + // effectively this tests that our destroySync is not stupid + run(() => { + reloadedBoat.unloadRecord(); + store.push({ + data: makeBoatOneForPersonOne(), + }); + }); + + let yaBoat = store.peekRecord('boat', '1'); + let yaBoatInternalModel = yaBoat._internalModel; + + assert.deepEqual( + idsFromOrderedSet(relationshipState.canonicalMembers), + ['1'], + 'canonical member size should be 1' + ); + assert.deepEqual( + idsFromOrderedSet(relationshipState.members), + ['1'], + 'members size should be 1' + ); + assert.ok( + yaBoatInternalModel === initialBoatInternalModel, + 'after an unloadRecord, subsequent same-loop push results in the same InternalModel' + ); + }); + + test('unloading a disconnected subgraph clears the relevant internal models', function(assert) { + adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Could be Anybody', + }, + relationships: { + boats: { + data: [{ type: 'boat', id: '1' }, { type: 'boat', id: '2' }], + }, + }, + }, + }); + }); + + run(() => { + store.push({ + data: { + type: 'boat', + id: '1', + attributes: { + name: 'Boaty McBoatface', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, + }); + }); + + run(() => { + store.push({ + data: { + type: 'boat', + id: '2', + attributes: { + name: 'The jackson', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, + }); + }); + + assert.equal( + store._internalModelsFor('person').models.length, + 1, + 'one person record is loaded' + ); + assert.equal(store._internalModelsFor('boat').models.length, 2, 'two boat records are loaded'); + assert.equal(store.hasRecordForId('person', 1), true); + assert.equal(store.hasRecordForId('boat', 1), true); + assert.equal(store.hasRecordForId('boat', 2), true); + + let checkOrphanCalls = 0; + let cleanupOrphanCalls = 0; + + function countOrphanCalls(record) { + let internalModel = record._internalModel; + let recordData = recordDataFor(record); + let origCheck = internalModel._checkForOrphanedInternalModels; + let origCleanup = recordData._cleanupOrphanedRecordDatas; + + internalModel._checkForOrphanedInternalModels = function() { + ++checkOrphanCalls; + return origCheck.apply(record._internalModel, arguments); + }; + + recordData._cleanupOrphanedRecordDatas = function() { + ++cleanupOrphanCalls; + return origCleanup.apply(recordData, arguments); + }; + } + countOrphanCalls(store.peekRecord('person', 1)); + countOrphanCalls(store.peekRecord('boat', 1)); + countOrphanCalls(store.peekRecord('boat', 2)); + + // make sure relationships are initialized + return store + .peekRecord('person', 1) + .get('boats') + .then(() => { + run(() => { + store.peekRecord('person', 1).unloadRecord(); + store.peekRecord('boat', 1).unloadRecord(); + store.peekRecord('boat', 2).unloadRecord(); + }); + + assert.equal(store._internalModelsFor('person').models.length, 0); + assert.equal(store._internalModelsFor('boat').models.length, 0); + + assert.equal(checkOrphanCalls, 3, 'each internalModel checks for cleanup'); + assert.equal(cleanupOrphanCalls, 3, 'each model data tries to cleanup'); + }); + }); + + test('Unloading a record twice only schedules destroy once', function(assert) { + let record; + + // populate initial record + run(function() { + record = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + }); + }); + + const internalModel = record._internalModel; + + run(function() { + store.unloadRecord(record); + store.unloadRecord(record); + internalModel.cancelDestroy(); + }); + + assert.equal(internalModel.isDestroyed, false, 'We cancelled destroy'); + }); + + test('Cancelling destroy leaves the record in the empty state', function(assert) { + let record; + + // populate initial record + run(function() { + record = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + }); + }); + + const internalModel = record._internalModel; + assert.equal( + internalModel.currentState.stateName, + 'root.loaded.saved', + 'We are loaded initially' + ); + + run(function() { + store.unloadRecord(record); + assert.equal(record.isDestroying, true, 'the record is destroying'); + assert.equal(internalModel.isDestroyed, false, 'the internal model is not destroyed'); + assert.equal(internalModel._isDematerializing, true, 'the internal model is dematerializing'); + internalModel.cancelDestroy(); + assert.equal( + internalModel.currentState.stateName, + 'root.empty', + 'We are unloaded after unloadRecord' + ); + }); + + assert.equal(internalModel.isDestroyed, false, 'the internal model was not destroyed'); + assert.equal( + internalModel._isDematerializing, + false, + 'the internal model is no longer dematerializing' + ); + assert.equal( + internalModel.currentState.stateName, + 'root.empty', + 'We are still unloaded after unloadRecord' + ); + }); + + test('after unloading a record, the record can be fetched again immediately', function(assert) { + // stub findRecord + adapter.findRecord = () => { + return { + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + }; + }; + + // populate initial record + let record = run(() => { + return store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + relationships: { + cars: { + data: [ + { + id: 1, + type: 'car', + }, + ], + }, + }, + }, + included: [ + { + type: 'car', + id: 1, + attributes: { + make: 'jeep', + model: 'wrangler', + }, + }, + ], + }); + }); + + const internalModel = record._internalModel; + assert.equal( + internalModel.currentState.stateName, + 'root.loaded.saved', + 'We are loaded initially' + ); + + // we test that we can sync call unloadRecord followed by findRecord + return run(() => { + store.unloadRecord(record); + assert.equal(record.isDestroying, true, 'the record is destroying'); + assert.equal( + internalModel.currentState.stateName, + 'root.empty', + 'We are unloaded after unloadRecord' + ); + return store.findRecord('person', '1').then(newRecord => { + assert.ok(internalModel === newRecord._internalModel, 'the old internalModel is reused'); + assert.equal( + newRecord._internalModel.currentState.stateName, + 'root.loaded.saved', + 'We are loaded after findRecord' + ); + }); + }); + }); + + test('after unloading a record, the record can be fetched again immediately (purge relationship)', function(assert) { + // stub findRecord + adapter.findRecord = () => { + return { + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + relationships: { + cars: { + data: [], + }, + }, + }, + }; + }; + + // populate initial record + let record = run(() => { + return store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + relationships: { + cars: { + data: [ + { + id: '1', + type: 'car', + }, + ], + }, + }, + }, + included: [ + { + type: 'car', + id: '1', + attributes: { + make: 'jeep', + model: 'wrangler', + }, + }, + ], + }); + }); + + const internalModel = record._internalModel; + assert.equal( + internalModel.currentState.stateName, + 'root.loaded.saved', + 'We are loaded initially' + ); + + // we test that we can sync call unloadRecord followed by findRecord + return run(() => { + assert.equal(record.get('cars.firstObject.make'), 'jeep'); + store.unloadRecord(record); + assert.equal(record.isDestroying, true, 'the record is destroying'); + assert.equal( + internalModel.currentState.stateName, + 'root.empty', + 'Expected the previous internal model tobe unloaded' + ); + + return store.findRecord('person', '1').then(record => { + assert.equal( + record.get('cars.length'), + 0, + 'Expected relationship to be cleared by the new push' + ); + assert.ok(internalModel === record._internalModel, 'the old internalModel is reused'); + assert.equal( + record._internalModel.currentState.stateName, + 'root.loaded.saved', + 'Expected the NEW internal model to be loaded' + ); + }); + }); + }); + + test('after unloading a record, the record can be fetched again immediately (with relationships)', function(assert) { + // stub findRecord + adapter.findRecord = () => { + return { + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + }; + }; + + // populate initial record + let record = run(() => { + return store.push({ + data: { + type: 'person', + id: '1', + relationships: { + bike: { + data: { type: 'bike', id: '1' }, + }, + }, + }, + + included: [ + { + id: '1', + type: 'bike', + attributes: { + name: 'mr bike', + }, + }, + ], + }); + }); + + const internalModel = record._internalModel; + const bike = store.peekRecord('bike', '1'); + assert.equal( + internalModel.currentState.stateName, + 'root.loaded.saved', + 'We are loaded initially' + ); + + assert.equal(record.get('bike.name'), 'mr bike'); + + // we test that we can sync call unloadRecord followed by findRecord + let wait = run(() => { + store.unloadRecord(record); + assert.equal(record.isDestroying, true, 'the record is destroying'); + assert.equal(record.isDestroyed, false, 'the record is NOT YET destroyed'); + assert.equal( + internalModel.currentState.stateName, + 'root.empty', + 'We are unloaded after unloadRecord' + ); + + let wait = store.findRecord('person', '1').then(newRecord => { + assert.equal(record.isDestroyed, false, 'the record is NOT YET destroyed'); + assert.ok( + newRecord.get('bike') === bike, + 'the newRecord should retain knowledge of the bike' + ); + }); + + assert.equal(record.isDestroyed, false, 'the record is NOT YET destroyed'); + return wait; + }); + + assert.equal(record.isDestroyed, true, 'the record IS destroyed'); + return wait; + }); + + test('after unloading a record, the record can be fetched again soon there after', function(assert) { + let record; + + // stub findRecord + adapter.findRecord = () => { + return EmberPromise.resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + }); + }; + + // populate initial record + run(function() { + record = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + }); + }); + + let internalModel = record._internalModel; + assert.equal( + internalModel.currentState.stateName, + 'root.loaded.saved', + 'We are loaded initially' + ); + + run(function() { + store.unloadRecord(record); + assert.equal(record.isDestroying, true, 'the record is destroying'); + assert.equal( + internalModel.currentState.stateName, + 'root.empty', + 'We are unloaded after unloadRecord' + ); + }); + + run(function() { + store.findRecord('person', '1'); + }); + + record = store.peekRecord('person', '1'); + internalModel = record._internalModel; + + assert.equal( + internalModel.currentState.stateName, + 'root.loaded.saved', + 'We are loaded after findRecord' + ); + }); + + test('after unloading a record, the record can be saved again immediately', function(assert) { + assert.expect(0); + + const data = { + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + }; + + adapter.createRecord = () => EmberPromise.resolve(data); + + run(() => { + // add an initial record with id '1' to the store + store.push(data); + + // unload the initial record + store.peekRecord('person', '1').unloadRecord(); + + // create a new record that will again get id '1' from the backend + store.createRecord('person').save(); + }); + }); + + test('after unloading a record, pushing a new copy will setup relationships', function(assert) { + const personData = { + data: { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', + }, + }, + }; + + function pushCar() { + store.push({ + data: { + type: 'car', + id: '10', + attributes: { + make: 'VW', + model: 'Beetle', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, + }); + } + + run(() => { + store.push(personData); + }); + + let adam = store.peekRecord('person', 1); + assert.equal(adam.get('cars.length'), 0, 'cars hasMany starts off empty'); + + run(() => pushCar()); + assert.equal(adam.get('cars.length'), 1, 'pushing car setups inverse relationship'); + + run(() => adam.get('cars.firstObject').unloadRecord()); + assert.equal(adam.get('cars.length'), 0, 'unloading car cleaned up hasMany'); + + run(() => pushCar()); + assert.equal(adam.get('cars.length'), 1, 'pushing car again setups inverse relationship'); + }); + + test('1:1 sync unload', function(assert) { + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + house: { + data: { + id: 2, + type: 'house', + }, + }, + }, + }, + included: [ + { + id: 2, + type: 'house', + }, + ], + }) + ); + + let person = store.peekRecord('person', 1); + let house = store.peekRecord('house', 2); + + assert.equal(person.get('house.id'), 2, 'initially relationship established lhs'); + assert.equal(house.get('person.id'), 1, 'initially relationship established rhs'); + + run(() => house.unloadRecord()); + + assert.equal(person.get('house'), null, 'unloading acts as a delete for sync relationships'); + assert.equal(store.hasRecordForId('house', 2), false, 'unloaded record gone from store'); + + house = run(() => + store.push({ + data: { + id: 2, + type: 'house', + }, + }) + ); + + assert.equal(store.hasRecordForId('house', 2), true, 'unloaded record can be restored'); + assert.equal( + person.get('house'), + null, + 'restoring unloaded record does not restore relationship' + ); + assert.equal( + house.get('person'), + null, + 'restoring unloaded record does not restore relationship' + ); + + run(() => + store.push({ + data: { + id: 2, + type: 'house', + relationships: { + person: { + data: { + id: 1, + type: 'person', + }, + }, + }, + }, + }) + ); + + assert.equal(person.get('house.id'), 2, 'after unloading, relationship can be restored'); + assert.equal(house.get('person.id'), 1, 'after unloading, relationship can be restored'); + }); + + test('1:many sync unload 1 side', function(assert) { + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + cars: { + data: [ + { + id: 2, + type: 'car', + }, + { + id: 3, + type: 'car', + }, + ], + }, + }, + }, + included: [ + { + id: 2, + type: 'car', + }, + { + id: 3, + type: 'car', + }, + ], + }) + ); + + let person = store.peekRecord('person', 1); + let car2 = store.peekRecord('car', 2); + let car3 = store.peekRecord('car', 3); + let cars = person.get('cars'); + + assert.equal(cars.isDestroyed, false, 'ManyArray not destroyed'); + assert.deepEqual( + person.get('cars').mapBy('id'), + ['2', '3'], + 'initialy relationship established lhs' + ); + assert.equal(car2.get('person.id'), 1, 'initially relationship established rhs'); + assert.equal(car3.get('person.id'), 1, 'initially relationship established rhs'); + + run(() => person.unloadRecord()); + + assert.equal(store.hasRecordForId('person', 1), false, 'unloaded record gone from store'); + + assert.equal(car2.get('person'), null, 'unloading acts as delete for sync relationships'); + assert.equal(car3.get('person'), null, 'unloading acts as delete for sync relationships'); + assert.equal(cars.isDestroyed, true, 'ManyArray destroyed'); + + person = run(() => + store.push({ + data: { + id: 1, + type: 'person', + }, + }) + ); + + assert.equal(store.hasRecordForId('person', 1), true, 'unloaded record can be restored'); + assert.deepEqual( + person.get('cars').mapBy('id'), + [], + 'restoring unloaded record does not restore relationship' + ); + assert.equal( + car2.get('person'), + null, + 'restoring unloaded record does not restore relationship' + ); + assert.equal( + car3.get('person'), + null, + 'restoring unloaded record does not restore relationship' + ); + + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + cars: { + data: [ + { + id: 2, + type: 'car', + }, + { + id: 3, + type: 'car', + }, + ], + }, + }, + }, + }) + ); + + assert.equal(car2.get('person.id'), '1', 'after unloading, relationship can be restored'); + assert.equal(car3.get('person.id'), '1', 'after unloading, relationship can be restored'); + assert.deepEqual( + person.get('cars').mapBy('id'), + ['2', '3'], + 'after unloading, relationship can be restored' + ); + }); + + test('1:many sync unload many side', function(assert) { + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + cars: { + data: [ + { + id: 2, + type: 'car', + }, + { + id: 3, + type: 'car', + }, + ], + }, + }, + }, + included: [ + { + id: 2, + type: 'car', + }, + { + id: 3, + type: 'car', + }, + ], + }) + ); + + let person = store.peekRecord('person', 1); + let car2 = store.peekRecord('car', 2); + let car3 = store.peekRecord('car', 3); + let cars = person.get('cars'); + + assert.equal(cars.isDestroyed, false, 'ManyArray not destroyed'); + assert.deepEqual( + person.get('cars').mapBy('id'), + ['2', '3'], + 'initialy relationship established lhs' + ); + assert.equal(car2.get('person.id'), 1, 'initially relationship established rhs'); + assert.equal(car3.get('person.id'), 1, 'initially relationship established rhs'); + + run(() => car2.unloadRecord()); + + assert.equal(store.hasRecordForId('car', 2), false, 'unloaded record gone from store'); + + assert.equal(cars.isDestroyed, false, 'ManyArray not destroyed'); + assert.deepEqual( + person.get('cars').mapBy('id'), + ['3'], + 'unload sync relationship acts as delete' + ); + assert.equal( + car3.get('person.id'), + '1', + 'unloading one of a sync hasMany does not affect the rest' + ); + + car2 = run(() => + store.push({ + data: { + id: 2, + type: 'car', + }, + }) + ); + + assert.equal(store.hasRecordForId('car', 2), true, 'unloaded record can be restored'); + assert.deepEqual( + person.get('cars').mapBy('id'), + ['3'], + 'restoring unloaded record does not restore relationship' + ); + assert.equal( + car2.get('person'), + null, + 'restoring unloaded record does not restore relationship' + ); + + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + cars: { + data: [ + { + id: 2, + type: 'car', + }, + { + id: 3, + type: 'car', + }, + ], + }, + }, + }, + }) + ); + + assert.equal(car2.get('person.id'), '1', 'after unloading, relationship can be restored'); + assert.deepEqual( + person.get('cars').mapBy('id'), + ['2', '3'], + 'after unloading, relationship can be restored' + ); + }); + + test('many:many sync unload', function(assert) { + run(() => + store.push({ + data: [ + { + id: 1, + type: 'person', + relationships: { + groups: { + data: [ + { + id: 3, + type: 'group', + }, + { + id: 4, + type: 'group', + }, + ], + }, + }, + }, + { + id: 2, + type: 'person', + relationships: { + groups: { + data: [ + { + id: 3, + type: 'group', + }, + { + id: 4, + type: 'group', + }, + ], + }, + }, + }, + ], + included: [ + { + id: 3, + type: 'group', + }, + { + id: 4, + type: 'group', + }, + ], + }) + ); + + let person1 = store.peekRecord('person', 1); + let person2 = store.peekRecord('person', 2); + let group3 = store.peekRecord('group', 3); + let group4 = store.peekRecord('group', 4); + let p2groups = person2.get('groups'); + let g3people = group3.get('people'); + + assert.deepEqual( + person1.get('groups').mapBy('id'), + ['3', '4'], + 'initially established relationship lhs' + ); + assert.deepEqual( + person2.get('groups').mapBy('id'), + ['3', '4'], + 'initially established relationship lhs' + ); + assert.deepEqual( + group3.get('people').mapBy('id'), + ['1', '2'], + 'initially established relationship lhs' + ); + assert.deepEqual( + group4.get('people').mapBy('id'), + ['1', '2'], + 'initially established relationship lhs' + ); + + assert.equal(p2groups.isDestroyed, false, 'groups is not destroyed'); + assert.equal(g3people.isDestroyed, false, 'people is not destroyed'); + + run(() => person2.unloadRecord()); + + assert.equal(p2groups.isDestroyed, true, 'groups (unloaded side) is destroyed'); + assert.equal(g3people.isDestroyed, false, 'people (inverse) is not destroyed'); + + assert.deepEqual( + person1.get('groups').mapBy('id'), + ['3', '4'], + 'unloaded record in many:many does not affect inverse of inverse' + ); + assert.deepEqual( + group3.get('people').mapBy('id'), + ['1'], + 'unloading acts as delete for sync relationships' + ); + assert.deepEqual( + group4.get('people').mapBy('id'), + ['1'], + 'unloading acts as delete for sync relationships' + ); + + assert.equal(store.hasRecordForId('person', 2), false, 'unloading removes record from store'); + + person2 = run(() => + store.push({ + data: { + id: 2, + type: 'person', + }, + }) + ); + + assert.equal(store.hasRecordForId('person', 2), true, 'unloaded record can be restored'); + assert.deepEqual( + person2.get('groups').mapBy('id'), + [], + 'restoring unloaded record does not restore relationship' + ); + assert.deepEqual( + group3.get('people').mapBy('id'), + ['1'], + 'restoring unloaded record does not restore relationship' + ); + assert.deepEqual( + group4.get('people').mapBy('id'), + ['1'], + 'restoring unloaded record does not restore relationship' + ); + + run(() => + store.push({ + data: { + id: 2, + type: 'person', + relationships: { + groups: { + data: [ + { + id: 3, + type: 'group', + }, + { + id: 4, + type: 'group', + }, + ], + }, + }, + }, + }) + ); + + assert.deepEqual( + person2.get('groups').mapBy('id'), + ['3', '4'], + 'after unloading, relationship can be restored' + ); + assert.deepEqual( + group3.get('people').mapBy('id'), + ['1', '2'], + 'after unloading, relationship can be restored' + ); + assert.deepEqual( + group4.get('people').mapBy('id'), + ['1', '2'], + 'after unloading, relationship can be restored' + ); + }); + + test('1:1 async unload', function(assert) { + let findRecordCalls = 0; + + adapter.findRecord = (store, type, id) => { + assert.equal(type, Mortgage, 'findRecord(_, type) is correct'); + assert.equal(id, '2', 'findRecord(_, _, id) is correct'); + ++findRecordCalls; + + return { + data: { + id: 2, + type: 'mortgage', + }, + }; + }; + + let person = run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + mortgage: { + data: { + id: 2, + type: 'mortgage', + }, + }, + }, + }, + }) + ); + let mortgage; + + return run(() => + person + .get('mortgage') + .then(asyncRecord => { + mortgage = asyncRecord; + return mortgage.get('person'); + }) + .then(() => { + assert.equal( + mortgage.belongsTo('person').id(), + '1', + 'initially relationship established lhs' + ); + assert.equal( + person.belongsTo('mortgage').id(), + '2', + 'initially relationship established rhs' + ); + + run(() => mortgage.unloadRecord()); + + assert.equal( + person.belongsTo('mortgage').id(), + '2', + 'unload async is not treated as delete' + ); + + return person.get('mortgage'); + }) + .then(refetchedMortgage => { + assert.notEqual( + mortgage, + refetchedMortgage, + 'the previously loaded record is not reused' + ); + + assert.equal( + person.belongsTo('mortgage').id(), + '2', + 'unload async is not treated as delete' + ); + assert.equal( + refetchedMortgage.belongsTo('person').id(), + '1', + 'unload async is not treated as delete' + ); + assert.equal(findRecordCalls, 2); + }) + ); + }); + + test('1:many async unload 1 side', function(assert) { + let findRecordCalls = 0; + let findManyCalls = 0; + + adapter.coalesceFindRequests = true; + + adapter.findRecord = (store, type, id) => { + assert.equal(type, Person, 'findRecord(_, type) is correct'); + assert.deepEqual(id, '1', 'findRecord(_, _, id) is correct'); + ++findRecordCalls; + + return { + data: { + id: 1, + type: 'person', + }, + }; + }; + + adapter.findMany = (store, type, ids) => { + assert.equal(type + '', Boat + '', 'findMany(_, type) is correct'); + assert.deepEqual(ids, ['2', '3'], 'findMany(_, _, ids) is correct'); + ++findManyCalls; + + return { + data: [ + { + id: 2, + type: 'boat', + }, + { + id: 3, + type: 'boat', + }, + ], + }; + }; + + let person = run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + boats: { + data: [ + { + id: 2, + type: 'boat', + }, + { + id: 3, + type: 'boat', + }, + ], + }, + }, + }, + }) + ); + let boats, boat2, boat3; + + return run(() => + person + .get('boats') + .then(asyncRecords => { + boats = asyncRecords; + [boat2, boat3] = boats.toArray(); + return EmberPromise.all([boat2, boat3].map(b => b.get('person'))); + }) + .then(() => { + assert.deepEqual( + person.hasMany('boats').ids(), + ['2', '3'], + 'initially relationship established lhs' + ); + assert.equal( + boat2.belongsTo('person').id(), + '1', + 'initially relationship established rhs' + ); + assert.equal( + boat3.belongsTo('person').id(), + '1', + 'initially relationship established rhs' + ); + + assert.equal(boats.isDestroyed, false, 'ManyArray is not destroyed'); + + run(() => person.unloadRecord()); + + assert.equal( + boats.isDestroyed, + false, + 'ManyArray is not destroyed when 1 side is unloaded' + ); + assert.equal( + boat2.belongsTo('person').id(), + '1', + 'unload async is not treated as delete' + ); + assert.equal( + boat3.belongsTo('person').id(), + '1', + 'unload async is not treated as delete' + ); + + return boat2.get('person'); + }) + .then(refetchedPerson => { + assert.notEqual(person, refetchedPerson, 'the previously loaded record is not reused'); + + assert.deepEqual( + person.hasMany('boats').ids(), + ['2', '3'], + 'unload async is not treated as delete' + ); + assert.equal( + boat2.belongsTo('person').id(), + '1', + 'unload async is not treated as delete' + ); + assert.equal( + boat3.belongsTo('person').id(), + '1', + 'unload async is not treated as delete' + ); + + assert.equal(findManyCalls, 1, 'findMany called as expected'); + assert.equal(findRecordCalls, 1, 'findRecord called as expected'); + }) + ); + }); + + test('1:many async unload many side', function(assert) { + let findManyCalls = 0; + + adapter.coalesceFindRequests = true; + + adapter.findMany = (store, type, ids) => { + assert.equal(type + '', Boat + '', 'findMany(_, type) is correct'); + assert.deepEqual(ids, ['2', '3'], 'findMany(_, _, ids) is correct'); + ++findManyCalls; + + return { + data: [ + { + id: 2, + type: 'boat', + }, + { + id: 3, + type: 'boat', + }, + ], + }; + }; + + let person = run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + boats: { + data: [ + { + id: 2, + type: 'boat', + }, + { + id: 3, + type: 'boat', + }, + ], + }, + }, + }, + }) + ); + let boats, boat2, boat3; + + return run(() => + person + .get('boats') + .then(asyncRecords => { + boats = asyncRecords; + [boat2, boat3] = boats.toArray(); + return EmberPromise.all([boat2, boat3].map(b => b.get('person'))); + }) + .then(() => { + assert.deepEqual( + person.hasMany('boats').ids(), + ['2', '3'], + 'initially relationship established lhs' + ); + assert.equal( + boat2.belongsTo('person').id(), + '1', + 'initially relationship established rhs' + ); + assert.equal( + boat3.belongsTo('person').id(), + '1', + 'initially relationship established rhs' + ); + + assert.deepEqual( + boats.mapBy('id'), + ['2', '3'], + 'many array is initially set up correctly' + ); + run(() => boat2.unloadRecord()); + assert.deepEqual( + boats.mapBy('id'), + ['3'], + 'unload async removes from previous many array' + ); + assert.equal(boats.isDestroyed, false, 'previous ManyArray not destroyed'); + + run(() => boat3.unloadRecord()); + assert.deepEqual(boats.mapBy('id'), [], 'unload async removes from previous many array'); + assert.equal(boats.isDestroyed, false, 'previous ManyArray not destroyed'); + + assert.deepEqual( + person.hasMany('boats').ids(), + ['2', '3'], + 'unload async is not treated as delete' + ); + assert.equal( + boat3.belongsTo('person').id(), + '1', + 'unload async is not treated as delete' + ); + + return person.get('boats'); + }) + .then(refetchedBoats => { + assert.equal( + boats.isDestroyed, + false, + 'previous ManyArray is not immediately destroyed after refetch' + ); + assert.equal( + boats.isDestroying, + true, + 'previous ManyArray is being destroyed immediately after refetch' + ); + assert.deepEqual(refetchedBoats.mapBy('id'), ['2', '3'], 'boats refetched'); + assert.deepEqual( + person.hasMany('boats').ids(), + ['2', '3'], + 'unload async is not treated as delete' + ); + assert.equal( + boat3.belongsTo('person').id(), + '1', + 'unload async is not treated as delete' + ); + + assert.equal(findManyCalls, 2, 'findMany called as expected'); + }) + ).then(() => { + assert.equal( + boats.isDestroyed, + true, + 'previous ManyArray is destroyed in the runloop after refetching' + ); + }); + }); + + test('many:many async unload', function(assert) { + let findManyCalls = 0; + + adapter.coalesceFindRequests = true; + + adapter.findMany = (store, type, ids) => { + assert.equal(type + '', Person + '', 'findMany(_, type) is correct'); + assert.deepEqual(ids, ['3', '4'], 'findMany(_, _, ids) is correct'); + ++findManyCalls; + + return { + data: [ + { + id: 3, + type: 'person', + }, + { + id: 4, + type: 'person', + }, + ], + }; + }; + + let [person1, person2] = run(() => + store.push({ + data: [ + { + id: 1, + type: 'person', + relationships: { + friends: { + data: [ + { + id: 3, + type: 'person', + }, + { + id: 4, + type: 'person', + }, + ], + }, + }, + }, + { + id: 2, + type: 'person', + relationships: { + friends: { + data: [ + { + id: 3, + type: 'person', + }, + { + id: 4, + type: 'person', + }, + ], + }, + }, + }, + ], + }) + ); + + let person1Friends, person3, person4; + + return run(() => + person1 + .get('friends') + .then(asyncRecords => { + person1Friends = asyncRecords; + [person3, person4] = person1Friends.toArray(); + return EmberPromise.all([person2, person3, person4].map(b => b.get('friends'))); + }) + .then(() => { + assert.deepEqual( + person1.hasMany('friends').ids(), + ['3', '4'], + 'initially relationship established lhs' + ); + assert.deepEqual( + person2.hasMany('friends').ids(), + ['3', '4'], + 'initially relationship established lhs' + ); + assert.deepEqual( + person3.hasMany('friends').ids(), + ['1', '2'], + 'initially relationship established rhs' + ); + assert.deepEqual( + person4.hasMany('friends').ids(), + ['1', '2'], + 'initially relationship established rhs' + ); + + run(() => person3.unloadRecord()); + assert.deepEqual( + person1Friends.mapBy('id'), + ['4'], + 'unload async removes from previous many array' + ); + assert.equal(person1Friends.isDestroyed, false, 'previous ManyArray not destroyed'); + + run(() => person4.unloadRecord()); + assert.deepEqual( + person1Friends.mapBy('id'), + [], + 'unload async removes from previous many array' + ); + assert.equal(person1Friends.isDestroyed, false, 'previous ManyArray not destroyed'); + + assert.deepEqual( + person1.hasMany('friends').ids(), + ['3', '4'], + 'unload async is not treated as delete' + ); + + return person1.get('friends'); + }) + .then(refetchedFriends => { + assert.equal( + person1Friends.isDestroyed, + false, + 'previous ManyArray is not immediately destroyed after refetch' + ); + assert.equal( + person1Friends.isDestroying, + true, + 'previous ManyArray is being destroyed immediately after refetch' + ); + assert.deepEqual(refetchedFriends.mapBy('id'), ['3', '4'], 'friends refetched'); + assert.deepEqual( + person1.hasMany('friends').ids(), + ['3', '4'], + 'unload async is not treated as delete' + ); + + assert.deepEqual( + refetchedFriends.map(p => p.hasMany('friends').ids()), + [['1', '2'], ['1', '2']], + 'unload async is not treated as delete' + ); + + assert.equal(findManyCalls, 2, 'findMany called as expected'); + }) + ).then(() => { + assert.equal( + person1Friends.isDestroyed, + true, + 'previous ManyArray is destroyed in the runloop after refetching' + ); + }); + }); + + test('1 sync : 1 async unload sync side', function(assert) { + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + favoriteBook: { + data: { + id: 2, + type: 'book', + }, + }, + }, + }, + included: [ + { + id: 2, + type: 'book', + }, + ], + }) + ); + + let person = store.peekRecord('person', 1); + let book = store.peekRecord('book', 2); + + return book.get('person').then(() => { + assert.equal(person.get('favoriteBook.id'), 2, 'initially relationship established lhs'); + assert.equal(book.belongsTo('person').id(), 1, 'initially relationship established rhs'); + + run(() => book.unloadRecord()); + + assert.equal(person.get('book'), null, 'unloading acts as a delete for sync relationships'); + assert.equal(store.hasRecordForId('book', 2), false, 'unloaded record gone from store'); + + book = run(() => + store.push({ + data: { + id: 2, + type: 'book', + }, + }) + ); + + assert.equal(store.hasRecordForId('book', 2), true, 'unloaded record can be restored'); + assert.equal( + person.get('book'), + null, + 'restoring unloaded record does not restore relationship' + ); + assert.equal( + book.belongsTo('person').id(), + null, + 'restoring unloaded record does not restore relationship' + ); + + run(() => + store.push({ + data: { + id: 2, + type: 'book', + relationships: { + person: { + data: { + id: 1, + type: 'person', + }, + }, + }, + }, + }) + ); + + assert.equal( + person.get('favoriteBook.id'), + 2, + 'after unloading, relationship can be restored' + ); + assert.equal(book.get('person.id'), 1, 'after unloading, relationship can be restored'); + }); + }); + + test('1 sync : 1 async unload async side', function(assert) { + let findRecordCalls = 0; + + adapter.findRecord = (store, type, id) => { + assert.equal(type, Person, 'findRecord(_, type) is correct'); + assert.equal(id, '1', 'findRecord(_, _, id) is correct'); + ++findRecordCalls; + + return { + data: { + id: 1, + type: 'person', + }, + }; + }; + + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + favoriteBook: { + data: { + id: 2, + type: 'book', + }, + }, + }, + }, + included: [ + { + id: 2, + type: 'book', + }, + ], + }) + ); + + let person = store.peekRecord('person', 1); + let book = store.peekRecord('book', 2); + + return run(() => + book + .get('person') + .then(() => { + assert.equal(person.get('favoriteBook.id'), 2, 'initially relationship established lhs'); + assert.equal(book.belongsTo('person').id(), 1, 'initially relationship established rhs'); + + run(() => person.unloadRecord()); + + assert.equal(book.belongsTo('person').id(), '1', 'unload async is not treated as delete'); + + return book.get('person'); + }) + .then(refetchedPerson => { + assert.notEqual(person, refetchedPerson, 'the previously loaded record is not reused'); + + assert.equal(book.belongsTo('person').id(), '1', 'unload async is not treated as delete'); + assert.equal( + refetchedPerson.get('favoriteBook.id'), + '2', + 'unload async is not treated as delete' + ); + assert.equal(findRecordCalls, 1); + }) + ); + }); + + test('1 async : many sync unload sync side', function(assert) { + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + favoriteSpoons: { + data: [ + { + id: 2, + type: 'spoon', + }, + { + id: 3, + type: 'spoon', + }, + ], + }, + }, + }, + included: [ + { + id: 2, + type: 'spoon', + }, + { + id: 3, + type: 'spoon', + }, + ], + }) + ); + + let person = store.peekRecord('person', 1); + let spoon2 = store.peekRecord('spoon', 2); + let spoon3 = store.peekRecord('spoon', 3); + let spoons = person.get('favoriteSpoons'); + + assert.equal(spoons.isDestroyed, false, 'ManyArray not destroyed'); + assert.deepEqual( + person.get('favoriteSpoons').mapBy('id'), + ['2', '3'], + 'initialy relationship established lhs' + ); + assert.equal(spoon2.belongsTo('person').id(), '1', 'initially relationship established rhs'); + assert.equal(spoon3.belongsTo('person').id(), '1', 'initially relationship established rhs'); + + run(() => spoon2.unloadRecord()); + + assert.equal(store.hasRecordForId('spoon', 2), false, 'unloaded record gone from store'); + + assert.equal(spoons.isDestroyed, false, 'ManyArray not destroyed'); + assert.deepEqual( + person.get('favoriteSpoons').mapBy('id'), + ['3'], + 'unload sync relationship acts as delete' + ); + assert.equal( + spoon3.belongsTo('person').id(), + '1', + 'unloading one of a sync hasMany does not affect the rest' + ); + + spoon2 = run(() => + store.push({ + data: { + id: 2, + type: 'spoon', + }, + }) + ); + + assert.equal(store.hasRecordForId('spoon', 2), true, 'unloaded record can be restored'); + assert.deepEqual( + person.get('favoriteSpoons').mapBy('id'), + ['3'], + 'restoring unloaded record does not restore relationship' + ); + assert.equal( + spoon2.belongsTo('person').id(), + null, + 'restoring unloaded record does not restore relationship' + ); + + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + favoriteSpoons: { + data: [ + { + id: 2, + type: 'spoon', + }, + { + id: 3, + type: 'spoon', + }, + ], + }, + }, + }, + }) + ); + + assert.equal( + spoon2.belongsTo('person').id(), + '1', + 'after unloading, relationship can be restored' + ); + assert.deepEqual( + person.get('favoriteSpoons').mapBy('id'), + ['2', '3'], + 'after unloading, relationship can be restored' + ); + }); + + test('1 async : many sync unload async side', function(assert) { + let findRecordCalls = 0; + + adapter.coalesceFindRequests = true; + + adapter.findRecord = (store, type, id) => { + assert.equal(type, Person, 'findRecord(_, type) is correct'); + assert.deepEqual(id, '1', 'findRecord(_, _, id) is correct'); + ++findRecordCalls; + + return { + data: { + id: 1, + type: 'person', + }, + }; + }; + + let person = run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + favoriteSpoons: { + data: [ + { + id: 2, + type: 'spoon', + }, + { + id: 3, + type: 'spoon', + }, + ], + }, + }, + }, + included: [ + { + id: 2, + type: 'spoon', + }, + { + id: 3, + type: 'spoon', + }, + ], + }) + ); + let spoon2 = store.peekRecord('spoon', 2); + let spoon3 = store.peekRecord('spoon', 3); + let spoons = person.get('favoriteSpoons'); + + return run(() => { + assert.deepEqual( + person.get('favoriteSpoons').mapBy('id'), + ['2', '3'], + 'initially relationship established lhs' + ); + assert.equal(spoon2.belongsTo('person').id(), '1', 'initially relationship established rhs'); + assert.equal(spoon3.belongsTo('person').id(), '1', 'initially relationship established rhs'); + + assert.equal(spoons.isDestroyed, false, 'ManyArray is not destroyed'); + + run(() => person.unloadRecord()); + + assert.equal(spoons.isDestroyed, false, 'ManyArray is not destroyed when 1 side is unloaded'); + assert.equal(spoon2.belongsTo('person').id(), '1', 'unload async is not treated as delete'); + assert.equal(spoon3.belongsTo('person').id(), '1', 'unload async is not treated as delete'); + + return spoon2.get('person'); + }).then(refetchedPerson => { + assert.notEqual(person, refetchedPerson, 'the previously loaded record is not reused'); + + assert.deepEqual( + person.get('favoriteSpoons').mapBy('id'), + ['2', '3'], + 'unload async is not treated as delete' + ); + assert.equal(spoon2.belongsTo('person').id(), '1', 'unload async is not treated as delete'); + assert.equal(spoon3.belongsTo('person').id(), '1', 'unload async is not treated as delete'); + + assert.equal(findRecordCalls, 1, 'findRecord called as expected'); + }); + }); + + test('1 sync : many async unload async side', function(assert) { + let findManyCalls = 0; + + adapter.coalesceFindRequests = true; + + adapter.findMany = (store, type, ids) => { + assert.equal(type + '', Show + '', 'findMany(_, type) is correct'); + assert.deepEqual(ids, ['2', '3'], 'findMany(_, _, ids) is correct'); + ++findManyCalls; + + return { + data: [ + { + id: 2, + type: 'show', + }, + { + id: 3, + type: 'show', + }, + ], + }; + }; + + let person = run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + favoriteShows: { + data: [ + { + id: 2, + type: 'show', + }, + { + id: 3, + type: 'show', + }, + ], + }, + }, + }, + }) + ); + + let shows, show2, show3; + + return run(() => + person + .get('favoriteShows') + .then(asyncRecords => { + shows = asyncRecords; + [show2, show3] = shows.toArray(); + + assert.deepEqual( + person.hasMany('favoriteShows').ids(), + ['2', '3'], + 'initially relationship established lhs' + ); + assert.equal(show2.get('person.id'), '1', 'initially relationship established rhs'); + assert.equal(show3.get('person.id'), '1', 'initially relationship established rhs'); + assert.deepEqual( + shows.mapBy('id'), + ['2', '3'], + 'many array is initially set up correctly' + ); + + run(() => show2.unloadRecord()); + + assert.deepEqual( + shows.mapBy('id'), + ['3'], + 'unload async removes from previous many array' + ); + assert.equal(shows.isDestroyed, false, 'previous many array not destroyed'); + + run(() => show3.unloadRecord()); + + assert.deepEqual(shows.mapBy('id'), [], 'unload async removes from previous many array'); + assert.equal(shows.isDestroyed, false, 'previous many array not destroyed'); + assert.deepEqual( + person.hasMany('favoriteShows').ids(), + ['2', '3'], + 'unload async is not treated as delete' + ); + + return person.get('favoriteShows'); + }) + .then(refetchedShows => { + assert.equal( + shows.isDestroyed, + false, + 'previous ManyArray is not immediately destroyed after refetch' + ); + assert.equal( + shows.isDestroying, + true, + 'previous ManyArray is being destroyed immediately after refetch' + ); + assert.deepEqual(refetchedShows.mapBy('id'), ['2', '3'], 'shows refetched'); + assert.deepEqual( + person.hasMany('favoriteShows').ids(), + ['2', '3'], + 'unload async is not treated as delete' + ); + + assert.equal(findManyCalls, 2, 'findMany called as expected'); + }) + ).then(() => { + assert.equal( + shows.isDestroyed, + true, + 'previous ManyArray is destroyed in the runloop after refetching' + ); + }); + }); + + test('1 sync : many async unload sync side', function(assert) { + let findManyCalls = 0; + + adapter.coalesceFindRequests = true; + + adapter.findMany = (store, type, ids) => { + assert.equal(type + '', Show + '', 'findMany(_, type) is correct'); + assert.deepEqual(ids, ['2', '3'], 'findMany(_, _, ids) is correct'); + ++findManyCalls; + + return { + data: [ + { + id: 2, + type: 'show', + }, + { + id: 3, + type: 'show', + }, + ], + }; + }; + + let person = run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + favoriteShows: { + data: [ + { + id: 2, + type: 'show', + }, + { + id: 3, + type: 'show', + }, + ], + }, + }, + }, + }) + ); + + let shows, show2, show3; + + return run(() => + person + .get('favoriteShows') + .then(asyncRecords => { + shows = asyncRecords; + [show2, show3] = shows.toArray(); + + assert.deepEqual( + person.hasMany('favoriteShows').ids(), + ['2', '3'], + 'initially relationship established lhs' + ); + assert.equal(show2.get('person.id'), '1', 'initially relationship established rhs'); + assert.equal(show3.get('person.id'), '1', 'initially relationship established rhs'); + assert.deepEqual( + shows.mapBy('id'), + ['2', '3'], + 'many array is initially set up correctly' + ); + + run(() => person.unloadRecord()); + + assert.equal(store.hasRecordForId('person', 1), false, 'unloaded record gone from store'); + + assert.equal(shows.isDestroyed, true, 'previous manyarray immediately destroyed'); + assert.equal( + show2.get('person.id'), + null, + 'unloading acts as delete for sync relationships' + ); + assert.equal( + show3.get('person.id'), + null, + 'unloading acts as delete for sync relationships' + ); + + person = run(() => + store.push({ + data: { + id: 1, + type: 'person', + }, + }) + ); + + assert.equal(store.hasRecordForId('person', 1), true, 'unloaded record can be restored'); + assert.deepEqual( + person.hasMany('favoriteShows').ids(), + [], + 'restoring unloaded record does not restore relationship' + ); + assert.equal( + show2.get('person.id'), + null, + 'restoring unloaded record does not restore relationship' + ); + assert.equal( + show3.get('person.id'), + null, + 'restoring unloaded record does not restore relationship' + ); + + run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + favoriteShows: { + data: [ + { + id: 2, + type: 'show', + }, + { + id: 3, + type: 'show', + }, + ], + }, + }, + }, + }) + ); + + assert.deepEqual( + person.hasMany('favoriteShows').ids(), + ['2', '3'], + 'relationship can be restored' + ); + + return person.get('favoriteShows'); + }) + .then(refetchedShows => { + assert.notEqual(refetchedShows, shows, 'ManyArray not reused'); + assert.deepEqual( + refetchedShows.mapBy('id'), + ['2', '3'], + 'unload async not treated as a delete' + ); + + assert.equal(findManyCalls, 1, 'findMany calls as expected'); + }) + ); + }); + + test('unload invalidates link promises', function(assert) { + let isUnloaded = false; + adapter.coalesceFindRequests = false; + + adapter.findRecord = (/* store, type, id */) => { + assert.notOk('Records only expected to be loaded via link'); + }; + + adapter.findHasMany = (store, snapshot, link) => { + assert.equal(snapshot.modelName, 'person', 'findHasMany(_, snapshot) is correct'); + assert.equal(link, 'boats', 'findHasMany(_, _, link) is correct'); + + let relationships = { + person: { + data: { + type: 'person', + id: 1, + }, + }, + }; + + let data = [ + { + id: 3, + type: 'boat', + relationships, + }, + ]; + + if (!isUnloaded) { + data.unshift({ + id: 2, + type: 'boat', + relationships, + }); + } + + return { + data, + }; + }; + + let person = run(() => + store.push({ + data: { + id: 1, + type: 'person', + relationships: { + boats: { + links: { related: 'boats' }, + }, + }, + }, + }) + ); + let boats, boat2, boat3; + + return run(() => + person + .get('boats') + .then(asyncRecords => { + boats = asyncRecords; + [boat2, boat3] = boats.toArray(); + }) + .then(() => { + assert.deepEqual( + person.hasMany('boats').ids(), + ['2', '3'], + 'initially relationship established rhs' + ); + assert.equal( + boat2.belongsTo('person').id(), + '1', + 'initially relationship established rhs' + ); + assert.equal( + boat3.belongsTo('person').id(), + '1', + 'initially relationship established rhs' + ); + + isUnloaded = true; + run(() => { + boat2.unloadRecord(); + person.get('boats'); + }); + + assert.deepEqual(boats.mapBy('id'), ['3'], 'unloaded boat is removed from ManyArray'); + }) + .then(() => { + return run(() => person.get('boats')); + }) + .then(newBoats => { + assert.equal(newBoats.length, 1, 'new ManyArray has only 1 boat after unload'); + }) + ); + }); + + test('fetching records cancels unloading', function(assert) { + adapter.findRecord = (store, type, id) => { + assert.equal(type, Person, 'findRecord(_, type) is correct'); + assert.deepEqual(id, '1', 'findRecord(_, _, id) is correct'); + + return { + data: { + id: 1, + type: 'person', + }, + }; + }; + + run(() => + store.push({ + data: { + id: 1, + type: 'person', + }, + }) + ); + + return run(() => + store + .findRecord('person', 1, { backgroundReload: true }) + .then(person => person.unloadRecord()) + ); + }); +}); diff --git a/tests/integration/references/belongs-to-test.js b/tests/integration/references/belongs-to-test.js new file mode 100644 index 00000000000..efbc7ab6b92 --- /dev/null +++ b/tests/integration/references/belongs-to-test.js @@ -0,0 +1,663 @@ +import { defer, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import DS from 'ember-data'; +import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +var env, Family; + +module('integration/references/belongs-to', { + beforeEach() { + Family = DS.Model.extend({ + persons: DS.hasMany(), + name: DS.attr(), + }); + var Person = DS.Model.extend({ + family: DS.belongsTo({ async: true }), + }); + + env = setupStore({ + person: Person, + family: Family, + }); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +testInDebug("record#belongsTo asserts when specified relationship doesn't exist", function(assert) { + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + }, + }); + }); + + assert.expectAssertion(function() { + run(function() { + person.belongsTo('unknown-relationship'); + }); + }, "There is no belongsTo relationship named 'unknown-relationship' on a model of modelClass 'person'"); +}); + +testInDebug( + "record#belongsTo asserts when the type of the specified relationship isn't the requested one", + function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + }, + }); + }); + + assert.expectAssertion(function() { + run(function() { + family.belongsTo('persons'); + }); + }, "You tried to get the 'persons' relationship on a 'family' via record.belongsTo('persons'), but the relationship is of kind 'hasMany'. Use record.hasMany('persons') instead."); + } +); + +test('record#belongsTo', function(assert) { + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + + assert.equal(familyReference.remoteType(), 'id'); + assert.equal(familyReference.type, 'family'); + assert.equal(familyReference.id(), 1); +}); + +test('record#belongsTo for a linked reference', function(assert) { + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + links: { related: '/families/1' }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + + assert.equal(familyReference.remoteType(), 'link'); + assert.equal(familyReference.type, 'family'); + assert.equal(familyReference.link(), '/families/1'); +}); + +test('BelongsToReference#parent is a reference to the parent where the relationship is defined', function(assert) { + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + }); + + var personReference = env.store.getReference('person', 1); + var familyReference = person.belongsTo('family'); + + assert.ok(personReference); + assert.equal(familyReference.parent, personReference); +}); + +test('BelongsToReference#meta() returns the most recent meta for the relationship', function(assert) { + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + links: { + related: '/families/1', + }, + meta: { + foo: true, + }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + assert.deepEqual(familyReference.meta(), { foo: true }); +}); + +test('push(object)', function(assert) { + var done = assert.async(); + + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + + run(function() { + var data = { + data: { + type: 'family', + id: 1, + attributes: { + name: 'Coreleone', + }, + }, + }; + + familyReference.push(data).then(function(record) { + assert.ok(Family.detectInstance(record), 'push resolves with the referenced record'); + assert.equal(get(record, 'name'), 'Coreleone', 'name is set'); + + done(); + }); + }); +}); + +testInDebug('push(record)', function(assert) { + var done = assert.async(); + + var person, family; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + family = env.store.push({ + data: { + type: 'family', + id: 1, + attributes: { + name: 'Coreleone', + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + + run(function() { + familyReference.push(family).then(function(record) { + assert.ok(Family.detectInstance(record), 'push resolves with the referenced record'); + assert.equal(get(record, 'name'), 'Coreleone', 'name is set'); + assert.equal(record, family); + + done(); + }); + }); +}); + +test('push(promise)', function(assert) { + var done = assert.async(); + + var push; + var deferred = defer(); + + run(function() { + var person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + var familyReference = person.belongsTo('family'); + push = familyReference.push(deferred.promise); + }); + + assert.ok(push.then, 'BelongsToReference.push returns a promise'); + + run(function() { + deferred.resolve({ + data: { + type: 'family', + id: 1, + attributes: { + name: 'Coreleone', + }, + }, + }); + }); + + run(function() { + push.then(function(record) { + assert.ok(Family.detectInstance(record), 'push resolves with the record'); + assert.equal(get(record, 'name'), 'Coreleone', 'name is updated'); + + done(); + }); + }); +}); + +testInDebug('push(record) asserts for invalid modelClass', function(assert) { + var person, anotherPerson; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + anotherPerson = env.store.push({ + data: { + type: 'person', + id: 2, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + + assert.expectAssertion(function() { + run(function() { + familyReference.push(anotherPerson); + }); + }, "The 'person' type does not implement 'family' and thus cannot be assigned to the 'family' relationship in 'person'. Make it a descendant of 'family' or use a mixin of the same name."); +}); + +testInDebug('push(record) works with polymorphic modelClass', function(assert) { + var done = assert.async(); + + var person, mafiaFamily; + + env.owner.register('model:mafia-family', Family.extend()); + + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + }, + }); + mafiaFamily = env.store.push({ + data: { + type: 'mafia-family', + id: 1, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + run(function() { + familyReference.push(mafiaFamily).then(function(family) { + assert.equal(family, mafiaFamily); + + done(); + }); + }); +}); + +test('value() is null when reference is not yet loaded', function(assert) { + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + assert.strictEqual(familyReference.value(), null); +}); + +test('value() returns the referenced record when loaded', function(assert) { + var person, family; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + family = env.store.push({ + data: { + type: 'family', + id: 1, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + assert.equal(familyReference.value(), family); +}); + +test('value() returns the referenced record when loaded even if links are present', function(assert) { + var person, family; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + links: { + related: '/this/should/not/matter', + }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + assert.equal(familyReference.value(), family); +}); + +test('load() fetches the record', function(assert) { + var done = assert.async(); + + const adapterOptions = { thing: 'one' }; + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); + return resolve({ + data: { + id: 1, + type: 'family', + attributes: { name: 'Coreleone' }, + }, + }); + }; + + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + + run(function() { + familyReference.load({ adapterOptions }).then(function(record) { + assert.equal(get(record, 'name'), 'Coreleone'); + + done(); + }); + }); +}); + +test('load() fetches link when remoteType is link', function(assert) { + var done = assert.async(); + + const adapterOptions = { thing: 'one' }; + + env.adapter.findBelongsTo = function(store, snapshot, link) { + assert.equal(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); + assert.equal(link, '/families/1'); + + return resolve({ + data: { + id: 1, + type: 'family', + attributes: { name: 'Coreleone' }, + }, + }); + }; + + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + links: { related: '/families/1' }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + assert.equal(familyReference.remoteType(), 'link'); + + run(function() { + familyReference.load({ adapterOptions }).then(function(record) { + assert.equal(get(record, 'name'), 'Coreleone'); + + done(); + }); + }); +}); + +test('reload() - loads the record when not yet loaded', function(assert) { + var done = assert.async(); + + const adapterOptions = { thing: 'one' }; + + var count = 0; + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); + + count++; + assert.equal(count, 1); + + return resolve({ + data: { + id: 1, + type: 'family', + attributes: { name: 'Coreleone' }, + }, + }); + }; + + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + + run(function() { + familyReference.reload({ adapterOptions }).then(function(record) { + assert.equal(get(record, 'name'), 'Coreleone'); + + done(); + }); + }); +}); + +test('reload() - reloads the record when already loaded', function(assert) { + var done = assert.async(); + + const adapterOptions = { thing: 'one' }; + + var count = 0; + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); + + count++; + assert.equal(count, 1); + + return resolve({ + data: { + id: 1, + type: 'family', + attributes: { name: 'Coreleone' }, + }, + }); + }; + + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + data: { type: 'family', id: 1 }, + }, + }, + }, + }); + env.store.push({ + data: { + type: 'family', + id: 1, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + + run(function() { + familyReference.reload({ adapterOptions }).then(function(record) { + assert.equal(get(record, 'name'), 'Coreleone'); + + done(); + }); + }); +}); + +test('reload() - uses link to reload record', function(assert) { + var done = assert.async(); + + const adapterOptions = { thing: 'one' }; + + env.adapter.findBelongsTo = function(store, snapshot, link) { + assert.equal(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); + + assert.equal(link, '/families/1'); + + return resolve({ + data: { + id: 1, + type: 'family', + attributes: { name: 'Coreleone' }, + }, + }); + }; + + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + relationships: { + family: { + links: { related: '/families/1' }, + }, + }, + }, + }); + }); + + var familyReference = person.belongsTo('family'); + + run(function() { + familyReference.reload({ adapterOptions }).then(function(record) { + assert.equal(get(record, 'name'), 'Coreleone'); + + done(); + }); + }); +}); diff --git a/tests/integration/references/has-many-test.js b/tests/integration/references/has-many-test.js new file mode 100755 index 00000000000..2d0d2721654 --- /dev/null +++ b/tests/integration/references/has-many-test.js @@ -0,0 +1,718 @@ +import { defer, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import DS from 'ember-data'; +import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +var env, Person; + +module('integration/references/has-many', { + beforeEach() { + var Family = DS.Model.extend({ + persons: DS.hasMany({ async: true }), + }); + Person = DS.Model.extend({ + name: DS.attr(), + family: DS.belongsTo(), + }); + env = setupStore({ + person: Person, + family: Family, + }); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +testInDebug("record#hasMany asserts when specified relationship doesn't exist", function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + }, + }); + }); + + assert.expectAssertion(function() { + run(function() { + family.hasMany('unknown-relationship'); + }); + }, "There is no hasMany relationship named 'unknown-relationship' on a model of modelClass 'family'"); +}); + +testInDebug( + "record#hasMany asserts when the type of the specified relationship isn't the requested one", + function(assert) { + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + }, + }); + }); + + assert.expectAssertion(function() { + run(function() { + person.hasMany('family'); + }); + }, "You tried to get the 'family' relationship on a 'person' via record.hasMany('family'), but the relationship is of kind 'belongsTo'. Use record.belongsTo('family') instead."); + } +); + +test('record#hasMany', function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + + assert.equal(personsReference.remoteType(), 'ids'); + assert.equal(personsReference.type, 'person'); + assert.deepEqual(personsReference.ids(), ['1', '2']); +}); + +test('record#hasMany for linked references', function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + links: { related: '/families/1/persons' }, + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + + assert.equal(personsReference.remoteType(), 'link'); + assert.equal(personsReference.type, 'person'); + assert.equal(personsReference.link(), '/families/1/persons'); +}); + +test('HasManyReference#parent is a reference to the parent where the relationship is defined', function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + }); + + var familyReference = env.store.getReference('family', 1); + var personsReference = family.hasMany('persons'); + + assert.ok(familyReference); + assert.equal(personsReference.parent, familyReference); +}); + +test('HasManyReference#meta() returns the most recent meta for the relationship', function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + links: { related: '/families/1/persons' }, + meta: { + foo: true, + }, + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + assert.deepEqual(personsReference.meta(), { foo: true }); +}); + +testInDebug('push(array)', function(assert) { + var done = assert.async(); + + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + + run(function() { + var data = [ + { data: { type: 'person', id: 1, attributes: { name: 'Vito' } } }, + { data: { type: 'person', id: 2, attributes: { name: 'Michael' } } }, + ]; + + personsReference.push(data).then(function(records) { + assert.ok(records instanceof DS.ManyArray, 'push resolves with the referenced records'); + assert.equal(get(records, 'length'), 2); + assert.equal(records.objectAt(0).get('name'), 'Vito'); + assert.equal(records.objectAt(1).get('name'), 'Michael'); + + done(); + }); + }); +}); + +testInDebug('push(array) works with polymorphic type', function(assert) { + var done = assert.async(); + + env.owner.register('model:mafia-boss', Person.extend()); + + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + + run(() => { + var data = [{ data: { type: 'mafia-boss', id: 1, attributes: { name: 'Vito' } } }]; + + personsReference.push(data).then(function(records) { + assert.ok(records instanceof DS.ManyArray, 'push resolves with the referenced records'); + assert.equal(get(records, 'length'), 1); + assert.equal(records.objectAt(0).get('name'), 'Vito'); + + done(); + }); + }); +}); + +testInDebug('push(array) asserts polymorphic type', function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + + assert.expectAssertion(() => { + run(() => { + var data = [{ data: { type: 'family', id: 1 } }]; + + personsReference.push(data); + }); + }, "The 'family' type does not implement 'person' and thus cannot be assigned to the 'persons' relationship in 'family'. Make it a descendant of 'person' or use a mixin of the same name."); +}); + +testInDebug('push(object) supports legacy, non-JSON-API-conform payload', function(assert) { + var done = assert.async(); + + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + + run(function() { + var payload = { + data: [ + { data: { type: 'person', id: 1, attributes: { name: 'Vito' } } }, + { data: { type: 'person', id: 2, attributes: { name: 'Michael' } } }, + ], + }; + + personsReference.push(payload).then(function(records) { + assert.ok(records instanceof DS.ManyArray, 'push resolves with the referenced records'); + assert.equal(get(records, 'length'), 2); + assert.equal(records.objectAt(0).get('name'), 'Vito'); + assert.equal(records.objectAt(1).get('name'), 'Michael'); + + done(); + }); + }); +}); + +test('push(promise)', function(assert) { + var done = assert.async(); + + var push; + var deferred = defer(); + + run(function() { + var family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + var personsReference = family.hasMany('persons'); + push = personsReference.push(deferred.promise); + }); + + assert.ok(push.then, 'HasManyReference.push returns a promise'); + + run(function() { + var payload = { + data: [ + { data: { type: 'person', id: 1, attributes: { name: 'Vito' } } }, + { data: { type: 'person', id: 2, attributes: { name: 'Michael' } } }, + ], + }; + + deferred.resolve(payload); + }); + + run(function() { + push.then(function(records) { + assert.ok(records instanceof DS.ManyArray, 'push resolves with the referenced records'); + assert.equal(get(records, 'length'), 2); + assert.equal(records.objectAt(0).get('name'), 'Vito'); + assert.equal(records.objectAt(1).get('name'), 'Michael'); + + done(); + }); + }); +}); + +test('value() returns null when reference is not yet loaded', function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + assert.strictEqual(personsReference.value(), null); +}); + +test('value() returns the referenced records when all records are loaded', function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + env.store.push({ data: { type: 'person', id: 1, attributes: { name: 'Vito' } } }); + env.store.push({ data: { type: 'person', id: 2, attributes: { name: 'Michael' } } }); + }); + + run(function() { + var personsReference = family.hasMany('persons'); + var records = personsReference.value(); + assert.equal(get(records, 'length'), 2); + assert.equal(records.isEvery('isLoaded'), true); + }); +}); + +test('value() returns an empty array when the reference is loaded and empty', function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [], + }, + }, + }, + }); + }); + + run(function() { + var personsReference = family.hasMany('persons'); + var records = personsReference.value(); + assert.equal(get(records, 'length'), 0); + }); +}); + +test('_isLoaded() returns an true array when the reference is loaded and empty', function(assert) { + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [], + }, + }, + }, + }); + }); + + run(function() { + var personsReference = family.hasMany('persons'); + var isLoaded = personsReference._isLoaded(); + assert.equal(isLoaded, true); + }); +}); + +test('load() fetches the referenced records', function(assert) { + var done = assert.async(); + + const adapterOptions = { thing: 'one' }; + + env.adapter.findMany = function(store, type, id, snapshots) { + assert.equal(snapshots[0].adapterOptions, adapterOptions, 'adapterOptions are passed in'); + return resolve({ + data: [ + { id: 1, type: 'person', attributes: { name: 'Vito' } }, + { id: 2, type: 'person', attributes: { name: 'Michael' } }, + ], + }); + }; + + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + + run(function() { + personsReference.load({ adapterOptions }).then(function(records) { + assert.ok(records instanceof DS.ManyArray, 'push resolves with the referenced records'); + assert.equal(get(records, 'length'), 2); + assert.equal(records.objectAt(0).get('name'), 'Vito'); + assert.equal(records.objectAt(1).get('name'), 'Michael'); + + done(); + }); + }); +}); + +test('load() fetches link when remoteType is link', function(assert) { + var done = assert.async(); + + const adapterOptions = { thing: 'one' }; + + env.adapter.findHasMany = function(store, snapshot, link) { + assert.equal(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); + assert.equal(link, '/families/1/persons'); + + return resolve({ + data: [ + { id: 1, type: 'person', attributes: { name: 'Vito' } }, + { id: 2, type: 'person', attributes: { name: 'Michael' } }, + ], + }); + }; + + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + links: { related: '/families/1/persons' }, + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + assert.equal(personsReference.remoteType(), 'link'); + + run(function() { + personsReference.load({ adapterOptions }).then(function(records) { + assert.ok(records instanceof DS.ManyArray, 'push resolves with the referenced records'); + assert.equal(get(records, 'length'), 2); + assert.equal(records.objectAt(0).get('name'), 'Vito'); + assert.equal(records.objectAt(1).get('name'), 'Michael'); + + done(); + }); + }); +}); + +test('load() fetches link when remoteType is link but an empty set of records is returned', function(assert) { + const adapterOptions = { thing: 'one' }; + + env.adapter.findHasMany = function(store, snapshot, link) { + assert.equal(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); + assert.equal(link, '/families/1/persons'); + + return resolve({ data: [] }); + }; + + let family; + run(() => { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + links: { related: '/families/1/persons' }, + }, + }, + }, + }); + }); + + let personsReference = family.hasMany('persons'); + assert.equal(personsReference.remoteType(), 'link'); + + return run(() => { + return personsReference.load({ adapterOptions }).then(records => { + assert.ok(records instanceof DS.ManyArray, 'push resolves with the referenced records'); + assert.equal(get(records, 'length'), 0); + assert.equal(get(personsReference.value(), 'length'), 0); + }); + }); +}); + +test('load() - only a single find is triggered', function(assert) { + var done = assert.async(); + + var deferred = defer(); + var count = 0; + + env.adapter.findMany = function(store, type, id) { + count++; + assert.equal(count, 1); + + return deferred.promise; + }; + + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + + run(function() { + personsReference.load(); + personsReference.load().then(function(records) { + assert.equal(get(records, 'length'), 2); + }); + }); + + run(function() { + deferred.resolve({ + data: [ + { id: 1, type: 'person', attributes: { name: 'Vito' } }, + { id: 2, type: 'person', attributes: { name: 'Michael' } }, + ], + }); + }); + + run(function() { + personsReference.load().then(function(records) { + assert.equal(get(records, 'length'), 2); + + done(); + }); + }); +}); + +test('reload()', function(assert) { + var done = assert.async(); + + const adapterOptions = { thing: 'one' }; + + env.adapter.findMany = function(store, type, id, snapshots) { + assert.equal(snapshots[0].adapterOptions, adapterOptions, 'adapterOptions are passed in'); + return resolve({ + data: [ + { id: 1, type: 'person', attributes: { name: 'Vito Coreleone' } }, + { id: 2, type: 'person', attributes: { name: 'Michael Coreleone' } }, + ], + }); + }; + + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + data: [{ type: 'person', id: 1 }, { type: 'person', id: 2 }], + }, + }, + }, + }); + env.store.push({ data: { type: 'person', id: 1, attributes: { name: 'Vito' } } }); + env.store.push({ data: { type: 'person', id: 2, attributes: { name: 'Michael' } } }); + }); + + var personsReference = family.hasMany('persons'); + + run(function() { + personsReference.reload({ adapterOptions }).then(function(records) { + assert.ok(records instanceof DS.ManyArray, 'push resolves with the referenced records'); + assert.equal(get(records, 'length'), 2); + assert.equal(records.objectAt(0).get('name'), 'Vito Coreleone'); + assert.equal(records.objectAt(1).get('name'), 'Michael Coreleone'); + + done(); + }); + }); +}); + +test('reload() fetches link when remoteType is link', function(assert) { + var done = assert.async(); + const adapterOptions = { thing: 'one' }; + + var count = 0; + env.adapter.findHasMany = function(store, snapshot, link) { + assert.equal(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); + count++; + assert.equal(link, '/families/1/persons'); + + if (count === 1) { + return resolve({ + data: [ + { id: 1, type: 'person', attributes: { name: 'Vito' } }, + { id: 2, type: 'person', attributes: { name: 'Michael' } }, + ], + }); + } else { + return resolve({ + data: [ + { id: 1, type: 'person', attributes: { name: 'Vito Coreleone' } }, + { id: 2, type: 'person', attributes: { name: 'Michael Coreleone' } }, + ], + }); + } + }; + + var family; + run(function() { + family = env.store.push({ + data: { + type: 'family', + id: 1, + relationships: { + persons: { + links: { related: '/families/1/persons' }, + }, + }, + }, + }); + }); + + var personsReference = family.hasMany('persons'); + assert.equal(personsReference.remoteType(), 'link'); + + run(function() { + personsReference + .load({ adapterOptions }) + .then(function() { + return personsReference.reload({ adapterOptions }); + }) + .then(function(records) { + assert.ok(records instanceof DS.ManyArray, 'push resolves with the referenced records'); + assert.equal(get(records, 'length'), 2); + assert.equal(records.objectAt(0).get('name'), 'Vito Coreleone'); + assert.equal(records.objectAt(1).get('name'), 'Michael Coreleone'); + + done(); + }); + }); +}); diff --git a/tests/integration/references/record-test.js b/tests/integration/references/record-test.js new file mode 100644 index 00000000000..d5484cfd814 --- /dev/null +++ b/tests/integration/references/record-test.js @@ -0,0 +1,260 @@ +import { defer, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import DS from 'ember-data'; +import setupStore from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; + +var env, Person; + +module('integration/references/record', { + beforeEach() { + Person = DS.Model.extend({ + name: DS.attr(), + }); + + env = setupStore({ + person: Person, + }); + }, + + afterEach() { + run(env.store, 'unloadAll'); + run(env.container, 'destroy'); + }, +}); + +test('a RecordReference can be retrieved via store.getReference(type, id)', function(assert) { + var recordReference = env.store.getReference('person', 1); + + assert.equal(recordReference.remoteType(), 'identity'); + assert.equal(recordReference.type, 'person'); + assert.equal(recordReference.id(), 1); +}); + +test('push(object)', function(assert) { + var done = assert.async(); + + var push; + var recordReference = env.store.getReference('person', 1); + + run(function() { + push = recordReference.push({ + data: { + type: 'person', + id: 1, + attributes: { + name: 'le name', + }, + }, + }); + }); + + assert.ok(push.then, 'RecordReference.push returns a promise'); + + run(function() { + push.then(function(record) { + assert.ok(record instanceof Person, 'push resolves with the record'); + assert.equal(get(record, 'name'), 'le name'); + + done(); + }); + }); +}); + +test('push(promise)', function(assert) { + var done = assert.async(); + + var push; + var deferred = defer(); + var recordReference = env.store.getReference('person', 1); + + run(function() { + push = recordReference.push(deferred.promise); + }); + + assert.ok(push.then, 'RecordReference.push returns a promise'); + + run(function() { + deferred.resolve({ + data: { + type: 'person', + id: 1, + attributes: { + name: 'le name', + }, + }, + }); + }); + + run(function() { + push.then(function(record) { + assert.ok(record instanceof Person, 'push resolves with the record'); + assert.equal(get(record, 'name'), 'le name', 'name is updated'); + + done(); + }); + }); +}); + +test('value() returns null when not yet loaded', function(assert) { + var recordReference = env.store.getReference('person', 1); + assert.strictEqual(recordReference.value(), null); +}); + +test('value() returns the record when loaded', function(assert) { + var person; + run(function() { + person = env.store.push({ + data: { + type: 'person', + id: 1, + }, + }); + }); + + var recordReference = env.store.getReference('person', 1); + assert.equal(recordReference.value(), person); +}); + +test('load() fetches the record', function(assert) { + var done = assert.async(); + + env.adapter.findRecord = function(store, type, id) { + return resolve({ + data: { + id: 1, + type: 'person', + attributes: { + name: 'Vito', + }, + }, + }); + }; + + var recordReference = env.store.getReference('person', 1); + + run(function() { + recordReference.load().then(function(record) { + assert.equal(get(record, 'name'), 'Vito'); + done(); + }); + }); +}); + +test('load() only a single find is triggered', function(assert) { + var done = assert.async(); + + var deferred = defer(); + var count = 0; + + env.adapter.shouldReloadRecord = function() { + return false; + }; + env.adapter.shouldBackgroundReloadRecord = function() { + return false; + }; + env.adapter.findRecord = function(store, type, id) { + count++; + assert.equal(count, 1); + + return deferred.promise; + }; + + var recordReference = env.store.getReference('person', 1); + + run(function() { + recordReference.load(); + recordReference.load().then(function(record) { + assert.equal(get(record, 'name'), 'Vito'); + }); + }); + + run(function() { + deferred.resolve({ + data: { + id: 1, + type: 'person', + attributes: { + name: 'Vito', + }, + }, + }); + }); + + run(function() { + recordReference.load().then(function(record) { + assert.equal(get(record, 'name'), 'Vito'); + + done(); + }); + }); +}); + +test('reload() loads the record if not yet loaded', function(assert) { + var done = assert.async(); + + var count = 0; + env.adapter.findRecord = function(store, type, id) { + count++; + assert.equal(count, 1); + + return resolve({ + data: { + id: 1, + type: 'person', + attributes: { + name: 'Vito Coreleone', + }, + }, + }); + }; + + var recordReference = env.store.getReference('person', 1); + + run(function() { + recordReference.reload().then(function(record) { + assert.equal(get(record, 'name'), 'Vito Coreleone'); + + done(); + }); + }); +}); + +test('reload() fetches the record', function(assert) { + var done = assert.async(); + + env.adapter.findRecord = function(store, type, id) { + return resolve({ + data: { + id: 1, + type: 'person', + attributes: { + name: 'Vito Coreleone', + }, + }, + }); + }; + + run(function() { + env.store.push({ + data: { + type: 'person', + id: 1, + attributes: { + name: 'Vito', + }, + }, + }); + }); + + var recordReference = env.store.getReference('person', 1); + + run(function() { + recordReference.reload().then(function(record) { + assert.equal(get(record, 'name'), 'Vito Coreleone'); + + done(); + }); + }); +}); diff --git a/tests/integration/relationships/belongs-to-test.js b/tests/integration/relationships/belongs-to-test.js new file mode 100644 index 00000000000..77d8b5940d8 --- /dev/null +++ b/tests/integration/relationships/belongs-to-test.js @@ -0,0 +1,2078 @@ +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import RSVP, { resolve } from 'rsvp'; +import setupStore from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import { setupTest } from 'ember-qunit'; +import Store from 'ember-data/store'; +import Model from 'ember-data/model'; +import { attr, belongsTo } from '@ember-decorators/data'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import DS from 'ember-data'; +import { + RecordData, + recordDataFor, + relationshipsFor, + relationshipStateFor, +} from 'ember-data/-private'; + +const { attr: DSattr, hasMany: DShasMany, belongsTo: DSbelongsTo } = DS; +const { hash } = RSVP; + +let env, store, User, Message, Post, Comment, Book, Book1, Chapter, Author, NewMessage, Section; + +module('integration/relationship/belongs-to BelongsTo Relationships (new-style)', function(hooks) { + let store; + setupTest(hooks); + + class Person extends Model { + @belongsTo('pet', { inverse: 'bestHuman', async: true }) + bestDog; + @attr + name; + } + + class Pet extends Model { + @belongsTo('person', { inverse: 'bestDog', async: false }) + bestHuman; + @attr + name; + } + + hooks.beforeEach(function() { + let { owner } = this; + owner.register('service:store', Store); + owner.register('model:person', Person); + owner.register('model:pet', Pet); + owner.register( + 'serializer:application', + JSONAPISerializer.extend({ + normalizeResponse(_, __, payload) { + return payload; + }, + }) + ); + store = owner.lookup('service:store'); + }); + + test("async belongsTo chains the related record's loading promise when present", async function(assert) { + let petFindRecordCalls = 0; + this.owner.register( + 'adapter:pet', + JSONAPIAdapter.extend({ + findRecord() { + assert.equal(++petFindRecordCalls, 1, 'We call findRecord only once for our pet'); + return resolve({ + data: { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + bestHuman: { + data: { type: 'person', id: '1' }, + }, + }, + }, + }); + }, + findBelongsTo() { + return this.store.adapterFor('person').findRecord(); + }, + }) + ); + let personFindRecordCalls = 0; + this.owner.register( + 'adapter:person', + JSONAPIAdapter.extend({ + findRecord() { + assert.equal(++personFindRecordCalls, 1, 'We call findRecord only once for our person'); + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { name: 'Chris' }, + relationships: { + bestDog: { + data: { type: 'pet', id: '1' }, + links: { + related: './pet/1', + }, + }, + }, + }, + }); + }, + findBelongsTo() { + return this.store.adapterFor('pet').findRecord(); + }, + }) + ); + + let person = await store.findRecord('person', '1'); + let petRequest = store.findRecord('pet', '1'); + let personPetRequest = person.get('bestDog'); + let personPet = await personPetRequest; + let pet = await petRequest; + + assert.ok(personPet === pet, 'We ended up in the same state'); + }); + + test('async belongsTo returns correct new value after a local change', async function(assert) { + let chris = store.push({ + data: { + type: 'person', + id: '1', + attributes: { name: 'Chris' }, + relationships: { + bestDog: { + data: null, + }, + }, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { name: 'Shen' }, + relationships: { + bestHuman: { + data: null, + }, + }, + }, + { + type: 'pet', + id: '2', + attributes: { name: 'Pirate' }, + relationships: { + bestHuman: { + data: null, + }, + }, + }, + ], + }); + + let shen = store.peekRecord('pet', '1'); + let pirate = store.peekRecord('pet', '2'); + let bestDog = await chris.get('bestDog'); + + assert.ok(shen.get('bestHuman') === null, 'precond - Shen has no best human'); + assert.ok(pirate.get('bestHuman') === null, 'precond - pirate has no best human'); + assert.ok(bestDog === null, 'precond - Chris has no best dog'); + + chris.set('bestDog', shen); + bestDog = await chris.get('bestDog'); + + assert.ok(shen.get('bestHuman') === chris, "scene 1 - Chris is Shen's best human"); + assert.ok(pirate.get('bestHuman') === null, 'scene 1 - pirate has no best human'); + assert.ok(bestDog === shen, "scene 1 - Shen is Chris's best dog"); + + chris.set('bestDog', pirate); + bestDog = await chris.get('bestDog'); + + assert.ok(shen.get('bestHuman') === null, "scene 2 - Chris is no longer Shen's best human"); + assert.ok(pirate.get('bestHuman') === chris, 'scene 2 - pirate now has Chris as best human'); + assert.ok(bestDog === pirate, "scene 2 - Pirate is now Chris's best dog"); + + chris.set('bestDog', null); + bestDog = await chris.get('bestDog'); + + assert.ok( + shen.get('bestHuman') === null, + "scene 3 - Chris remains no longer Shen's best human" + ); + assert.ok( + pirate.get('bestHuman') === null, + 'scene 3 - pirate no longer has Chris as best human' + ); + assert.ok(bestDog === null, 'scene 3 - Chris has no best dog'); + }); +}); + +module('integration/relationship/belongs_to Belongs-To Relationships', { + beforeEach() { + User = DS.Model.extend({ + name: DSattr('string'), + messages: DShasMany('message', { polymorphic: true, async: false }), + favouriteMessage: DSbelongsTo('message', { polymorphic: true, inverse: null, async: false }), + }); + + Message = DS.Model.extend({ + user: DSbelongsTo('user', { inverse: 'messages', async: false }), + created_at: DSattr('date'), + }); + + Post = Message.extend({ + title: DSattr('string'), + comments: DShasMany('comment', { async: false, inverse: null }), + }); + + Comment = Message.extend({ + body: DS.attr('string'), + message: DS.belongsTo('message', { polymorphic: true, async: false, inverse: null }), + }); + + Book = DS.Model.extend({ + name: DSattr('string'), + author: DSbelongsTo('author', { async: false }), + chapters: DShasMany('chapters', { async: false, inverse: 'book' }), + }); + + Book1 = DS.Model.extend({ + name: DSattr('string'), + }); + + Chapter = DS.Model.extend({ + title: DSattr('string'), + book: DSbelongsTo('book', { async: false, inverse: 'chapters' }), + }); + + Author = DS.Model.extend({ + name: DSattr('string'), + books: DShasMany('books', { async: false }), + }); + + Section = DS.Model.extend({ + name: DSattr('string'), + }); + + env = setupStore({ + user: User, + post: Post, + comment: Comment, + message: Message, + book: Book, + book1: Book1, + chapter: Chapter, + author: Author, + section: Section, + }); + + env.registry.optionsForType('serializer', { singleton: false }); + env.registry.optionsForType('adapter', { singleton: false }); + + env.owner.register( + 'serializer:user', + DS.JSONAPISerializer.extend({ + attrs: { + favouriteMessage: { embedded: 'always' }, + }, + }) + ); + + store = env.store; + + User = store.modelFor('user'); + Post = store.modelFor('post'); + Comment = store.modelFor('comment'); + Message = store.modelFor('message'); + Book = store.modelFor('book'); + Chapter = store.modelFor('chapter'); + Author = store.modelFor('author'); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('returning a null relationship from payload sets the relationship to null on both sides', function(assert) { + env.owner.register( + 'model:app', + DS.Model.extend({ + name: DSattr('string'), + team: DSbelongsTo('team', { async: true }), + }) + ); + env.owner.register( + 'model:team', + DS.Model.extend({ + apps: DShasMany('app', { async: true }), + }) + ); + run(() => { + env.store.push({ + data: { + id: '1', + type: 'app', + relationships: { + team: { + data: { + id: '1', + type: 'team', + }, + }, + }, + }, + included: [ + { + id: '1', + type: 'team', + relationships: { + apps: { + data: [ + { + id: '1', + type: 'app', + }, + ], + }, + }, + }, + ], + }); + }); + + const app = env.store.peekRecord('app', '1'); + const team = env.store.peekRecord('team', '1'); + assert.equal(app.get('team.id'), team.get('id'), 'sets team correctly on app'); + assert.deepEqual( + team + .get('apps') + .toArray() + .mapBy('id'), + ['1'], + 'sets apps correctly on team' + ); + + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.updateRecord = (store, type, snapshot) => { + return RSVP.resolve({ + data: { + id: '1', + type: 'app', + attributes: { + name: 'Hello', + }, + relationships: { + team: { + data: null, + }, + }, + }, + }); + }; + + return run(() => { + app.set('name', 'Hello'); + return app.save().then(() => { + assert.equal(app.get('team.id'), null, 'team removed from app relationship'); + assert.deepEqual( + team + .get('apps') + .toArray() + .mapBy('id'), + [], + 'app removed from team apps relationship' + ); + }); + }); +}); + +test('The store can materialize a non loaded monomorphic belongsTo association', function(assert) { + assert.expect(1); + + env.store.modelFor('post').reopen({ + user: DS.belongsTo('user', { + async: true, + inverse: 'messages', + }), + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.ok(true, "The adapter's find method should be called"); + return resolve({ + data: { + id, + type: snapshot.modelName, + }, + }); + }; + + run(() => { + env.store.push({ + data: { + id: '1', + type: 'post', + relationships: { + user: { + data: { + id: '2', + type: 'user', + }, + }, + }, + }, + }); + }); + + return run(() => { + return env.store.findRecord('post', 1).then(post => { + post.get('user'); + }); + }); +}); + +testInDebug('Invalid belongsTo relationship identifiers throw errors', function(assert) { + assert.expect(2); + let { store } = env; + + // test null id + assert.expectAssertion(() => { + run(() => { + let post = store.push({ + data: { + id: '1', + type: 'post', + relationships: { + user: { + data: { + id: null, + type: 'user', + }, + }, + }, + }, + }); + post.get('user'); + }); + }, `Assertion Failed: Encountered a relationship identifier without an id for the belongsTo relationship 'user' on , expected a json-api identifier but found '{"id":null,"type":"user"}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`); + + // test missing type + assert.expectAssertion(() => { + run(() => { + let post = store.push({ + data: { + id: '2', + type: 'post', + relationships: { + user: { + data: { + id: '1', + type: null, + }, + }, + }, + }, + }); + post.get('user'); + }); + }, `Assertion Failed: Encountered a relationship identifier without a type for the belongsTo relationship 'user' on , expected a json-api identifier with type 'user' but found '{"id":"1","type":null}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`); +}); + +testInDebug( + 'Only a record of the same modelClass can be used with a monomorphic belongsTo relationship', + function(assert) { + assert.expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; + run(() => { + store.push({ + data: { + id: '1', + type: 'post', + }, + }); + store.push({ + data: { + id: '2', + type: 'comment', + }, + }); + }); + + return run(() => { + return hash({ + post: store.findRecord('post', 1), + comment: store.findRecord('comment', 2), + }).then(records => { + assert.expectAssertion(() => { + records.post.set('user', records.comment); + }, /The 'comment' type does not implement 'user' and thus cannot be assigned to the 'user' relationship in 'post'/); + }); + }); + } +); + +testInDebug( + 'Only a record of the same base modelClass can be used with a polymorphic belongsTo relationship', + function(assert) { + env.adapter.shouldBackgroundReloadRecord = () => false; + assert.expect(1); + run(() => { + store.push({ + data: [ + { + id: '1', + type: 'comment', + }, + { + id: '2', + type: 'comment', + }, + ], + }); + store.push({ + data: { + id: '1', + type: 'post', + }, + }); + store.push({ + data: { + id: '3', + type: 'user', + }, + }); + }); + + return run(() => { + let asyncRecords = hash({ + user: store.findRecord('user', 3), + post: store.findRecord('post', 1), + comment: store.findRecord('comment', 1), + anotherComment: store.findRecord('comment', 2), + }); + + return asyncRecords.then(records => { + let comment = records.comment; + + comment.set('message', records.anotherComment); + comment.set('message', records.post); + comment.set('message', null); + + assert.expectAssertion(() => { + comment.set('message', records.user); + }, /The 'user' type does not implement 'message' and thus cannot be assigned to the 'message' relationship in 'comment'. Make it a descendant of 'message'/); + }); + }); + } +); + +test('The store can load a polymorphic belongsTo association', function(assert) { + env.adapter.shouldBackgroundReloadRecord = () => false; + run(() => { + env.store.push({ + data: { + id: '1', + type: 'post', + }, + }); + + env.store.push({ + data: { + id: '2', + type: 'comment', + relationships: { + message: { + data: { + id: '1', + type: 'post', + }, + }, + }, + }, + }); + }); + + return run(() => { + return hash({ + message: store.findRecord('post', 1), + comment: store.findRecord('comment', 2), + }).then(records => { + assert.equal(records.comment.get('message'), records.message); + }); + }); +}); + +test('The store can serialize a polymorphic belongsTo association', function(assert) { + env.adapter.shouldBackgroundReloadRecord = () => false; + let serializerInstance = store.serializerFor('comment'); + + serializerInstance.serializePolymorphicType = function(record, json, relationship) { + assert.ok(true, "The serializer's serializePolymorphicType method should be called"); + json['message_type'] = 'post'; + }; + + return run(() => { + env.store.push({ + data: { + id: '1', + type: 'post', + }, + }); + + env.store.push({ + data: { + id: '2', + type: 'comment', + relationships: { + message: { + data: { + id: '1', + type: 'post', + }, + }, + }, + }, + }); + + return store.findRecord('comment', 2).then(comment => { + let serialized = comment.serialize({ includeId: true }); + assert.equal(serialized.data.relationships.message.data.id, 1); + assert.equal(serialized.data.relationships.message.data.type, 'posts'); + }); + }); +}); + +test('A serializer can materialize a belongsTo as a link that gets sent back to findBelongsTo', function(assert) { + env.adapter.shouldBackgroundReloadRecord = () => false; + let Group = DS.Model.extend({ + people: DS.hasMany('person', { async: false }), + }); + + let Person = DS.Model.extend({ + group: DS.belongsTo({ async: true }), + }); + + env.owner.register('model:group', Group); + env.owner.register('model:person', Person); + + run(() => { + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + group: { + links: { + related: '/people/1/group', + }, + }, + }, + }, + }); + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + throw new Error("Adapter's find method should not be called"); + }; + + env.adapter.findBelongsTo = function(store, snapshot, link, relationship) { + assert.equal(relationship.type, 'group'); + assert.equal(relationship.key, 'group'); + assert.equal(link, '/people/1/group'); + + return resolve({ + data: { + id: 1, + type: 'group', + relationships: { + people: { + data: [{ id: 1, type: 'person' }], + }, + }, + }, + }); + }; + + return run(() => { + return env.store + .findRecord('person', 1) + .then(person => { + return person.get('group'); + }) + .then(group => { + assert.ok(group instanceof Group, 'A group object is loaded'); + assert.ok(group.get('id') === '1', 'It is the group we are expecting'); + }); + }); +}); + +test('A record with an async belongsTo relationship always returns a promise for that relationship', function(assert) { + env.adapter.shouldBackgroundReloadRecord = () => false; + let Seat = DS.Model.extend({ + person: DS.belongsTo('person', { async: false }), + }); + + let Person = DS.Model.extend({ + seat: DS.belongsTo('seat', { async: true }), + }); + + env.owner.register('model:seat', Seat); + env.owner.register('model:person', Person); + + run(() => { + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + seat: { + links: { + related: '/people/1/seat', + }, + }, + }, + }, + }); + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + throw new Error("Adapter's find method should not be called"); + }; + + env.adapter.findBelongsTo = function(store, snapshot, link, relationship) { + return resolve({ data: { id: 1, type: 'seat' } }); + }; + + return run(() => { + return env.store.findRecord('person', 1).then(person => { + return person.get('seat').then(seat => { + // this assertion fails too + // ok(seat.get('person') === person, 'parent relationship should be populated'); + seat.set('person', person); + assert.ok(person.get('seat').then, 'seat should be a PromiseObject'); + }); + }); + }); +}); + +test('A record with an async belongsTo relationship returning null should resolve null', function(assert) { + assert.expect(1); + + env.adapter.shouldBackgroundReloadRecord = () => false; + let Group = DS.Model.extend({ + people: DS.hasMany('person', { async: false }), + }); + + let Person = DS.Model.extend({ + group: DS.belongsTo({ async: true }), + }); + + env.owner.register('model:group', Group); + env.owner.register('model:person', Person); + + run(() => { + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + group: { + links: { + related: '/people/1/group', + }, + }, + }, + }, + }); + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + throw new Error("Adapter's find method should not be called"); + }; + + env.adapter.findBelongsTo = function(store, snapshot, link, relationship) { + return resolve({ data: null }); + }; + + return env.store + .findRecord('person', '1') + .then(person => { + return person.get('group'); + }) + .then(group => { + assert.ok(group === null, 'group should be null'); + }); +}); + +test('A record can be created with a resolved belongsTo promise', function(assert) { + assert.expect(1); + + env.adapter.shouldBackgroundReloadRecord = () => false; + let Group = DS.Model.extend({ + people: DS.hasMany('person', { async: false }), + }); + + let Person = DS.Model.extend({ + group: DS.belongsTo({ async: true }), + }); + + env.owner.register('model:group', Group); + env.owner.register('model:person', Person); + + run(() => { + store.push({ + data: { + id: 1, + type: 'group', + }, + }); + }); + + let groupPromise = store.findRecord('group', 1); + return groupPromise.then(group => { + let person = env.store.createRecord('person', { + group: groupPromise, + }); + assert.equal(person.get('group.content'), group); + }); +}); + +test('polymorphic belongsTo class-checks check the superclass', function(assert) { + assert.expect(1); + + run(() => { + let igor = env.store.createRecord('user', { name: 'Igor' }); + let post = env.store.createRecord('post', { title: "Igor's unimaginative blog post" }); + + igor.set('favouriteMessage', post); + + assert.equal(igor.get('favouriteMessage.title'), "Igor's unimaginative blog post"); + }); +}); + +test('the subclass in a polymorphic belongsTo relationship is an instanceof its superclass', function(assert) { + assert.expect(1); + + let message = env.store.createRecord('message', { id: 1 }); + let comment = env.store.createRecord('comment', { id: 2, message: message }); + assert.ok(comment instanceof Message, 'a comment is an instance of a message'); +}); + +test('relationshipsByName does not cache a factory', function(assert) { + // The model is loaded up via a container. It has relationshipsByName + // called on it. + let modelViaFirstFactory = store.modelFor('user'); + get(modelViaFirstFactory, 'relationshipsByName'); + + // An app is reset, or the container otherwise destroyed. + run(env.container, 'destroy'); + + // A new model for a relationship is created. + NewMessage = Message.extend(); + + // A new store is created. + env = setupStore({ + user: User, + message: NewMessage, + }); + store = env.store; + + // relationshipsByName is called again. + let modelViaSecondFactory = store.modelFor('user'); + let relationshipsByName = get(modelViaSecondFactory, 'relationshipsByName'); + let messageType = relationshipsByName.get('messages').type; + + // A model is looked up in the store based on a string, via user input + let messageModelFromStore = store.modelFor('message'); + // And the model is lookup up internally via the relationship type + let messageModelFromRelationType = store.modelFor(messageType); + + assert.equal( + messageModelFromRelationType, + messageModelFromStore, + 'model factory based on relationship type matches the model based on store.modelFor' + ); +}); + +test('relationship changes shouldn’t cause async fetches', function(assert) { + assert.expect(2); + + /* Scenario: + * --------- + * + * post HM async comments + * comments bt sync post + * + * scenario: + * - post hm C [1,2,3] + * - post has a partially realized comments array comment#1 has been realized + * - comment has not yet realized its post relationship + * - comment is destroyed + */ + + env.store.modelFor('post').reopen({ + comments: DS.hasMany('comment', { + async: true, + inverse: 'post', + }), + }); + + env.store.modelFor('comment').reopen({ + post: DS.belongsTo('post', { async: false }), + }); + let comment; + run(() => { + env.store.push({ + data: { + id: '1', + type: 'post', + relationships: { + comments: { + data: [ + { + id: '1', + type: 'comment', + }, + { + id: '2', + type: 'comment', + }, + { + id: '3', + type: 'comment', + }, + ], + }, + }, + }, + }); + + comment = env.store.push({ + data: { + id: '1', + type: 'comment', + relationships: { + post: { + data: { + id: '1', + type: 'post', + }, + }, + }, + }, + }); + }); + + env.adapter.deleteRecord = function(store, type, snapshot) { + assert.ok(snapshot.record instanceof type); + assert.equal(snapshot.id, 1, 'should first comment'); + return snapshot.record.toJSON({ includeId: true }); + }; + + env.adapter.findMany = function(store, type, ids, snapshots) { + assert.ok(false, 'should not need to findMay more comments, but attempted to anyways'); + }; + + run(comment, 'destroyRecord'); +}); + +test('Destroying a record with an unloaded aync belongsTo association does not fetch the record', function(assert) { + assert.expect(2); + let post; + + env.store.modelFor('message').reopen({ + user: DS.hasMany('user', { + async: true, + }), + }); + + env.store.modelFor('post').reopen({ + user: DS.belongsTo('user', { + async: true, + inverse: 'messages', + }), + }); + + run(() => { + post = env.store.push({ + data: { + id: '1', + type: 'post', + relationships: { + user: { + data: { + id: '2', + type: 'user', + }, + }, + }, + }, + }); + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + throw new Error("Adapter's find method should not be called"); + }; + + env.adapter.deleteRecord = function(store, type, snapshot) { + assert.ok(snapshot.record instanceof type); + assert.equal(snapshot.id, 1, 'should first post'); + return { + data: { + id: '1', + type: 'post', + attributes: { + title: null, + 'created-at': null, + }, + relationships: { + user: { + data: { + id: '2', + type: 'user', + }, + }, + }, + }, + }; + }; + + run(post, 'destroyRecord'); +}); + +testInDebug('A sync belongsTo errors out if the record is unloaded', function(assert) { + let message; + run(() => { + message = env.store.push({ + data: { + id: '1', + type: 'message', + relationships: { + user: { + data: { + id: '2', + type: 'user', + }, + }, + }, + }, + }); + }); + + assert.expectAssertion(() => { + message.get('user'); + }, /You looked up the 'user' relationship on a 'message' with id 1 but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async \(`DS.belongsTo\({ async: true }\)`\)/); +}); + +test('Rollbacking attributes for a deleted record restores implicit relationship - async', function(assert) { + Book.reopen({ + author: DS.belongsTo('author', { async: true }), + }); + let book, author; + run(() => { + book = env.store.push({ + data: { + id: '1', + type: 'book', + attributes: { + name: "Stanley's Amazing Adventures", + }, + relationships: { + author: { + data: { + id: '2', + type: 'author', + }, + }, + }, + }, + }); + author = env.store.push({ + data: { + id: '2', + type: 'author', + attributes: { + name: 'Stanley', + }, + }, + }); + }); + return run(() => { + author.deleteRecord(); + author.rollbackAttributes(); + + return book.get('author').then(fetchedAuthor => { + assert.equal(fetchedAuthor, author, 'Book has an author after rollback attributes'); + }); + }); +}); + +test('Rollbacking attributes for a deleted record restores implicit relationship - sync', function(assert) { + let book, author; + + run(() => { + book = env.store.push({ + data: { + id: '1', + type: 'book', + attributes: { + name: "Stanley's Amazing Adventures", + }, + relationships: { + author: { + data: { + id: '2', + type: 'author', + }, + }, + }, + }, + }); + + author = env.store.push({ + data: { + id: '2', + type: 'author', + attributes: { + name: 'Stanley', + }, + }, + }); + }); + + run(() => { + author.deleteRecord(); + author.rollbackAttributes(); + }); + + assert.equal(book.get('author'), author, 'Book has an author after rollback attributes'); +}); + +testInDebug('Passing a model as type to belongsTo should not work', function(assert) { + assert.expect(1); + + assert.expectAssertion(() => { + User = DS.Model.extend(); + + DS.Model.extend({ + user: DSbelongsTo(User, { async: false }), + }); + }, /The first argument to DS.belongsTo must be a string/); +}); + +test('belongsTo hasAnyRelationshipData async loaded', function(assert) { + assert.expect(1); + + Book.reopen({ + author: DSbelongsTo('author', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'book', + attributes: { name: 'The Greatest Book' }, + relationships: { + author: { data: { id: 2, type: 'author' } }, + }, + }, + }); + }; + + return run(() => { + return store.findRecord('book', 1).then(book => { + let relationship = relationshipStateFor(book, 'author'); + assert.equal(relationship.hasAnyRelationshipData, true, 'relationship has data'); + }); + }); +}); + +test('belongsTo hasAnyRelationshipData sync loaded', function(assert) { + assert.expect(1); + + env.adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'book', + attributes: { name: 'The Greatest Book' }, + relationships: { + author: { data: { id: 2, type: 'author' } }, + }, + }, + }); + }; + + return run(() => { + return store.findRecord('book', 1).then(book => { + let relationship = relationshipStateFor(book, 'author'); + assert.equal(relationship.hasAnyRelationshipData, true, 'relationship has data'); + }); + }); +}); + +test('belongsTo hasAnyRelationshipData async not loaded', function(assert) { + assert.expect(1); + + Book.reopen({ + author: DSbelongsTo('author', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'book', + attributes: { name: 'The Greatest Book' }, + relationships: { + author: { links: { related: 'author' } }, + }, + }, + }); + }; + + return run(() => { + return store.findRecord('book', 1).then(book => { + let relationship = relationshipStateFor(book, 'author'); + assert.equal(relationship.hasAnyRelationshipData, false, 'relationship does not have data'); + }); + }); +}); + +test('belongsTo hasAnyRelationshipData sync not loaded', function(assert) { + assert.expect(1); + + env.adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'book', + attributes: { name: 'The Greatest Book' }, + }, + }); + }; + + return run(() => { + return store.findRecord('book', 1).then(book => { + let relationship = relationshipStateFor(book, 'author'); + assert.equal(relationship.hasAnyRelationshipData, false, 'relationship does not have data'); + }); + }); +}); + +test('belongsTo hasAnyRelationshipData NOT created', function(assert) { + assert.expect(2); + + Book.reopen({ + author: DSbelongsTo('author', { async: true }), + }); + + run(() => { + let author = store.createRecord('author'); + let book = store.createRecord('book', { name: 'The Greatest Book' }); + let relationship = relationshipStateFor(book, 'author'); + + assert.equal(relationship.hasAnyRelationshipData, false, 'relationship does not have data'); + + book = store.createRecord('book', { + name: 'The Greatest Book', + author, + }); + + relationship = relationshipStateFor(book, 'author'); + + assert.equal(relationship.hasAnyRelationshipData, true, 'relationship has data'); + }); +}); + +test('belongsTo hasAnyRelationshipData sync created', function(assert) { + assert.expect(2); + + run(() => { + let author = store.createRecord('author'); + let book = store.createRecord('book', { + name: 'The Greatest Book', + }); + + let relationship = relationshipStateFor(book, 'author'); + assert.equal(relationship.hasAnyRelationshipData, false, 'relationship does not have data'); + + book = store.createRecord('book', { + name: 'The Greatest Book', + author, + }); + + relationship = relationshipStateFor(book, 'author'); + assert.equal(relationship.hasAnyRelationshipData, true, 'relationship has data'); + }); +}); + +test("Model's belongsTo relationship should not be created during model creation", function(assert) { + let user; + + run(() => { + user = env.store.push({ + data: { + id: '1', + type: 'user', + }, + }); + + assert.ok( + !relationshipsFor(user).has('favouriteMessage'), + 'Newly created record should not have relationships' + ); + }); +}); + +test("Model's belongsTo relationship should be created during model creation if relationship passed in constructor", function(assert) { + let message = env.store.createRecord('message'); + let user = env.store.createRecord('user', { + name: 'John Doe', + favouriteMessage: message, + }); + + assert.ok( + relationshipsFor(user).has('favouriteMessage'), + 'Newly created record with relationships in params passed in its constructor should have relationships' + ); +}); + +test("Model's belongsTo relationship should be created during 'set' method", function(assert) { + let user, message; + + run(() => { + message = env.store.createRecord('message'); + user = env.store.createRecord('user'); + user.set('favouriteMessage', message); + assert.ok( + relationshipsFor(user).has('favouriteMessage'), + 'Newly created record with relationships in params passed in its constructor should have relationships' + ); + }); +}); + +test("Model's belongsTo relationship should be created during 'get' method", function(assert) { + let user; + + run(() => { + user = env.store.createRecord('user'); + user.get('favouriteMessage'); + assert.ok( + relationshipsFor(user).has('favouriteMessage'), + 'Newly created record with relationships in params passed in its constructor should have relationships' + ); + }); +}); + +test('Related link should be fetched when no relationship data is present', function(assert) { + assert.expect(3); + + Book.reopen({ + author: DS.belongsTo('author', { async: true }), + }); + + env.adapter.findBelongsTo = function(store, snapshot, url, relationship) { + assert.equal(url, 'author', 'url is correct'); + assert.ok(true, "The adapter's findBelongsTo method should be called"); + return resolve({ + data: { + id: '1', + type: 'author', + attributes: { name: 'This is author' }, + }, + }); + }; + + return run(() => { + let book = env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + author: { + links: { + related: 'author', + }, + }, + }, + }, + }); + + return book.get('author').then(author => { + assert.equal(author.get('name'), 'This is author', 'author name is correct'); + }); + }); +}); + +test('Related link should take precedence over relationship data if no local record data is available', function(assert) { + assert.expect(2); + + Book.reopen({ + author: DS.belongsTo('author', { async: true }), + }); + + env.adapter.findBelongsTo = function(store, snapshot, url, relationship) { + assert.ok(true, "The adapter's findBelongsTo method should be called"); + return resolve({ + data: { + id: 1, + type: 'author', + attributes: { name: 'This is author' }, + }, + }); + }; + + env.adapter.findRecord = function() { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + + return run(() => { + let book = env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + author: { + links: { + related: 'author', + }, + data: { type: 'author', id: '1' }, + }, + }, + }, + }); + + return book.get('author').then(author => { + assert.equal(author.get('name'), 'This is author', 'author name is correct'); + }); + }); +}); + +test('Relationship data should take precedence over related link when local record data is available', function(assert) { + assert.expect(1); + + Book.reopen({ + author: DS.belongsTo('author', { async: true }), + }); + + env.adapter.shouldBackgroundReloadRecord = () => { + return false; + }; + env.adapter.findBelongsTo = function(store, snapshot, url, relationship) { + assert.ok(false, "The adapter's findBelongsTo method should not be called"); + }; + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + + return run(() => { + let book = env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + author: { + links: { + related: 'author', + }, + data: { type: 'author', id: '1' }, + }, + }, + }, + included: [ + { + id: '1', + type: 'author', + attributes: { name: 'This is author' }, + }, + ], + }); + + return book.get('author').then(author => { + assert.equal(author.get('name'), 'This is author', 'author name is correct'); + }); + }); +}); + +test('New related link should take precedence over local data', function(assert) { + assert.expect(3); + + Book.reopen({ + author: DS.belongsTo('author', { async: true }), + }); + + env.adapter.findBelongsTo = function(store, snapshot, url, relationship) { + assert.equal(url, 'author-new-link', 'url is correct'); + assert.ok(true, "The adapter's findBelongsTo method should be called"); + return resolve({ + data: { + id: 1, + type: 'author', + attributes: { name: 'This is author' }, + }, + }); + }; + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + + return run(() => { + let book = env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + author: { + data: { + type: 'author', + id: '1', + }, + }, + }, + }, + }); + + env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + author: { + links: { + related: 'author-new-link', + }, + }, + }, + }, + }); + + book.get('author').then(author => { + assert.equal(author.get('name'), 'This is author', 'author name is correct'); + }); + }); +}); + +test('Updated related link should take precedence over relationship data and local record data', function(assert) { + assert.expect(4); + + Book.reopen({ + author: DS.belongsTo('author', { async: true }), + }); + + env.adapter.findBelongsTo = function(store, snapshot, url, relationship) { + assert.equal(url, 'author-updated-link', 'url is correct'); + assert.ok(true, "The adapter's findBelongsTo method should be called"); + return resolve({ + data: { + id: '1', + type: 'author', + attributes: { + name: 'This is updated author', + }, + }, + }); + }; + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + + return run(() => { + let book = env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + author: { + links: { + related: 'author', + }, + data: { type: 'author', id: '1' }, + }, + }, + }, + included: [ + { + type: 'author', + id: '1', + attributes: { + name: 'This is author', + }, + }, + ], + }); + + return book + .get('author') + .then(author => { + assert.equal(author.get('name'), 'This is author', 'author name is correct'); + }) + .then(() => { + env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + author: { + links: { + related: 'author-updated-link', + }, + }, + }, + }, + }); + + return book.get('author').then(author => { + assert.equal(author.get('name'), 'This is updated author', 'author name is correct'); + }); + }); + }); +}); + +test('Updated identical related link should not take precedence over local data', function(assert) { + assert.expect(2); + + Book.reopen({ + author: DS.belongsTo('author', { async: true }), + }); + + env.adapter.findBelongsTo = function() { + assert.ok(false, "The adapter's findBelongsTo method should not be called"); + }; + + env.adapter.findRecord = function() { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + + return run(() => { + let book = env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + author: { + links: { + related: 'author', + }, + data: { type: 'author', id: '1' }, + }, + }, + }, + included: [ + { + type: 'author', + id: '1', + attributes: { + name: 'This is author', + }, + }, + ], + }); + + return book + .get('author') + .then(author => { + assert.equal(author.get('name'), 'This is author', 'author name is correct'); + }) + .then(() => { + env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + author: { + links: { + related: 'author', + }, + }, + }, + }, + }); + + return book.get('author').then(author => { + assert.equal(author.get('name'), 'This is author', 'author name is correct'); + }); + }); + }); +}); + +test('A belongsTo relationship can be reloaded using the reference if it was fetched via link', function(assert) { + Chapter.reopen({ + book: DS.belongsTo({ async: true }), + }); + + env.adapter.findRecord = function() { + return resolve({ + data: { + id: 1, + type: 'chapter', + relationships: { + book: { + links: { related: '/books/1' }, + }, + }, + }, + }); + }; + + env.adapter.findBelongsTo = function() { + return resolve({ + data: { + id: 1, + type: 'book', + attributes: { name: 'book title' }, + }, + }); + }; + + return run(() => { + let chapter; + + return store + .findRecord('chapter', 1) + .then(_chapter => { + chapter = _chapter; + + return chapter.get('book'); + }) + .then(book => { + assert.equal(book.get('name'), 'book title'); + + env.adapter.findBelongsTo = function() { + return resolve({ + data: { + id: 1, + type: 'book', + attributes: { name: 'updated book title' }, + }, + }); + }; + + return chapter.belongsTo('book').reload(); + }) + .then(book => { + assert.equal(book.get('name'), 'updated book title'); + }); + }); +}); + +test('A synchronous belongsTo relationship can be reloaded using a reference if it was fetched via id', function(assert) { + Chapter.reopen({ + book: DS.belongsTo({ async: false }), + }); + + let chapter; + run(() => { + chapter = env.store.push({ + data: { + type: 'chapter', + id: '1', + relationships: { + book: { + data: { type: 'book', id: '1' }, + }, + }, + }, + }); + env.store.push({ + data: { + type: 'book', + id: '1', + attributes: { + name: 'book title', + }, + }, + }); + }); + + env.adapter.findRecord = function() { + return resolve({ + data: { + id: '1', + type: 'book', + attributes: { name: 'updated book title' }, + }, + }); + }; + + return run(() => { + let book = chapter.get('book'); + assert.equal(book.get('name'), 'book title'); + + return chapter + .belongsTo('book') + .reload() + .then(function(book) { + assert.equal(book.get('name'), 'updated book title'); + }); + }); +}); + +test('A belongsTo relationship can be reloaded using a reference if it was fetched via id', function(assert) { + Chapter.reopen({ + book: DS.belongsTo({ async: true }), + }); + + let chapter; + run(() => { + chapter = env.store.push({ + data: { + type: 'chapter', + id: 1, + relationships: { + book: { + data: { type: 'book', id: 1 }, + }, + }, + }, + }); + }); + + env.adapter.findRecord = function() { + return resolve({ + data: { + id: 1, + type: 'book', + attributes: { name: 'book title' }, + }, + }); + }; + + return run(() => { + return chapter + .get('book') + .then(book => { + assert.equal(book.get('name'), 'book title'); + + env.adapter.findRecord = function() { + return resolve({ + data: { + id: 1, + type: 'book', + attributes: { name: 'updated book title' }, + }, + }); + }; + + return chapter.belongsTo('book').reload(); + }) + .then(book => { + assert.equal(book.get('name'), 'updated book title'); + }); + }); +}); + +testInDebug( + 'A belongsTo relationship warns if malformatted data is pushed into the store', + function(assert) { + assert.expectAssertion(() => { + run(() => { + let chapter = env.store.push({ + data: { + type: 'chapter', + id: 1, + relationships: { + book: { + data: { id: 1, name: 'The Gallic Wars' }, + }, + }, + }, + }); + chapter.get('book'); + }); + }, /Encountered a relationship identifier without a type for the belongsTo relationship 'book' on , expected a json-api identifier with type 'book'/); + } +); + +test("belongsTo relationship with links doesn't trigger extra change notifications - #4942", function(assert) { + Chapter.reopen({ + book: DS.belongsTo({ async: true }), + }); + + run(() => { + env.store.push({ + data: { + type: 'chapter', + id: '1', + relationships: { + book: { + data: { type: 'book', id: '1' }, + links: { related: '/chapter/1/book' }, + }, + }, + }, + included: [{ type: 'book', id: '1' }], + }); + }); + + let chapter = env.store.peekRecord('chapter', '1'); + let count = 0; + + chapter.addObserver('book', () => { + count++; + }); + + run(() => { + chapter.get('book'); + }); + + assert.equal(count, 0); +}); + +test("belongsTo relationship doesn't trigger when model data doesn't support implicit relationship", function(assert) { + class TestRecordData extends RecordData { + constructor(modelName, id, clientId, storeWrapper, store) { + super(modelName, id, clientId, storeWrapper, store); + delete this.__implicitRelationships; + delete this.__relationships; + } + + _destroyRelationships() {} + + _allRelatedRecordDatas() {} + + _cleanupOrphanedRecordDatas() {} + + _directlyRelatedRecordDatas() { + return []; + } + + destroy() { + this.isDestroyed = true; + this.storeWrapper.disconnectRecord(this.modelName, this.id, this.clientId); + } + + get _implicitRelationships() { + return undefined; + } + get _relationships() { + return undefined; + } + } + + Chapter.reopen({ + // book is still an inverse from prior to the reopen + sections: DS.hasMany('section', { async: false }), + book1: DS.belongsTo('book1', { async: false, inverse: 'chapters' }), // incorrect inverse + book2: DS.belongsTo('book1', { async: false, inverse: null }), // correct inverse + }); + + const createRecordDataFor = env.store.createRecordDataFor; + env.store.createRecordDataFor = function(modelName, id, lid, storeWrapper) { + if (modelName === 'book1' || modelName === 'section') { + return new TestRecordData(modelName, id, lid, storeWrapper, this); + } + return createRecordDataFor.call(this, modelName, id, lid, storeWrapper); + }; + + const data = { + data: { + type: 'chapter', + id: '1', + relationships: { + book1: { + data: { type: 'book1', id: '1' }, + }, + book2: { + data: { type: 'book1', id: '2' }, + }, + book: { + data: { type: 'book', id: '1' }, + }, + sections: { + data: [ + { + type: 'section', + id: 1, + }, + { + type: 'section', + id: 2, + }, + ], + }, + }, + }, + included: [ + { type: 'book1', id: '1' }, + { type: 'book1', id: '2' }, + { type: 'section', id: '1' }, + { type: 'book', id: '1' }, + { type: 'section', id: '2' }, + ], + }; + + // Expect assertion failure as Book1 RecordData + // doesn't have relationship attribute + // and inverse is not set to null in + // DSbelongsTo + assert.expectAssertion(() => { + run(() => { + env.store.push(data); + }); + }, `Assertion Failed: We found no inverse relationships by the name of 'chapters' on the 'book1' model. This is most likely due to a missing attribute on your model definition.`); + + //Update setup + // with inverse set to null + // no errors thrown + Chapter.reopen({ + book1: DS.belongsTo({ async: false }), + sections: DS.hasMany('section', { async: false }), + book: DS.belongsTo({ async: false, inverse: null }), + }); + + run(() => { + env.store.push(data); + }); + + let chapter = env.store.peekRecord('chapter', '1'); + let book1 = env.store.peekRecord('book1', '1'); + let book2 = env.store.peekRecord('book1', '2'); + let book = env.store.peekRecord('book', '1'); + let section1 = env.store.peekRecord('section', '1'); + let section2 = env.store.peekRecord('section', '2'); + + let sections = chapter.get('sections'); + + assert.equal(chapter.get('book1.id'), '1'); + assert.equal(chapter.get('book2.id'), '2'); + assert.equal(chapter.get('book.id'), '1'); + + // No inverse setup created for book1 + // as Model-Data of book1 doesn't support this + // functionality. + assert.notOk(book1.get('chapter')); + assert.notOk(book2.get('chapter')); + assert.notOk(book.get('chapter')); + assert.notOk( + recordDataFor(book1)._implicitRelationships, + 'no support for implicit relationship in custom RecordData' + ); + assert.notOk( + recordDataFor(book2)._implicitRelationships, + 'no support for implicit relationship in custom RecordData' + ); + assert.ok( + recordDataFor(book)._implicitRelationships, + 'support for implicit relationship in default RecordData' + ); + + // No inverse setup is created for section + assert.notOk(section1.get('chapter')); + assert.notOk(section2.get('chapter')); + + // Removing the sections + // shouldnot throw error + // as Model-data of section + // doesn't support implicit Relationship + run(() => { + chapter.get('sections').removeObject(section1); + assert.notOk(recordDataFor(section1)._implicitRelationships); + + chapter.get('sections').removeObject(section2); + assert.notOk(recordDataFor(section2)._implicitRelationships); + }); + + assert.equal(chapter.get('sections.length'), 0); + + // Update the current state of chapter by + // adding new sections + // shouldnot throw error during + // setup of implicit inverse + run(() => { + sections.addObject(env.store.createRecord('section', { id: 3 })); + sections.addObject(env.store.createRecord('section', { id: 4 })); + sections.addObject(env.store.createRecord('section', { id: 5 })); + }); + assert.equal(chapter.get('sections.length'), 3); + assert.notOk(recordDataFor(sections.get('firstObject'))._implicitRelationships); +}); diff --git a/tests/integration/relationships/has-many-test.js b/tests/integration/relationships/has-many-test.js new file mode 100644 index 00000000000..052a0cf923a --- /dev/null +++ b/tests/integration/relationships/has-many-test.js @@ -0,0 +1,3887 @@ +/*eslint no-unused-vars: ["error", { "args": "none", "varsIgnorePattern": "(page)" }]*/ + +import { A } from '@ember/array'; +import { resolve, Promise as EmberPromise, all, reject, hash } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test, skip } from 'qunit'; +import { relationshipStateFor, relationshipsFor } from 'ember-data/-private'; +import DS from 'ember-data'; + +let env, store, User, Contact, Email, Phone, Message, Post, Comment; +let Book, Chapter, Page; + +const { attr, hasMany, belongsTo } = DS; + +module('integration/relationships/has_many - Has-Many Relationships', { + beforeEach() { + User = DS.Model.extend({ + name: attr('string'), + messages: hasMany('message', { polymorphic: true, async: false }), + contacts: hasMany('user', { inverse: null, async: false }), + }); + + Contact = DS.Model.extend({ + user: belongsTo('user', { async: false }), + }); + Contact.reopenClass({ toString: () => 'Contact' }); + + Email = Contact.extend({ + email: attr('string'), + }); + Email.reopenClass({ toString: () => 'Email' }); + + Phone = Contact.extend({ + number: attr('string'), + }); + Phone.reopenClass({ toString: () => 'Phone' }); + + Message = DS.Model.extend({ + user: belongsTo('user', { async: false }), + created_at: attr('date'), + }); + Message.reopenClass({ toString: () => 'Message' }); + + Post = Message.extend({ + title: attr('string'), + comments: hasMany('comment', { async: false }), + }); + Post.reopenClass({ toString: () => 'Post' }); + + Comment = Message.extend({ + body: DS.attr('string'), + message: DS.belongsTo('post', { polymorphic: true, async: true }), + }); + Comment.reopenClass({ toString: () => 'Comment' }); + + Book = DS.Model.extend({ + title: attr(), + chapters: hasMany('chapter', { async: true }), + }); + Book.reopenClass({ toString: () => 'Book' }); + + Chapter = DS.Model.extend({ + title: attr(), + pages: hasMany('page', { async: false }), + }); + Chapter.reopenClass({ toString: () => 'Chapter' }); + + Page = DS.Model.extend({ + number: attr('number'), + chapter: belongsTo('chapter', { async: false }), + }); + Page.reopenClass({ toString: () => 'Page' }); + + env = setupStore({ + user: User, + contact: Contact, + email: Email, + phone: Phone, + post: Post, + comment: Comment, + message: Message, + book: Book, + chapter: Chapter, + page: Page, + }); + + store = env.store; + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +testInDebug('Invalid hasMany relationship identifiers throw errors', function(assert) { + assert.expect(2); + let { store } = env; + + // test null id + assert.expectAssertion(() => { + run(() => { + let post = store.push({ + data: { + id: '1', + type: 'post', + relationships: { + comments: { + data: [{ id: null, type: 'comment' }], + }, + }, + }, + }); + + post.get('comments'); + }); + }, `Assertion Failed: Encountered a relationship identifier without an id for the hasMany relationship 'comments' on , expected a json-api identifier but found '{"id":null,"type":"comment"}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`); + + // test missing type + assert.expectAssertion(() => { + run(() => { + let post = store.push({ + data: { + id: '2', + type: 'post', + relationships: { + comments: { + data: [{ id: '1', type: null }], + }, + }, + }, + }); + post.get('comments'); + }); + }, `Assertion Failed: Encountered a relationship identifier without a type for the hasMany relationship 'comments' on , expected a json-api identifier with type 'comment' but found '{"id":"1","type":null}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`); +}); + +test("When a hasMany relationship is accessed, the adapter's findMany method should not be called if all the records in the relationship are already loaded", function(assert) { + assert.expect(0); + + let postData = { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], + }, + }, + }; + + env.adapter.findMany = function(store, type, ids, snapshots) { + assert.ok(false, "The adapter's find method should not be called"); + }; + + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { data: postData }; + }; + + return run(() => { + env.store.push({ + data: postData, + included: [ + { + type: 'comment', + id: '1', + }, + ], + }); + + return env.store.findRecord('post', 1).then(post => { + return post.get('comments'); + }); + }); +}); + +test('hasMany + canonical vs currentState + destroyRecord ', function(assert) { + assert.expect(6); + + let postData = { + type: 'user', + id: '1', + attributes: { + name: 'omg', + }, + relationships: { + contacts: { + data: [ + { + type: 'user', + id: 2, + }, + { + type: 'user', + id: 3, + }, + { + type: 'user', + id: 4, + }, + ], + }, + }, + }; + + run(() => { + env.store.push({ + data: postData, + included: [ + { + type: 'user', + id: 2, + }, + { + type: 'user', + id: 3, + }, + { + type: 'user', + id: 4, + }, + ], + }); + }); + + let user = env.store.peekRecord('user', 1); + let contacts = user.get('contacts'); + + env.store.adapterFor('user').deleteRecord = function() { + return { data: { type: 'user', id: 2 } }; + }; + + assert.deepEqual( + contacts.map(c => c.get('id')), + ['2', '3', '4'], + 'user should have expected contacts' + ); + + run(() => { + contacts.addObject(env.store.createRecord('user', { id: 5 })); + contacts.addObject(env.store.createRecord('user', { id: 6 })); + contacts.addObject(env.store.createRecord('user', { id: 7 })); + }); + + assert.deepEqual( + contacts.map(c => c.get('id')), + ['2', '3', '4', '5', '6', '7'], + 'user should have expected contacts' + ); + + run(() => { + env.store.peekRecord('user', 2).destroyRecord(); + env.store.peekRecord('user', 6).destroyRecord(); + }); + + assert.deepEqual( + contacts.map(c => c.get('id')), + ['3', '4', '5', '7'], + `user's contacts should have expected contacts` + ); + assert.equal(contacts, user.get('contacts')); + + run(() => { + contacts.addObject(env.store.createRecord('user', { id: 8 })); + }); + + assert.deepEqual( + contacts.map(c => c.get('id')), + ['3', '4', '5', '7', '8'], + `user's contacts should have expected contacts` + ); + assert.equal(contacts, user.get('contacts')); +}); + +test('hasMany + canonical vs currentState + unloadRecord', function(assert) { + assert.expect(6); + + let postData = { + type: 'user', + id: '1', + attributes: { + name: 'omg', + }, + relationships: { + contacts: { + data: [ + { + type: 'user', + id: 2, + }, + { + type: 'user', + id: 3, + }, + { + type: 'user', + id: 4, + }, + ], + }, + }, + }; + + run(() => { + env.store.push({ + data: postData, + included: [ + { + type: 'user', + id: 2, + }, + { + type: 'user', + id: 3, + }, + { + type: 'user', + id: 4, + }, + ], + }); + }); + + let user = env.store.peekRecord('user', 1); + let contacts = user.get('contacts'); + + env.store.adapterFor('user').deleteRecord = function() { + return { data: { type: 'user', id: 2 } }; + }; + + assert.deepEqual( + contacts.map(c => c.get('id')), + ['2', '3', '4'], + 'user should have expected contacts' + ); + + run(() => { + contacts.addObject(env.store.createRecord('user', { id: 5 })); + contacts.addObject(env.store.createRecord('user', { id: 6 })); + contacts.addObject(env.store.createRecord('user', { id: 7 })); + }); + + assert.deepEqual( + contacts.map(c => c.get('id')), + ['2', '3', '4', '5', '6', '7'], + 'user should have expected contacts' + ); + + run(() => { + env.store.peekRecord('user', 2).unloadRecord(); + env.store.peekRecord('user', 6).unloadRecord(); + }); + + assert.deepEqual( + contacts.map(c => c.get('id')), + ['3', '4', '5', '7'], + `user's contacts should have expected contacts` + ); + assert.equal(contacts, user.get('contacts')); + + run(() => { + contacts.addObject(env.store.createRecord('user', { id: 8 })); + }); + + assert.deepEqual( + contacts.map(c => c.get('id')), + ['3', '4', '5', '7', '8'], + `user's contacts should have expected contacts` + ); + assert.equal(contacts, user.get('contacts')); +}); + +test('adapter.findMany only gets unique IDs even if duplicate IDs are present in the hasMany relationship', function(assert) { + assert.expect(2); + + let bookData = { + type: 'book', + id: '1', + relationships: { + chapters: { + data: [ + { type: 'chapter', id: '2' }, + { type: 'chapter', id: '3' }, + { type: 'chapter', id: '3' }, + ], + }, + }, + }; + + env.adapter.findMany = function(store, type, ids, snapshots) { + assert.equal(type, Chapter, 'type passed to adapter.findMany is correct'); + assert.deepEqual(ids, ['2', '3'], 'ids passed to adapter.findMany are unique'); + + return resolve({ + data: [ + { id: 2, type: 'chapter', attributes: { title: 'Chapter One' } }, + { id: 3, type: 'chapter', attributes: { title: 'Chapter Two' } }, + ], + }); + }; + + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { data: bookData }; + }; + + return run(() => { + env.store.push({ + data: bookData, + }); + + return env.store.findRecord('book', 1).then(book => { + return book.get('chapters'); + }); + }); +}); + +// This tests the case where a serializer materializes a has-many +// relationship as a internalModel that it can fetch lazily. The most +// common use case of this is to provide a URL to a collection that +// is loaded later. +test("A serializer can materialize a hasMany as an opaque token that can be lazily fetched via the adapter's findHasMany hook", function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + // When the store asks the adapter for the record with ID 1, + // provide some fake data. + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(type, Post, 'find type was Post'); + assert.equal(id, '1', 'find id was 1'); + + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + links: { + related: '/posts/1/comments', + }, + }, + }, + }, + }); + }; + //({ id: 1, links: { comments: "/posts/1/comments" } }); + + env.adapter.findMany = function(store, type, ids, snapshots) { + throw new Error("Adapter's findMany should not be called"); + }; + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + assert.equal(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); + assert.equal(relationship.type, 'comment', 'relationship was passed correctly'); + + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + + return run(() => { + return env.store + .findRecord('post', 1) + .then(post => { + return post.get('comments'); + }) + .then(comments => { + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(comments.get('length'), 2, 'comments have 2 length'); + assert.equal(comments.objectAt(0).get('body'), 'First', 'comment loaded successfully'); + }); + }); +}); + +test('Accessing a hasMany backed by a link multiple times triggers only one request', function(assert) { + assert.expect(2); + let count = 0; + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + Comment.reopen({ + message: DS.belongsTo('post', { async: true }), + }); + let post; + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: '/posts/1/comments', + }, + }, + }, + }, + }); + post = env.store.peekRecord('post', 1); + }); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + count++; + assert.equal(count, 1, 'findHasMany has only been called once'); + return new EmberPromise((resolve, reject) => { + setTimeout(() => { + let value = { + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }; + resolve(value); + }, 100); + }); + }; + + let promise1, promise2; + + run(() => { + promise1 = post.get('comments'); + //Invalidate the post.comments CP + env.store.push({ + data: { + type: 'comment', + id: '1', + relationships: { + message: { + data: { type: 'post', id: '1' }, + }, + }, + }, + }); + promise2 = post.get('comments'); + }); + + return all([promise1, promise2]).then(() => { + assert.equal( + promise1.get('promise'), + promise2.get('promise'), + 'Same promise is returned both times' + ); + }); +}); + +test('A hasMany backed by a link remains a promise after a record has been added to it', function(assert) { + assert.expect(1); + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + Comment.reopen({ + message: DS.belongsTo('post', { async: true }), + }); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + let post; + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: '/posts/1/comments', + }, + }, + }, + }, + }); + post = env.store.peekRecord('post', 1); + }); + + return run(() => { + return post.get('comments').then(() => { + env.store.push({ + data: { + type: 'comment', + id: '3', + relationships: { + message: { + data: { type: 'post', id: '1' }, + }, + }, + }, + }); + + return post.get('comments').then(() => { + assert.ok(true, 'Promise was called'); + }); + }); + }); +}); + +test('A hasMany updated link should not remove new children', function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + Comment.reopen({ + message: DS.belongsTo('post', { async: true }), + }); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + return resolve({ data: [] }); + }; + + env.adapter.createRecord = function(store, snapshot, link, relationship) { + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + links: { related: '/some/link' }, + }, + }, + }, + }); + }; + + return run(() => { + let post = env.store.createRecord('post', {}); + env.store.createRecord('comment', { message: post }); + + return post + .get('comments') + .then(comments => { + assert.equal(comments.get('length'), 1, 'initially we have one comment'); + + return post.save(); + }) + .then(() => post.get('comments')) + .then(comments => { + assert.equal(comments.get('length'), 1, 'after saving, we still have one comment'); + }); + }); +}); + +test('A hasMany updated link should not remove new children when the parent record has children already', function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + Comment.reopen({ + message: DS.belongsTo('post', { async: true }), + }); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + return resolve({ + data: [{ id: 5, type: 'comment', attributes: { body: 'hello' } }], + }); + }; + + env.adapter.createRecord = function(store, snapshot, link, relationship) { + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + links: { related: '/some/link' }, + }, + }, + }, + }); + }; + + return run(() => { + let post = env.store.createRecord('post', {}); + env.store.createRecord('comment', { message: post }); + + return post + .get('comments') + .then(comments => { + assert.equal(comments.get('length'), 1); + return post.save(); + }) + .then(() => post.get('comments')) + .then(comments => { + assert.equal(comments.get('length'), 2); + }); + }); +}); + +test("A hasMany relationship doesn't contain duplicate children, after the canonical state of the relationship is updated via store#push", function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + Comment.reopen({ + message: DS.belongsTo('post', { async: true }), + }); + + env.adapter.createRecord = function(store, snapshot, link, relationship) { + return resolve({ data: { id: 1, type: 'post' } }); + }; + + return run(() => { + let post = env.store.createRecord('post', {}); + + // create a new comment with id 'local', which is in the 'comments' + // relationship of post + let localComment = env.store.createRecord('comment', { id: 'local', message: post }); + + return post + .get('comments') + .then(comments => { + assert.equal(comments.get('length'), 1); + assert.equal(localComment.get('isNew'), true); + + return post.save(); + }) + .then(() => { + // Now the post is saved but the locally created comment with the id + // 'local' is still in the created state since it hasn't been saved + // yet. + // + // As next we are pushing the post into the store again, having the + // locally created comment in the 'comments' relationship. By this the + // canonical state of the relationship is defined to consist of one + // comment: the one with id 'local'. + // + // This setup is needed to demonstrate the bug which has been fixed + // in #4154, where the locally created comment was duplicated in the + // comment relationship. + env.store.push({ + data: { + type: 'post', + id: 1, + relationships: { + comments: { + data: [{ id: 'local', type: 'comment' }], + }, + }, + }, + }); + }) + .then(() => post.get('comments')) + .then(comments => { + assert.equal(comments.get('length'), 1); + assert.equal(localComment.get('isNew'), true); + }); + }); +}); + +test('A hasMany relationship can be reloaded if it was fetched via a link', function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(type, Post, 'find type was Post'); + assert.equal(id, '1', 'find id was 1'); + + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + links: { related: '/posts/1/comments' }, + }, + }, + }, + }); + }; + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + assert.equal(relationship.type, 'comment', 'findHasMany relationship type was Comment'); + assert.equal(relationship.key, 'comments', 'findHasMany relationship key was comments'); + assert.equal(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); + + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + + run(function() { + run(env.store, 'findRecord', 'post', 1) + .then(function(post) { + return post.get('comments'); + }) + .then(function(comments) { + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(comments.get('length'), 2, 'comments have 2 length'); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + assert.equal(relationship.type, 'comment', 'findHasMany relationship type was Comment'); + assert.equal(relationship.key, 'comments', 'findHasMany relationship key was comments'); + assert.equal(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); + + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + { id: 3, type: 'comment', attributes: { body: 'Thirds' } }, + ], + }); + }; + + return comments.reload(); + }) + .then(function(newComments) { + assert.equal(newComments.get('length'), 3, 'reloaded comments have 3 length'); + }); + }); +}); + +test('A sync hasMany relationship can be reloaded if it was fetched via ids', function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { async: false }), + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(type, Post, 'find type was Post'); + assert.equal(id, '1', 'find id was 1'); + + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + data: [{ id: 1, type: 'comment' }, { id: 2, type: 'comment' }], + }, + }, + }, + }); + }; + + run(function() { + env.store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'First', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'Second', + }, + }, + ], + }); + + env.store + .findRecord('post', '1') + .then(function(post) { + let comments = post.get('comments'); + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(comments.get('length'), 2, 'comments have a length of 2'); + + env.adapter.findMany = function(store, type, ids, snapshots) { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'FirstUpdated' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + + return comments.reload(); + }) + .then(function(newComments) { + assert.equal( + newComments.get('firstObject.body'), + 'FirstUpdated', + 'Record body was correctly updated' + ); + }); + }); +}); + +test('A hasMany relationship can be reloaded if it was fetched via ids', function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(type, Post, 'find type was Post'); + assert.equal(id, '1', 'find id was 1'); + + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + data: [{ id: 1, type: 'comment' }, { id: 2, type: 'comment' }], + }, + }, + }, + }); + }; + + env.adapter.findMany = function(store, type, ids, snapshots) { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + + run(function() { + env.store + .findRecord('post', 1) + .then(function(post) { + return post.get('comments'); + }) + .then(function(comments) { + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(comments.get('length'), 2, 'comments have 2 length'); + + env.adapter.findMany = function(store, type, ids, snapshots) { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'FirstUpdated' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + + return comments.reload(); + }) + .then(function(newComments) { + assert.equal( + newComments.get('firstObject.body'), + 'FirstUpdated', + 'Record body was correctly updated' + ); + }); + }); +}); + +skip('A hasMany relationship can be reloaded even if it failed at the first time', async function(assert) { + assert.expect(6); + + const { store, adapter } = env; + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + adapter.findRecord = function(store, type, id) { + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + links: { related: '/posts/1/comments' }, + }, + }, + }, + }); + }; + + let loadingCount = -1; + adapter.findHasMany = function(store, record, link, relationship) { + loadingCount++; + if (loadingCount % 2 === 0) { + return reject({ data: null }); + } else { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'FirstUpdated' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + } + }; + + let post = await store.findRecord('post', 1); + let comments = post.get('comments'); + let manyArray = await comments.catch(() => { + assert.ok(true, 'An error was thrown on the first reload of comments'); + return comments.reload(); + }); + + assert.equal(manyArray.get('isLoaded'), true, 'the reload worked, comments are now loaded'); + + await manyArray.reload().catch(() => { + assert.ok(true, 'An error was thrown on the second reload via manyArray'); + }); + + assert.equal( + manyArray.get('isLoaded'), + true, + 'the second reload failed, comments are still loaded though' + ); + + let reloadedManyArray = await manyArray.reload(); + + assert.equal( + reloadedManyArray.get('isLoaded'), + true, + 'the third reload worked, comments are loaded again' + ); + assert.ok(reloadedManyArray === manyArray, 'the many array stays the same'); +}); + +test('A hasMany relationship can be directly reloaded if it was fetched via links', function(assert) { + assert.expect(6); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id) { + assert.equal(type, Post, 'find type was Post'); + assert.equal(id, '1', 'find id was 1'); + + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + links: { related: '/posts/1/comments' }, + }, + }, + }, + }); + }; + + env.adapter.findHasMany = function(store, record, link, relationship) { + assert.equal(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); + + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'FirstUpdated' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + run(function() { + env.store.findRecord('post', 1).then(function(post) { + return post + .get('comments') + .reload() + .then(function(comments) { + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(comments.get('length'), 2, 'comments have 2 length'); + assert.equal( + comments.get('firstObject.body'), + 'FirstUpdated', + 'Record body was correctly updated' + ); + }); + }); + }); +}); + +test('Has many via links - Calling reload multiple times does not send a new request if the first one is not settled', function(assert) { + assert.expect(1); + let done = assert.async(); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id) { + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + links: { related: '/posts/1/comments' }, + }, + }, + }, + }); + }; + + let count = 0; + env.adapter.findHasMany = function(store, record, link, relationship) { + count++; + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + run(function() { + env.store.findRecord('post', 1).then(function(post) { + post.get('comments').then(function(comments) { + all([comments.reload(), comments.reload(), comments.reload()]).then(function(comments) { + assert.equal( + count, + 2, + 'One request for the original access and only one request for the mulitple reloads' + ); + done(); + }); + }); + }); + }); +}); + +test('A hasMany relationship can be directly reloaded if it was fetched via ids', function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(type, Post, 'find type was Post'); + assert.equal(id, '1', 'find id was 1'); + + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + data: [{ id: 1, type: 'comment' }, { id: 2, type: 'comment' }], + }, + }, + }, + }); + }; + + env.adapter.findMany = function(store, type, ids, snapshots) { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'FirstUpdated' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + + run(function() { + env.store.findRecord('post', 1).then(function(post) { + return post + .get('comments') + .reload() + .then(function(comments) { + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(comments.get('length'), 2, 'comments have 2 length'); + assert.equal( + comments.get('firstObject.body'), + 'FirstUpdated', + 'Record body was correctly updated' + ); + }); + }); + }); +}); + +test('Has many via ids - Calling reload multiple times does not send a new request if the first one is not settled', function(assert) { + assert.expect(1); + let done = assert.async(); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'post', + relationships: { + comments: { + data: [{ id: 1, type: 'comment' }, { id: 2, type: 'comment' }], + }, + }, + }, + }); + }; + + let count = 0; + env.adapter.findMany = function(store, type, ids, snapshots) { + count++; + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'FirstUpdated' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + + run(function() { + env.store.findRecord('post', 1).then(function(post) { + post.get('comments').then(function(comments) { + all([comments.reload(), comments.reload(), comments.reload()]).then(function(comments) { + assert.equal( + count, + 2, + 'One request for the original access and only one request for the mulitple reloads' + ); + done(); + }); + }); + }); + }); +}); + +test('PromiseArray proxies createRecord to its ManyArray once the hasMany is loaded', function(assert) { + assert.expect(4); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + let post; + + run(function() { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'someLink', + }, + }, + }, + }, + }); + post = env.store.peekRecord('post', 1); + }); + + run(function() { + post.get('comments').then(function(comments) { + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(comments.get('length'), 2, 'comments have 2 length'); + + let newComment = post.get('comments').createRecord({ body: 'Third' }); + assert.equal(newComment.get('body'), 'Third', 'new comment is returned'); + assert.equal(comments.get('length'), 3, 'comments have 3 length, including new record'); + }); + }); +}); + +test('PromiseArray proxies evented methods to its ManyArray', function(assert) { + assert.expect(6); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + let post, comments; + + run(function() { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'someLink', + }, + }, + }, + }, + }); + post = env.store.peekRecord('post', 1); + comments = post.get('comments'); + }); + + comments.on('on-event', function() { + assert.ok(true); + }); + + run(function() { + comments.trigger('on-event'); + }); + + assert.equal(comments.has('on-event'), true); + + comments.on('off-event', function() { + assert.ok(false); + }); + + comments.off('off-event'); + + assert.equal(comments.has('off-event'), false); + + comments.one('one-event', function() { + assert.ok(true); + }); + + assert.equal(comments.has('one-event'), true); + + run(function() { + comments.trigger('one-event'); + }); + + assert.equal(comments.has('one-event'), false); +}); + +test('An updated `links` value should invalidate a relationship cache', function(assert) { + assert.expect(8); + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + assert.equal(relationship.type, 'comment', 'relationship was passed correctly'); + + if (link === '/first') { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + } else if (link === '/second') { + return resolve({ + data: [ + { id: 3, type: 'comment', attributes: { body: 'Third' } }, + { id: 4, type: 'comment', attributes: { body: 'Fourth' } }, + { id: 5, type: 'comment', attributes: { body: 'Fifth' } }, + ], + }); + } + }; + let post; + + run(function() { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: '/first', + }, + }, + }, + }, + }); + post = env.store.peekRecord('post', 1); + }); + + run(function() { + post.get('comments').then(function(comments) { + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(comments.get('length'), 2, 'comments have 2 length'); + assert.equal(comments.objectAt(0).get('body'), 'First', 'comment 1 successfully loaded'); + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: '/second', + }, + }, + }, + }, + }); + post.get('comments').then(function(newComments) { + assert.equal(comments, newComments, 'hasMany array was kept the same'); + assert.equal(newComments.get('length'), 3, 'comments updated successfully'); + assert.equal( + newComments.objectAt(0).get('body'), + 'Third', + 'third comment loaded successfully' + ); + }); + }); + }); +}); + +test("When a polymorphic hasMany relationship is accessed, the adapter's findMany method should not be called if all the records in the relationship are already loaded", function(assert) { + assert.expect(1); + + let userData = { + type: 'user', + id: '1', + relationships: { + messages: { + data: [{ type: 'post', id: '1' }, { type: 'comment', id: '3' }], + }, + }, + }; + + env.adapter.findMany = function(store, type, ids, snapshots) { + assert.ok(false, "The adapter's find method should not be called"); + }; + + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { data: userData }; + }; + + run(function() { + env.store.push({ + data: userData, + included: [ + { + type: 'post', + id: '1', + }, + { + type: 'comment', + id: '3', + }, + ], + }); + }); + + run(function() { + env.store.findRecord('user', 1).then(function(user) { + let messages = user.get('messages'); + assert.equal(messages.get('length'), 2, 'The messages are correctly loaded'); + }); + }); +}); + +test("When a polymorphic hasMany relationship is accessed, the store can call multiple adapters' findMany or find methods if the records are not loaded", function(assert) { + User.reopen({ + messages: hasMany('message', { polymorphic: true, async: true }), + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.findRecord = function(store, type, id, snapshot) { + if (type === Post) { + return resolve({ data: { id: 1, type: 'post' } }); + } else if (type === Comment) { + return resolve({ data: { id: 3, type: 'comment' } }); + } + }; + + run(function() { + env.store.push({ + data: { + type: 'user', + id: '1', + relationships: { + messages: { + data: [{ type: 'post', id: '1' }, { type: 'comment', id: '3' }], + }, + }, + }, + }); + }); + + run(function() { + env.store + .findRecord('user', 1) + .then(function(user) { + return user.get('messages'); + }) + .then(function(messages) { + assert.equal(messages.get('length'), 2, 'The messages are correctly loaded'); + }); + }); +}); + +test('polymorphic hasMany type-checks check the superclass', function(assert) { + assert.expect(1); + + run(function() { + let igor = env.store.createRecord('user', { name: 'Igor' }); + let comment = env.store.createRecord('comment', { + body: 'Well I thought the title was fine', + }); + + igor.get('messages').addObject(comment); + + assert.equal(igor.get('messages.firstObject.body'), 'Well I thought the title was fine'); + }); +}); + +test('Type can be inferred from the key of a hasMany relationship', function(assert) { + assert.expect(1); + + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { + data: { + id: 1, + type: 'user', + relationships: { + contacts: { + data: [{ id: 1, type: 'contact' }], + }, + }, + }, + }; + }; + + run(function() { + env.store.push({ + data: { + type: 'user', + id: '1', + relationships: { + contacts: { + data: [{ type: 'contact', id: '1' }], + }, + }, + }, + included: [ + { + type: 'contact', + id: '1', + }, + ], + }); + }); + run(function() { + env.store + .findRecord('user', 1) + .then(function(user) { + return user.get('contacts'); + }) + .then(function(contacts) { + assert.equal(contacts.get('length'), 1, 'The contacts relationship is correctly set up'); + }); + }); +}); + +test('Type can be inferred from the key of an async hasMany relationship', function(assert) { + assert.expect(1); + + User.reopen({ + contacts: DS.hasMany({ async: true }), + }); + + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { + data: { + id: 1, + type: 'user', + relationships: { + contacts: { + data: [{ id: 1, type: 'contact' }], + }, + }, + }, + }; + }; + + run(function() { + env.store.push({ + data: { + type: 'user', + id: '1', + relationships: { + contacts: { + data: [{ type: 'contact', id: '1' }], + }, + }, + }, + included: [ + { + type: 'contact', + id: '1', + }, + ], + }); + }); + run(function() { + env.store + .findRecord('user', 1) + .then(function(user) { + return user.get('contacts'); + }) + .then(function(contacts) { + assert.equal(contacts.get('length'), 1, 'The contacts relationship is correctly set up'); + }); + }); +}); + +test('Polymorphic relationships work with a hasMany whose type is inferred', function(assert) { + User.reopen({ + contacts: DS.hasMany({ polymorphic: true, async: false }), + }); + + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { data: { id: 1, type: 'user' } }; + }; + + assert.expect(1); + run(function() { + env.store.push({ + data: { + type: 'user', + id: '1', + relationships: { + contacts: { + data: [{ type: 'email', id: '1' }, { type: 'phone', id: '2' }], + }, + }, + }, + included: [ + { + type: 'email', + id: '1', + }, + { + type: 'phone', + id: '2', + }, + ], + }); + }); + run(function() { + env.store + .findRecord('user', 1) + .then(function(user) { + return user.get('contacts'); + }) + .then(function(contacts) { + assert.equal(contacts.get('length'), 2, 'The contacts relationship is correctly set up'); + }); + }); +}); + +test('Polymorphic relationships with a hasMany is set up correctly on both sides', function(assert) { + assert.expect(2); + + Contact.reopen({ + posts: DS.hasMany('post', { async: false }), + }); + + Post.reopen({ + contact: DS.belongsTo('contact', { polymorphic: true, async: false }), + }); + + let email = env.store.createRecord('email'); + let post = env.store.createRecord('post', { + contact: email, + }); + + assert.equal(post.get('contact'), email, 'The polymorphic belongsTo is set up correctly'); + assert.equal( + get(email, 'posts.length'), + 1, + 'The inverse has many is set up correctly on the email side.' + ); +}); + +testInDebug("A record can't be created from a polymorphic hasMany relationship", function(assert) { + env.adapter.shouldBackgroundReloadRecord = () => false; + run(function() { + env.store.push({ + data: { + type: 'user', + id: '1', + relationships: { + messages: { + data: [], + }, + }, + }, + }); + }); + + run(function() { + env.store + .findRecord('user', 1) + .then(function(user) { + return user.get('messages'); + }) + .then(function(messages) { + assert.expectAssertion(function() { + messages.createRecord(); + }, /You cannot add 'message' records to this polymorphic relationship/); + }); + }); +}); + +testInDebug( + 'Only records of the same type can be added to a monomorphic hasMany relationship', + function(assert) { + assert.expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; + run(function() { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + relationships: { + comments: { + data: [], + }, + }, + }, + { + type: 'post', + id: '2', + }, + ], + }); + }); + + run(function() { + all([env.store.findRecord('post', 1), env.store.findRecord('post', 2)]).then(function( + records + ) { + assert.expectAssertion(function() { + records[0].get('comments').pushObject(records[1]); + }, /The 'post' type does not implement 'comment' and thus cannot be assigned to the 'comments' relationship in 'post'/); + }); + }); + } +); + +testInDebug( + 'Only records of the same base modelClass can be added to a polymorphic hasMany relationship', + function(assert) { + assert.expect(2); + env.adapter.shouldBackgroundReloadRecord = () => false; + run(function() { + env.store.push({ + data: [ + { + type: 'user', + id: '1', + relationships: { + messages: { + data: [], + }, + }, + }, + { + type: 'user', + id: '2', + relationships: { + messages: { + data: [], + }, + }, + }, + ], + included: [ + { + type: 'post', + id: '1', + relationships: { + comments: { + data: [], + }, + }, + }, + { + type: 'comment', + id: '3', + }, + ], + }); + }); + let asyncRecords; + + run(function() { + asyncRecords = hash({ + user: env.store.findRecord('user', 1), + anotherUser: env.store.findRecord('user', 2), + post: env.store.findRecord('post', 1), + comment: env.store.findRecord('comment', 3), + }); + + asyncRecords + .then(function(records) { + records.messages = records.user.get('messages'); + return hash(records); + }) + .then(function(records) { + records.messages.pushObject(records.post); + records.messages.pushObject(records.comment); + assert.equal(records.messages.get('length'), 2, 'The messages are correctly added'); + + assert.expectAssertion(function() { + records.messages.pushObject(records.anotherUser); + }, /The 'user' type does not implement 'message' and thus cannot be assigned to the 'messages' relationship in 'user'. Make it a descendant of 'message'/); + }); + }); + } +); + +test('A record can be removed from a polymorphic association', function(assert) { + assert.expect(4); + env.adapter.shouldBackgroundReloadRecord = () => false; + run(function() { + env.store.push({ + data: { + type: 'user', + id: '1', + relationships: { + messages: { + data: [{ type: 'comment', id: '3' }], + }, + }, + }, + included: [ + { + type: 'comment', + id: '3', + }, + ], + }); + }); + let asyncRecords; + + run(function() { + asyncRecords = hash({ + user: env.store.findRecord('user', 1), + comment: env.store.findRecord('comment', 3), + }); + + asyncRecords + .then(function(records) { + records.messages = records.user.get('messages'); + return hash(records); + }) + .then(function(records) { + assert.equal(records.messages.get('length'), 1, 'The user has 1 message'); + + let removedObject = records.messages.popObject(); + + assert.equal(removedObject, records.comment, 'The message is correctly removed'); + assert.equal(records.messages.get('length'), 0, 'The user does not have any messages'); + assert.equal(records.messages.objectAt(0), null, "No messages can't be fetched"); + }); + }); +}); + +test('When a record is created on the client, its hasMany arrays should be in a loaded state', function(assert) { + assert.expect(3); + + let post = env.store.createRecord('post'); + + assert.ok(get(post, 'isLoaded'), 'The post should have isLoaded flag'); + let comments; + run(function() { + comments = get(post, 'comments'); + }); + + assert.equal(get(comments, 'length'), 0, 'The comments should be an empty array'); + + assert.ok(get(comments, 'isLoaded'), 'The comments should have isLoaded flag'); +}); + +test('When a record is created on the client, its async hasMany arrays should be in a loaded state', function(assert) { + assert.expect(4); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + let post = env.store.createRecord('post'); + + assert.ok(get(post, 'isLoaded'), 'The post should have isLoaded flag'); + + run(function() { + get(post, 'comments').then(function(comments) { + assert.ok(true, 'Comments array successfully resolves'); + assert.equal(get(comments, 'length'), 0, 'The comments should be an empty array'); + assert.ok(get(comments, 'isLoaded'), 'The comments should have isLoaded flag'); + }); + }); +}); + +test('we can set records SYNC HM relationship', function(assert) { + assert.expect(1); + let post = env.store.createRecord('post'); + + run(function() { + env.store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'First', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'Second', + }, + }, + ], + }); + post.set('comments', env.store.peekAll('comment')); + }); + assert.equal(get(post, 'comments.length'), 2, 'we can set HM relationship'); +}); + +test('We can set records ASYNC HM relationship', function(assert) { + assert.expect(1); + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + let post = env.store.createRecord('post'); + + run(function() { + env.store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'First', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'Second', + }, + }, + ], + }); + post.set('comments', env.store.peekAll('comment')); + }); + + return post.get('comments').then(comments => { + assert.equal(comments.get('length'), 2, 'we can set async HM relationship'); + }); +}); + +test('When a record is saved, its unsaved hasMany records should be kept', function(assert) { + assert.expect(1); + + let post, comment; + + env.adapter.createRecord = function(store, type, snapshot) { + return resolve({ data: { id: 1, type: snapshot.modelName } }); + }; + + return run(() => { + post = env.store.createRecord('post'); + comment = env.store.createRecord('comment'); + post.get('comments').pushObject(comment); + return post.save(); + }).then(() => { + assert.equal( + get(post, 'comments.length'), + 1, + "The unsaved comment should be in the post's comments array" + ); + }); +}); + +test('dual non-async HM <-> BT', function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { inverse: 'post', async: false }), + }); + + Comment.reopen({ + post: DS.belongsTo('post', { async: false }), + }); + + env.adapter.createRecord = function(store, type, snapshot) { + let serialized = snapshot.record.serialize(); + serialized.data.id = 2; + return resolve(serialized); + }; + let post, firstComment; + + run(function() { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], + }, + }, + }, + }); + env.store.push({ + data: { + type: 'comment', + id: '1', + relationships: { + comments: { + post: { type: 'post', id: '1' }, + }, + }, + }, + }); + post = env.store.peekRecord('post', 1); + firstComment = env.store.peekRecord('comment', 1); + + env.store + .createRecord('comment', { + post: post, + }) + .save() + .then(function(comment) { + let commentPost = comment.get('post'); + let postComments = comment.get('post.comments'); + let postCommentsLength = comment.get('post.comments.length'); + + assert.deepEqual(post, commentPost, 'expect the new comments post, to be the correct post'); + assert.ok(postComments, 'comments should exist'); + assert.equal( + postCommentsLength, + 2, + "comment's post should have a internalModel back to comment" + ); + assert.ok( + postComments && postComments.indexOf(firstComment) !== -1, + 'expect to contain first comment' + ); + assert.ok( + postComments && postComments.indexOf(comment) !== -1, + 'expected to contain the new comment' + ); + }); + }); +}); + +test('When an unloaded record is added to the hasMany, it gets fetched once the hasMany is accessed even if the hasMany has been already fetched', async function(assert) { + assert.expect(6); + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + const { store, adapter } = env; + + let findManyCalls = 0; + let findRecordCalls = 0; + + adapter.findMany = function(store, type, ids, snapshots) { + assert.ok(true, `findMany called ${++findManyCalls}x`); + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'first' } }, + { id: 2, type: 'comment', attributes: { body: 'second' } }, + ], + }); + }; + + adapter.findRecord = function(store, type, id, snapshot) { + assert.ok(true, `findRecord called ${++findRecordCalls}x`); + + return resolve({ data: { id: 3, type: 'comment', attributes: { body: 'third' } } }); + }; + + let post = store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }, { type: 'comment', id: '2' }], + }, + }, + }, + }); + + let fetchedComments = await post.get('comments'); + + assert.equal(fetchedComments.get('length'), 2, 'comments fetched successfully'); + assert.equal( + fetchedComments.objectAt(0).get('body'), + 'first', + 'first comment loaded successfully' + ); + + store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + }); + + let newlyFetchedComments = await post.get('comments'); + + assert.equal(newlyFetchedComments.get('length'), 3, 'all three comments fetched successfully'); + assert.equal( + newlyFetchedComments.objectAt(2).get('body'), + 'third', + 'third comment loaded successfully' + ); +}); + +skip('A sync hasMany errors out if there are unloaded records in it', function(assert) { + let post = run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }, { type: 'comment', id: '2' }], + }, + }, + }, + }); + return env.store.peekRecord('post', 1); + }); + + assert.expectAssertion(() => { + run(post, 'get', 'comments'); + }, /You looked up the 'comments' relationship on a 'post' with id 1 but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async \(`DS.hasMany\({ async: true }\)`\)/); +}); + +test('After removing and unloading a record, a hasMany relationship should still be valid', function(assert) { + const post = run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], + }, + }, + }, + included: [{ type: 'comment', id: '1' }], + }); + const post = env.store.peekRecord('post', 1); + const comments = post.get('comments'); + const comment = comments.objectAt(0); + comments.removeObject(comment); + env.store.unloadRecord(comment); + assert.equal(comments.get('length'), 0); + return post; + }); + + // Explicitly re-get comments + assert.equal(run(post, 'get', 'comments.length'), 0); +}); + +test('If reordered hasMany data has been pushed to the store, the many array reflects the ordering change - sync', function(assert) { + let comment1, comment2, comment3, comment4; + let post; + + run(() => { + env.store.push({ + data: [ + { + type: 'comment', + id: '1', + }, + { + type: 'comment', + id: '2', + }, + { + type: 'comment', + id: '3', + }, + { + type: 'comment', + id: '4', + }, + ], + }); + + comment1 = env.store.peekRecord('comment', 1); + comment2 = env.store.peekRecord('comment', 2); + comment3 = env.store.peekRecord('comment', 3); + comment4 = env.store.peekRecord('comment', 4); + }); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }, { type: 'comment', id: '2' }], + }, + }, + }, + }); + post = env.store.peekRecord('post', 1); + + assert.deepEqual( + post.get('comments').toArray(), + [comment1, comment2], + 'Initial ordering is correct' + ); + }); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '2' }, { type: 'comment', id: '1' }], + }, + }, + }, + }); + }); + assert.deepEqual( + post.get('comments').toArray(), + [comment2, comment1], + 'Updated ordering is correct' + ); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '2' }], + }, + }, + }, + }); + }); + assert.deepEqual(post.get('comments').toArray(), [comment2], 'Updated ordering is correct'); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + { type: 'comment', id: '4' }, + ], + }, + }, + }, + }); + }); + assert.deepEqual( + post.get('comments').toArray(), + [comment1, comment2, comment3, comment4], + 'Updated ordering is correct' + ); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '4' }, { type: 'comment', id: '3' }], + }, + }, + }, + }); + }); + assert.deepEqual( + post.get('comments').toArray(), + [comment4, comment3], + 'Updated ordering is correct' + ); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [ + { type: 'comment', id: '4' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + { type: 'comment', id: '1' }, + ], + }, + }, + }, + }); + }); + + assert.deepEqual( + post.get('comments').toArray(), + [comment4, comment2, comment3, comment1], + 'Updated ordering is correct' + ); +}); + +test('Rollbacking attributes for deleted record restores implicit relationship correctly when the hasMany side has been deleted - async', function(assert) { + let book, chapter; + + run(() => { + env.store.push({ + data: { + type: 'book', + id: '1', + attributes: { + title: "Stanley's Amazing Adventures", + }, + relationships: { + chapters: { + data: [{ type: 'chapter', id: '2' }], + }, + }, + }, + included: [ + { + type: 'chapter', + id: '2', + attributes: { + title: 'Sailing the Seven Seas', + }, + }, + ], + }); + book = env.store.peekRecord('book', 1); + chapter = env.store.peekRecord('chapter', 2); + }); + + run(() => { + chapter.deleteRecord(); + chapter.rollbackAttributes(); + }); + + return run(() => { + return book.get('chapters').then(fetchedChapters => { + assert.equal( + fetchedChapters.objectAt(0), + chapter, + 'Book has a chapter after rollback attributes' + ); + }); + }); +}); + +test('Rollbacking attributes for deleted record restores implicit relationship correctly when the hasMany side has been deleted - sync', function(assert) { + let book, chapter; + + run(() => { + env.store.push({ + data: { + type: 'book', + id: '1', + attributes: { + title: "Stanley's Amazing Adventures", + }, + relationships: { + chapters: { + data: [{ type: 'chapter', id: '2' }], + }, + }, + }, + included: [ + { + type: 'chapter', + id: '2', + attributes: { + title: 'Sailing the Seven Seas', + }, + }, + ], + }); + book = env.store.peekRecord('book', 1); + chapter = env.store.peekRecord('chapter', 2); + }); + + run(() => { + chapter.deleteRecord(); + chapter.rollbackAttributes(); + }); + + run(() => { + assert.equal( + book.get('chapters.firstObject'), + chapter, + 'Book has a chapter after rollback attributes' + ); + }); +}); + +test('Rollbacking attributes for deleted record restores implicit relationship correctly when the belongsTo side has been deleted - async', function(assert) { + Page.reopen({ + chapter: DS.belongsTo('chapter', { async: true }), + }); + + let chapter, page; + + run(() => { + env.store.push({ + data: { + type: 'chapter', + id: '2', + attributes: { + title: 'Sailing the Seven Seas', + }, + }, + included: [ + { + type: 'page', + id: '3', + attributes: { + number: 1, + }, + relationships: { + chapter: { + data: { type: 'chapter', id: '2' }, + }, + }, + }, + ], + }); + chapter = env.store.peekRecord('chapter', 2); + page = env.store.peekRecord('page', 3); + }); + + run(() => { + chapter.deleteRecord(); + chapter.rollbackAttributes(); + }); + + return run(() => { + return page.get('chapter').then(fetchedChapter => { + assert.equal(fetchedChapter, chapter, 'Page has a chapter after rollback attributes'); + }); + }); +}); + +test('Rollbacking attributes for deleted record restores implicit relationship correctly when the belongsTo side has been deleted - sync', function(assert) { + let chapter, page; + run(() => { + env.store.push({ + data: { + type: 'chapter', + id: '2', + attributes: { + title: 'Sailing the Seven Seas', + }, + }, + included: [ + { + type: 'page', + id: '3', + attributes: { + number: 1, + }, + relationships: { + chapter: { + data: { type: 'chapter', id: '2' }, + }, + }, + }, + ], + }); + chapter = env.store.peekRecord('chapter', 2); + page = env.store.peekRecord('page', 3); + }); + + run(() => { + chapter.deleteRecord(); + chapter.rollbackAttributes(); + }); + + run(() => { + assert.equal(page.get('chapter'), chapter, 'Page has a chapter after rollback attributes'); + }); +}); + +test('ManyArray notifies the array observers and flushes bindings when removing', function(assert) { + assert.expect(2); + let chapter, page, page2; + let observe = false; + + run(() => { + env.store.push({ + data: [ + { + type: 'page', + id: '1', + attributes: { + number: 1, + }, + }, + { + type: 'page', + id: '2', + attributes: { + number: 2, + }, + }, + { + type: 'chapter', + id: '1', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + pages: { + data: [{ type: 'page', id: '1' }, { type: 'page', id: '2' }], + }, + }, + }, + ], + }); + page = env.store.peekRecord('page', 1); + page2 = env.store.peekRecord('page', 2); + chapter = env.store.peekRecord('chapter', 1); + + chapter.get('pages').addArrayObserver(this, { + willChange(pages, index, removeCount, addCount) { + if (observe) { + assert.equal(pages.objectAt(index), page2, 'page2 is passed to willChange'); + } + }, + didChange(pages, index, removeCount, addCount) { + if (observe) { + assert.equal(removeCount, 1, 'removeCount is correct'); + } + }, + }); + }); + + run(() => { + observe = true; + page2.set('chapter', null); + observe = false; + }); +}); + +test('ManyArray notifies the array observers and flushes bindings when adding', function(assert) { + assert.expect(2); + let chapter, page, page2; + let observe = false; + + run(() => { + env.store.push({ + data: [ + { + type: 'page', + id: '1', + attributes: { + number: 1, + }, + }, + { + type: 'page', + id: '2', + attributes: { + number: 2, + }, + }, + { + type: 'chapter', + id: '1', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + pages: { + data: [{ type: 'page', id: '1' }], + }, + }, + }, + ], + }); + page = env.store.peekRecord('page', 1); + page2 = env.store.peekRecord('page', 2); + chapter = env.store.peekRecord('chapter', 1); + + chapter.get('pages').addArrayObserver(this, { + willChange(pages, index, removeCount, addCount) { + if (observe) { + assert.equal(addCount, 1, 'addCount is correct'); + } + }, + didChange(pages, index, removeCount, addCount) { + if (observe) { + assert.equal(pages.objectAt(index), page2, 'page2 is passed to didChange'); + } + }, + }); + }); + + run(() => { + observe = true; + page2.set('chapter', chapter); + observe = false; + }); +}); + +testInDebug('Passing a model as type to hasMany should not work', function(assert) { + assert.expect(1); + + assert.expectAssertion(() => { + User = DS.Model.extend(); + + Contact = DS.Model.extend({ + users: hasMany(User, { async: false }), + }); + }, /The first argument to DS.hasMany must be a string/); +}); + +test('Relationship.clear removes all records correctly', function(assert) { + let post; + + Comment.reopen({ + post: DS.belongsTo('post', { async: false }), + }); + + Post.reopen({ + comments: DS.hasMany('comment', { inverse: 'post', async: false }), + }); + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '2', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }, { type: 'comment', id: '2' }], + }, + }, + }, + { + type: 'comment', + id: '1', + relationships: { + post: { + data: { type: 'post', id: '2' }, + }, + }, + }, + { + type: 'comment', + id: '2', + relationships: { + post: { + data: { type: 'post', id: '2' }, + }, + }, + }, + { + type: 'comment', + id: '3', + relationships: { + post: { + data: { type: 'post', id: '2' }, + }, + }, + }, + ], + }); + post = env.store.peekRecord('post', 2); + }); + + run(() => { + relationshipStateFor(post, 'comments').clear(); + let comments = A(env.store.peekAll('comment')); + assert.deepEqual(comments.mapBy('post'), [null, null, null]); + }); +}); + +test('unloading a record with associated records does not prevent the store from tearing down', function(assert) { + let post; + + Comment.reopen({ + post: DS.belongsTo('post', { async: false }), + }); + + Post.reopen({ + comments: DS.hasMany('comment', { inverse: 'post', async: false }), + }); + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '2', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }, { type: 'comment', id: '2' }], + }, + }, + }, + { + type: 'comment', + id: '1', + relationships: { + post: { + data: { type: 'post', id: '2' }, + }, + }, + }, + { + type: 'comment', + id: '2', + relationships: { + post: { + data: { type: 'post', id: '2' }, + }, + }, + }, + ], + }); + post = env.store.peekRecord('post', 2); + + // This line triggers the original bug that gets manifested + // in teardown for apps, e.g. store.destroy that is caused by + // App.destroy(). + // Relationship#clear uses Ember.Set#forEach, which does incorrect + // iteration when the set is being mutated (in our case, the index gets off + // because records are being removed) + env.store.unloadRecord(post); + }); + + try { + run(() => { + env.store.destroy(); + }); + assert.ok(true, 'store destroyed correctly'); + } catch (error) { + assert.ok(false, 'store prevented from being destroyed'); + } +}); + +test('adding and removing records from hasMany relationship #2666', function(assert) { + assert.expect(4); + + let Post = DS.Model.extend({ + comments: DS.hasMany('comment', { async: true }), + }); + Post.reopenClass({ toString: () => 'Post' }); + + let Comment = DS.Model.extend({ + post: DS.belongsTo('post', { async: false }), + }); + Comment.reopenClass({ toString: () => 'Comment' }); + + env = setupStore({ + post: Post, + comment: Comment, + adapter: DS.RESTAdapter.extend({ + shouldBackgroundReloadRecord: () => false, + }), + }); + + let commentId = 4; + env.owner.register( + 'adapter:comment', + DS.RESTAdapter.extend({ + deleteRecord(record) { + return resolve(); + }, + updateRecord(record) { + return resolve(); + }, + createRecord() { + return resolve({ comments: { id: commentId++ } }); + }, + }) + ); + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + { + type: 'comment', + id: '1', + }, + { + type: 'comment', + id: '2', + }, + { + type: 'comment', + id: '3', + }, + ], + }); + }); + + return run(() => { + return env.store.findRecord('post', 1).then(post => { + let comments = post.get('comments'); + assert.equal(comments.get('length'), 3, 'Initial comments count'); + + // Add comment #4 + let comment = env.store.createRecord('comment'); + comments.addObject(comment); + + return comment + .save() + .then(() => { + let comments = post.get('comments'); + assert.equal(comments.get('length'), 4, 'Comments count after first add'); + + // Delete comment #4 + return comments.get('lastObject').destroyRecord(); + }) + .then(() => { + let comments = post.get('comments'); + let length = comments.get('length'); + + assert.equal(length, 3, 'Comments count after destroy'); + + // Add another comment #4 + let comment = env.store.createRecord('comment'); + comments.addObject(comment); + return comment.save(); + }) + .then(() => { + let comments = post.get('comments'); + assert.equal(comments.get('length'), 4, 'Comments count after second add'); + }); + }); + }); +}); + +test('hasMany hasAnyRelationshipData async loaded', function(assert) { + assert.expect(1); + + Chapter.reopen({ + pages: hasMany('pages', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'chapter', + attributes: { title: 'The Story Begins' }, + relationships: { + pages: { + data: [{ id: 2, type: 'page' }, { id: 3, type: 'page' }], + }, + }, + }, + }); + }; + + return run(() => { + return store.findRecord('chapter', 1).then(chapter => { + let relationship = relationshipStateFor(chapter, 'pages'); + assert.equal(relationship.hasAnyRelationshipData, true, 'relationship has data'); + }); + }); +}); + +test('hasMany hasAnyRelationshipData sync loaded', function(assert) { + assert.expect(1); + + env.adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'chapter', + attributes: { title: 'The Story Begins' }, + relationships: { + pages: { + data: [{ id: 2, type: 'page' }, { id: 3, type: 'page' }], + }, + }, + }, + }); + }; + + return run(() => { + return store.findRecord('chapter', 1).then(chapter => { + let relationship = relationshipStateFor(chapter, 'pages'); + assert.equal(relationship.hasAnyRelationshipData, true, 'relationship has data'); + }); + }); +}); + +test('hasMany hasAnyRelationshipData async not loaded', function(assert) { + assert.expect(1); + + Chapter.reopen({ + pages: hasMany('pages', { async: true }), + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'chapter', + attributes: { title: 'The Story Begins' }, + relationships: { + pages: { + links: { related: 'pages' }, + }, + }, + }, + }); + }; + + return run(() => { + return store.findRecord('chapter', 1).then(chapter => { + let relationship = relationshipStateFor(chapter, 'pages'); + assert.equal(relationship.hasAnyRelationshipData, false, 'relationship does not have data'); + }); + }); +}); + +test('hasMany hasAnyRelationshipData sync not loaded', function(assert) { + assert.expect(1); + + env.adapter.findRecord = function(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: 'chapter', + attributes: { title: 'The Story Begins' }, + }, + }); + }; + + return run(() => { + return store.findRecord('chapter', 1).then(chapter => { + let relationship = relationshipStateFor(chapter, 'pages'); + assert.equal(relationship.hasAnyRelationshipData, false, 'relationship does not have data'); + }); + }); +}); + +test('hasMany hasAnyRelationshipData async created', function(assert) { + assert.expect(2); + + Chapter.reopen({ + pages: hasMany('pages', { async: true }), + }); + + let chapter = store.createRecord('chapter', { title: 'The Story Begins' }); + let page = store.createRecord('page'); + + let relationship = relationshipStateFor(chapter, 'pages'); + assert.equal(relationship.hasAnyRelationshipData, false, 'relationship does not have data'); + + chapter = store.createRecord('chapter', { + title: 'The Story Begins', + pages: [page], + }); + + relationship = relationshipStateFor(chapter, 'pages'); + assert.equal(relationship.hasAnyRelationshipData, true, 'relationship has data'); +}); + +test('hasMany hasAnyRelationshipData sync created', function(assert) { + assert.expect(2); + + let chapter = store.createRecord('chapter', { title: 'The Story Begins' }); + let relationship = relationshipStateFor(chapter, 'pages'); + + assert.equal(relationship.hasAnyRelationshipData, false, 'relationship does not have data'); + + chapter = store.createRecord('chapter', { + title: 'The Story Begins', + pages: [store.createRecord('page')], + }); + relationship = relationshipStateFor(chapter, 'pages'); + + assert.equal(relationship.hasAnyRelationshipData, true, 'relationship has data'); +}); + +test("Model's hasMany relationship should not be created during model creation", function(assert) { + let user; + run(() => { + env.store.push({ + data: { + type: 'user', + id: '1', + }, + }); + user = env.store.peekRecord('user', 1); + assert.ok( + !relationshipsFor(user).has('messages'), + 'Newly created record should not have relationships' + ); + }); +}); + +test("Model's belongsTo relationship should be created during 'get' method", function(assert) { + let user; + run(() => { + user = env.store.createRecord('user'); + user.get('messages'); + assert.ok( + relationshipsFor(user).has('messages'), + 'Newly created record with relationships in params passed in its constructor should have relationships' + ); + }); +}); + +test('metadata is accessible when pushed as a meta property for a relationship', function(assert) { + assert.expect(1); + let book; + env.adapter.findHasMany = function() { + return resolve({}); + }; + + run(() => { + env.store.push({ + data: { + type: 'book', + id: '1', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + chapters: { + meta: { + where: 'the lefkada sea', + }, + links: { + related: '/chapters', + }, + }, + }, + }, + }); + book = env.store.peekRecord('book', 1); + }); + + run(() => { + assert.equal( + relationshipStateFor(book, 'chapters').meta.where, + 'the lefkada sea', + 'meta is there' + ); + }); +}); + +test('metadata is accessible when return from a fetchLink', function(assert) { + assert.expect(1); + env.owner.register('serializer:application', DS.RESTSerializer); + + env.adapter.findHasMany = function() { + return resolve({ + meta: { + foo: 'bar', + }, + chapters: [{ id: '2' }, { id: '3' }], + }); + }; + + let book; + + run(() => { + env.store.push({ + data: { + type: 'book', + id: '1', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + chapters: { + links: { + related: '/chapters', + }, + }, + }, + }, + }); + book = env.store.peekRecord('book', 1); + }); + + return run(() => { + return book.get('chapters').then(chapters => { + let meta = chapters.get('meta'); + assert.equal(get(meta, 'foo'), 'bar', 'metadata is available'); + }); + }); +}); + +test('metadata should be reset between requests', function(assert) { + let counter = 0; + env.owner.register('serializer:application', DS.RESTSerializer); + + env.adapter.findHasMany = function() { + let data = { + meta: { + foo: 'bar', + }, + chapters: [{ id: '2' }, { id: '3' }], + }; + + assert.ok(true, 'findHasMany should be called twice'); + + if (counter === 1) { + delete data.meta; + } + + counter++; + + return resolve(data); + }; + + let book1, book2; + + run(() => { + env.store.push({ + data: [ + { + type: 'book', + id: '1', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + chapters: { + links: { + related: 'chapters', + }, + }, + }, + }, + { + type: 'book', + id: '2', + attributes: { + title: 'Another book title', + }, + relationships: { + chapters: { + links: { + related: 'chapters', + }, + }, + }, + }, + ], + }); + book1 = env.store.peekRecord('book', 1); + book2 = env.store.peekRecord('book', 2); + }); + + return run(() => { + return book1.get('chapters').then(chapters => { + let meta = chapters.get('meta'); + assert.equal(get(meta, 'foo'), 'bar', 'metadata should available'); + + return book2.get('chapters').then(chapters => { + let meta = chapters.get('meta'); + assert.equal(meta, undefined, 'metadata should not be available'); + }); + }); + }); +}); + +test('Related link should be fetched when no relationship data is present', function(assert) { + assert.expect(3); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true, inverse: 'post' }), + }); + Comment.reopen({ + post: DS.belongsTo('post', { async: false, inverse: 'comments' }), + }); + env.adapter.shouldBackgroundReloadRecord = () => { + return false; + }; + env.adapter.findRecord = () => { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + env.adapter.findMany = () => { + assert.ok(false, "The adapter's findMany method should not be called"); + }; + + env.adapter.findHasMany = function(store, snapshot, url, relationship) { + assert.equal(url, 'get-comments', 'url is correct'); + assert.ok(true, "The adapter's findHasMany method should be called"); + return resolve({ + data: [ + { + id: '1', + type: 'comment', + attributes: { + body: 'This is comment', + }, + }, + ], + }); + }; + + return run(() => { + let post = env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'get-comments', + }, + }, + }, + }, + }); + + return post.get('comments').then(comments => { + assert.equal(comments.get('firstObject.body'), 'This is comment', 'comment body is correct'); + }); + }); +}); + +test('Related link should take precedence over relationship data when local record data is missing', function(assert) { + assert.expect(3); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true, inverse: 'post' }), + }); + Comment.reopen({ + post: DS.belongsTo('post', { async: false, inverse: 'comments' }), + }); + env.adapter.shouldBackgroundReloadRecord = () => { + return false; + }; + env.adapter.findRecord = () => { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + env.adapter.findMany = () => { + assert.ok(false, "The adapter's findMany method should not be called"); + }; + + env.adapter.findHasMany = function(store, snapshot, url, relationship) { + assert.equal(url, 'get-comments', 'url is correct'); + assert.ok(true, "The adapter's findHasMany method should be called"); + return resolve({ + data: [ + { + id: '1', + type: 'comment', + attributes: { + body: 'This is comment', + }, + }, + ], + }); + }; + + return run(() => { + let post = env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'get-comments', + }, + data: [{ type: 'comment', id: '1' }], + }, + }, + }, + }); + + return post.get('comments').then(comments => { + assert.equal(comments.get('firstObject.body'), 'This is comment', 'comment body is correct'); + }); + }); +}); + +test('Local relationship data should take precedence over related link when local record data is available', function(assert) { + assert.expect(1); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true, inverse: 'post' }), + }); + Comment.reopen({ + post: DS.belongsTo('post', { async: false, inverse: 'comments' }), + }); + env.adapter.shouldBackgroundReloadRecord = () => { + return false; + }; + env.adapter.findRecord = () => { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + env.adapter.findMany = () => { + assert.ok(false, "The adapter's findMany method should not be called"); + }; + + env.adapter.findHasMany = function(store, snapshot, url, relationship) { + assert.ok(false, "The adapter's findHasMany method should not be called"); + }; + + return run(() => { + let post = env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'get-comments', + }, + data: [{ type: 'comment', id: '1' }], + }, + }, + }, + included: [ + { + id: '1', + type: 'comment', + attributes: { + body: 'This is comment', + }, + }, + ], + }); + + return post.get('comments').then(comments => { + assert.equal(comments.get('firstObject.body'), 'This is comment', 'comment body is correct'); + }); + }); +}); + +test('Related link should take precedence over local record data when relationship data is not initially available', function(assert) { + assert.expect(3); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true, inverse: 'post' }), + }); + Comment.reopen({ + post: DS.belongsTo('post', { async: false, inverse: 'comments' }), + }); + env.adapter.shouldBackgroundReloadRecord = () => { + return false; + }; + env.adapter.findRecord = () => { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + env.adapter.findMany = () => { + assert.ok(false, "The adapter's findMany method should not be called"); + }; + + env.adapter.findHasMany = function(store, snapshot, url, relationship) { + assert.equal(url, 'get-comments', 'url is correct'); + assert.ok(true, "The adapter's findHasMany method should be called"); + return resolve({ + data: [ + { + id: '1', + type: 'comment', + attributes: { + body: 'This is comment fetched by link', + }, + }, + ], + }); + }; + + return run(() => { + let post = env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'get-comments', + }, + }, + }, + }, + included: [ + { + id: '1', + type: 'comment', + attributes: { + body: 'This is comment', + }, + relationships: { + post: { + data: { + type: 'post', + id: '1', + }, + }, + }, + }, + ], + }); + + return post.get('comments').then(comments => { + assert.equal( + comments.get('firstObject.body'), + 'This is comment fetched by link', + 'comment body is correct' + ); + }); + }); +}); + +test('Updated related link should take precedence over relationship data and local record data', function(assert) { + assert.expect(3); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findHasMany = function(store, snapshot, url, relationship) { + assert.equal(url, 'comments-updated-link', 'url is correct'); + assert.ok(true, "The adapter's findHasMany method should be called"); + return resolve({ + data: [{ id: 1, type: 'comment', attributes: { body: 'This is updated comment' } }], + }); + }; + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.ok(false, "The adapter's findRecord method should not be called"); + }; + + return run(() => { + let post = env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'comments', + }, + data: [{ type: 'comment', id: '1' }], + }, + }, + }, + }); + + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'comments-updated-link', + }, + }, + }, + }, + }); + + return post.get('comments').then(comments => { + assert.equal( + comments.get('firstObject.body'), + 'This is updated comment', + 'comment body is correct' + ); + }); + }); +}); + +test('PromiseArray proxies createRecord to its ManyArray before the hasMany is loaded', function(assert) { + assert.expect(1); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + env.adapter.findHasMany = function(store, record, link, relationship) { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + + return run(() => { + let post = env.store.push({ + data: { + type: 'post', + id: 1, + relationships: { + comments: { + links: { + related: 'someLink', + }, + }, + }, + }, + }); + + let comments = post.get('comments'); + comments.createRecord(); + return comments.then(comments => { + assert.equal(comments.get('length'), 3, 'comments have 3 length, including new record'); + }); + }); +}); + +test('deleteRecord + unloadRecord fun', function(assert) { + User.reopen({ + posts: DS.hasMany('post', { inverse: null }), + }); + Post.reopen({ + user: DS.belongsTo('user', { inverse: null, async: false }), + }); + + run(() => { + env.store.push({ + data: [ + { + type: 'user', + id: 'user-1', + attributes: { + name: 'Adolfo Builes', + }, + relationships: { + posts: { + data: [ + { type: 'post', id: 'post-1' }, + { type: 'post', id: 'post-2' }, + { type: 'post', id: 'post-3' }, + { type: 'post', id: 'post-4' }, + { type: 'post', id: 'post-5' }, + ], + }, + }, + }, + { type: 'post', id: 'post-1' }, + { type: 'post', id: 'post-2' }, + { type: 'post', id: 'post-3' }, + { type: 'post', id: 'post-4' }, + { type: 'post', id: 'post-5' }, + ], + }); + + let user = env.store.peekRecord('user', 'user-1'); + let posts = user.get('posts'); + + env.store.adapterFor('post').deleteRecord = function() { + // just acknowledge all deletes, but with a noop + return { data: null }; + }; + + assert.deepEqual(posts.map(x => x.get('id')), [ + 'post-1', + 'post-2', + 'post-3', + 'post-4', + 'post-5', + ]); + + return run(() => { + return env.store + .peekRecord('post', 'post-2') + .destroyRecord() + .then(record => { + return env.store.unloadRecord(record); + }); + }) + .then(() => { + assert.deepEqual(posts.map(x => x.get('id')), ['post-1', 'post-3', 'post-4', 'post-5']); + return env.store + .peekRecord('post', 'post-3') + .destroyRecord() + .then(record => { + return env.store.unloadRecord(record); + }); + }) + .then(() => { + assert.deepEqual(posts.map(x => x.get('id')), ['post-1', 'post-4', 'post-5']); + return env.store + .peekRecord('post', 'post-4') + .destroyRecord() + .then(record => { + return env.store.unloadRecord(record); + }); + }) + .then(() => { + assert.deepEqual(posts.map(x => x.get('id')), ['post-1', 'post-5']); + }); + }); +}); + +test('unloading and reloading a record with hasMany relationship - #3084', function(assert) { + let user; + let message; + + run(() => { + env.store.push({ + data: [ + { + type: 'user', + id: 'user-1', + attributes: { + name: 'Adolfo Builes', + }, + relationships: { + messages: { + data: [{ type: 'message', id: 'message-1' }], + }, + }, + }, + { + type: 'message', + id: 'message-1', + }, + ], + }); + + user = env.store.peekRecord('user', 'user-1'); + message = env.store.peekRecord('message', 'message-1'); + + assert.equal(get(user, 'messages.firstObject.id'), 'message-1'); + assert.equal(get(message, 'user.id'), 'user-1'); + }); + + run(() => { + env.store.unloadRecord(user); + }); + + run(() => { + // The record is resurrected for some reason. + env.store.push({ + data: [ + { + type: 'user', + id: 'user-1', + attributes: { + name: 'Adolfo Builes', + }, + relationships: { + messages: { + data: [{ type: 'message', id: 'message-1' }], + }, + }, + }, + ], + }); + + user = env.store.peekRecord('user', 'user-1'); + + assert.equal(get(user, 'messages.firstObject.id'), 'message-1', 'user points to message'); + assert.equal(get(message, 'user.id'), 'user-1', 'message points to user'); + }); +}); + +test('deleted records should stay deleted', function(assert) { + let user; + let message; + + env.adapter.deleteRecord = function(store, type, id) { + return null; + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'user', + id: 'user-1', + attributes: { + name: 'Adolfo Builes', + }, + relationships: { + messages: { + data: [{ type: 'message', id: 'message-1' }, { type: 'message', id: 'message-2' }], + }, + }, + }, + { + type: 'message', + id: 'message-1', + }, + { + type: 'message', + id: 'message-2', + }, + ], + }); + + user = env.store.peekRecord('user', 'user-1'); + message = env.store.peekRecord('message', 'message-1'); + + assert.equal(get(user, 'messages.length'), 2); + }); + + run(() => message.destroyRecord()); + + run(() => { + // a new message is added to the user should not resurrected the + // deleted message + env.store.push({ + data: [ + { + type: 'message', + id: 'message-3', + relationships: { + user: { + data: { type: 'user', id: 'user-1' }, + }, + }, + }, + ], + }); + + assert.deepEqual( + get(user, 'messages').mapBy('id'), + ['message-2', 'message-3'], + 'user should have 2 message since 1 was deleted' + ); + }); +}); + +test("hasMany relationship with links doesn't trigger extra change notifications - #4942", function(assert) { + run(() => { + env.store.push({ + data: { + type: 'book', + id: '1', + relationships: { + chapters: { + data: [{ type: 'chapter', id: '1' }], + links: { related: '/book/1/chapters' }, + }, + }, + }, + included: [{ type: 'chapter', id: '1' }], + }); + }); + + let book = env.store.peekRecord('book', '1'); + let count = 0; + + book.addObserver('chapters', () => { + count++; + }); + + run(() => { + book.get('chapters'); + }); + + assert.equal(count, 0); +}); + +test('A hasMany relationship with a link will trigger the link request even if a inverse related object is pushed to the store', function(assert) { + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), + }); + + Comment.reopen({ + message: DS.belongsTo('post', { async: true }), + }); + + const postID = '1'; + + run(function() { + // load a record with a link hasMany relationship + env.store.push({ + data: { + type: 'post', + id: postID, + relationships: { + comments: { + links: { + related: '/posts/1/comments', + }, + }, + }, + }, + }); + + // if a related comment is pushed into the store, + // the post.comments.link will not be requested + // + // If this comment is not inserted into the store, everything works properly + env.store.push({ + data: { + type: 'comment', + id: '1', + attributes: { body: 'First' }, + relationships: { + message: { + data: { type: 'post', id: postID }, + }, + }, + }, + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + throw new Error(`findRecord for ${type} should not be called`); + }; + + let hasManyCounter = 0; + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + assert.equal(relationship.type, 'comment', 'findHasMany relationship type was Comment'); + assert.equal(relationship.key, 'comments', 'findHasMany relationship key was comments'); + assert.equal(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); + hasManyCounter++; + + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + + const post = env.store.peekRecord('post', postID); + post.get('comments').then(function(comments) { + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(hasManyCounter, 1, 'link was requested'); + assert.equal(comments.get('length'), 2, 'comments have 2 length'); + + post + .hasMany('comments') + .reload() + .then(function(comments) { + assert.equal(comments.get('isLoaded'), true, 'comments are loaded'); + assert.equal(hasManyCounter, 2, 'link was requested'); + assert.equal(comments.get('length'), 2, 'comments have 2 length'); + }); + }); + }); +}); diff --git a/tests/integration/relationships/inverse-relationship-load-test.js b/tests/integration/relationships/inverse-relationship-load-test.js new file mode 100644 index 00000000000..d642df61eaa --- /dev/null +++ b/tests/integration/relationships/inverse-relationship-load-test.js @@ -0,0 +1,4989 @@ +import { module, test } from 'qunit'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import { setupTest } from 'ember-qunit'; +import Store from 'ember-data/store'; +import Model from 'ember-data/model'; +import { resolve } from 'rsvp'; +import { attr, belongsTo, hasMany } from '@ember-decorators/data'; +import testInDebug from '../../helpers/test-in-debug'; + +module('inverse relationship load test', function(hooks) { + let store; + setupTest(hooks); + + hooks.beforeEach(function() { + let { owner } = this; + owner.register('service:store', Store); + store = owner.lookup('service:store'); + owner.register( + 'serializer:application', + JSONAPISerializer.extend({ + normalizeResponse(_, __, payload) { + return payload; + }, + }) + ); + }); + + test('one-to-many - findHasMany/implicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 2, 'hasMany relationship has correct number of records'); + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('person'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'record removed from hasMany relationship after deletion'); + assert.equal(dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many (left hand async, right hand sync) - findHasMany/implicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 2, 'hasMany relationship has correct number of records'); + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('person'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'record removed from hasMany relationship after deletion'); + assert.equal(dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many - findHasMany/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + inverse: 'pal', + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + pal; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 2, 'hasMany relationship has correct number of records'); + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('pal'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('pal'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'record removed from hasMany relationship after deletion'); + assert.equal(dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many (left hand async, right hand sync) - findHasMany/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + inverse: 'pal', + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + inverse: 'dogs', + }) + pal; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 2, 'hasMany relationship has correct number of records'); + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('pal'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('pal'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'record removed from hasMany relationship after deletion'); + assert.equal(dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many - findHasMany/null inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord() { + return resolve({ + data: null, + }); + }, + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dogs', { + inverse: null, + async: true, + }) + dogs; + @attr + name; + } + owner.register('model:person', Person); + + class Dog extends Model { + @attr + name; + } + + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + assert.equal(dogs.get('length'), 2); + assert.deepEqual(dogs.mapBy('id'), ['1', '2']); + + let dog1 = dogs.get('firstObject'); + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), '1'); + assert.equal(dogs.get('firstObject.id'), '2'); + }); + + test('one-to-one - findBelongsTo/implicit inverse - ensures inverse relationship is set up when payload does not return parent relationship info', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord() { + return resolve({ + data: null, + }); + }, + findBelongsTo() { + return resolve({ + data: { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @attr + name; + @belongsTo('dog', { async: true }) + favoriteDog; + } + owner.register('model:person', Person); + + class Dog extends Model { + @attr + name; + @belongsTo('person', { async: true }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + favoriteDog: { + links: { + related: 'http://example.com/person/1/favorite-dog', + }, + }, + }, + }, + }); + + let favoriteDog = await person.get('favoriteDog'); + assert.equal(person.belongsTo('favoriteDog').belongsToRelationship.relationshipIsEmpty, false); + assert.equal(favoriteDog.get('id'), '1', 'favoriteDog id is set correctly'); + let favoriteDogPerson = await favoriteDog.get('person'); + assert.equal( + favoriteDogPerson.get('id'), + '1', + 'favoriteDog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + await favoriteDog.destroyRecord(); + favoriteDog = await person.get('favoriteDog'); + assert.equal(favoriteDog, null); + }); + + test('one-to-one (left hand async, right hand sync) - findBelongsTo/implicit inverse - ensures inverse relationship is set up when payload does not return parent relationship info', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord() { + return resolve({ + data: null, + }); + }, + findBelongsTo() { + return resolve({ + data: { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @attr + name; + @belongsTo('dog', { async: true }) + favoriteDog; + } + owner.register('model:person', Person); + + class Dog extends Model { + @attr + name; + @belongsTo('person', { async: true }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + favoriteDog: { + links: { + related: 'http://example.com/person/1/favorite-dog', + }, + }, + }, + }, + }); + + let favoriteDog = await person.get('favoriteDog'); + assert.equal(person.belongsTo('favoriteDog').belongsToRelationship.relationshipIsEmpty, false); + assert.equal(favoriteDog.get('id'), '1', 'favoriteDog id is set correctly'); + let favoriteDogPerson = await favoriteDog.get('person'); + assert.equal( + favoriteDogPerson.get('id'), + '1', + 'favoriteDog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + await favoriteDog.destroyRecord(); + favoriteDog = await person.get('favoriteDog'); + assert.equal(favoriteDog, null); + }); + + test('one-to-one - findBelongsTo/explicit inverse - ensures inverse relationship is set up when payload does not return parent relationship info', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord() { + return resolve({ + data: null, + }); + }, + findBelongsTo() { + return resolve({ + data: { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @attr + name; + @belongsTo('dog', { async: true, inverse: 'pal' }) + favoriteDog; + } + owner.register('model:person', Person); + + class Dog extends Model { + @attr + name; + @belongsTo('person', { async: true }) + pal; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + favoriteDog: { + links: { + related: 'http://example.com/person/1/favorite-dog', + }, + }, + }, + }, + }); + + let favoriteDog = await person.get('favoriteDog'); + assert.equal(person.belongsTo('favoriteDog').belongsToRelationship.relationshipIsEmpty, false); + assert.equal(favoriteDog.get('id'), '1', 'favoriteDog id is set correctly'); + let favoriteDogPerson = await favoriteDog.get('pal'); + assert.equal( + favoriteDogPerson.get('id'), + '1', + 'favoriteDog.pal inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + await favoriteDog.destroyRecord(); + favoriteDog = await person.get('favoriteDog'); + assert.equal(favoriteDog, null); + }); + + test('one-to-one (left hand async, right hand sync) - findBelongsTo/explicit inverse - ensures inverse relationship is set up when payload does not return parent relationship info', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord() { + return resolve({ + data: null, + }); + }, + findBelongsTo() { + return resolve({ + data: { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @attr + name; + @belongsTo('dog', { async: true, inverse: 'pal' }) + favoriteDog; + } + owner.register('model:person', Person); + + class Dog extends Model { + @attr + name; + @belongsTo('person', { async: true }) + pal; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + favoriteDog: { + links: { + related: 'http://example.com/person/1/favorite-dog', + }, + }, + }, + }, + }); + + let favoriteDog = await person.get('favoriteDog'); + assert.equal(person.belongsTo('favoriteDog').belongsToRelationship.relationshipIsEmpty, false); + assert.equal(favoriteDog.get('id'), '1', 'favoriteDog id is set correctly'); + let favoriteDogPerson = await favoriteDog.get('pal'); + assert.equal( + favoriteDogPerson.get('id'), + '1', + 'favoriteDog.pal inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + await favoriteDog.destroyRecord(); + favoriteDog = await person.get('favoriteDog'); + assert.equal(favoriteDog, null); + }); + + test('one-to-one - findBelongsTo/null inverse - ensures inverse relationship is set up when payload does not return parent relationship info', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord() { + return resolve({ + data: null, + }); + }, + findBelongsTo() { + return resolve({ + data: { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @attr + name; + @belongsTo('dog', { async: true }) + favoriteDog; + } + owner.register('model:person', Person); + + class Dog extends Model { + @attr + name; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + favoriteDog: { + links: { + related: 'http://example.com/person/1/favorite-dog', + }, + }, + }, + }, + }); + + let favoriteDog = await person.get('favoriteDog'); + assert.equal(person.belongsTo('favoriteDog').belongsToRelationship.relationshipIsEmpty, false); + assert.equal(favoriteDog.get('id'), '1', 'favoriteDog id is set correctly'); + await favoriteDog.destroyRecord(); + favoriteDog = await person.get('favoriteDog'); + assert.equal(favoriteDog, null); + }); + + test('many-to-many - findHasMany/implicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: true, + }) + walkers; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + let [dog1, dog2] = dogs.toArray(); + let dog1Walkers = await dog1.get('walkers'); + assert.equal( + dog1Walkers.length, + 1, + 'dog1.walkers inverse relationship includes correct number of records' + ); + assert.equal( + dog1Walkers.get('firstObject.id'), + '1', + 'dog1.walkers inverse relationship is set up correctly' + ); + + let dog2Walkers = await dog2.get('walkers'); + assert.equal( + dog2Walkers.length, + 1, + 'dog2.walkers inverse relationship includes correct number of records' + ); + assert.equal( + dog2Walkers.get('firstObject.id'), + '1', + 'dog2.walkers inverse relationship is set up correctly' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'person.dogs relationship was updated when record removed'); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + }); + + test('many-to-many (left hand async, right hand sync) - findHasMany/implicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: false, + }) + walkers; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + let [dog1, dog2] = dogs.toArray(); + let dog1Walkers = await dog1.get('walkers'); + assert.equal( + dog1Walkers.length, + 1, + 'dog1.walkers inverse relationship includes correct number of records' + ); + assert.equal( + dog1Walkers.get('firstObject.id'), + '1', + 'dog1.walkers inverse relationship is set up correctly' + ); + + let dog2Walkers = await dog2.get('walkers'); + assert.equal( + dog2Walkers.length, + 1, + 'dog2.walkers inverse relationship includes correct number of records' + ); + assert.equal( + dog2Walkers.get('firstObject.id'), + '1', + 'dog2.walkers inverse relationship is set up correctly' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'person.dogs relationship was updated when record removed'); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + }); + + test('many-to-many - findHasMany/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + inverse: 'pals', + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: true, + }) + pals; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + let [dog1, dog2] = dogs.toArray(); + let dog1Pals = await dog1.get('pals'); + assert.equal( + dog1Pals.length, + 1, + 'dog1.pals inverse relationship includes correct number of records' + ); + assert.equal( + dog1Pals.get('firstObject.id'), + '1', + 'dog1.pals inverse relationship is set up correctly' + ); + + let dog2Pals = await dog2.get('pals'); + assert.equal( + dog2Pals.length, + 1, + 'dog2.pals inverse relationship includes correct number of records' + ); + assert.equal( + dog2Pals.get('firstObject.id'), + '1', + 'dog2.pals inverse relationship is set up correctly' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'person.dogs relationship was updated when record removed'); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + }); + + test('many-to-many (left hand async, right hand sync) - findHasMany/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + inverse: 'pals', + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: false, + }) + pals; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + let [dog1, dog2] = dogs.toArray(); + let dog1Pals = await dog1.get('pals'); + assert.equal( + dog1Pals.length, + 1, + 'dog1.pals inverse relationship includes correct number of records' + ); + assert.equal( + dog1Pals.get('firstObject.id'), + '1', + 'dog1.pals inverse relationship is set up correctly' + ); + + let dog2Pals = await dog2.get('pals'); + assert.equal( + dog2Pals.length, + 1, + 'dog2.pals inverse relationship includes correct number of records' + ); + assert.equal( + dog2Pals.get('firstObject.id'), + '1', + 'dog2.pals inverse relationship is set up correctly' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'person.dogs relationship was updated when record removed'); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + }); + + test('many-to-one - findBelongsTo/implicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let dog = store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'A Really Good Dog', + }, + relationships: { + person: { + links: { + related: 'http://example.com/person/1', + }, + }, + }, + }, + }); + + let person = await dog.get('person'); + assert.equal( + dog.belongsTo('person').belongsToRelationship.relationshipIsEmpty, + false, + 'belongsTo relationship state was populated' + ); + assert.equal(person.get('id'), '1', 'dog.person relationship is correctly set up'); + + let dogs = await person.get('dogs'); + + assert.equal( + dogs.get('length'), + 1, + 'person.dogs inverse relationship includes correct number of records' + ); + let [dog1] = dogs.toArray(); + assert.equal(dog1.id, '1', 'dog1.person inverse relationship is set up correctly'); + + await person.destroyRecord(); + dog = await dog.get('person'); + assert.equal(dog, null, 'record deleted removed from belongsTo relationship'); + }); + + test('many-to-one (left hand async, right hand sync) - findBelongsTo/implicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: false, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let dog = store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'A Really Good Dog', + }, + relationships: { + person: { + links: { + related: 'http://example.com/person/1', + }, + }, + }, + }, + }); + + let person = await dog.get('person'); + assert.equal( + dog.belongsTo('person').belongsToRelationship.relationshipIsEmpty, + false, + 'belongsTo relationship state was populated' + ); + assert.equal(person.get('id'), '1', 'dog.person relationship is correctly set up'); + + let dogs = await person.get('dogs'); + + assert.equal( + dogs.get('length'), + 1, + 'person.dogs inverse relationship includes correct number of records' + ); + let [dog1] = dogs.toArray(); + assert.equal(dog1.id, '1', 'dog1.person inverse relationship is set up correctly'); + + await person.destroyRecord(); + dog = await dog.get('person'); + assert.equal(dog, null, 'record deleted removed from belongsTo relationship'); + }); + + test('many-to-one - findBelongsTo/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + inverse: 'pal', + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + pal; + } + owner.register('model:dog', Dog); + + let dog = store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'A Really Good Dog', + }, + relationships: { + pal: { + links: { + related: 'http://example.com/person/1', + }, + }, + }, + }, + }); + + let person = await dog.get('pal'); + assert.equal( + dog.belongsTo('pal').belongsToRelationship.relationshipIsEmpty, + false, + 'belongsTo relationship state was populated' + ); + assert.equal(person.get('id'), '1', 'dog.person relationship is correctly set up'); + + let dogs = await person.get('dogs'); + + assert.equal( + dogs.get('length'), + 1, + 'person.dogs inverse relationship includes correct number of records' + ); + let [dog1] = dogs.toArray(); + assert.equal(dog1.id, '1', 'dog1.person inverse relationship is set up correctly'); + + await person.destroyRecord(); + dog = await dog.get('pal'); + assert.equal(dog, null, 'record deleted removed from belongsTo relationship'); + }); + + test('many-to-one (left hand async, right hand sync) - findBelongsTo/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: false, + inverse: 'pal', + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + pal; + } + owner.register('model:dog', Dog); + + let dog = store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'A Really Good Dog', + }, + relationships: { + pal: { + links: { + related: 'http://example.com/person/1', + }, + }, + }, + }, + }); + + let person = await dog.get('pal'); + assert.equal( + dog.belongsTo('pal').belongsToRelationship.relationshipIsEmpty, + false, + 'belongsTo relationship state was populated' + ); + assert.equal(person.get('id'), '1', 'dog.person relationship is correctly set up'); + + let dogs = await person.get('dogs'); + + assert.equal( + dogs.get('length'), + 1, + 'person.dogs inverse relationship includes correct number of records' + ); + let [dog1] = dogs.toArray(); + assert.equal(dog1.id, '1', 'dog1.person inverse relationship is set up correctly'); + + await person.destroyRecord(); + dog = await dog.get('pal'); + assert.equal(dog, null, 'record deleted removed from belongsTo relationship'); + }); + + testInDebug( + 'one-to-many - findHasMany/implicit inverse - fixes mismatched parent relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + assert.equal(dogs.get('length'), 2); + + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('person'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1); + assert.equal(dogs.get('firstObject.id'), '2'); + } + ); + + testInDebug( + 'one-to-many (left hand async, right hand sync) - findHasMany/implicit inverse - fixes mismatched parent relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + assert.equal(dogs.get('length'), 2); + + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('person'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1); + assert.equal(dogs.get('firstObject.id'), '2'); + } + ); + + testInDebug( + 'one-to-many - findHasMany/implicit inverse - fixes null relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: null, + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + person: { + data: null, + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + assert.equal(dogs.get('length'), 2); + + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('person'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1); + assert.equal(dogs.get('firstObject.id'), '2'); + } + ); + + testInDebug( + 'one-to-many (left hand async, right hand sync) - findHasMany/implicit inverse - fixes null relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: null, + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + person: { + data: null, + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + assert.equal(dogs.get('length'), 2); + + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('person'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1); + assert.equal(dogs.get('firstObject.id'), '2'); + } + ); + + testInDebug( + 'one-to-one - findBelongsTo/implicit inverse - fixes mismatched parent relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + id: '1', + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @belongsTo('dog', { + async: true, + }) + dog; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dog: { + links: { + related: 'http://example.com/person/1/dog', + }, + }, + }, + }, + }); + + let dog = await person.get('dog'); + assert.expectDeprecation(/Encountered mismatched relationship/); + + let dogFromStore = await store.peekRecord('dog', '1'); + + // weirdly these pass + assert.equal(dogFromStore.belongsTo('person').id(), '1'); + assert.equal(person.belongsTo('dog').id(), '1'); + assert.equal(dog.id, '1', 'dog.person relationship loaded correctly'); + assert.equal( + person.belongsTo('dog').belongsToRelationship.relationshipIsEmpty, + false, + 'relationship is not empty' + ); + + let dogPerson1 = await dog.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog.destroyRecord(); + dog = await person.get('dog'); + assert.equal(dog, null, 'record was removed from belongsTo relationship'); + } + ); + + testInDebug( + 'one-to-one (left hand async, right hand sync) - findBelongsTo/implicit inverse - fixes mismatched parent relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + id: '1', + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @belongsTo('dog', { + async: true, + }) + dog; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dog: { + links: { + related: 'http://example.com/person/1/dog', + }, + }, + }, + }, + }); + + let dog = await person.get('dog'); + assert.expectDeprecation(/Encountered mismatched relationship/); + + let dogFromStore = store.peekRecord('dog', '1'); + + // weirdly these pass + assert.equal(dogFromStore.belongsTo('person').id(), '1'); + assert.equal(person.belongsTo('dog').id(), '1'); + assert.equal(dog.id, '1', 'dog.person relationship loaded correctly'); + + assert.equal( + person.belongsTo('dog').belongsToRelationship.relationshipIsEmpty, + false, + 'relationship is not empty' + ); + + let dogPerson1 = dog.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog.destroyRecord(); + dog = await person.get('dog'); + assert.equal(dog, null, 'record was removed from belongsTo relationship'); + } + ); + + testInDebug( + 'one-to-one - findBelongsTo/implicit inverse - fixes null relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + id: '1', + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: null, + }, + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @belongsTo('dog', { + async: true, + }) + dog; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dog: { + links: { + related: 'http://example.com/person/1/dog', + }, + }, + }, + }, + }); + + let dog = await person.get('dog'); + assert.expectDeprecation(/Encountered mismatched relationship/); + + let dogFromStore = await store.peekRecord('dog', '1'); + + // weirdly these pass + assert.equal(dogFromStore.belongsTo('person').id(), '1'); + assert.equal(person.belongsTo('dog').id(), '1'); + assert.equal(dog.id, '1', 'dog.person relationship loaded correctly'); + + assert.equal( + person.belongsTo('dog').belongsToRelationship.relationshipIsEmpty, + false, + 'relationship is not empty' + ); + + let dogPerson1 = await dog.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog.destroyRecord(); + dog = await person.get('dog'); + assert.equal(dog, null, 'record was removed from belongsTo relationship'); + } + ); + + testInDebug( + 'one-to-one (left hand async, right hand sync) - findBelongsTo/implicit inverse - fixes null relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + id: '1', + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: null, + }, + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @belongsTo('dog', { + async: true, + }) + dog; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dog: { + links: { + related: 'http://example.com/person/1/dog', + }, + }, + }, + }, + }); + + let dog = await person.get('dog'); + assert.expectDeprecation(/Encountered mismatched relationship/); + + let dogFromStore = await store.peekRecord('dog', '1'); + + // weirdly these pass + assert.equal(dogFromStore.belongsTo('person').id(), '1'); + assert.equal(person.belongsTo('dog').id(), '1'); + assert.equal(dog.id, '1', 'dog.person relationship loaded correctly'); + + assert.equal( + person.belongsTo('dog').belongsToRelationship.relationshipIsEmpty, + false, + 'relationship is not empty' + ); + + let dogPerson1 = await dog.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog.destroyRecord(); + dog = await person.get('dog'); + assert.equal(dog, null, 'record was removed from belongsTo relationship'); + } + ); + + testInDebug( + 'many-to-one - findBelongsTo/implicitInverse - fixes mismatched parent relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let dog = store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'A Really Good Dog', + }, + relationships: { + person: { + links: { + related: 'http://example.com/person/1', + }, + }, + }, + }, + }); + + let person = await dog.get('person'); + assert.expectDeprecation(/Encountered mismatched relationship/); + let dogFromStore = await store.peekRecord('dog', '1'); + + assert.equal( + dogFromStore.belongsTo('person').id(), + '1', + 'dog relationship is set up correctly' + ); + let dogPerson1 = await dog.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship is not empty' + ); + + await dog.destroyRecord(); + dog = await person.get('dog'); + assert.equal(dog, null, 'record was removed from belongsTo relationship'); + } + ); + + testInDebug( + 'many-to-one (left hand async, right hand sync) - findBelongsTo/implicitInverse - fixes mismatched parent relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: false, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let dog = store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'A Really Good Dog', + }, + relationships: { + person: { + links: { + related: 'http://example.com/person/1', + }, + }, + }, + }, + }); + + let person = await dog.get('person'); + assert.expectDeprecation(/Encountered mismatched relationship/); + let dogFromStore = await store.peekRecord('dog', '1'); + + assert.equal( + dogFromStore.belongsTo('person').id(), + '1', + 'dog relationship is set up correctly' + ); + let dogPerson1 = await dog.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship is not empty' + ); + + await dog.destroyRecord(); + dog = await person.get('dog'); + assert.equal(dog, null, 'record was removed from belongsTo relationship'); + } + ); + + testInDebug( + 'many-to-one - findBelongsTo/implicitInverse - fixes null relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [], + }, + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let dog = store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'A Really Good Dog', + }, + relationships: { + person: { + links: { + related: 'http://example.com/person/1', + }, + }, + }, + }, + }); + + let person = await dog.get('person'); + assert.expectDeprecation(/Encountered mismatched relationship/); + let dogFromStore = await store.peekRecord('dog', '1'); + + assert.equal( + dogFromStore.belongsTo('person').id(), + '1', + 'dog relationship is set up correctly' + ); + let dogPerson1 = await dog.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship is not empty' + ); + + await dog.destroyRecord(); + dog = await person.get('dog'); + assert.equal(dog, null, 'record was removed from belongsTo relationship'); + } + ); + + testInDebug( + 'many-to-one (left hand async, right hand sync) - findBelongsTo/implicitInverse - fixes null relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [], + }, + }, + }, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: false, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let dog = store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'A Really Good Dog', + }, + relationships: { + person: { + links: { + related: 'http://example.com/person/1', + }, + }, + }, + }, + }); + + let person = await dog.get('person'); + assert.expectDeprecation(/Encountered mismatched relationship/); + let dogFromStore = await store.peekRecord('dog', '1'); + + assert.equal( + dogFromStore.belongsTo('person').id(), + '1', + 'dog relationship is set up correctly' + ); + let dogPerson1 = await dog.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship is not empty' + ); + + await dog.destroyRecord(); + dog = await person.get('dog'); + assert.equal(dog, null, 'record was removed from belongsTo relationship'); + } + ); + + testInDebug( + 'many-to-many - findHasMany/implicitInverse - fixes mismatched parent relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + walkers: { + data: [ + { + id: '2', + type: 'person', + }, + ], + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + walkers: { + data: [ + { + id: '2', + type: 'person', + }, + ], + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: true, + }) + walkers; + } + owner.register('model:dog', Dog); + + let person1 = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + let person2 = store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'Fond Memories', + }, + }, + }); + + let person1Dogs = await person1.get('dogs'); + + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person1.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + let dog1 = store.peekRecord('dog', '1'); + let dog2 = store.peekRecord('dog', '2'); + + for (let person of [person1, person2]) { + const dogs = await person.get('dogs'); + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + assert.ok( + dogs.indexOf(dog1) >= 0, + 'relationship includes the parent even though it was not specified' + ); + assert.ok( + dogs.indexOf(dog2) >= 0, + 'relationship also includes records the payload specified' + ); + + for (let dog of [dog1, dog2]) { + let walkers = await dog.get('walkers'); + assert.equal( + walkers.length, + 2, + 'dog1.walkers inverse relationship includes correct number of records' + ); + assert.ok( + walkers.indexOf(person1) >= 0, + 'dog1Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + assert.ok( + walkers.indexOf(person2) >= 0, + 'dog1Walkers includes records the response returned in data.relationships' + ); + } + } + + await dog1.destroyRecord(); + + for (let person of [person1, person2]) { + let dogs = await person.get('dogs'); + assert.equal( + dogs.get('length'), + 1, + 'person1.dogs relationship was updated when record removed' + ); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + } + + let dog2Walkers = await dog2.get('walkers'); + assert.equal( + dog2Walkers.get('length'), + 2, + 'dog2 still has correct number of records for hasMany relationship' + ); + assert.ok( + dog2Walkers.indexOf(person1) >= 0, + 'dog2Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + assert.ok( + dog2Walkers.indexOf(person2) >= 0, + 'dog2Walkers includes records the response returned in data.relationships' + ); + + // now delete another side of the many-to-many + + await person2.destroyRecord(); + + assert.equal(person1Dogs.get('length'), 1, 'person1 has correct # of dogs'); + assert.equal( + person1Dogs.get('firstObject.id'), + dog2.get('id'), + 'person1 has dog2 in its hasMany relationship; dog1 is not present because it was destroyed.' + ); + assert.equal( + dog2Walkers.get('length'), + 1, + 'dog2 has correct # of records after record specified by server response is destroyed' + ); + assert.equal( + dog2Walkers.get('firstObject.id'), + person1.get('id'), + 'dog2 has person1 in its hasMany relationship; person2 is not present because it was destroyed.' + ); + + // finally, destroy person1, the record that loaded all this data through the relationship + + await person1.destroyRecord(); + assert.equal( + dog2Walkers.get('length'), + 0, + 'dog2 hasMany relationship is empty after all person records are destroyed' + ); + } + ); + + testInDebug( + 'many-to-many (left hand async, right hand sync) - findHasMany/implicitInverse - fixes mismatched parent relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + walkers: { + data: [ + { + id: '2', + type: 'person', + }, + ], + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + walkers: { + data: [ + { + id: '2', + type: 'person', + }, + ], + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: false, + }) + walkers; + } + owner.register('model:dog', Dog); + + let person1 = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + let person2 = store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'Fond Memories', + }, + }, + }); + + let person1Dogs = await person1.get('dogs'); + + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person1.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + let dog1 = store.peekRecord('dog', '1'); + let dog2 = store.peekRecord('dog', '2'); + + for (let person of [person1, person2]) { + const dogs = await person.get('dogs'); + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + assert.ok( + dogs.indexOf(dog1) >= 0, + 'relationship includes the parent even though it was not specified' + ); + assert.ok( + dogs.indexOf(dog2) >= 0, + 'relationship also includes records the payload specified' + ); + + for (let dog of [dog1, dog2]) { + let walkers = await dog.get('walkers'); + assert.equal( + walkers.length, + 2, + 'dog1.walkers inverse relationship includes correct number of records' + ); + assert.ok( + walkers.indexOf(person1) >= 0, + 'dog1Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + assert.ok( + walkers.indexOf(person2) >= 0, + 'dog1Walkers includes records the response returned in data.relationships' + ); + } + } + + await dog1.destroyRecord(); + + for (let person of [person1, person2]) { + let dogs = await person.get('dogs'); + assert.equal( + dogs.get('length'), + 1, + 'person1.dogs relationship was updated when record removed' + ); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + } + + let dog2Walkers = await dog2.get('walkers'); + assert.equal( + dog2Walkers.get('length'), + 2, + 'dog2 still has correct number of records for hasMany relationship' + ); + assert.ok( + dog2Walkers.indexOf(person1) >= 0, + 'dog2Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + assert.ok( + dog2Walkers.indexOf(person2) >= 0, + 'dog2Walkers includes records the response returned in data.relationships' + ); + + // now delete another side of the many-to-many + + await person2.destroyRecord(); + + assert.equal(person1Dogs.get('length'), 1, 'person1 has correct # of dogs'); + assert.equal( + person1Dogs.get('firstObject.id'), + dog2.get('id'), + 'person1 has dog2 in its hasMany relationship; dog1 is not present because it was destroyed.' + ); + assert.equal( + dog2Walkers.get('length'), + 1, + 'dog2 has correct # of records after record specified by server response is destroyed' + ); + assert.equal( + dog2Walkers.get('firstObject.id'), + person1.get('id'), + 'dog2 has person1 in its hasMany relationship; person2 is not present because it was destroyed.' + ); + + // finally, destroy person1, the record that loaded all this data through the relationship + + await person1.destroyRecord(); + assert.equal( + dog2Walkers.get('length'), + 0, + 'dog2 hasMany relationship is empty after all person records are destroyed' + ); + } + ); + + testInDebug( + 'many-to-many - findHasMany/implicitInverse - fixes empty relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + walkers: { + data: [], + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + walkers: { + data: [], + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: true, + }) + walkers; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + await person.get('dogs'); + + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + let dog1 = store.peekRecord('dog', '1'); + let dog2 = store.peekRecord('dog', '2'); + + const dogs = await person.get('dogs'); + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + assert.ok( + dogs.indexOf(dog1) >= 0, + 'relationship includes the parent even though it was not specified' + ); + assert.ok( + dogs.indexOf(dog2) >= 0, + 'relationship also includes records the payload specified' + ); + + for (let dog of [dog1, dog2]) { + let walkers = await dog.get('walkers'); + assert.equal( + walkers.length, + 1, + 'dog1.walkers inverse relationship includes correct number of records' + ); + assert.ok( + walkers.indexOf(person) >= 0, + 'dog1Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + } + + await dog1.destroyRecord(); + + assert.equal( + dogs.get('length'), + 1, + 'person1.dogs relationship was updated when record removed' + ); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + + let dog2Walkers = await dog2.get('walkers'); + assert.equal( + dog2Walkers.get('length'), + 1, + 'dog2 still has correct number of records for hasMany relationship' + ); + assert.ok( + dog2Walkers.indexOf(person) >= 0, + 'dog2Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + + // finally, destroy person1, the record that loaded all this data through the relationship + await person.destroyRecord(); + assert.equal( + dog2Walkers.get('length'), + 0, + 'dog2 hasMany relationship is empty after all person records are destroyed' + ); + } + ); + + testInDebug( + 'many-to-many (left hand async, right hand sync) - findHasMany/implicitInverse - fixes empty relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + walkers: { + data: [], + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + walkers: { + data: [], + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: false, + }) + walkers; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + await person.get('dogs'); + + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + let dog1 = store.peekRecord('dog', '1'); + let dog2 = store.peekRecord('dog', '2'); + + const dogs = await person.get('dogs'); + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + assert.ok( + dogs.indexOf(dog1) >= 0, + 'relationship includes the parent even though it was not specified' + ); + assert.ok( + dogs.indexOf(dog2) >= 0, + 'relationship also includes records the payload specified' + ); + + for (let dog of [dog1, dog2]) { + let walkers = await dog.get('walkers'); + assert.equal( + walkers.length, + 1, + 'dog1.walkers inverse relationship includes correct number of records' + ); + assert.ok( + walkers.indexOf(person) >= 0, + 'dog1Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + } + + await dog1.destroyRecord(); + + assert.equal( + dogs.get('length'), + 1, + 'person1.dogs relationship was updated when record removed' + ); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + + let dog2Walkers = await dog2.get('walkers'); + assert.equal( + dog2Walkers.get('length'), + 1, + 'dog2 still has correct number of records for hasMany relationship' + ); + assert.ok( + dog2Walkers.indexOf(person) >= 0, + 'dog2Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + + // finally, destroy person1, the record that loaded all this data through the relationship + await person.destroyRecord(); + assert.equal( + dog2Walkers.get('length'), + 0, + 'dog2 hasMany relationship is empty after all person records are destroyed' + ); + } + ); + + testInDebug( + 'many-to-many - findHasMany/implicitInverse - fixes null relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + walkers: { + data: null, + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + walkers: { + data: null, + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: true, + }) + walkers; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + let dog1 = store.peekRecord('dog', '1'); + let dog2 = store.peekRecord('dog', '2'); + + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + assert.ok( + dogs.indexOf(dog1) >= 0, + 'relationship includes the parent even though it was not specified' + ); + assert.ok( + dogs.indexOf(dog2) >= 0, + 'relationship also includes records the payload specified' + ); + + for (let dog of [dog1, dog2]) { + let walkers = await dog.get('walkers'); + assert.equal( + walkers.length, + 1, + 'dog1.walkers inverse relationship includes correct number of records' + ); + assert.ok( + walkers.indexOf(person) >= 0, + 'dog1Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + } + + await dog1.destroyRecord(); + + assert.equal( + dogs.get('length'), + 1, + 'person1.dogs relationship was updated when record removed' + ); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + + let dog2Walkers = await dog2.get('walkers'); + assert.equal( + dog2Walkers.get('length'), + 1, + 'dog2 still has correct number of records for hasMany relationship' + ); + assert.ok( + dog2Walkers.indexOf(person) >= 0, + 'dog2Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + + // finally, destroy person1, the record that loaded all this data through the relationship + await person.destroyRecord(); + assert.equal( + dog2Walkers.get('length'), + 0, + 'dog2 hasMany relationship is empty after all person records are destroyed' + ); + } + ); + + testInDebug( + 'many-to-many (left hand async, right hand sync) - findHasMany/implicitInverse - fixes null relationship information from the payload and deprecates', + async function(assert) { + let { owner } = this; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findHasMany: () => { + return resolve({ + data: [ + { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + walkers: { + data: null, + }, + }, + }, + { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + walkers: { + data: null, + }, + }, + }, + ], + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @hasMany('person', { + async: false, + }) + walkers; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + + assert.expectDeprecation(/Encountered mismatched relationship/); + assert.equal(person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, false); + + let dog1 = store.peekRecord('dog', '1'); + let dog2 = store.peekRecord('dog', '2'); + + assert.equal( + dogs.get('length'), + 2, + 'left hand side relationship is set up with correct number of records' + ); + assert.ok( + dogs.indexOf(dog1) >= 0, + 'relationship includes the parent even though it was not specified' + ); + assert.ok( + dogs.indexOf(dog2) >= 0, + 'relationship also includes records the payload specified' + ); + + for (let dog of [dog1, dog2]) { + let walkers = await dog.get('walkers'); + assert.equal( + walkers.length, + 1, + 'dog1.walkers inverse relationship includes correct number of records' + ); + assert.ok( + walkers.indexOf(person) >= 0, + 'dog1Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + } + + await dog1.destroyRecord(); + + assert.equal( + dogs.get('length'), + 1, + 'person1.dogs relationship was updated when record removed' + ); + assert.equal( + dogs.get('firstObject.id'), + '2', + 'person.dogs relationship has the correct records' + ); + + let dog2Walkers = await dog2.get('walkers'); + assert.equal( + dog2Walkers.get('length'), + 1, + 'dog2 still has correct number of records for hasMany relationship' + ); + assert.ok( + dog2Walkers.indexOf(person) >= 0, + 'dog2Walkers includes the record that requested the relationship but was not specified in the relationships of the records in the response' + ); + + // finally, destroy person1, the record that loaded all this data through the relationship + await person.destroyRecord(); + assert.equal( + dog2Walkers.get('length'), + 0, + 'dog2 hasMany relationship is empty after all person records are destroyed' + ); + } + ); + + test('one-to-many - ids/non-link/implicit inverse - ids - records loaded through ids/findRecord are linked to the parent if the response from the server does not include relationship information', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 2, 'hasMany relationship has correct number of records'); + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('person'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'record removed from hasMany relationship after deletion'); + assert.equal(dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many (left hand async, right hand sync) - ids/non-link/implicit inverse - ids - records loaded through ids/findRecord are linked to the parent if the response from the server does not include relationship information', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 2, 'hasMany relationship has correct number of records'); + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('person'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('person'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'record removed from hasMany relationship after deletion'); + assert.equal(dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many - ids/non-link/explicit inverse - ids - records loaded through ids/findRecord are linked to the parent if the response from the server does not include relationship information', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + inverse: 'pal', + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + pal; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 2, 'hasMany relationship has correct number of records'); + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('pal'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('pal'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'record removed from hasMany relationship after deletion'); + assert.equal(dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many (left hand async, right hand sync) - ids/non-link/explicit inverse - ids - records loaded through ids/findRecord are linked to the parent if the response from the server does not include relationship information', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + inverse: 'pal', + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + }) + pal; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 2, 'hasMany relationship has correct number of records'); + let dog1 = dogs.get('firstObject'); + let dogPerson1 = await dog1.get('pal'); + assert.equal( + dogPerson1.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + let dogPerson2 = await dogs.objectAt(1).get('pal'); + assert.equal( + dogPerson2.get('id'), + '1', + 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' + ); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'record removed from hasMany relationship after deletion'); + assert.equal(dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many - ids/non-link/null inverse - ids - records loaded through ids/findRecord are linked to the parent if the response from the server does not include relationship information', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + inverse: null, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model {} + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 2, 'hasMany relationship has correct number of records'); + let dog1 = dogs.get('firstObject'); + + await dog1.destroyRecord(); + assert.equal(dogs.get('length'), 1, 'record removed from hasMany relationship after deletion'); + assert.equal(dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many - ids/non-link/implicit inverse - records loaded through ids/findRecord do not get associated with the parent if the server specifies another resource as the relationship value in the response', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let person2 = store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'ok', + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 0, 'hasMany relationship for parent is empty'); + + let person2Dogs = await person2.get('dogs'); + assert.equal( + person2Dogs.get('length'), + 2, + 'hasMany relationship on specified record has correct number of associated records' + ); + + for (let dog of store.peekAll('dogs').toArray()) { + let dogPerson = await dog.get('person'); + assert.equal( + dogPerson.get('id'), + person2.get('id'), + 'right hand side has correct belongsTo value' + ); + } + + let dog1 = store.peekRecord('dog', '1'); + await dog1.destroyRecord(); + assert.equal( + person2Dogs.get('length'), + 1, + 'record removed from hasMany relationship after deletion' + ); + assert.equal( + person2Dogs.get('firstObject.id'), + '2', + 'hasMany relationship has correct records' + ); + }); + + test('one-to-many (left hand async, right hand sync) - ids/non-link/implicit inverse - records loaded through ids/findRecord do not get associated with the parent if the server specifies another resource as the relationship value in the response', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + person: { + data: { + id: '2', + type: 'person', + }, + }, + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let person2 = store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'ok', + }, + }, + }); + + let dogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 0, 'hasMany relationship for parent is empty'); + + let person2Dogs = await person2.get('dogs'); + assert.equal( + person2Dogs.get('length'), + 2, + 'hasMany relationship on specified record has correct number of associated records' + ); + + for (let dog of store.peekAll('dogs').toArray()) { + let dogPerson = await dog.get('person'); + assert.equal( + dogPerson.get('id'), + person2.get('id'), + 'right hand side has correct belongsTo value' + ); + } + + let dog1 = store.peekRecord('dog', '1'); + await dog1.destroyRecord(); + assert.equal( + person2Dogs.get('length'), + 1, + 'record removed from hasMany relationship after deletion' + ); + assert.equal( + person2Dogs.get('firstObject.id'), + '2', + 'hasMany relationship has correct records' + ); + }); + + test('one-to-many - ids/non-link/implicit inverse - records loaded through ids/findRecord do not get associated with the parent if the server specifies null as the relationship value in the response', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: null, + }, + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + person: { + data: null, + }, + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let personDogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(personDogs.get('length'), 0, 'hasMany relationship for parent is empty'); + + for (let dog of store.peekAll('dogs').toArray()) { + let dogPerson = await dog.get('person'); + assert.equal(dogPerson, null, 'right hand side has correct belongsTo value'); + } + + let dog1 = store.peekRecord('dog', '1'); + await dog1.destroyRecord(); + + assert.equal(personDogs.get('length'), 0); + }); + + test('one-to-many (left hand async, right hand sync) - ids/non-link/implicit inverse - records loaded through ids/findRecord do not get associated with the parent if the server specifies null as the relationship value in the response', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: null, + }, + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + person: { + data: null, + }, + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: false, + }) + person; + } + owner.register('model:dog', Dog); + + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let personDogs = await person.get('dogs'); + assert.equal( + person.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(personDogs.get('length'), 0, 'hasMany relationship for parent is empty'); + + for (let dog of store.peekAll('dogs').toArray()) { + let dogPerson = await dog.get('person'); + assert.equal(dogPerson, null, 'right hand side has correct belongsTo value'); + } + + let dog1 = store.peekRecord('dog', '1'); + await dog1.destroyRecord(); + + assert.equal(personDogs.get('length'), 0); + }); + + test('one-to-many - ids/non-link/explicit inverse - records loaded through ids/findRecord do not get associated with the parent if the server specifies another resource as the relationship value in the response', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + pal: { + data: { + id: '2', + type: 'pal', + }, + }, + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + pal: { + data: { + id: '2', + type: 'pal', + }, + }, + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:pal', Person); + + class Dog extends Model { + @belongsTo('pal', { + async: true, + }) + pal; + } + owner.register('model:dog', Dog); + + let pal = store.push({ + data: { + type: 'pal', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let pal2 = store.push({ + data: { + type: 'pal', + id: '2', + attributes: { + name: 'ok', + }, + }, + }); + + let dogs = await pal.get('dogs'); + assert.equal( + pal.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 0, 'hasMany relationship for parent is empty'); + + let pal2Dogs = await pal2.get('dogs'); + assert.equal( + pal2Dogs.get('length'), + 2, + 'hasMany relationship on specified record has correct number of associated records' + ); + + for (let dog of store.peekAll('dogs').toArray()) { + let dogPerson = await dog.get('pal'); + assert.equal( + dogPerson.get('id'), + pal2.get('id'), + 'right hand side has correct belongsTo value' + ); + } + + let dog1 = store.peekRecord('dog', '1'); + await dog1.destroyRecord(); + assert.equal( + pal2Dogs.get('length'), + 1, + 'record removed from hasMany relationship after deletion' + ); + assert.equal(pal2Dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test('one-to-many (left hand async, right hand sync) - ids/non-link/explicit inverse - records loaded through ids/findRecord do not get associated with the parent if the server specifies another resource as the relationship value in the response', async function(assert) { + let { owner } = this; + + const scooby = { + id: 1, + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + pal: { + data: { + id: '2', + type: 'pal', + }, + }, + }, + }; + + const scrappy = { + id: 2, + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + pal: { + data: { + id: '2', + type: 'pal', + }, + }, + }, + }; + + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: true, + }) + dogs; + } + owner.register('model:pal', Person); + + class Dog extends Model { + @belongsTo('pal', { + async: false, + }) + pal; + } + owner.register('model:dog', Dog); + + let pal = store.push({ + data: { + type: 'pal', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + data: [ + { + id: '1', + type: 'dog', + }, + { + id: '2', + type: 'dog', + }, + ], + }, + }, + }, + }); + + let pal2 = store.push({ + data: { + type: 'pal', + id: '2', + attributes: { + name: 'ok', + }, + }, + }); + + let dogs = await pal.get('dogs'); + assert.equal( + pal.hasMany('dogs').hasManyRelationship.relationshipIsEmpty, + false, + 'relationship state was set up correctly' + ); + + assert.equal(dogs.get('length'), 0, 'hasMany relationship for parent is empty'); + + let pal2Dogs = await pal2.get('dogs'); + assert.equal( + pal2Dogs.get('length'), + 2, + 'hasMany relationship on specified record has correct number of associated records' + ); + + for (let dog of store.peekAll('dogs').toArray()) { + let dogPerson = await dog.get('pal'); + assert.equal( + dogPerson.get('id'), + pal2.get('id'), + 'right hand side has correct belongsTo value' + ); + } + + let dog1 = store.peekRecord('dog', '1'); + await dog1.destroyRecord(); + assert.equal( + pal2Dogs.get('length'), + 1, + 'record removed from hasMany relationship after deletion' + ); + assert.equal(pal2Dogs.get('firstObject.id'), '2', 'hasMany relationship has correct records'); + }); + + test("loading belongsTo doesn't remove inverse relationship for other instances", async function(assert) { + let { owner } = this; + + const scooby = { + id: '1', + type: 'dog', + attributes: { + name: 'Scooby', + }, + relationships: { + person: { + data: { id: '1', type: 'person' }, + links: { related: 'http://example.com/dogs/1/person' }, + }, + }, + }; + const scrappy = { + id: '2', + type: 'dog', + attributes: { + name: 'Scrappy', + }, + relationships: { + person: { + data: { id: '1', type: 'person' }, + links: { related: 'http://example.com/dogs/1/person' }, + }, + }, + }; + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + deleteRecord: () => resolve({ data: null }), + findBelongsTo: () => { + return resolve({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://example.com/person/1/dogs', + }, + }, + }, + }, + }); + }, + findRecord: (_store, _type, id) => { + const dog = id === '1' ? scooby : scrappy; + return resolve({ + data: dog, + }); + }, + }) + ); + + class Person extends Model { + @hasMany('dog', { + async: false, + }) + dogs; + } + + owner.register('model:person', Person); + + class Dog extends Model { + @belongsTo('person', { + async: true, + }) + person; + + @attr('string') + name; + } + + owner.register('model:dog', Dog); + + // load em into store + let dog1 = await owner.lookup('service:store').findRecord('dog', '1'); + let dog2 = await owner.lookup('service:store').findRecord('dog', '2'); + + assert.equal(dog1.belongsTo('person').id(), '1'); + assert.equal(dog2.belongsTo('person').id(), '1'); + + await dog1.get('person'); + + assert.equal(dog1.belongsTo('person').id(), '1'); + assert.equal(dog2.belongsTo('person').id(), '1'); + }); +}); diff --git a/tests/integration/relationships/inverse-relationships-test.js b/tests/integration/relationships/inverse-relationships-test.js new file mode 100644 index 00000000000..0af743b1bc1 --- /dev/null +++ b/tests/integration/relationships/inverse-relationships-test.js @@ -0,0 +1,706 @@ +import { module, test } from 'qunit'; +import { belongsTo, hasMany, attr } from '@ember-decorators/data'; +import { setupTest } from 'ember-qunit'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import Model from 'ember-data/model'; + +module('integration/relationships/inverse_relationships - Inverse Relationships', function(hooks) { + setupTest(hooks); + + let store; + let register; + + hooks.beforeEach(function() { + const { owner } = this; + + store = owner.lookup('service:store'); + register = owner.register.bind(owner); + }); + + test('When a record is added to a has-many relationship, the inverse belongsTo is determined automatically', async function(assert) { + class Post extends Model { + @hasMany('comment', { async: false }) + comments; + } + + class Comment extends Model { + @belongsTo('post', { async: false }) + post; + } + + register('model:Post', Post); + register('model:Comment', Comment); + + const comment = store.createRecord('comment'); + const post = store.createRecord('post'); + + assert.equal(comment.get('post'), null, 'no post has been set on the comment'); + + post.get('comments').pushObject(comment); + assert.equal(comment.get('post'), post, 'post was set on the comment'); + }); + + test('Inverse relationships can be explicitly nullable', function(assert) { + class User extends Model { + @hasMany('post', { inverse: 'participants', async: false }) + posts; + } + + class Post extends Model { + @belongsTo('user', { inverse: null, async: false }) + lastParticipant; + + @hasMany('user', { inverse: 'posts', async: false }) + participants; + } + + register('model:User', User); + register('model:Post', Post); + + const user = store.createRecord('user'); + const post = store.createRecord('post'); + + assert.equal( + user.inverseFor('posts').name, + 'participants', + 'User.posts inverse is Post.participants' + ); + assert.equal(post.inverseFor('lastParticipant'), null, 'Post.lastParticipant has no inverse'); + assert.equal( + post.inverseFor('participants').name, + 'posts', + 'Post.participants inverse is User.posts' + ); + }); + + test('Null inverses are excluded from potential relationship resolutions', function(assert) { + class User extends Model { + @hasMany('post', { async: false }) + posts; + } + + class Post extends Model { + @belongsTo('user', { inverse: null, async: false }) + lastParticipant; + + @hasMany('user', { async: false }) + participants; + } + + register('model:User', User); + register('model:Post', Post); + + const user = store.createRecord('user'); + const post = store.createRecord('post'); + + assert.equal( + user.inverseFor('posts').name, + 'participants', + 'User.posts inverse is Post.participants' + ); + assert.equal(post.inverseFor('lastParticipant'), null, 'Post.lastParticipant has no inverse'); + assert.equal( + post.inverseFor('participants').name, + 'posts', + 'Post.participants inverse is User.posts' + ); + }); + + test('When a record is added to a has-many relationship, the inverse belongsTo can be set explicitly', async function(assert) { + class Post extends Model { + @hasMany('comment', { inverse: 'redPost', async: false }) + comments; + } + + class Comment extends Model { + @belongsTo('post', { async: false }) + onePost; + + @belongsTo('post', { async: false }) + twoPost; + + @belongsTo('post', { async: false }) + redPost; + + @belongsTo('post', { async: false }) + bluePost; + } + + register('model:Post', Post); + register('model:Comment', Comment); + + const comment = store.createRecord('comment'); + const post = store.createRecord('post'); + + assert.equal(comment.get('onePost'), null, 'onePost has not been set on the comment'); + assert.equal(comment.get('twoPost'), null, 'twoPost has not been set on the comment'); + assert.equal(comment.get('redPost'), null, 'redPost has not been set on the comment'); + assert.equal(comment.get('bluePost'), null, 'bluePost has not been set on the comment'); + + post.get('comments').pushObject(comment); + + assert.equal(comment.get('onePost'), null, 'onePost has not been set on the comment'); + assert.equal(comment.get('twoPost'), null, 'twoPost has not been set on the comment'); + assert.equal(comment.get('redPost'), post, 'redPost has been set on the comment'); + assert.equal(comment.get('bluePost'), null, 'bluePost has not been set on the comment'); + }); + + test("When a record's belongsTo relationship is set, it can specify the inverse hasMany to which the new child should be added", async function(assert) { + class Post extends Model { + @hasMany('comment', { async: false }) + meComments; + + @hasMany('comment', { async: false }) + youComments; + + @hasMany('comment', { async: false }) + everyoneWeKnowComments; + } + + class Comment extends Model { + @belongsTo('post', { inverse: 'youComments', async: false }) + post; + } + + register('model:Post', Post); + register('model:Comment', Comment); + + let comment, post; + + comment = store.createRecord('comment'); + post = store.createRecord('post'); + + assert.equal(post.get('meComments.length'), 0, 'meComments has no posts'); + assert.equal(post.get('youComments.length'), 0, 'youComments has no posts'); + assert.equal( + post.get('everyoneWeKnowComments.length'), + 0, + 'everyoneWeKnowComments has no posts' + ); + + comment.set('post', post); + + assert.equal(comment.get('post'), post, 'The post that was set can be retrieved'); + + assert.equal(post.get('meComments.length'), 0, 'meComments has no posts'); + assert.equal(post.get('youComments.length'), 1, 'youComments had the post added'); + assert.equal( + post.get('everyoneWeKnowComments.length'), + 0, + 'everyoneWeKnowComments has no posts' + ); + }); + + test('When setting a belongsTo, the OneToOne invariant is respected even when other records have been previously used', async function(assert) { + class Post extends Model { + @belongsTo('comment', { async: false }) + bestComment; + } + + class Comment extends Model { + @belongsTo('post', { async: false }) + post; + } + + register('model:Post', Post); + register('model:Comment', Comment); + + const comment = store.createRecord('comment'); + const post = store.createRecord('post'); + const post2 = store.createRecord('post'); + + comment.set('post', post); + post2.set('bestComment', null); + + assert.equal(comment.get('post'), post); + assert.equal(post.get('bestComment'), comment); + assert.strictEqual(post2.get('bestComment'), null); + + comment.set('post', post2); + + assert.equal(comment.get('post'), post2); + assert.strictEqual(post.get('bestComment'), null); + assert.equal(post2.get('bestComment'), comment); + }); + + test('When setting a belongsTo, the OneToOne invariant is transitive', async function(assert) { + class Post extends Model { + @belongsTo('comment', { async: false }) + bestComment; + } + + class Comment extends Model { + @belongsTo('post', { async: false }) + post; + } + + register('model:Post', Post); + register('model:Comment', Comment); + + const comment = store.createRecord('comment'); + const post = store.createRecord('post'); + const post2 = store.createRecord('post'); + + comment.set('post', post); + + assert.equal(comment.get('post'), post); + assert.equal(post.get('bestComment'), comment); + assert.strictEqual(post2.get('bestComment'), null); + + post2.set('bestComment', comment); + + assert.equal(comment.get('post'), post2); + assert.strictEqual(post.get('bestComment'), null); + assert.equal(post2.get('bestComment'), comment); + }); + + test('When setting a belongsTo, the OneToOne invariant is commutative', async function(assert) { + class Post extends Model { + @belongsTo('comment', { async: false }) + bestComment; + } + + class Comment extends Model { + @belongsTo('post', { async: false }) + post; + } + + register('model:Post', Post); + register('model:Comment', Comment); + + const post = store.createRecord('post'); + const comment = store.createRecord('comment'); + const comment2 = store.createRecord('comment'); + + comment.set('post', post); + + assert.equal(comment.get('post'), post); + assert.equal(post.get('bestComment'), comment); + assert.strictEqual(comment2.get('post'), null); + + post.set('bestComment', comment2); + + assert.strictEqual(comment.get('post'), null); + assert.equal(post.get('bestComment'), comment2); + assert.equal(comment2.get('post'), post); + }); + + test('OneToNone relationship works', async function(assert) { + assert.expect(3); + + class Post extends Model { + @attr('string') + name; + } + + class Comment extends Model { + @belongsTo('post', { async: false }) + post; + } + + register('model:Post', Post); + register('model:Comment', Comment); + + const comment = store.createRecord('comment'); + const post1 = store.createRecord('post'); + const post2 = store.createRecord('post'); + + comment.set('post', post1); + assert.equal(comment.get('post'), post1, 'the post is set to the first one'); + + comment.set('post', post2); + assert.equal(comment.get('post'), post2, 'the post is set to the second one'); + + comment.set('post', post1); + assert.equal(comment.get('post'), post1, 'the post is re-set to the first one'); + }); + + test('When a record is added to or removed from a polymorphic has-many relationship, the inverse belongsTo can be set explicitly', async function(assert) { + class User extends Model { + @hasMany('message', { async: false, inverse: 'redUser', polymorphic: true }) + messages; + } + + class Message extends Model { + @belongsTo('user', { async: false }) + oneUser; + + @belongsTo('user', { async: false }) + twoUser; + + @belongsTo('user', { async: false }) + redUser; + + @belongsTo('user', { async: false }) + blueUser; + } + + class Post extends Message {} + + register('model:User', User); + register('model:Message', Message); + register('model:Post', Post); + + const post = store.createRecord('post'); + const user = store.createRecord('user'); + + assert.equal(post.get('oneUser'), null, 'oneUser has not been set on the user'); + assert.equal(post.get('twoUser'), null, 'twoUser has not been set on the user'); + assert.equal(post.get('redUser'), null, 'redUser has not been set on the user'); + assert.equal(post.get('blueUser'), null, 'blueUser has not been set on the user'); + + user.get('messages').pushObject(post); + + assert.equal(post.get('oneUser'), null, 'oneUser has not been set on the user'); + assert.equal(post.get('twoUser'), null, 'twoUser has not been set on the user'); + assert.equal(post.get('redUser'), user, 'redUser has been set on the user'); + assert.equal(post.get('blueUser'), null, 'blueUser has not been set on the user'); + + user.get('messages').popObject(); + + assert.equal(post.get('oneUser'), null, 'oneUser has not been set on the user'); + assert.equal(post.get('twoUser'), null, 'twoUser has not been set on the user'); + assert.equal(post.get('redUser'), null, 'redUser has bot been set on the user'); + assert.equal(post.get('blueUser'), null, 'blueUser has not been set on the user'); + }); + + test("When a record's belongsTo relationship is set, it can specify the inverse polymorphic hasMany to which the new child should be added or removed", async function(assert) { + class User extends Model { + @hasMany('message', { polymorphic: true, async: false }) + meMessages; + + @hasMany('message', { polymorphic: true, async: false }) + youMessages; + + @hasMany('message', { polymorphic: true, async: false }) + everyoneWeKnowMessages; + } + + class Message extends Model { + @belongsTo('user', { inverse: 'youMessages', async: false }) + user; + } + + class Post extends Message {} + + register('model:User', User); + register('model:Message', Message); + register('model:Post', Post); + + const user = store.createRecord('user'); + const post = store.createRecord('post'); + + assert.equal(user.get('meMessages.length'), 0, 'meMessages has no posts'); + assert.equal(user.get('youMessages.length'), 0, 'youMessages has no posts'); + assert.equal( + user.get('everyoneWeKnowMessages.length'), + 0, + 'everyoneWeKnowMessages has no posts' + ); + + post.set('user', user); + + assert.equal(user.get('meMessages.length'), 0, 'meMessages has no posts'); + assert.equal(user.get('youMessages.length'), 1, 'youMessages had the post added'); + assert.equal( + user.get('everyoneWeKnowMessages.length'), + 0, + 'everyoneWeKnowMessages has no posts' + ); + + post.set('user', null); + + assert.equal(user.get('meMessages.length'), 0, 'meMessages has no posts'); + assert.equal(user.get('youMessages.length'), 0, 'youMessages has no posts'); + assert.equal( + user.get('everyoneWeKnowMessages.length'), + 0, + 'everyoneWeKnowMessages has no posts' + ); + }); + + test("When a record's polymorphic belongsTo relationship is set, it can specify the inverse hasMany to which the new child should be added", async function(assert) { + class Message extends Model { + @hasMany('comment', { inverse: null, async: false }) + meMessages; + + @hasMany('comment', { inverse: 'message', async: false }) + youMessages; + + @hasMany('comment', { inverse: null, async: false }) + everyoneWeKnowMessages; + } + + class Post extends Message {} + + class Comment extends Message { + @belongsTo('message', { async: false, polymorphic: true, inverse: 'youMessages' }) + message; + } + + register('model:Message', Message); + register('model:Post', Post); + register('model:Comment', Comment); + + const comment = store.createRecord('comment'); + const post = store.createRecord('post'); + + assert.equal(post.get('meMessages.length'), 0, 'meMessages has no posts'); + assert.equal(post.get('youMessages.length'), 0, 'youMessages has no posts'); + assert.equal( + post.get('everyoneWeKnowMessages.length'), + 0, + 'everyoneWeKnowMessages has no posts' + ); + + comment.set('message', post); + + assert.equal(post.get('meMessages.length'), 0, 'meMessages has no posts'); + assert.equal(post.get('youMessages.length'), 1, 'youMessages had the post added'); + assert.equal( + post.get('everyoneWeKnowMessages.length'), + 0, + 'everyoneWeKnowMessages has no posts' + ); + + comment.set('message', null); + + assert.equal(post.get('meMessages.length'), 0, 'meMessages has no posts'); + assert.equal(post.get('youMessages.length'), 0, 'youMessages has no posts'); + assert.equal( + post.get('everyoneWeKnowMessages.length'), + 0, + 'everyoneWeKnowMessages has no posts' + ); + }); + + testInDebug( + "Inverse relationships that don't exist throw a nice error for a hasMany", + async function(assert) { + class User extends Model {} + + class Comment extends Model {} + + class Post extends Model { + @hasMany('comment', { inverse: 'testPost', async: false }) + comments; + } + + register('model:User', User); + register('model:Comment', Comment); + register('model:Post', Post); + + let post; + + store.createRecord('comment'); + + assert.expectAssertion(function() { + post = store.createRecord('post'); + post.get('comments'); + }, /We found no inverse relationships by the name of 'testPost' on the 'comment' model/); + } + ); + + testInDebug( + "Inverse relationships that don't exist throw a nice error for a belongsTo", + async function(assert) { + class User extends Model {} + + class Comment extends Model {} + + class Post extends Model { + @belongsTo('user', { inverse: 'testPost', async: false }) + user; + } + + register('model:User', User); + register('model:Comment', Comment); + register('model:Post', Post); + + let post; + store.createRecord('user'); + + assert.expectAssertion(function() { + post = store.createRecord('post'); + post.get('user'); + }, /We found no inverse relationships by the name of 'testPost' on the 'user' model/); + } + ); + + test('inverseFor is only called when inverse is not null', async function(assert) { + assert.expect(2); + + class Post extends Model { + @hasMany('comment', { async: false, inverse: null }) + comments; + } + + class Comment extends Model { + @belongsTo('post', { async: false, inverse: null }) + post; + } + + class User extends Model { + @hasMany('message', { async: false, inverse: 'user' }) + messages; + } + + class Message extends Model { + @belongsTo('user', { async: false, inverse: 'messages' }) + user; + } + + register('model:Post', Post); + register('model:Comment', Comment); + register('model:User', User); + register('model:Message', Message); + + Post.inverseFor = function() { + assert.notOk(true, 'Post model inverseFor is not called'); + }; + + Comment.inverseFor = function() { + assert.notOk(true, 'Comment model inverseFor is not called'); + }; + + Message.inverseFor = function() { + assert.ok(true, 'Message model inverseFor is called'); + }; + + User.inverseFor = function() { + assert.ok(true, 'User model inverseFor is called'); + }; + + store.push({ + data: { + id: '1', + type: 'post', + relationships: { + comments: { + data: [ + { + id: '1', + type: 'comment', + }, + { + id: '2', + type: 'comment', + }, + ], + }, + }, + }, + }); + store.push({ + data: [ + { + id: '1', + type: 'comment', + relationships: { + post: { + data: { + id: '1', + type: 'post', + }, + }, + }, + }, + { + id: '2', + type: 'comment', + relationships: { + post: { + data: { + id: '1', + type: 'post', + }, + }, + }, + }, + ], + }); + store.push({ + data: { + id: '1', + type: 'user', + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + { + id: '2', + type: 'message', + }, + ], + }, + }, + }, + }); + store.push({ + data: [ + { + id: '1', + type: 'message', + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + { + id: '2', + type: 'message', + relationships: { + post: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + ], + }); + }); + + testInDebug( + "Inverse null relationships with models that don't exist throw a nice error if trying to use that relationship", + function(assert) { + class User extends Model { + @belongsTo('post', { inverse: null }) + post; + } + + register('model:User', User); + + assert.expectAssertion(() => { + store.createRecord('user', { post: null }); + }, /No model was found for/); + + // but don't error if the relationship is not used + store.createRecord('user', {}); + } + ); + + test('No inverse configuration - should default to a null inverse', async function(assert) { + class User extends Model {} + + class Comment extends Model { + @belongsTo('user') + user; + } + + register('model:User', User); + register('model:Comment', Comment); + + const comment = store.createRecord('comment'); + + assert.equal(comment.inverseFor('user'), null, 'Defaults to a null inverse'); + }); +}); diff --git a/tests/integration/relationships/json-api-links-test.js b/tests/integration/relationships/json-api-links-test.js new file mode 100644 index 00000000000..7d819029b02 --- /dev/null +++ b/tests/integration/relationships/json-api-links-test.js @@ -0,0 +1,2054 @@ +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import { resolve } from 'rsvp'; +import setupStore from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import deepCopy from 'dummy/tests/helpers/deep-copy'; + +const { Model, attr, hasMany, belongsTo } = DS; + +let env, User, Organisation; + +module('integration/relationship/json-api-links | Relationship state updates', { + beforeEach() {}, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('Loading link with inverse:null on other model caches the two ends separately', function(assert) { + User = DS.Model.extend({ + organisation: belongsTo('organisation', { inverse: null }), + }); + + Organisation = DS.Model.extend({ + adminUsers: hasMany('user', { inverse: null }), + }); + + env = setupStore({ + user: User, + organisation: Organisation, + }); + + env.registry.optionsForType('serializer', { singleton: false }); + env.registry.optionsForType('adapter', { singleton: false }); + + const store = env.store; + + User = store.modelFor('user'); + Organisation = store.modelFor('organisation'); + + env.owner.register( + 'adapter:user', + DS.JSONAPISerializer.extend({ + findRecord(store, type, id) { + return resolve({ + data: { + id, + type: 'user', + relationships: { + organisation: { + data: { id: 1, type: 'organisation' }, + }, + }, + }, + }); + }, + }) + ); + + env.owner.register( + 'adapter:organisation', + DS.JSONAPISerializer.extend({ + findRecord(store, type, id) { + return resolve({ + data: { + type: 'organisation', + id, + relationships: { + 'admin-users': { + links: { + related: '/org-admins', + }, + }, + }, + }, + }); + }, + }) + ); + + return run(() => { + return store.findRecord('user', 1).then(user1 => { + assert.ok(user1, 'user should be populated'); + + return store.findRecord('organisation', 2).then(org2FromFind => { + assert.equal( + user1.belongsTo('organisation').remoteType(), + 'id', + `user's belongsTo is based on id` + ); + assert.equal( + user1.belongsTo('organisation').id(), + 1, + `user's belongsTo has its id populated` + ); + + return user1.get('organisation').then(orgFromUser => { + assert.equal( + user1.belongsTo('organisation').belongsToRelationship.relationshipIsStale, + false, + 'user should have loaded its belongsTo relationship' + ); + + assert.ok(org2FromFind, 'organisation we found should be populated'); + assert.ok(orgFromUser, "user's organisation should be populated"); + }); + }); + }); + }); +}); + +test('Pushing child record should not mark parent:children as loaded', function(assert) { + let Child = DS.Model.extend({ + parent: belongsTo('parent', { inverse: 'children' }), + }); + + let Parent = DS.Model.extend({ + children: hasMany('child', { inverse: 'parent' }), + }); + + env = setupStore({ + parent: Parent, + child: Child, + }); + + env.registry.optionsForType('serializer', { singleton: false }); + env.registry.optionsForType('adapter', { singleton: false }); + + const store = env.store; + + Parent = store.modelFor('parent'); + Child = store.modelFor('child'); + + return run(() => { + const parent = store.push({ + data: { + id: 'p1', + type: 'parent', + relationships: { + children: { + links: { + related: '/parent/1/children', + }, + }, + }, + }, + }); + + store.push({ + data: { + id: 'c1', + type: 'child', + relationships: { + parent: { + data: { + id: 'p1', + type: 'parent', + }, + }, + }, + }, + }); + + assert.equal( + parent.hasMany('children').hasManyRelationship.relationshipIsStale, + true, + 'parent should think that children still needs to be loaded' + ); + }); +}); + +test('pushing has-many payloads with data (no links), then more data (no links) works as expected', function(assert) { + const User = Model.extend({ + pets: hasMany('pet', { async: true, inverse: 'owner' }), + }); + const Pet = Model.extend({ + owner: belongsTo('user', { async: false, inverse: 'pets' }), + }); + const Adapter = JSONAPIAdapter.extend({ + findHasMany() { + assert.ok(false, 'We dont fetch a link when we havent given a link'); + }, + findMany() { + assert.ok(false, 'adapter findMany called instead of using findRecord'); + }, + findRecord(_, __, id) { + assert.ok(id !== '1', `adapter findRecord called for all IDs except "1", called for "${id}"`); + return resolve({ + data: { + type: 'pet', + id, + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + }); + }, + }); + + env = setupStore({ + adapter: Adapter, + user: User, + pet: Pet, + }); + + let { store } = env; + + // push data, no links + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + }, + }, + }) + ); + + // push links, no data + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '2' }, { type: 'pet', id: '3' }], + }, + }, + }, + }) + ); + + let Chris = run(() => store.peekRecord('user', '1')); + run(() => get(Chris, 'pets')); +}); + +test('pushing has-many payloads with data (no links), then links (no data) works as expected', function(assert) { + const User = Model.extend({ + pets: hasMany('pet', { async: true, inverse: 'owner' }), + }); + const Pet = Model.extend({ + owner: belongsTo('user', { async: false, inverse: 'pets' }), + }); + const Adapter = JSONAPIAdapter.extend({ + findHasMany(_, __, link) { + assert.ok(link === './user/1/pets', 'We fetched via the correct link'); + return resolve({ + data: [ + { + type: 'pet', + id: '1', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + { + type: 'pet', + id: '2', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + ], + }); + }, + findMany() { + assert.ok(false, 'adapter findMany called instead of using findHasMany with a link'); + }, + findRecord() { + assert.ok(false, 'adapter findRecord called instead of using findHasMany with a link'); + }, + }); + + env = setupStore({ + adapter: Adapter, + user: User, + pet: Pet, + }); + + let { store } = env; + + // push data, no links + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + }, + }, + }) + ); + + // push links, no data + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + links: { + related: './user/1/pets', + }, + }, + }, + }, + }) + ); + + let Chris = run(() => store.peekRecord('user', '1')); + run(() => get(Chris, 'pets')); +}); + +test('pushing has-many payloads with links (no data), then data (no links) works as expected', function(assert) { + const User = Model.extend({ + pets: hasMany('pet', { async: true, inverse: 'owner' }), + }); + const Pet = Model.extend({ + owner: belongsTo('user', { async: false, inverse: 'pets' }), + }); + const Adapter = JSONAPIAdapter.extend({ + findHasMany(_, __, link) { + assert.ok(link === './user/1/pets', 'We fetched via the correct link'); + return resolve({ + data: [ + { + type: 'pet', + id: '1', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + { + type: 'pet', + id: '2', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + ], + }); + }, + findMany() { + assert.ok(false, 'adapter findMany called instead of using findHasMany with a link'); + }, + findRecord() { + assert.ok(false, 'adapter findRecord called instead of using findHasMany with a link'); + }, + }); + + env = setupStore({ + adapter: Adapter, + user: User, + pet: Pet, + }); + + let { store } = env; + + // push links, no data + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + links: { + related: './user/1/pets', + }, + }, + }, + }, + }) + ); + + // push data, no links + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + }, + }, + }) + ); + + let Chris = run(() => store.peekRecord('user', '1')); + + // we expect to still use the link info + run(() => get(Chris, 'pets')); +}); + +test('pushing has-many payloads with links, then links again works as expected', function(assert) { + const User = Model.extend({ + pets: hasMany('pet', { async: true, inverse: 'owner' }), + }); + const Pet = Model.extend({ + owner: belongsTo('user', { async: false, inverse: 'pets' }), + }); + const Adapter = JSONAPIAdapter.extend({ + findHasMany(_, __, link) { + assert.ok(link === './user/1/pets', 'We fetched via the correct link'); + return resolve({ + data: [ + { + type: 'pet', + id: '1', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + { + type: 'pet', + id: '2', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + ], + }); + }, + findMany() { + assert.ok(false, 'adapter findMany called instead of using findHasMany with a link'); + }, + findRecord() { + assert.ok(false, 'adapter findRecord called instead of using findHasMany with a link'); + }, + }); + + env = setupStore({ + adapter: Adapter, + user: User, + pet: Pet, + }); + + let { store } = env; + + // push links, no data + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + links: { + related: './user/1/not-pets', + }, + }, + }, + }, + }) + ); + + // push data, no links + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + links: { + related: './user/1/pets', + }, + }, + }, + }, + }) + ); + + let Chris = run(() => store.peekRecord('user', '1')); + + // we expect to use the link info from the second push + run(() => get(Chris, 'pets')); +}); + +test('pushing has-many payloads with links and data works as expected', function(assert) { + const User = Model.extend({ + pets: hasMany('pet', { async: true, inverse: 'owner' }), + }); + const Pet = Model.extend({ + owner: belongsTo('user', { async: false, inverse: 'pets' }), + }); + const Adapter = JSONAPIAdapter.extend({ + findHasMany(_, __, link) { + assert.ok(link === './user/1/pets', 'We fetched via the correct link'); + return resolve({ + data: [ + { + type: 'pet', + id: '1', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + { + type: 'pet', + id: '2', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + ], + }); + }, + findMany() { + assert.ok(false, 'adapter findMany called instead of using findHasMany with a link'); + }, + findRecord() { + assert.ok(false, 'adapter findRecord called instead of using findHasMany with a link'); + }, + }); + + env = setupStore({ + adapter: Adapter, + user: User, + pet: Pet, + }); + + let { store } = env; + + // push data and links + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + links: { + related: './user/1/pets', + }, + }, + }, + }, + }) + ); + + let Chris = run(() => store.peekRecord('user', '1')); + run(() => get(Chris, 'pets')); +}); + +test('pushing has-many payloads with links, then one with links and data works as expected', function(assert) { + const User = Model.extend({ + pets: hasMany('pet', { async: true, inverse: 'owner' }), + }); + const Pet = Model.extend({ + owner: belongsTo('user', { async: false, inverse: 'pets' }), + }); + const Adapter = JSONAPIAdapter.extend({ + findHasMany(_, __, link) { + assert.ok(link === './user/1/pets', 'We fetched via the correct link'); + return resolve({ + data: [ + { + type: 'pet', + id: '1', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + { + type: 'pet', + id: '2', + relationships: { + owner: { + data: { type: 'user', id: '1' }, + }, + }, + }, + ], + }); + }, + findMany() { + assert.ok(false, 'adapter findMany called instead of using findHasMany with a link'); + }, + findRecord() { + assert.ok(false, 'adapter findRecord called instead of using findHasMany with a link'); + }, + }); + + env = setupStore({ + adapter: Adapter, + user: User, + pet: Pet, + }); + + let { store } = env; + + // push data, no links + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + }, + }, + }) + ); + + // push links and data + run(() => + store.push({ + data: { + type: 'user', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }, { type: 'pet', id: '2' }, { type: 'pet', id: '3' }], + links: { + related: './user/1/pets', + }, + }, + }, + }, + }) + ); + + let Chris = run(() => store.peekRecord('user', '1')); + run(() => get(Chris, 'pets')); +}); + +module('integration/relationship/json-api-links | Relationship fetching', { + beforeEach() { + const User = Model.extend({ + name: attr(), + pets: hasMany('pet', { async: true, inverse: 'owner' }), + home: belongsTo('home', { async: true, inverse: 'owner' }), + }); + const Home = Model.extend({ + address: attr(), + owner: belongsTo('user', { async: false, inverse: 'home' }), + }); + const Pet = Model.extend({ + name: attr(), + owner: belongsTo('user', { async: false, inverse: 'pets' }), + friends: hasMany('pet', { async: false, inverse: 'friends' }), + }); + const Adapter = JSONAPIAdapter.extend(); + + env = setupStore({ + adapter: Adapter, + user: User, + pet: Pet, + home: Home, + }); + }, + + afterEach() { + run(env.container, 'destroy'); + env = null; + }, +}); + +/* +Tests: + +Fetches Link +- get/reload hasMany with a link (no data) +- get/reload hasMany with a link and data (not available in store) +- get/reload hasMany with a link and empty data (`data: []`) + +Uses Link for Reload +- get/reload hasMany with a link and data (available in store) + +Does Not Use Link (as there is none) +- get/reload hasMany with data, no links +- get/reload hasMany with no data, no links +*/ + +/* + Used for situations when even initially we should fetch via link + */ +function shouldFetchLinkTests(description, payloads) { + test(`get+reload hasMany with ${description}`, function(assert) { + assert.expect(3); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = (_, __, link) => { + assert.ok( + link === payloads.user.data.relationships.pets.links.related, + 'We fetched the appropriate link' + ); + return resolve(deepCopy(payloads.pets)); + }; + + // setup user + let user = run(() => store.push(deepCopy(payloads.user))); + let pets = run(() => user.get('pets')); + + assert.ok(!!pets, 'We found our pets'); + + run(() => pets.reload()); + }); + test(`get+unload+get hasMany with ${description}`, function(assert) { + assert.expect(3); + let { store, adapter } = env; + + let petRelationshipData = payloads.user.data.relationships.pets.data; + let petRelDataWasEmpty = petRelationshipData && petRelationshipData.length === 0; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = (_, __, link) => { + if (petRelDataWasEmpty) { + assert.ok( + link === payloads.user.data.relationships.pets.links.related, + 'We fetched this link even though we really should not have' + ); + } else { + assert.ok( + link === payloads.user.data.relationships.pets.links.related, + 'We fetched the appropriate link' + ); + } + return resolve(deepCopy(payloads.pets)); + }; + + // setup user + let user = run(() => store.push(deepCopy(payloads.user))); + let pets = run(() => user.get('pets')); + + assert.ok(!!pets, 'We found our pets'); + + if (!petRelDataWasEmpty) { + run(() => pets.objectAt(0).unloadRecord()); + run(() => user.get('pets')); + } else { + assert.ok(true, `We cant dirty a relationship we have no knowledge of`); + } + }); + test(`get+reload belongsTo with ${description}`, function(assert) { + assert.expect(3); + let { store, adapter } = env; + + let homeRelationshipData = payloads.user.data.relationships.home.data; + let homeRelWasEmpty = homeRelationshipData === null; + let isInitialFetch = true; + let didFetchInitially = false; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findBelongsTo = (_, __, link) => { + if (isInitialFetch && homeRelWasEmpty) { + assert.ok(false, 'We should not fetch a relationship we believe is empty'); + didFetchInitially = true; + } else { + assert.ok( + link === payloads.user.data.relationships.home.links.related, + 'We fetched the appropriate link' + ); + } + return resolve(deepCopy(payloads.home)); + }; + + // setup user + let user = run(() => store.push(deepCopy(payloads.user))); + let home = run(() => user.get('home')); + + if (homeRelWasEmpty) { + assert.ok(!didFetchInitially, 'We did not fetch'); + } + + assert.ok(!!home, 'We found our home'); + isInitialFetch = false; + + run(() => home.reload()); + }); + test(`get+unload+get belongsTo with ${description}`, function(assert) { + assert.expect(3); + let { store, adapter } = env; + + let homeRelationshipData = payloads.user.data.relationships.home.data; + let homeRelWasEmpty = homeRelationshipData === null; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findBelongsTo = (_, __, link) => { + assert.ok( + !homeRelWasEmpty && link === payloads.user.data.relationships.home.links.related, + 'We fetched the appropriate link' + ); + return resolve(deepCopy(payloads.home)); + }; + + // setup user + let user = run(() => store.push(deepCopy(payloads.user))); + let home = run(() => user.get('home')); + + assert.ok(!!home, 'We found our home'); + + if (!homeRelWasEmpty) { + run(() => home.then(h => h.unloadRecord())); + run(() => user.get('home')); + } else { + assert.ok(true, `We cant dirty a relationship we have no knowledge of`); + assert.ok(true, `Nor should we have fetched it.`); + } + }); +} + +shouldFetchLinkTests('a link (no data)', { + user: { + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + links: { + related: './runspired/pets', + }, + }, + home: { + links: { + related: './runspired/address', + }, + }, + }, + }, + }, + pets: { + data: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + ], + }, + home: { + data: { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, Ca', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }, +}); + +shouldFetchLinkTests('a link and data (not available in the store)', { + user: { + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + links: { + related: './runspired/pets', + }, + data: [{ type: 'pet', id: '1' }], + }, + home: { + links: { + related: './runspired/address', + }, + data: { type: 'home', id: '1' }, + }, + }, + }, + }, + pets: { + data: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + links: { + related: './user/1', + }, + }, + }, + }, + ], + }, + home: { + data: { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, Ca', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + links: { + related: './user/1', + }, + }, + }, + }, + }, +}); + +/* + Used for situations when initially we have data, but reload/missing data + situations should be done via link + */ +function shouldReloadWithLinkTests(description, payloads) { + test(`get+reload hasMany with ${description}`, function(assert) { + assert.expect(2); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = (_, __, link) => { + assert.ok( + link === payloads.user.data.relationships.pets.links.related, + 'We fetched the appropriate link' + ); + return resolve(deepCopy(payloads.pets)); + }; + + // setup user and pets + let user = run(() => store.push(deepCopy(payloads.user))); + run(() => store.push(deepCopy(payloads.pets))); + let pets = run(() => user.get('pets')); + + assert.ok(!!pets, 'We found our pets'); + + run(() => pets.reload()); + }); + test(`get+unload+get hasMany with ${description}`, function(assert) { + assert.expect(2); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = (_, __, link) => { + assert.ok( + link === payloads.user.data.relationships.pets.links.related, + 'We fetched the appropriate link' + ); + return resolve(deepCopy(payloads.pets)); + }; + + // setup user and pets + let user = run(() => store.push(deepCopy(payloads.user))); + run(() => store.push(deepCopy(payloads.pets))); + let pets = run(() => user.get('pets')); + + assert.ok(!!pets, 'We found our pets'); + + run(() => pets.objectAt(0).unloadRecord()); + run(() => user.get('pets')); + }); + test(`get+reload belongsTo with ${description}`, function(assert) { + assert.expect(2); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findBelongsTo = (_, __, link) => { + assert.ok( + link === payloads.user.data.relationships.home.links.related, + 'We fetched the appropriate link' + ); + return resolve(deepCopy(payloads.home)); + }; + + // setup user and home + let user = run(() => store.push(deepCopy(payloads.user))); + run(() => store.push(deepCopy(payloads.home))); + let home = run(() => user.get('home')); + + assert.ok(!!home, 'We found our home'); + + run(() => home.reload()); + }); + test(`get+unload+get belongsTo with ${description}`, function(assert) { + assert.expect(2); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findBelongsTo = (_, __, link) => { + assert.ok( + link === payloads.user.data.relationships.home.links.related, + 'We fetched the appropriate link' + ); + return resolve(deepCopy(payloads.home)); + }; + + // setup user + let user = run(() => store.push(deepCopy(payloads.user))); + run(() => store.push(deepCopy(payloads.home))); + let home; + run(() => user.get('home').then(h => (home = h))); + + assert.ok(!!home, 'We found our home'); + + run(() => home.unloadRecord()); + run(() => user.get('home')); + }); +} + +shouldReloadWithLinkTests('a link and data (available in the store)', { + user: { + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + links: { + related: './runspired/pets', + }, + data: [{ type: 'pet', id: '1' }], + }, + home: { + links: { + related: './runspired/address', + }, + data: { type: 'home', id: '1' }, + }, + }, + }, + }, + pets: { + data: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + ], + }, + home: { + data: { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, Ca', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }, +}); + +shouldReloadWithLinkTests( + 'a link and empty data (`data: []` or `data: null`), true inverse loaded', + { + user: { + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + links: { + related: './runspired/pets', + }, + data: [], + }, + home: { + links: { + related: './runspired/address', + }, + data: null, + }, + }, + }, + }, + pets: { + data: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + links: { + related: './user/1', + }, + }, + }, + }, + ], + }, + home: { + data: { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, Ca', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + links: { + related: './user/1', + }, + }, + }, + }, + }, + } +); + +shouldReloadWithLinkTests( + 'a link and empty data (`data: []` or `data: null`), true inverse unloaded', + { + user: { + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + links: { + related: './runspired/pets', + }, + data: [], + }, + home: { + links: { + related: './runspired/address', + }, + data: null, + }, + }, + }, + }, + pets: { + data: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + ], + }, + home: { + data: { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, Ca', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }, + } +); + +/* + Ad Hoc Situations when we don't have a link + */ + +// data, no links +test(`get+reload hasMany with data, no links`, function(assert) { + assert.expect(3); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(true, 'We should call findRecord'); + return resolve({ + data: { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + + // setup user + let user = run(() => + store.push({ + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + home: { + data: { type: 'home', id: '1' }, + }, + }, + }, + }) + ); + let pets = run(() => user.get('pets')); + + assert.ok(!!pets, 'We found our pets'); + + run(() => pets.reload()); +}); +test(`get+unload+get hasMany with data, no links`, function(assert) { + assert.expect(3); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(true, 'We should call findRecord'); + return resolve({ + data: { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + + // setup user + let user = run(() => + store.push({ + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + home: { + data: { type: 'home', id: '1' }, + }, + }, + }, + }) + ); + let pets = run(() => user.get('pets')); + + assert.ok(!!pets, 'We found our pets'); + + run(() => pets.objectAt(0).unloadRecord()); + run(() => user.get('pets')); +}); +test(`get+reload belongsTo with data, no links`, function(assert) { + assert.expect(3); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(true, 'We should call findRecord'); + return resolve({ + data: { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, CA', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + + // setup user + let user = run(() => + store.push({ + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + home: { + data: { type: 'home', id: '1' }, + }, + }, + }, + }) + ); + let home = run(() => user.get('home')); + + assert.ok(!!home, 'We found our home'); + + run(() => home.reload()); +}); +test(`get+unload+get belongsTo with data, no links`, function(assert) { + assert.expect(3); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(true, 'We should call findRecord'); + return resolve({ + data: { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, Ca', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + + // setup user + let user = run(() => + store.push({ + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + home: { + data: { type: 'home', id: '1' }, + }, + }, + }, + }) + ); + let home = run(() => user.get('home')); + + assert.ok(!!home, 'We found our home'); + + run(() => home.then(h => h.unloadRecord())); + run(() => user.get('home')); +}); + +// missing data setup from the other side, no links +test(`get+reload hasMany with missing data setup from the other side, no links`, function(assert) { + assert.expect(2); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(true, 'We should call findRecord'); + return resolve({ + data: { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + + // setup user and pet + let user = run(() => + store.push({ + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: {}, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + ], + }) + ); + let pets = run(() => user.get('pets')); + + assert.ok(!!pets, 'We found our pets'); + + run(() => pets.reload()); +}); +test(`get+unload+get hasMany with missing data setup from the other side, no links`, function(assert) { + assert.expect(2); + let { store, adapter } = env; + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(true, 'We should call findRecord'); + return resolve({ + data: { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + + // setup user and pet + let user = run(() => + store.push({ + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: {}, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + ], + }) + ); + + // should trigger a fetch bc we don't consider `pets` to have complete knowledge + let pets = run(() => user.get('pets')); + + assert.ok(!!pets, 'We found our pets'); + + run(() => pets.objectAt(0).unloadRecord()); + + // should trigger a findRecord for the unloaded pet + run(() => user.get('pets')); +}); +test(`get+reload belongsTo with missing data setup from the other side, no links`, function(assert) { + assert.expect(2); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(true, 'We should call findRecord'); + return resolve({ + data: { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, CA', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + + // setup user and home + let user = run(() => + store.push({ + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: {}, + }, + included: [ + { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, CA', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + ], + }) + ); + let home = run(() => user.get('home')); + + assert.ok(!!home, 'We found our home'); + + run(() => home.reload()); +}); +test(`get+unload+get belongsTo with missing data setup from the other side, no links`, function(assert) { + assert.expect(2); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(true, 'We should call findRecord'); + return resolve({ + data: { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, CA', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + }); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + + // setup user and home + let user = run(() => + store.push({ + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: {}, + }, + included: [ + { + type: 'home', + id: '1', + attributes: { + address: 'Oakland, CA', + }, + relationships: { + owner: { + data: { + type: 'user', + id: '1', + }, + }, + }, + }, + ], + }) + ); + let home = run(() => user.get('home')); + + assert.ok(!!home, 'We found our home'); + + run(() => home.then(h => h.unloadRecord())); + run(() => user.get('home')); +}); + +// empty data, no links +test(`get+reload hasMany with empty data, no links`, function(assert) { + assert.expect(1); + let { store, adapter } = env; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + + // setup user + let user = run(() => + store.push({ + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + data: [], + }, + home: { + data: null, + }, + }, + }, + }) + ); + let pets = run(() => user.get('pets')); + + assert.ok(!!pets, 'We found our pets'); + + run(() => pets.reload()); +}); + +/* + Ad hoc situations where we do have a link + */ +test('We should not fetch a hasMany relationship with links that we know is empty', function(assert) { + assert.expect(1); + let { store, adapter } = env; + + let user1Payload = { + data: { + type: 'user', + id: '1', + attributes: { + name: '@runspired', + }, + relationships: { + pets: { + links: { + related: './runspired/pets', + }, + data: [], // we are explicitly told this is empty + }, + }, + }, + }; + let user2Payload = { + data: { + type: 'user', + id: '2', + attributes: { + name: '@hjdivad', + }, + relationships: { + pets: { + links: { + related: './hjdivad/pets', + }, + // we have no data, so we do not know that this is empty + }, + }, + }, + }; + let requestedUser = null; + let failureDescription = ''; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = (_, __, link) => { + if (!requestedUser) { + assert.ok(false, failureDescription); + } else { + assert.ok( + link === requestedUser.data.relationships.pets.links.related, + 'We fetched the appropriate link' + ); + } + + return resolve({ + data: [], + }); + }; + + // setup users + let user1 = run(() => store.push(deepCopy(user1Payload))); + let user2 = run(() => store.push(deepCopy(user2Payload))); + + // should not fire a request + requestedUser = null; + failureDescription = 'We improperly fetched the link for a known empty relationship'; + run(() => user1.get('pets')); + + // still should not fire a request + requestedUser = null; + failureDescription = 'We improperly fetched the link (again) for a known empty relationship'; + run(() => user1.get('pets')); + + // should fire a request + requestedUser = user2Payload; + run(() => user2.get('pets')); + + // should not fire a request + requestedUser = null; + failureDescription = + 'We improperly fetched the link for a previously fetched and found to be empty relationship'; + run(() => user2.get('pets')); +}); + +test('We should not fetch a sync hasMany relationship with a link that is missing the data member', function(assert) { + assert.expect(1); + let { store, adapter } = env; + + let petPayload = { + data: { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + friends: { + links: { + related: './shen/friends', + }, + }, + }, + }, + }; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + adapter.findBelongsTo = () => { + assert.ok(false, 'We should not call findBelongsTo'); + }; + + // setup users + let shen = run(() => store.push(petPayload)); + + // should not fire a request + run(() => shen.get('pets')); + + assert.ok(true, 'We reached the end of the test'); +}); + +test('We should not fetch a sync belongsTo relationship with a link that is missing the data member', function(assert) { + assert.expect(1); + let { store, adapter } = env; + + let petPayload = { + data: { + type: 'pet', + id: '1', + attributes: { + name: 'Shen', + }, + relationships: { + owner: { + links: { + related: './shen/owner', + self: './owner/a', + }, + }, + }, + }, + }; + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.findRecord = () => { + assert.ok(false, 'We should not call findRecord'); + }; + adapter.findMany = () => { + assert.ok(false, 'We should not call findMany'); + }; + adapter.findHasMany = () => { + assert.ok(false, 'We should not call findHasMany'); + }; + adapter.findBelongsTo = () => { + assert.ok(false, 'We should not call findBelongsTo'); + }; + + // setup users + let shen = run(() => store.push(petPayload)); + + // should not fire a request + run(() => shen.get('owner')); + + assert.ok(true, 'We reached the end of the test'); +}); diff --git a/tests/integration/relationships/many-to-many-test.js b/tests/integration/relationships/many-to-many-test.js new file mode 100644 index 00000000000..e8ca4bcbfe1 --- /dev/null +++ b/tests/integration/relationships/many-to-many-test.js @@ -0,0 +1,649 @@ +/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(ada)" }]*/ + +import { resolve, Promise as EmberPromise } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import setupStore from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; +import todo from '../../helpers/todo'; +import DS from 'ember-data'; + +const { attr, hasMany } = DS; + +let Account, Topic, User, store, env; + +module('integration/relationships/many_to_many_test - ManyToMany relationships', { + beforeEach() { + User = DS.Model.extend({ + name: attr('string'), + topics: hasMany('topic', { async: true }), + accounts: hasMany('account', { async: false }), + }); + + Account = DS.Model.extend({ + state: attr(), + users: hasMany('user', { async: false }), + }); + + Topic = DS.Model.extend({ + title: attr('string'), + users: hasMany('user', { async: true }), + }); + + env = setupStore({ + user: User, + topic: Topic, + account: Account, + adapter: DS.Adapter.extend({ + deleteRecord: () => resolve(), + }), + }); + + store = env.store; + }, + + afterEach() { + run(() => env.container.destroy()); + }, +}); + +/* + Server loading tests +*/ + +test('Loading from one hasMany side reflects on the other hasMany side - async', function(assert) { + run(() => { + store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + topics: { + data: [ + { + id: '2', + type: 'topic', + }, + { + id: '3', + type: 'topic', + }, + ], + }, + }, + }, + }); + }); + + let topic = run(() => { + return store.push({ + data: { + id: '2', + type: 'topic', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + + return run(() => { + return topic.get('users').then(fetchedUsers => { + assert.equal(fetchedUsers.get('length'), 1, 'User relationship was set up correctly'); + }); + }); +}); + +test('Relationship is available from one hasMany side even if only loaded from the other hasMany side - sync', function(assert) { + var account; + run(() => { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + }); + + run(() => { + assert.equal(account.get('users.length'), 1, 'User relationship was set up correctly'); + }); +}); + +test('Fetching a hasMany where a record was removed reflects on the other hasMany side - async', function(assert) { + let user, topic; + + run(() => { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + topics: { + data: [{ id: '2', type: 'topic' }], + }, + }, + }, + }); + topic = store.push({ + data: { + id: '2', + type: 'topic', + attributes: { + title: 'EmberFest was great', + }, + relationships: { + users: { + data: [], + }, + }, + }, + }); + }); + + return run(() => { + return user.get('topics').then(fetchedTopics => { + assert.equal(fetchedTopics.get('length'), 0, 'Topics were removed correctly'); + assert.equal(fetchedTopics.objectAt(0), null, "Topics can't be fetched"); + return topic.get('users').then(fetchedUsers => { + assert.equal(fetchedUsers.get('length'), 0, 'Users were removed correctly'); + assert.equal(fetchedUsers.objectAt(0), null, "User can't be fetched"); + }); + }); + }); +}); + +test('Fetching a hasMany where a record was removed reflects on the other hasMany side - sync', function(assert) { + let account, user; + run(() => { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + relationships: { + users: { + data: [], + }, + }, + }, + }); + }); + + run(() => { + assert.equal(user.get('accounts.length'), 0, 'Accounts were removed correctly'); + assert.equal(account.get('users.length'), 0, 'Users were removed correctly'); + }); +}); + +/* + Local edits +*/ + +test('Pushing to a hasMany reflects on the other hasMany side - async', function(assert) { + assert.expect(1); + let user, topic; + + run(() => { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + topics: { + data: [], + }, + }, + }, + }); + topic = store.push({ + data: { + id: '2', + type: 'topic', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + + return run(() => { + return topic.get('users').then(fetchedUsers => { + fetchedUsers.pushObject(user); + return user.get('topics').then(fetchedTopics => { + assert.equal(fetchedTopics.get('length'), 1, 'User relationship was set up correctly'); + }); + }); + }); +}); + +test('Pushing to a hasMany reflects on the other hasMany side - sync', function(assert) { + let account, stanley; + run(() => { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + stanley = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + stanley.get('accounts').pushObject(account); + }); + + run(() => { + assert.equal(account.get('users.length'), 1, 'User relationship was set up correctly'); + }); +}); + +test('Removing a record from a hasMany reflects on the other hasMany side - async', function(assert) { + let user, topic; + run(() => { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + topics: { + data: [ + { + id: '2', + type: 'topic', + }, + ], + }, + }, + }, + }); + topic = store.push({ + data: { + id: '2', + type: 'topic', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + + return run(() => { + return user.get('topics').then(fetchedTopics => { + assert.equal(fetchedTopics.get('length'), 1, 'Topics were setup correctly'); + fetchedTopics.removeObject(topic); + return topic.get('users').then(fetchedUsers => { + assert.equal(fetchedUsers.get('length'), 0, 'Users were removed correctly'); + assert.equal(fetchedUsers.objectAt(0), null, "User can't be fetched"); + }); + }); + }); +}); + +test('Removing a record from a hasMany reflects on the other hasMany side - sync', function(assert) { + let account, user; + run(() => { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + }); + + run(() => { + assert.equal(account.get('users.length'), 1, 'Users were setup correctly'); + account.get('users').removeObject(user); + assert.equal(user.get('accounts.length'), 0, 'Accounts were removed correctly'); + assert.equal(account.get('users.length'), 0, 'Users were removed correctly'); + }); +}); + +/* + Rollback Attributes tests +*/ + +test('Rollbacking attributes for a deleted record that has a ManyToMany relationship works correctly - async', function(assert) { + let user, topic; + run(() => { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + topics: { + data: [ + { + id: '2', + type: 'topic', + }, + ], + }, + }, + }, + }); + topic = store.push({ + data: { + id: '2', + type: 'topic', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + + run(() => { + topic.deleteRecord(); + topic.rollbackAttributes(); + }); + + return run(() => { + let users = topic.get('users').then(fetchedUsers => { + assert.equal(fetchedUsers.get('length'), 1, 'Users are still there'); + }); + + let topics = user.get('topics').then(fetchedTopics => { + assert.equal(fetchedTopics.get('length'), 1, 'Topic got rollbacked into the user'); + }); + + return EmberPromise.all([users, topics]); + }); +}); + +test('Deleting a record that has a hasMany relationship removes it from the otherMany array but does not remove the other record from itself - sync', function(assert) { + let account, user; + run(() => { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + }); + + run(() => { + account.deleteRecord(); + account.rollbackAttributes(); + assert.equal(account.get('users.length'), 1, 'Users are still there'); + assert.equal(user.get('accounts.length'), 1, 'Account got rolledback correctly into the user'); + }); +}); + +test('Rollbacking attributes for a created record that has a ManyToMany relationship works correctly - async', function(assert) { + let user, topic; + run(() => { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + + topic = store.createRecord('topic'); + }); + + return run(() => { + return user.get('topics').then(fetchedTopics => { + fetchedTopics.pushObject(topic); + topic.rollbackAttributes(); + + let users = topic.get('users').then(fetchedUsers => { + assert.equal(fetchedUsers.get('length'), 0, 'Users got removed'); + assert.equal(fetchedUsers.objectAt(0), null, "User can't be fetched"); + }); + + let topics = user.get('topics').then(fetchedTopics => { + assert.equal(fetchedTopics.get('length'), 0, 'Topics got removed'); + assert.equal(fetchedTopics.objectAt(0), null, "Topic can't be fetched"); + }); + + return EmberPromise.all([users, topics]); + }); + }); +}); + +test('Deleting an unpersisted record via rollbackAttributes that has a hasMany relationship removes it from the otherMany array but does not remove the other record from itself - sync', function(assert) { + let account, user; + run(() => { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + + user = store.createRecord('user'); + }); + + run(() => { + account.get('users').pushObject(user); + user.rollbackAttributes(); + }); + + assert.equal(account.get('users.length'), 0, 'Users got removed'); + assert.equal(user.get('accounts.length'), 0, 'Accounts got rolledback correctly'); +}); + +todo( + 'Re-loading a removed record should re add it to the relationship when the removed record is the last one in the relationship', + function(assert) { + assert.expect(4); + let account, ada, byron; + + run(() => { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'account 1', + }, + }, + }); + ada = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Ada Lovelace', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + byron = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: 'Lord Byron', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + account.get('users').removeObject(byron); + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'account 1', + }, + relationships: { + users: { + data: [ + { + id: '1', + type: 'user', + }, + { + id: '2', + type: 'user', + }, + ], + }, + }, + }, + }); + }); + + let state = account.hasMany('users').hasManyRelationship.canonicalMembers.list; + let users = account.get('users'); + + assert.todo.equal(users.get('length'), 1, 'Accounts were updated correctly (ui state)'); + assert.todo.deepEqual( + users.map(r => get(r, 'id')), + ['1'], + 'Accounts were updated correctly (ui state)' + ); + assert.equal(state.length, 2, 'Accounts were updated correctly (server state)'); + assert.deepEqual( + state.map(r => r.id), + ['1', '2'], + 'Accounts were updated correctly (server state)' + ); + } +); diff --git a/tests/integration/relationships/nested-relationship-test.js b/tests/integration/relationships/nested-relationship-test.js new file mode 100644 index 00000000000..6957fe16459 --- /dev/null +++ b/tests/integration/relationships/nested-relationship-test.js @@ -0,0 +1,153 @@ +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +const { attr, hasMany, belongsTo } = DS; + +let env, store, Elder, MiddleAger, Kid; + +module('integration/relationships/nested_relationships_test - Nested relationships', { + beforeEach() { + Elder = DS.Model.extend({ + name: attr('string'), + middleAgers: hasMany('middle-ager'), + }); + + MiddleAger = DS.Model.extend({ + name: attr('string'), + elder: belongsTo('elder'), + kids: hasMany('kid'), + }); + + Kid = DS.Model.extend({ + name: attr('string'), + middleAger: belongsTo('middle-ager'), + }); + + env = setupStore({ + elder: Elder, + 'middle-ager': MiddleAger, + kid: Kid, + adapter: DS.JSONAPIAdapter, + }); + + store = env.store; + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +/* + Server loading tests +*/ + +test('Sideloaded nested relationships load correctly', function(assert) { + env.adapter.shouldBackgroundReloadRecord = () => { + return false; + }; + run(() => { + store.push({ + data: { + id: '1', + type: 'kid', + links: { + self: '/kids/1', + }, + attributes: { + name: 'Kid 1', + }, + relationships: { + middleAger: { + links: { + self: '/kids/1/relationships/middle-ager', + related: '/kids/1/middle-ager', + }, + data: { + type: 'middle-ager', + id: '1', + }, + }, + }, + }, + included: [ + { + id: '1', + type: 'middle-ager', + links: { + self: '/middle-ager/1', + }, + attributes: { + name: 'Middle Ager 1', + }, + relationships: { + elder: { + links: { + self: '/middle-agers/1/relationships/elder', + related: '/middle-agers/1/elder', + }, + data: { + type: 'elder', + id: '1', + }, + }, + kids: { + links: { + self: '/middle-agers/1/relationships/kids', + related: '/middle-agers/1/kids', + }, + data: [ + { + type: 'kid', + id: '1', + }, + ], + }, + }, + }, + + { + id: '1', + type: 'elder', + links: { + self: '/elders/1', + }, + attributes: { + name: 'Elder 1', + }, + relationships: { + middleAger: { + links: { + self: '/elders/1/relationships/middle-agers', + related: '/elders/1/middle-agers', + }, + }, + }, + }, + ], + }); + }); + + return run(() => { + let kid = store.peekRecord('kid', '1'); + + return kid.get('middleAger').then(middleAger => { + assert.ok(middleAger, 'MiddleAger relationship was set up correctly'); + + let middleAgerName = get(middleAger, 'name'); + assert.equal(middleAgerName, 'Middle Ager 1', 'MiddleAger name is there'); + assert.ok(middleAger.get('kids').includes(kid)); + + return middleAger.get('elder').then(elder => { + assert.notEqual(elder, null, 'Elder relationship was set up correctly'); + let elderName = get(elder, 'name'); + assert.equal(elderName, 'Elder 1', 'Elder name is there'); + }); + }); + }); +}); diff --git a/tests/integration/relationships/one-to-many-test.js b/tests/integration/relationships/one-to-many-test.js new file mode 100644 index 00000000000..fd82252b2f8 --- /dev/null +++ b/tests/integration/relationships/one-to-many-test.js @@ -0,0 +1,1567 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var env, store, User, Message, Account; + +var attr = DS.attr; +var hasMany = DS.hasMany; +var belongsTo = DS.belongsTo; + +module('integration/relationships/one_to_many_test - OneToMany relationships', { + beforeEach() { + User = DS.Model.extend({ + name: attr('string'), + messages: hasMany('message', { async: true }), + accounts: hasMany('account', { async: false }), + }); + + Account = DS.Model.extend({ + state: attr(), + user: belongsTo('user', { async: false }), + }); + + Message = DS.Model.extend({ + title: attr('string'), + user: belongsTo('user', { async: true }), + }); + + env = setupStore({ + user: User, + message: Message, + account: Account, + adapter: DS.Adapter.extend({ + deleteRecord: () => resolve(), + }), + }); + + store = env.store; + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +/* + Server loading tests +*/ + +test('Relationship is available from the belongsTo side even if only loaded from the hasMany side - async', function(assert) { + var user, message; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '2', + type: 'message', + }, + ], + }, + }, + }, + }); + message = store.push({ + data: { + id: '2', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + run(function() { + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'User relationship was set up correctly'); + }); + }); +}); + +test('Relationship is available from the belongsTo side even if only loaded from the hasMany side - sync', function(assert) { + var account, user; + run(function() { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + }); + assert.equal(account.get('user'), user, 'User relationship was set up correctly'); +}); + +test('Relationship is available from the hasMany side even if only loaded from the belongsTo side - async', function(assert) { + var user, message; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + message = store.push({ + data: { + id: '2', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + }); + run(function() { + user.get('messages').then(function(fetchedMessages) { + assert.equal( + fetchedMessages.objectAt(0), + message, + 'Messages relationship was set up correctly' + ); + }); + }); +}); + +test('Relationship is available from the hasMany side even if only loaded from the belongsTo side - sync', function(assert) { + var user, account; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + }); + run(function() { + assert.equal( + user.get('accounts').objectAt(0), + account, + 'Accounts relationship was set up correctly' + ); + }); +}); + +test('Fetching a belongsTo that is set to null removes the record from a relationship - async', function(assert) { + var user; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + { + id: '2', + type: 'message', + }, + ], + }, + }, + }, + }); + }); + run(function() { + store.push({ + data: [ + { + id: '1', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + { + id: '2', + type: 'message', + attributes: { + title: 'EmberConf will be better', + }, + relationships: { + user: { + data: null, + }, + }, + }, + ], + }); + }); + run(function() { + user.get('messages').then(function(fetchedMessages) { + assert.equal(get(fetchedMessages, 'length'), 1, 'Messages relationship was set up correctly'); + }); + }); +}); + +test('Fetching a belongsTo that is set to null removes the record from a relationship - sync', function(assert) { + var user; + run(function() { + store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + + store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + relationships: { + user: { + data: null, + }, + }, + }, + }); + }); + + run(function() { + assert.equal(user.get('accounts').objectAt(0), null, 'Account was sucesfully removed'); + }); +}); + +test('Fetching a belongsTo that is not defined does not remove the record from a relationship - async', function(assert) { + var user; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + { + id: '2', + type: 'message', + }, + ], + }, + }, + }, + }); + }); + run(function() { + store.push({ + data: [ + { + id: '1', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + { + id: '2', + type: 'message', + attributes: { + title: 'EmberConf will be better', + }, + }, + ], + }); + }); + run(function() { + user.get('messages').then(function(fetchedMessages) { + assert.equal(get(fetchedMessages, 'length'), 2, 'Messages relationship was set up correctly'); + }); + }); +}); + +test('Fetching a belongsTo that is not defined does not remove the record from a relationship - sync', function(assert) { + var account, user; + run(function() { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + }); + + run(function() { + assert.equal(user.get('accounts').objectAt(0), account, 'Account was sucesfully removed'); + }); +}); + +test("Fetching the hasMany that doesn't contain the belongsTo, sets the belongsTo to null - async", function(assert) { + let user, message, message2; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + ], + }, + }, + }, + }); + message = store.push({ + data: { + id: '1', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + message2 = store.push({ + data: { + id: '2', + type: 'message', + attributes: { + title: 'EmberConf is gonna be better', + }, + }, + }); + }); + run(function() { + store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '2', + type: 'message', + }, + ], + }, + }, + }, + }); + }); + run(function() { + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'User was removed correctly'); + }); + + message2.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'User was set on the second message'); + }); + }); +}); + +test("Fetching the hasMany that doesn't contain the belongsTo, sets the belongsTo to null - sync", function(assert) { + let account1; + let account2; + let user; + + run(function() { + // tell the store user:1 has account:1 + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [{ id: '1', type: 'account' }], + }, + }, + }, + }); + + // tell the store account:1 has user:1 + account1 = store.push({ + data: { + id: '1', + type: 'account', + attributes: { + state: 'great', + }, + relationships: { + user: { + data: { id: '1', type: 'user' }, + }, + }, + }, + }); + + // tell the store account:2 has no user + account2 = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'awesome', + }, + }, + }); + + // tell the store user:1 has account:2 and not account:1 + store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [{ id: '2', type: 'account' }], + }, + }, + }, + }); + }); + + run(function() { + assert.ok(account1.get('user') === null, 'User was removed correctly'); + assert.ok(account2.get('user') === user, 'User was added correctly'); + }); +}); + +test('Fetching the hasMany side where the hasMany is undefined does not change the belongsTo side - async', function(assert) { + var message, user; + run(function() { + store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + ], + }, + }, + }, + }); + message = store.push({ + data: { + id: '1', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + }); + + run(function() { + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'User was not removed'); + }); + }); +}); + +test('Fetching the hasMany side where the hasMany is undefined does not change the belongsTo side - sync', function(assert) { + var account, user; + run(function() { + store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '1', + type: 'account', + }, + ], + }, + }, + }, + }); + account = store.push({ + data: { + id: '1', + type: 'account', + attributes: { + state: 'great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'awesome', + }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + }); + + run(function() { + assert.equal(account.get('user'), user, 'User was not removed'); + }); +}); + +/* + Local edits +*/ + +test('Pushing to the hasMany reflects the change on the belongsTo side - async', function(assert) { + var user, message2; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + ], + }, + }, + }, + }); + store.push({ + data: { + id: '1', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + message2 = store.push({ + data: { + id: '2', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + + run(function() { + user.get('messages').then(function(fetchedMessages) { + fetchedMessages.pushObject(message2); + message2.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'user got set correctly'); + }); + }); + }); +}); + +test('Pushing to the hasMany reflects the change on the belongsTo side - sync', function(assert) { + var user, account2; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '1', + type: 'account', + }, + ], + }, + }, + }, + }); + store.push({ + data: { + id: '1', + type: 'account', + attributes: { + state: 'great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + + account2 = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'awesome', + }, + }, + }); + user.get('accounts').pushObject(account2); + }); + + assert.equal(account2.get('user'), user, 'user got set correctly'); +}); + +test('Removing from the hasMany side reflects the change on the belongsTo side - async', function(assert) { + var user, message; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + ], + }, + }, + }, + }); + message = store.push({ + data: { + id: '1', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + + run(function() { + user.get('messages').then(function(fetchedMessages) { + fetchedMessages.removeObject(message); + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'user got removed correctly'); + }); + }); + }); +}); + +test('Removing from the hasMany side reflects the change on the belongsTo side - sync', function(assert) { + var user, account; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attirbutes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '1', + type: 'account', + }, + ], + }, + }, + }, + }); + account = store.push({ + data: { + id: '1', + type: 'account', + attirbutes: { + state: 'great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + }); + run(function() { + user.get('accounts').removeObject(account); + }); + + assert.equal(account.get('user'), null, 'user got removed correctly'); +}); + +test('Pushing to the hasMany side keeps the oneToMany invariant on the belongsTo side - async', function(assert) { + assert.expect(2); + var user, user2, message; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + ], + }, + }, + }, + }); + user2 = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: 'Tomhuda', + }, + }, + }); + message = store.push({ + data: { + id: '1', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + + run(function() { + user2.get('messages').then(function(fetchedMessages) { + fetchedMessages.pushObject(message); + + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user2, 'user got set correctly'); + }); + + user.get('messages').then(function(newFetchedMessages) { + assert.equal( + get(newFetchedMessages, 'length'), + 0, + 'message got removed from the old messages hasMany' + ); + }); + }); + }); +}); + +test('Pushing to the hasMany side keeps the oneToMany invariant - sync', function(assert) { + var user, user2, account; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '1', + type: 'account', + }, + ], + }, + }, + }, + }); + user2 = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + account = store.push({ + data: { + id: '1', + type: 'account', + attributes: { + state: 'great', + }, + }, + }); + user2.get('accounts').pushObject(account); + }); + assert.equal(account.get('user'), user2, 'user got set correctly'); + assert.equal(user.get('accounts.length'), 0, 'the account got removed correctly'); + assert.equal(user2.get('accounts.length'), 1, 'the account got pushed correctly'); +}); + +test('Setting the belongsTo side keeps the oneToMany invariant on the hasMany- async', function(assert) { + assert.expect(2); + var user, user2, message; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + ], + }, + }, + }, + }); + user2 = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: 'Tomhuda', + }, + }, + }); + message = store.push({ + data: { + id: '1', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + message.set('user', user2); + }); + + run(function() { + user.get('messages').then(function(fetchedMessages) { + assert.equal( + get(fetchedMessages, 'length'), + 0, + 'message got removed from the first user correctly' + ); + }); + }); + run(function() { + user2.get('messages').then(function(fetchedMessages) { + assert.equal( + get(fetchedMessages, 'length'), + 1, + 'message got added to the second user correctly' + ); + }); + }); +}); + +test('Setting the belongsTo side keeps the oneToMany invariant on the hasMany- sync', function(assert) { + var user, user2, account; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '1', + type: 'account', + }, + ], + }, + }, + }, + }); + user2 = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + account = store.push({ + data: { + id: '1', + type: 'account', + attributes: { + state: 'great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + account.set('user', user2); + }); + assert.equal(account.get('user'), user2, 'user got set correctly'); + assert.equal(user.get('accounts.length'), 0, 'the account got removed correctly'); + assert.equal(user2.get('accounts.length'), 1, 'the account got pushed correctly'); +}); + +test('Setting the belongsTo side to null removes the record from the hasMany side - async', function(assert) { + assert.expect(2); + var user, message; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '1', + type: 'message', + }, + ], + }, + }, + }, + }); + message = store.push({ + data: { + id: '1', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + message.set('user', null); + }); + run(function() { + user.get('messages').then(function(fetchedMessages) { + assert.equal( + get(fetchedMessages, 'length'), + 0, + 'message got removed from the user correctly' + ); + }); + }); + + run(function() { + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'user got set to null correctly'); + }); + }); +}); + +test('Setting the belongsTo side to null removes the record from the hasMany side - sync', function(assert) { + var user, account; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '1', + type: 'account', + }, + ], + }, + }, + }, + }); + account = store.push({ + data: { + id: '1', + type: 'account', + attributes: { + state: 'great', + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', + }, + }, + }, + }, + }); + account.set('user', null); + }); + + assert.equal(account.get('user'), null, 'user got set to null correctly'); + + assert.equal(user.get('accounts.length'), 0, 'the account got removed correctly'); +}); + +/* +Rollback attributes from deleted state +*/ + +test('Rollbacking attributes of a deleted record works correctly when the hasMany side has been deleted - async', function(assert) { + var user, message; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '2', + type: 'message', + }, + ], + }, + }, + }, + }); + message = store.push({ + data: { + id: '2', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + run(function() { + message.deleteRecord(); + message.rollbackAttributes(); + }); + run(function() { + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'Message still has the user'); + }); + user.get('messages').then(function(fetchedMessages) { + assert.equal(fetchedMessages.objectAt(0), message, 'User has the message'); + }); + }); +}); + +test('Rollbacking attributes of a deleted record works correctly when the hasMany side has been deleted - sync', function(assert) { + var account, user; + run(function() { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + }); + run(function() { + account.deleteRecord(); + account.rollbackAttributes(); + assert.equal(user.get('accounts.length'), 1, 'Accounts are rolled back'); + assert.equal(account.get('user'), user, 'Account still has the user'); + }); +}); + +test('Rollbacking attributes of deleted record works correctly when the belongsTo side has been deleted - async', function(assert) { + var user, message; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [ + { + id: '2', + type: 'message', + }, + ], + }, + }, + }, + }); + message = store.push({ + data: { + id: '2', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + }); + run(function() { + user.deleteRecord(); + user.rollbackAttributes(); + }); + run(function() { + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'Message has the user again'); + }); + user.get('messages').then(function(fetchedMessages) { + assert.equal(fetchedMessages.get('length'), 1, 'User still has the messages'); + }); + }); +}); + +test('Rollbacking attributes of a deleted record works correctly when the belongsTo side has been deleted - sync', function(assert) { + var account, user; + run(function() { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + accounts: { + data: [ + { + id: '2', + type: 'account', + }, + ], + }, + }, + }, + }); + }); + run(function() { + user.deleteRecord(); + user.rollbackAttributes(); + assert.equal(user.get('accounts.length'), 1, 'User still has the accounts'); + assert.equal(account.get('user'), user, 'Account has the user again'); + }); +}); + +/* +Rollback attributes from created state +*/ + +test('Rollbacking attributes of a created record works correctly when the hasMany side has been created - async', function(assert) { + var user, message; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + message = store.createRecord('message', { + user: user, + }); + }); + run(message, 'rollbackAttributes'); + run(function() { + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'Message does not have the user anymore'); + }); + user.get('messages').then(function(fetchedMessages) { + assert.equal(fetchedMessages.get('length'), 0, 'User does not have the message anymore'); + assert.equal(fetchedMessages.get('firstObject'), null, "User message can't be accessed"); + }); + }); +}); + +test('Rollbacking attributes of a created record works correctly when the hasMany side has been created - sync', function(assert) { + var user, account; + run(function() { + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + account = store.createRecord('account', { + user: user, + }); + }); + run(account, 'rollbackAttributes'); + assert.equal(user.get('accounts.length'), 0, 'Accounts are rolled back'); + assert.equal(account.get('user'), null, 'Account does not have the user anymore'); +}); + +test('Rollbacking attributes of a created record works correctly when the belongsTo side has been created - async', function(assert) { + var message, user; + run(function() { + message = store.push({ + data: { + id: '2', + type: 'message', + attributes: { + title: 'EmberFest was great', + }, + }, + }); + user = store.createRecord('user'); + }); + run(function() { + user.get('messages').then(function(messages) { + messages.pushObject(message); + user.rollbackAttributes(); + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'Message does not have the user anymore'); + }); + user.get('messages').then(function(fetchedMessages) { + assert.equal(fetchedMessages.get('length'), 0, 'User does not have the message anymore'); + assert.equal(fetchedMessages.get('firstObject'), null, "User message can't be accessed"); + }); + }); + }); +}); + +test('Rollbacking attributes of a created record works correctly when the belongsTo side has been created - sync', function(assert) { + var account, user; + run(function() { + account = store.push({ + data: { + id: '2', + type: 'account', + attributes: { + state: 'lonely', + }, + }, + }); + user = store.createRecord('user'); + }); + run(function() { + user.get('accounts').pushObject(account); + }); + run(user, 'rollbackAttributes'); + assert.equal(user.get('accounts.length'), 0, 'User does not have the account anymore'); + assert.equal(account.get('user'), null, 'Account does not have the user anymore'); +}); + +test('createRecord updates inverse record array which has observers', function(assert) { + env.adapter.findAll = () => { + return { + data: [ + { + id: '2', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + ], + }; + }; + + return store.findAll('user').then(users => { + assert.equal(users.get('length'), 1, 'Exactly 1 user'); + + let user = users.get('firstObject'); + assert.equal(user.get('messages.length'), 0, 'Record array is initially empty'); + + // set up an observer + user.addObserver('messages.@each.title', () => {}); + user.get('messages.firstObject'); + + let message = store.createRecord('message', { user, title: 'EmberFest was great' }); + assert.equal(user.get('messages.length'), 1, 'The message is added to the record array'); + + let messageFromArray = user.get('messages.firstObject'); + assert.ok(message === messageFromArray, 'Only one message record instance should be created'); + }); +}); diff --git a/tests/integration/relationships/one-to-one-test.js b/tests/integration/relationships/one-to-one-test.js new file mode 100644 index 00000000000..e5eaa0bda6f --- /dev/null +++ b/tests/integration/relationships/one-to-one-test.js @@ -0,0 +1,1028 @@ +import { resolve, Promise as EmberPromise } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var env, store, User, Job; + +var attr = DS.attr; +var belongsTo = DS.belongsTo; + +module('integration/relationships/one_to_one_test - OneToOne relationships', { + beforeEach() { + User = DS.Model.extend({ + name: attr('string'), + bestFriend: belongsTo('user', { async: true, inverse: 'bestFriend' }), + job: belongsTo('job', { async: false }), + }); + + Job = DS.Model.extend({ + name: attr(), + isGood: attr(), + user: belongsTo('user', { async: false }), + }); + + env = setupStore({ + user: User, + job: Job, + adapter: DS.Adapter.extend({ + deleteRecord: () => resolve(), + }), + }); + + store = env.store; + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +/* + Server loading tests +*/ + +test('Relationship is available from both sides even if only loaded from one side - async', function(assert) { + var stanley, stanleysFriend; + run(function() { + stanley = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: 2, + type: 'user', + }, + }, + }, + }, + }); + stanleysFriend = store.push({ + data: { + id: 2, + type: 'user', + attributes: { + name: "Stanley's friend", + }, + }, + }); + + stanleysFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, stanley, 'User relationship was set up correctly'); + }); + }); +}); + +test('Relationship is available from both sides even if only loaded from one side - sync', function(assert) { + var job, user; + run(function() { + job = store.push({ + data: { + id: 2, + type: 'job', + attributes: { + isGood: true, + }, + }, + }); + user = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: 2, + type: 'job', + }, + }, + }, + }, + }); + }); + assert.equal(job.get('user'), user, 'User relationship was set up correctly'); +}); + +test('Fetching a belongsTo that is set to null removes the record from a relationship - async', function(assert) { + var stanleysFriend; + run(function() { + stanleysFriend = store.push({ + data: { + id: 2, + type: 'user', + attributes: { + name: "Stanley's friend", + }, + relationships: { + bestFriend: { + data: { + id: 1, + type: 'user', + }, + }, + }, + }, + }); + store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: null, + }, + }, + }, + }); + stanleysFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'User relationship was removed correctly'); + }); + }); +}); + +test('Fetching a belongsTo that is set to null removes the record from a relationship - sync', function(assert) { + var job; + run(function() { + job = store.push({ + data: { + id: 2, + type: 'job', + attributes: { + isGood: true, + }, + }, + }); + store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: 2, + type: 'job', + }, + }, + }, + }, + }); + }); + run(function() { + job = store.push({ + data: { + id: 2, + type: 'job', + attributes: { + isGood: true, + }, + relationships: { + user: { + data: null, + }, + }, + }, + }); + }); + assert.equal(job.get('user'), null, 'User relationship was removed correctly'); +}); + +test('Fetching a belongsTo that is set to a different record, sets the old relationship to null - async', async function(assert) { + let user1 = store.push({ + data: { + type: 'user', + id: '1', + attributes: { name: 'Chris' }, + relationships: { + bestFriend: { + data: { type: 'user', id: '2' }, + }, + }, + }, + included: [ + { + type: 'user', + id: '2', + attributes: { name: 'Igor' }, + relationships: { + bestFriend: { + data: { type: 'user', id: '1' }, + }, + }, + }, + ], + }); + + let user2 = store.peekRecord('user', '2'); + let user1Friend = await user1.get('bestFriend'); + + assert.equal(user1Friend, user2, '.bestFriend is '); + + /* + Now we "reload" but with a new bestFriend. While this only gives + us new canonical information for and , it also severs + the previous canonical relationship with . We infer from this + that the new canonical state for .bestFriend is `null`. + + Users for whom this is not true should either + + - include information for user:1 in the payload severing this link + - manually reload user:1 or use the belongsToReference to reload user:1.bestFriend + */ + store.push({ + data: { + type: 'user', + id: '2', + attributes: { name: 'Igor' }, + relationships: { + bestFriend: { + data: { type: 'user', id: '3' }, + }, + }, + }, + included: [ + { + type: 'user', + id: '3', + attributes: { name: 'Evan' }, + relationships: { + bestFriend: { + data: { type: 'user', id: '2' }, + }, + }, + }, + ], + }); + + let user3 = store.peekRecord('user', '3'); + let user1bestFriend = await user1.get('bestFriend'); + let user2bestFriend = await user2.get('bestFriend'); + let user3bestFriend = await user3.get('bestFriend'); + + assert.equal(user3bestFriend, user2, '.bestFriend is '); + assert.equal(user2bestFriend, user3, '.bestFriend is '); + assert.equal(user1bestFriend, null, '.bestFriend is null'); + + let user1bestFriendState = user1.belongsTo('bestFriend').belongsToRelationship; + + assert.equal(user1bestFriendState.canonicalState, null, '.job is canonically empty'); + assert.equal(user1bestFriendState.currentState, null, '.job is locally empty'); + assert.equal(user1bestFriendState.relationshipIsEmpty, true, 'The relationship is empty'); + assert.equal(user1bestFriendState.relationshipIsStale, false, 'The relationship is not stale'); + assert.equal( + user1bestFriendState.shouldForceReload, + false, + 'The relationship does not require reload' + ); + assert.equal( + user1bestFriendState.hasAnyRelationshipData, + true, + 'The relationship considers its canonical data complete' + ); + assert.equal( + user1bestFriendState.allInverseRecordsAreLoaded, + true, + 'The relationship has all required data' + ); +}); + +test('Fetching a belongsTo that is set to a different record, sets the old relationship to null - sync', async function(assert) { + let user1 = store.push({ + data: { + type: 'user', + id: '1', + attributes: { name: 'Chris' }, + relationships: { + job: { + data: { type: 'job', id: '1' }, + }, + }, + }, + included: [ + { + type: 'job', + id: '1', + attributes: { name: 'Golf Picker Mechanic' }, + relationships: { + user: { + data: { type: 'user', id: '1' }, + }, + }, + }, + ], + }); + + let job1 = store.peekRecord('job', '1'); + + assert.equal(user1.get('job'), job1, '.job is '); + + /* + Now we "reload" but with a new user. While this only gives + us new canonical information for and , it also severs + the previous canonical relationship with . We infer from this + that the new canonical state for .job is `null`. + + Users for whom this is not true should either + + - include information for user:1 in the payload severing this link + - manually reload user:1 or use the belongsToReference to reload user:1.job + */ + store.push({ + data: { + type: 'job', + id: '1', + attributes: { name: 'Golf Picker Mechanic' }, + relationships: { + user: { + data: { type: 'user', id: '2' }, + }, + }, + }, + included: [ + { + type: 'user', + id: '2', + attributes: { name: 'Evan' }, + relationships: { + job: { + data: { type: 'job', id: '1' }, + }, + }, + }, + ], + }); + + let user2 = store.peekRecord('user', '2'); + + assert.equal(user2.get('job'), job1, '.job is '); + assert.equal(job1.get('user'), user2, '.user is '); + assert.equal(user1.get('job'), null, '.job is null'); + + let user1JobState = user1.belongsTo('job').belongsToRelationship; + + assert.equal(user1JobState.canonicalState, null, '.job is canonically empty'); + assert.equal(user1JobState.currentState, null, '.job is locally empty'); + assert.equal(user1JobState.relationshipIsEmpty, true, 'The relationship is empty'); + assert.equal(user1JobState.relationshipIsStale, false, 'The relationship is not stale'); + assert.equal(user1JobState.shouldForceReload, false, 'The relationship does not require reload'); + assert.equal( + user1JobState.hasAnyRelationshipData, + true, + 'The relationship considers its canonical data complete' + ); + assert.equal( + user1JobState.allInverseRecordsAreLoaded, + true, + 'The relationship has all required data' + ); +}); + +/* + Local edits +*/ + +test('Setting a OneToOne relationship reflects correctly on the other side- async', function(assert) { + var stanley, stanleysFriend; + run(function() { + stanley = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + stanleysFriend = store.push({ + data: { + id: 2, + type: 'user', + attributes: { + name: "Stanley's friend", + }, + }, + }); + }); + run(function() { + stanley.set('bestFriend', stanleysFriend); + stanleysFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, stanley, 'User relationship was updated correctly'); + }); + }); +}); + +test('Setting a OneToOne relationship reflects correctly on the other side- sync', function(assert) { + var job, user; + run(function() { + job = store.push({ + data: { + id: 2, + type: 'job', + attributes: { + isGood: true, + }, + }, + }); + user = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + }); + run(function() { + user.set('job', job); + }); + assert.equal(job.get('user'), user, 'User relationship was set up correctly'); +}); + +test('Setting a BelongsTo to a promise unwraps the promise before setting- async', function(assert) { + var stanley, stanleysFriend, newFriend; + run(function() { + stanley = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: 2, + type: 'user', + }, + }, + }, + }, + }); + stanleysFriend = store.push({ + data: { + id: 2, + type: 'user', + attributes: { + name: "Stanley's friend", + }, + }, + }); + newFriend = store.push({ + data: { + id: 3, + type: 'user', + attributes: { + name: 'New friend', + }, + }, + }); + }); + run(function() { + newFriend.set('bestFriend', stanleysFriend.get('bestFriend')); + stanley.get('bestFriend').then(function(fetchedUser) { + assert.equal( + fetchedUser, + newFriend, + `Stanley's bestFriend relationship was updated correctly to newFriend` + ); + }); + newFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal( + fetchedUser, + stanley, + `newFriend's bestFriend relationship was updated correctly to be Stanley` + ); + }); + }); +}); + +test('Setting a BelongsTo to a promise works when the promise returns null- async', function(assert) { + var igor, newFriend; + run(function() { + store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + igor = store.push({ + data: { + id: 2, + type: 'user', + attributes: { + name: 'Igor', + }, + }, + }); + newFriend = store.push({ + data: { + id: 3, + type: 'user', + attributes: { + name: 'New friend', + }, + relationships: { + bestFriend: { + data: { + id: 1, + type: 'user', + }, + }, + }, + }, + }); + }); + run(function() { + newFriend.set('bestFriend', igor.get('bestFriend')); + newFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'User relationship was updated correctly'); + }); + }); +}); + +testInDebug( + "Setting a BelongsTo to a promise that didn't come from a relationship errors out", + function(assert) { + var stanley, igor; + run(function() { + stanley = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: 2, + type: 'user', + }, + }, + }, + }, + }); + igor = store.push({ + data: { + id: 3, + type: 'user', + attributes: { + name: 'Igor', + }, + }, + }); + }); + + assert.expectAssertion(function() { + run(function() { + stanley.set('bestFriend', resolve(igor)); + }); + }, /You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo or hasMany relationship to the get call./); + } +); + +test('Setting a BelongsTo to a promise multiple times is resistant to race conditions- async', function(assert) { + assert.expect(1); + var stanley, igor, newFriend; + run(function() { + stanley = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: 2, + type: 'user', + }, + }, + }, + }, + }); + igor = store.push({ + data: { + id: 3, + type: 'user', + attributes: { + name: 'Igor', + }, + relationships: { + bestFriend: { + data: { + id: 5, + type: 'user', + }, + }, + }, + }, + }); + newFriend = store.push({ + data: { + id: 7, + type: 'user', + attributes: { + name: 'New friend', + }, + }, + }); + }); + + env.adapter.findRecord = function(store, type, id, snapshot) { + if (id === '5') { + return resolve({ data: { id: 5, type: 'user', attributes: { name: "Igor's friend" } } }); + } else if (id === '2') { + let done = assert.async(); + return new EmberPromise(function(resolve, reject) { + setTimeout(function() { + done(); + resolve({ data: { id: 2, type: 'user', attributes: { name: "Stanley's friend" } } }); + }, 1); + }); + } + }; + + run(function() { + newFriend.set('bestFriend', stanley.get('bestFriend')); + newFriend.set('bestFriend', igor.get('bestFriend')); + newFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal( + fetchedUser.get('name'), + "Igor's friend", + 'User relationship was updated correctly' + ); + }); + }); +}); + +test('Setting a OneToOne relationship to null reflects correctly on the other side - async', function(assert) { + var stanley, stanleysFriend; + run(function() { + stanley = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: 2, + type: 'user', + }, + }, + }, + }, + }); + stanleysFriend = store.push({ + data: { + id: 2, + type: 'user', + attributes: { + name: "Stanley's friend", + }, + relationships: { + bestFriend: { + data: { + id: 1, + type: 'user', + }, + }, + }, + }, + }); + }); + + run(function() { + stanley.set('bestFriend', null); // :( + stanleysFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'User relationship was removed correctly'); + }); + }); +}); + +test('Setting a OneToOne relationship to null reflects correctly on the other side - sync', function(assert) { + var job, user; + run(function() { + job = store.push({ + data: { + id: 2, + type: 'job', + attributes: { + isGood: false, + }, + relationships: { + user: { + data: { + id: 1, + type: 'user', + }, + }, + }, + }, + }); + user = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: 2, + type: 'job', + }, + }, + }, + }, + }); + }); + + run(function() { + user.set('job', null); + }); + assert.equal(job.get('user'), null, 'User relationship was removed correctly'); +}); + +test('Setting a belongsTo to a different record, sets the old relationship to null - async', function(assert) { + assert.expect(3); + + var stanley, stanleysFriend; + run(function() { + stanley = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: 2, + type: 'user', + }, + }, + }, + }, + }); + stanleysFriend = store.push({ + data: { + id: 2, + type: 'user', + attributes: { + name: "Stanley's friend", + }, + relationships: { + bestFriend: { + data: { + id: 1, + type: 'user', + }, + }, + }, + }, + }); + + stanleysFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, stanley, 'User relationship was initally setup correctly'); + var stanleysNewFriend = store.push({ + data: { + id: 3, + type: 'user', + attributes: { + name: "Stanley's New friend", + }, + }, + }); + + run(function() { + stanleysNewFriend.set('bestFriend', stanley); + }); + + stanley.get('bestFriend').then(function(fetchedNewFriend) { + assert.equal( + fetchedNewFriend, + stanleysNewFriend, + 'User relationship was updated correctly' + ); + }); + + stanleysFriend.get('bestFriend').then(function(fetchedOldFriend) { + assert.equal(fetchedOldFriend, null, 'The old relationship was set to null correctly'); + }); + }); + }); +}); + +test('Setting a belongsTo to a different record, sets the old relationship to null - sync', function(assert) { + var job, user, newBetterJob; + run(function() { + job = store.push({ + data: { + id: 2, + type: 'job', + attributes: { + isGood: false, + }, + }, + }); + user = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: 2, + type: 'job', + }, + }, + }, + }, + }); + }); + + assert.equal(job.get('user'), user, 'Job and user initially setup correctly'); + + run(function() { + newBetterJob = store.push({ + data: { + id: 3, + type: 'job', + attributes: { + isGood: true, + }, + }, + }); + + newBetterJob.set('user', user); + }); + + assert.equal(user.get('job'), newBetterJob, 'Job updated correctly'); + assert.equal(job.get('user'), null, 'Old relationship nulled out correctly'); + assert.equal(newBetterJob.get('user'), user, 'New job setup correctly'); +}); + +/* +Rollback attributes tests +*/ + +test('Rollbacking attributes of deleted record restores the relationship on both sides - async', function(assert) { + var stanley, stanleysFriend; + run(function() { + stanley = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: 2, + type: 'user', + }, + }, + }, + }, + }); + stanleysFriend = store.push({ + data: { + id: 2, + type: 'user', + attributes: { + name: "Stanley's friend", + }, + }, + }); + }); + run(function() { + stanley.deleteRecord(); + }); + run(function() { + stanley.rollbackAttributes(); + stanleysFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, stanley, 'Stanley got rollbacked correctly'); + }); + stanley.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, stanleysFriend, 'Stanleys friend did not get removed'); + }); + }); +}); + +test('Rollbacking attributes of deleted record restores the relationship on both sides - sync', function(assert) { + var job, user; + run(function() { + job = store.push({ + data: { + id: 2, + type: 'job', + attributes: { + isGood: true, + }, + }, + }); + user = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: 2, + type: 'job', + }, + }, + }, + }, + }); + }); + run(function() { + job.deleteRecord(); + job.rollbackAttributes(); + }); + assert.equal(user.get('job'), job, 'Job got rollbacked correctly'); + assert.equal(job.get('user'), user, 'Job still has the user'); +}); + +test('Rollbacking attributes of created record removes the relationship on both sides - async', function(assert) { + var stanleysFriend, stanley; + run(function() { + stanleysFriend = store.push({ + data: { + id: 2, + type: 'user', + attributes: { + name: "Stanley's friend", + }, + }, + }); + + stanley = store.createRecord('user', { bestFriend: stanleysFriend }); + }); + run(function() { + stanley.rollbackAttributes(); + stanleysFriend.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'Stanley got rollbacked correctly'); + }); + stanley.get('bestFriend').then(function(fetchedUser) { + assert.equal(fetchedUser, null, 'Stanleys friend did got removed'); + }); + }); +}); + +test('Rollbacking attributes of created record removes the relationship on both sides - sync', function(assert) { + var user, job; + run(function() { + user = store.push({ + data: { + id: 1, + type: 'user', + attributes: { + name: 'Stanley', + }, + }, + }); + + job = store.createRecord('job', { user: user }); + }); + run(function() { + job.rollbackAttributes(); + }); + assert.equal(user.get('job'), null, 'Job got rollbacked correctly'); + assert.equal(job.get('user'), null, 'Job does not have user anymore'); +}); diff --git a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js new file mode 100644 index 00000000000..0faa938713c --- /dev/null +++ b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js @@ -0,0 +1,241 @@ +import Mixin from '@ember/object/mixin'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var env, store, User, Message, Video, NotMessage; + +var attr = DS.attr; +var belongsTo = DS.belongsTo; + +module( + 'integration/relationships/polymorphic_mixins_belongs_to_test - Polymorphic belongsTo relationships with mixins', + { + beforeEach() { + User = DS.Model.extend({ + name: attr('string'), + bestMessage: belongsTo('message', { async: true, polymorphic: true }), + }); + + Message = Mixin.create({ + title: attr('string'), + user: belongsTo('user', { async: true }), + }); + + NotMessage = DS.Model.extend({ + video: attr(), + }); + + Video = DS.Model.extend(Message, { + video: attr(), + }); + + env = setupStore({ + user: User, + video: Video, + notMessage: NotMessage, + }); + + env.owner.register('mixin:message', Message); + store = env.store; + }, + + afterEach() { + run(env.container, 'destroy'); + }, + } +); + +/* + Server loading tests +*/ + +test('Relationship is available from the belongsTo side even if only loaded from the inverse side - async', function(assert) { + var user, video; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + relationships: { + bestMessage: { + data: { type: 'video', id: '2' }, + }, + }, + }, + { + type: 'video', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + video = store.peekRecord('video', 2); + }); + run(function() { + user.get('bestMessage').then(function(message) { + assert.equal(message, video, 'The message was loaded correctly'); + message.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'The inverse was setup correctly'); + }); + }); + }); +}); + +/* + Local edits +*/ +test('Setting the polymorphic belongsTo gets propagated to the inverse side - async', function(assert) { + var user, video; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + }, + { + type: 'video', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + video = store.peekRecord('video', 2); + }); + + run(function() { + user.set('bestMessage', video); + video.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'user got set correctly'); + }); + user.get('bestMessage').then(function(message) { + assert.equal(message, video, 'The message was set correctly'); + }); + }); +}); + +testInDebug( + 'Setting the polymorphic belongsTo with an object that does not implement the mixin errors out', + function(assert) { + var user, video; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + }, + { + type: 'not-message', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + video = store.peekRecord('not-message', 2); + }); + + run(function() { + assert.expectAssertion(function() { + user.set('bestMessage', video); + }, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'bestMessage' relationship in 'user'. Make it a descendant of 'message'/); + }); + } +); + +test('Setting the polymorphic belongsTo gets propagated to the inverse side - model injections true', function(assert) { + assert.expect(2); + + var user, video; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + }, + { + type: 'video', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + video = store.peekRecord('video', 2); + }); + + run(function() { + user.set('bestMessage', video); + video.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'user got set correctly'); + }); + user.get('bestMessage').then(function(message) { + assert.equal(message, video, 'The message was set correctly'); + }); + }); +}); + +testInDebug( + 'Setting the polymorphic belongsTo with an object that does not implement the mixin errors out - model injections true', + function(assert) { + var user, video; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + }, + { + type: 'not-message', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + video = store.peekRecord('not-message', 2); + }); + + run(function() { + assert.expectAssertion(function() { + user.set('bestMessage', video); + }, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'bestMessage' relationship in 'user'. Make it a descendant of 'message'/); + }); + } +); diff --git a/tests/integration/relationships/polymorphic-mixins-has-many-test.js b/tests/integration/relationships/polymorphic-mixins-has-many-test.js new file mode 100644 index 00000000000..fe6db675f45 --- /dev/null +++ b/tests/integration/relationships/polymorphic-mixins-has-many-test.js @@ -0,0 +1,271 @@ +import Mixin from '@ember/object/mixin'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var env, store, User, Message, NotMessage, Video; + +var attr = DS.attr; +var hasMany = DS.hasMany; +var belongsTo = DS.belongsTo; + +module( + 'integration/relationships/polymorphic_mixins_has_many_test - Polymorphic hasMany relationships with mixins', + { + beforeEach() { + User = DS.Model.extend({ + name: attr('string'), + messages: hasMany('message', { async: true, polymorphic: true }), + }); + + Message = Mixin.create({ + title: attr('string'), + user: belongsTo('user', { async: true }), + }); + + Video = DS.Model.extend(Message, { + video: attr(), + }); + + NotMessage = DS.Model.extend({ + video: attr(), + }); + + env = setupStore({ + user: User, + video: Video, + notMessage: NotMessage, + }); + + env.owner.register('mixin:message', Message); + store = env.store; + }, + + afterEach() { + run(env.container, 'destroy'); + }, + } +); + +/* + Server loading tests +*/ + +test('Relationship is available from the belongsTo side even if only loaded from the hasMany side - async', function(assert) { + var user, video; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [{ type: 'video', id: '2' }], + }, + }, + }, + { + type: 'video', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + video = store.peekRecord('video', 2); + }); + run(function() { + user.get('messages').then(function(messages) { + assert.equal(messages.objectAt(0), video, 'The hasMany has loaded correctly'); + messages + .objectAt(0) + .get('user') + .then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'The inverse was setup correctly'); + }); + }); + }); +}); + +/* + Local edits +*/ +test('Pushing to the hasMany reflects the change on the belongsTo side - async', function(assert) { + var user, video; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [], + }, + }, + }, + { + type: 'video', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + video = store.peekRecord('video', 2); + }); + + run(function() { + user.get('messages').then(function(fetchedMessages) { + fetchedMessages.pushObject(video); + video.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'user got set correctly'); + }); + }); + }); +}); + +/* + Local edits +*/ +testInDebug( + 'Pushing a an object that does not implement the mixin to the mixin accepting array errors out', + function(assert) { + var user, notMessage; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [], + }, + }, + }, + { + type: 'not-message', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + notMessage = store.peekRecord('not-message', 2); + }); + + run(function() { + user.get('messages').then(function(fetchedMessages) { + assert.expectAssertion(function() { + fetchedMessages.pushObject(notMessage); + }, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'messages' relationship in 'user'. Make it a descendant of 'message/); + }); + }); + } +); + +test('Pushing to the hasMany reflects the change on the belongsTo side - model injections true', function(assert) { + var user, video; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [], + }, + }, + }, + { + type: 'video', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + video = store.peekRecord('video', 2); + }); + + run(function() { + user.get('messages').then(function(fetchedMessages) { + fetchedMessages.pushObject(video); + video.get('user').then(function(fetchedUser) { + assert.equal(fetchedUser, user, 'user got set correctly'); + }); + }); + }); +}); + +/* + Local edits +*/ +testInDebug( + 'Pushing a an object that does not implement the mixin to the mixin accepting array errors out - model injections true', + function(assert) { + var user, notMessage; + run(function() { + store.push({ + data: [ + { + type: 'user', + id: '1', + attributes: { + name: 'Stanley', + }, + relationships: { + messages: { + data: [], + }, + }, + }, + { + type: 'not-message', + id: '2', + attributes: { + video: 'Here comes Youtube', + }, + }, + ], + }); + user = store.peekRecord('user', 1); + notMessage = store.peekRecord('not-message', 2); + }); + + run(function() { + user.get('messages').then(function(fetchedMessages) { + assert.expectAssertion(function() { + fetchedMessages.pushObject(notMessage); + }, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'messages' relationship in 'user'. Make it a descendant of 'message'/); + }); + }); + } +); diff --git a/tests/integration/serializers/embedded-records-mixin-test.js b/tests/integration/serializers/embedded-records-mixin-test.js new file mode 100644 index 00000000000..d452d114d17 --- /dev/null +++ b/tests/integration/serializers/embedded-records-mixin-test.js @@ -0,0 +1,2878 @@ +import { setupTest } from 'ember-qunit'; +import { module, test } from 'qunit'; +import testInDebug from '../../helpers/test-in-debug'; + +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +import { belongsTo, hasMany } from 'ember-data/relationships'; + +import RESTAdapter from 'ember-data/adapters/rest'; +import RESTSerializer from 'ember-data/serializers/rest'; +import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin'; + +module('integration/embedded-records-mixin', function(hooks) { + setupTest(hooks); + let store; + + hooks.beforeEach(function() { + let { owner } = this; + + const SuperVillain = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: true }), + secretLab: belongsTo('secret-lab', { async: false }), + secretWeapons: hasMany('secret-weapon', { async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + const HomePlanet = Model.extend({ + name: attr('string'), + villains: hasMany('super-villain', { inverse: 'homePlanet', async: false }), + }); + const SecretLab = Model.extend({ + minionCapacity: attr('number'), + vicinity: attr('string'), + superVillain: belongsTo('super-villain', { async: false }), + }); + const BatCave = SecretLab.extend({ + infiltrated: attr('boolean'), + }); + const SecretWeapon = Model.extend({ + name: attr('string'), + superVillain: belongsTo('super-villain', { async: false }), + }); + const LightSaber = SecretWeapon.extend({ + color: attr('string'), + }); + const EvilMinion = Model.extend({ + superVillain: belongsTo('super-villain', { async: false }), + name: attr('string'), + }); + const Comment = Model.extend({ + body: attr('string'), + root: attr('boolean'), + children: hasMany('comment', { inverse: null, async: false }), + }); + + owner.register('model:super-villain', SuperVillain); + owner.register('model:home-planet', HomePlanet); + owner.register('model:secret-lab', SecretLab); + owner.register('model:bat-cave', BatCave); + owner.register('model:secret-weapon', SecretWeapon); + owner.register('model:light-saber', LightSaber); + owner.register('model:evil-minion', EvilMinion); + owner.register('model:comment', Comment); + + owner.register('adapter:application', RESTAdapter); + owner.register('serializer:application', RESTSerializer.extend(EmbeddedRecordsMixin)); + + store = owner.lookup('service:store'); + }); + + module('Normalize using findRecord', function() { + test('normalizeResponse with embedded objects', async function(assert) { + this.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + }, + }) + ); + const serializer = store.serializerFor('home-planet'); + const HomePlanet = store.modelFor('home-planet'); + const rawPayload = { + homePlanet: { + id: '1', + name: 'Umber', + villains: [ + { + id: '2', + firstName: 'Tom', + lastName: 'Dale', + }, + ], + }, + }; + + const normalizedJsonApi = serializer.normalizeResponse( + store, + HomePlanet, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + id: '1', + type: 'home-planet', + attributes: { + name: 'Umber', + }, + relationships: { + villains: { + data: [{ id: '2', type: 'super-villain' }], + }, + }, + }, + included: [ + { + id: '2', + type: 'super-villain', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'We normalized to json-api and extracted the super-villain' + ); + }); + + test('normalizeResponse with embedded objects inside embedded objects', async function(assert) { + this.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + }, + }) + ); + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + evilMinions: { embedded: 'always' }, + }, + }) + ); + + const serializer = store.serializerFor('home-planet'); + const HomePlanet = store.modelFor('home-planet'); + const rawPayload = { + homePlanet: { + id: '1', + name: 'Umber', + villains: [ + { + id: '2', + firstName: 'Tom', + lastName: 'Dale', + evilMinions: [ + { + id: '3', + name: 'Alex', + }, + ], + }, + ], + }, + }; + + const normalizedJsonApi = serializer.normalizeResponse( + store, + HomePlanet, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + id: '1', + type: 'home-planet', + attributes: { + name: 'Umber', + }, + relationships: { + villains: { + data: [{ id: '2', type: 'super-villain' }], + }, + }, + }, + included: [ + { + id: '2', + type: 'super-villain', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + relationships: { + evilMinions: { + data: [{ id: '3', type: 'evil-minion' }], + }, + }, + }, + { + id: '3', + type: 'evil-minion', + attributes: { + name: 'Alex', + }, + relationships: {}, + }, + ], + }; + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'We normalized to json-api and extracted embedded records two levels deep' + ); + }); + + test('normalizeResponse with embedded objects of same type', async function(assert) { + this.owner.register( + 'serializer:comment', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + children: { embedded: 'always' }, + }, + }) + ); + + const serializer = store.serializerFor('comment'); + const Comment = store.modelFor('comment'); + const rawPayload = { + comment: { + id: '1', + body: 'Hello', + root: true, + children: [ + { + id: '2', + body: 'World', + root: false, + }, + { + id: '3', + body: 'Foo', + root: false, + }, + ], + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + Comment, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + id: '1', + type: 'comment', + attributes: { + body: 'Hello', + root: true, + }, + relationships: { + children: { + data: [{ id: '2', type: 'comment' }, { id: '3', type: 'comment' }], + }, + }, + }, + included: [ + { + id: '2', + type: 'comment', + attributes: { + body: 'World', + root: false, + }, + relationships: {}, + }, + { + id: '3', + type: 'comment', + attributes: { + body: 'Foo', + root: false, + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'We normalized to json-api keeping the primary record in data and the related record of the same type in included' + ); + }); + + test('normalizeResponse with embedded objects inside embedded objects of same type', async function(assert) { + this.owner.register( + 'serializer:comment', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + children: { embedded: 'always' }, + }, + }) + ); + + const serializer = store.serializerFor('comment'); + const Comment = store.modelFor('comment'); + const rawPayload = { + comment: { + id: '1', + body: 'Hello', + root: true, + children: [ + { + id: '2', + body: 'World', + root: false, + children: [ + { + id: '4', + body: 'Another', + root: false, + }, + ], + }, + { + id: '3', + body: 'Foo', + root: false, + }, + ], + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + Comment, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + id: '1', + type: 'comment', + attributes: { + body: 'Hello', + root: true, + }, + relationships: { + children: { + data: [{ id: '2', type: 'comment' }, { id: '3', type: 'comment' }], + }, + }, + }, + included: [ + { + id: '2', + type: 'comment', + attributes: { + body: 'World', + root: false, + }, + relationships: { + children: { + data: [{ id: '4', type: 'comment' }], + }, + }, + }, + { + id: '4', + type: 'comment', + attributes: { + body: 'Another', + root: false, + }, + relationships: {}, + }, + { + id: '3', + type: 'comment', + attributes: { + body: 'Foo', + root: false, + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'We normalized to json-api keeping the primary record in data and the related record of the same type in included multiple levels deep' + ); + }); + + test('normalizeResponse with embedded objects of same type, but from separate attributes', async function(assert) { + let { owner } = this; + const HomePlanetKlass = Model.extend({ + name: attr('string'), + villains: hasMany('super-villain', { inverse: 'homePlanet', async: false }), + reformedVillains: hasMany('superVillain', { inverse: null, async: false }), + }); + owner.unregister('model:home-planet'); + owner.register('model:home-planet', HomePlanetKlass); + owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + reformedVillains: { embedded: 'always' }, + }, + }) + ); + + const serializer = store.serializerFor('home-planet'); + const HomePlanet = store.modelFor('home-planet'); + const rawPayload = { + homePlanet: { + id: '1', + name: 'Earth', + villains: [ + { + id: '1', + firstName: 'Tom', + }, + { + id: '3', + firstName: 'Yehuda', + }, + ], + reformedVillains: [ + { + id: '2', + firstName: 'Alex', + }, + { + id: '4', + firstName: 'Erik', + }, + ], + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + HomePlanet, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + id: '1', + type: 'home-planet', + attributes: { + name: 'Earth', + }, + relationships: { + villains: { + data: [{ id: '1', type: 'super-villain' }, { id: '3', type: 'super-villain' }], + }, + reformedVillains: { + data: [{ id: '2', type: 'super-villain' }, { id: '4', type: 'super-villain' }], + }, + }, + }, + included: [ + { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + }, + relationships: {}, + }, + { + id: '3', + type: 'super-villain', + attributes: { + firstName: 'Yehuda', + }, + relationships: {}, + }, + { + id: '2', + type: 'super-villain', + attributes: { + firstName: 'Alex', + }, + relationships: {}, + }, + { + id: '4', + type: 'super-villain', + attributes: { + firstName: 'Erik', + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'Extracting embedded works with multiple inverses of the same type' + ); + }); + + test('normalizeResponse with multiply-nested belongsTo', async function(assert) { + let { owner } = this; + owner.register( + 'serializer:evil-minion', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + superVillain: { embedded: 'always' }, + }, + }) + ); + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + homePlanet: { embedded: 'always' }, + }, + }) + ); + + const serializer = store.serializerFor('evil-minion'); + const EvilMinion = store.modelFor('evil-minion'); + const rawPayload = { + evilMinion: { + id: '1', + name: 'Alex', + superVillain: { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + evilMinions: ['1'], + homePlanet: { + id: '1', + name: 'Umber', + villains: ['1'], + }, + }, + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + EvilMinion, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + id: '1', + type: 'evil-minion', + attributes: { + name: 'Alex', + }, + relationships: { + superVillain: { + data: { id: '1', type: 'super-villain' }, + }, + }, + }, + included: [ + { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + relationships: { + evilMinions: { + data: [{ id: '1', type: 'evil-minion' }], + }, + homePlanet: { + data: { id: '1', type: 'home-planet' }, + }, + }, + }, + { + id: '1', + type: 'home-planet', + attributes: { + name: 'Umber', + }, + relationships: { + villains: { + data: [{ id: '1', type: 'super-villain' }], + }, + }, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'we normalized to json-api and extracted the multiply nested belongTos' + ); + }); + + test('normalizeResponse with polymorphic hasMany and custom primary key', async function(assert) { + let { owner } = this; + const SuperVillainClass = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: true }), + secretLab: belongsTo('secret-lab', { async: false }), + secretWeapons: hasMany('secretWeapon', { polymorphic: true, async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + + owner.register( + 'serializer:light-saber', + RESTSerializer.extend({ + primaryKey: 'custom', + }) + ); + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretWeapons: { embedded: 'always' }, + }, + }) + ); + owner.unregister('model:super-villain'); + owner.register('model:super-villain', SuperVillainClass); + + const serializer = store.serializerFor('super-villain'); + const SuperVillain = store.modelFor('super-villain'); + const rawPayload = { + super_villain: { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + secretWeapons: [ + { + custom: '1', + type: 'LightSaber', + name: "Tom's LightSaber", + color: 'Red', + }, + { + id: '1', + type: 'SecretWeapon', + name: 'The Death Star', + }, + ], + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + SuperVillain, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + id: '1', + relationships: { + secretWeapons: { + data: [{ type: 'light-saber', id: '1' }, { type: 'secret-weapon', id: '1' }], + }, + }, + type: 'super-villain', + }, + included: [ + { + attributes: { + color: 'Red', + name: "Tom's LightSaber", + }, + id: '1', + relationships: {}, + type: 'light-saber', + }, + { + attributes: { + name: 'The Death Star', + }, + id: '1', + relationships: {}, + type: 'secret-weapon', + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'we normalized to json-api and extracted the polymorphic hasMany with a custom key' + ); + }); + + test('normalizeResponse with polymorphic belongsTo', async function(assert) { + let { owner } = this; + const SuperVillainClass = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: true }), + secretLab: belongsTo('secretLab', { polymorphic: true, async: true }), + secretWeapons: hasMany('secret-weapon', { async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { embedded: 'always' }, + }, + }) + ); + owner.unregister('model:super-villain'); + owner.register('model:super-villain', SuperVillainClass); + + const serializer = store.serializerFor('super-villain'); + const SuperVillain = store.modelFor('super-villain'); + const rawPayload = { + super_villain: { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + secretLab: { + id: '1', + type: 'bat-cave', + infiltrated: true, + }, + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + SuperVillain, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + relationships: { + secretLab: { + data: { id: '1', type: 'bat-cave' }, + }, + }, + }, + included: [ + { + id: '1', + type: 'bat-cave', + attributes: { + infiltrated: true, + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'we normalize to json-api and extract the polymorphic belongsTo' + ); + }); + + test('normalizeResponse with polymorphic belongsTo and custom primary key', async function(assert) { + let { owner } = this; + const SuperVillainClass = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: true }), + secretLab: belongsTo('secretLab', { polymorphic: true, async: true }), + secretWeapons: hasMany('secret-weapon', { async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { embedded: 'always' }, + }, + }) + ); + owner.register( + 'serializer:bat-cave', + RESTSerializer.extend({ + primaryKey: 'custom', + }) + ); + owner.unregister('model:super-villain'); + owner.register('model:super-villain', SuperVillainClass); + + const serializer = store.serializerFor('super-villain'); + const SuperVillain = store.modelFor('super-villain'); + const rawPayload = { + superVillain: { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + secretLab: { + custom: '1', + type: 'bat-cave', + infiltrated: true, + }, + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + SuperVillain, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + id: '1', + relationships: { + secretLab: { + data: { + id: '1', + type: 'bat-cave', + }, + }, + }, + type: 'super-villain', + }, + included: [ + { + attributes: { + infiltrated: true, + }, + id: '1', + relationships: {}, + type: 'bat-cave', + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'we normalize to json-api and extract the polymorphic belongsTo with a custom key' + ); + }); + + test('normalize with custom belongsTo primary key', async function(assert) { + let { owner } = this; + owner.register( + 'serializer:evil-minion', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + superVillain: { embedded: 'always' }, + }, + }) + ); + owner.register( + 'serializer:super-villain', + RESTSerializer.extend({ + primaryKey: 'custom', + }) + ); + + const serializer = store.serializerFor('evil-minion'); + const EvilMinion = store.modelFor('evil-minion'); + const rawPayload = { + evilMinion: { + id: '1', + name: 'Alex', + superVillain: { + custom: '1', + firstName: 'Tom', + lastName: 'Dale', + }, + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + EvilMinion, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + id: '1', + type: 'evil-minion', + attributes: { + name: 'Alex', + }, + relationships: { + superVillain: { + data: { id: '1', type: 'super-villain' }, + }, + }, + }, + included: [ + { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'we normalize to json-api with custom belongsTo primary key' + ); + }); + }); + + module('Normalize using findAll', function() { + test('normalizeResponse with embedded objects', async function(assert) { + this.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + }, + }) + ); + + const serializer = store.serializerFor('home-planet'); + const HomePlanet = store.modelFor('home-planet'); + const rawPayload = { + homePlanets: [ + { + id: '1', + name: 'Umber', + villains: [ + { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + }, + ], + }, + ], + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + HomePlanet, + rawPayload, + null, + 'findAll' + ); + const expectedOutput = { + data: [ + { + id: '1', + type: 'home-planet', + attributes: { + name: 'Umber', + }, + relationships: { + villains: { + data: [{ id: '1', type: 'super-villain' }], + }, + }, + }, + ], + included: [ + { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + relationships: {}, + }, + ], + }; + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'extracts embedded records for all resources in the primary payload' + ); + }); + + test('normalizeResponse with embedded objects with custom primary key', async function(assert) { + let { owner } = this; + owner.register( + 'serializer:super-villain', + RESTSerializer.extend({ + primaryKey: 'villain_id', + }) + ); + owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + }, + }) + ); + const serializer = store.serializerFor('home-planet'); + const HomePlanet = store.modelFor('home-planet'); + const rawPayload = { + homePlanets: [ + { + id: '1', + name: 'Umber', + villains: [ + { + villain_id: '2', + firstName: 'Alex', + lastName: 'Baizeau', + }, + ], + }, + ], + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + HomePlanet, + rawPayload, + null, + 'findAll' + ); + const expectedOutput = { + data: [ + { + id: '1', + type: 'home-planet', + attributes: { + name: 'Umber', + }, + relationships: { + villains: { + data: [{ id: '2', type: 'super-villain' }], + }, + }, + }, + ], + included: [ + { + id: '2', + type: 'super-villain', + attributes: { + firstName: 'Alex', + lastName: 'Baizeau', + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual(normalizedJsonApi, expectedOutput, 'works with custom primaryKey'); + }); + + // TODO this is a super weird test, probably not a valid scenario to have any guarantees around + test('normalizeResponse with embedded objects with identical relationship and attribute key ', async function(assert) { + this.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + }, + //Makes the keyForRelationship and keyForAttribute collide. + keyForRelationship(key, type) { + if (key === 'villains') { + return 'ourVillains'; + } + return this._super(key, type); + }, + keyForAttribute(key, type) { + if (key === 'name') { + return 'ourVillains'; + } + return this._super(key, type); + }, + }) + ); + + const serializer = store.serializerFor('home-planet'); + const HomePlanet = store.modelFor('home-planet'); + const rawPayload = { + homePlanets: [ + { + id: '1', + name: 'Umber', + ourVillains: [ + { + id: '1', + firstName: 'Alex', + lastName: 'Baizeau', + }, + ], + }, + ], + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + HomePlanet, + rawPayload, + null, + 'findAll' + ); + const expectedOutput = { + data: [ + { + id: '1', + type: 'home-planet', + attributes: { + // nothing maps to the original "name" key + // instead we find the "ourVillains" object for attributes as well + // bc "name" is defined using the "string" transform, we cast it to + // a "string" + name: `${[ + { + id: '1', + firstName: 'Alex', + lastName: 'Baizeau', + }, + ]}`, + }, + // we find this key for the relationship too + relationships: { + villains: { + data: [{ id: '1', type: 'super-villain' }], + }, + }, + }, + ], + included: [ + { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Alex', + lastName: 'Baizeau', + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'when the key for a relationship and an attribute collide, ' + ); + }); + + test('normalizeResponse with embedded objects of same type as primary type', async function(assert) { + this.owner.register( + 'serializer:comment', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + children: { embedded: 'always' }, + }, + }) + ); + const serializer = store.serializerFor('comment'); + const Comment = store.modelFor('comment'); + const rawPayload = { + comments: [ + { + id: '1', + body: 'Hello', + root: true, + children: [ + { + id: '2', + body: 'World', + root: false, + }, + { + id: '3', + body: 'Foo', + root: false, + }, + ], + }, + ], + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + Comment, + rawPayload, + null, + 'findAll' + ); + const expectedOutput = { + data: [ + { + id: '1', + type: 'comment', + attributes: { + body: 'Hello', + root: true, + }, + relationships: { + children: { + data: [{ id: '2', type: 'comment' }, { id: '3', type: 'comment' }], + }, + }, + }, + ], + included: [ + { + id: '2', + type: 'comment', + attributes: { + body: 'World', + root: false, + }, + relationships: {}, + }, + { + id: '3', + type: 'comment', + attributes: { + body: 'Foo', + root: false, + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'We normalized to json-api and data only includes the primary resources' + ); + }); + + test('normalizeResponse with embedded objects of same type, but from separate attributes', async function(assert) { + let { owner } = this; + const HomePlanetClass = Model.extend({ + name: attr('string'), + villains: hasMany('super-villain', { inverse: 'homePlanet', async: false }), + reformedVillains: hasMany('superVillain', { async: false }), + }); + owner.unregister('model:home-planet'); + owner.register('model:home-planet', HomePlanetClass); + owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + reformedVillains: { embedded: 'always' }, + }, + }) + ); + const serializer = store.serializerFor('home-planet'); + const HomePlanet = store.modelFor('home-planet'); + const rawPayload = { + homePlanets: [ + { + id: '1', + name: 'Earth', + villains: [ + { + id: '1', + firstName: 'Tom', + }, + { + id: '3', + firstName: 'Yehuda', + }, + ], + reformedVillains: [ + { + id: '2', + firstName: 'Alex', + }, + { + id: '4', + firstName: 'Erik', + }, + ], + }, + { + id: '2', + name: 'Mars', + villains: [ + { + id: '1', + firstName: 'Tom', + }, + { + id: '3', + firstName: 'Yehuda', + }, + ], + reformedVillains: [ + { + id: '5', + firstName: 'Peter', + }, + { + id: '6', + firstName: 'Trek', + }, + ], + }, + ], + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + HomePlanet, + rawPayload, + null, + 'findAll' + ); + const expectedOutput = { + data: [ + { + id: '1', + type: 'home-planet', + attributes: { + name: 'Earth', + }, + relationships: { + reformedVillains: { + data: [{ id: '2', type: 'super-villain' }, { id: '4', type: 'super-villain' }], + }, + villains: { + data: [{ id: '1', type: 'super-villain' }, { id: '3', type: 'super-villain' }], + }, + }, + }, + { + id: '2', + type: 'home-planet', + attributes: { + name: 'Mars', + }, + relationships: { + reformedVillains: { + data: [{ id: '5', type: 'super-villain' }, { id: '6', type: 'super-villain' }], + }, + villains: { + data: [{ id: '1', type: 'super-villain' }, { id: '3', type: 'super-villain' }], + }, + }, + }, + ], + included: [ + { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + }, + relationships: {}, + }, + { + id: '3', + type: 'super-villain', + attributes: { + firstName: 'Yehuda', + }, + relationships: {}, + }, + { + id: '2', + type: 'super-villain', + attributes: { + firstName: 'Alex', + }, + relationships: {}, + }, + { + id: '4', + type: 'super-villain', + attributes: { + firstName: 'Erik', + }, + relationships: {}, + }, + { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + }, + relationships: {}, + }, + { + id: '3', + type: 'super-villain', + attributes: { + firstName: 'Yehuda', + }, + relationships: {}, + }, + { + id: '5', + type: 'super-villain', + attributes: { + firstName: 'Peter', + }, + relationships: {}, + }, + { + id: '6', + type: 'super-villain', + attributes: { + firstName: 'Trek', + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'We normalized to json-api and only the primary resources are in data, embedded of the same type is in included' + ); + }); + + test('normalizeResponse with embedded object (belongsTo relationship)', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { embedded: 'always' }, + }, + }) + ); + + const serializer = store.serializerFor('super-villain'); + const SuperVillain = store.modelFor('super-villain'); + const rawPayload = { + super_villain: { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + evilMinions: ['1', '2', '3'], + secretLab: { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }, + secretWeapons: [], + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + SuperVillain, + rawPayload, + '1', + 'findRecord' + ); + const expectedOutput = { + data: { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + relationships: { + evilMinions: { + data: [ + { id: '1', type: 'evil-minion' }, + { id: '2', type: 'evil-minion' }, + { id: '3', type: 'evil-minion' }, + ], + }, + homePlanet: { + data: { id: '123', type: 'home-planet' }, + }, + secretLab: { + data: { id: '101', type: 'secret-lab' }, + }, + secretWeapons: { + data: [], + }, + }, + }, + included: [ + { + id: '101', + type: 'secret-lab', + attributes: { + minionCapacity: 5000, + vicinity: 'California, USA', + }, + relationships: {}, + }, + ], + }; + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'we normalized to json-api and extracted the embedded belongsTo' + ); + }); + + test('normalizeResponse with polymorphic hasMany', async function(assert) { + let { owner } = this; + + const SuperVillainClass = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: true }), + secretLab: belongsTo('secret-lab', { async: false }), + secretWeapons: hasMany('secretWeapon', { polymorphic: true, async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretWeapons: { embedded: 'always' }, + }, + }) + ); + owner.unregister('model:super-villain'); + owner.register('model:super-villain', SuperVillainClass); + + const serializer = store.serializerFor('super-villain'); + const SuperVillain = store.modelFor('super-villain'); + const rawPayload = { + super_villain: { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + secretWeapons: [ + { + id: '1', + type: 'LightSaber', + name: "Tom's LightSaber", + color: 'Red', + }, + { + id: '1', + type: 'SecretWeapon', + name: 'The Death Star', + }, + ], + }, + }; + const normalizedJsonApi = serializer.normalizeResponse( + store, + SuperVillain, + rawPayload, + '1', + 'findAll' + ); + const expectedOutput = { + data: { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + relationships: { + secretWeapons: { + data: [{ id: '1', type: 'light-saber' }, { id: '1', type: 'secret-weapon' }], + }, + }, + }, + included: [ + { + id: '1', + type: 'light-saber', + attributes: { + color: 'Red', + name: "Tom's LightSaber", + }, + relationships: {}, + }, + { + id: '1', + type: 'secret-weapon', + attributes: { + name: 'The Death Star', + }, + relationships: {}, + }, + ], + }; + + assert.deepEqual( + normalizedJsonApi, + expectedOutput, + 'We normalize to json-api with a polymorphic hasMany' + ); + }); + }); + + module('Serialize', function() { + test('serialize supports serialize:false on non-relationship properties', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + firstName: { serialize: false }, + }, + }) + ); + + const serializer = store.serializerFor('super-villain'); + const tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + }); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + lastName: 'Dale', + homePlanet: null, + secretLab: null, + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We do not serialize attrs defined with serialize:false' + ); + }); + + test('Mixin can be used with RESTSerializer which does not define keyForAttribute', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + evilMinions: { serialize: 'records', deserialize: 'records' }, + }, + }) + ); + + let homePlanet = store.createRecord('home-planet', { name: 'Villain League', id: '123' }); + let secretLab = store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }); + let superVillain = store.createRecord('super-villain', { + id: '1', + firstName: 'Super', + lastName: 'Villian', + homePlanet, + secretLab, + }); + let secretWeapon = store.createRecord('secret-weapon', { + id: '1', + name: 'Secret Weapon', + superVillain, + }); + + superVillain.get('secretWeapons').pushObject(secretWeapon); + + let evilMinion = store.createRecord('evil-minion', { + id: '1', + name: 'Evil Minion', + superVillain, + }); + superVillain.get('evilMinions').pushObject(evilMinion); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(superVillain._createSnapshot()); + const expectedOutput = { + firstName: 'Super', + lastName: 'Villian', + homePlanet: '123', + evilMinions: [ + { + id: '1', + name: 'Evil Minion', + superVillain: '1', + }, + ], + secretLab: '101', + // "manyToOne" relation does not serialize by default + // secretWeapons: ["1"] + }; + + assert.deepEqual(serializedRestJson, expectedOutput, 'we serialize correctly'); + }); + + test('serializing relationships with an embedded and without calls super when not attr not present', async function(assert) { + let { owner } = this; + let calledSerializeBelongsTo = false; + let calledSerializeHasMany = false; + + const Serializer = RESTSerializer.extend({ + serializeBelongsTo(snapshot, json, relationship) { + calledSerializeBelongsTo = true; + return this._super(snapshot, json, relationship); + }, + + serializeHasMany(snapshot, json, relationship) { + calledSerializeHasMany = true; + let key = relationship.key; + let payloadKey = this.keyForRelationship ? this.keyForRelationship(key, 'hasMany') : key; + let relationshipType = snapshot.type.determineRelationshipType(relationship); + // "manyToOne" not supported in ActiveModelSerializer.prototype.serializeHasMany + let relationshipTypes = ['manyToNone', 'manyToMany', 'manyToOne']; + if (relationshipTypes.indexOf(relationshipType) > -1) { + json[payloadKey] = snapshot.hasMany(key, { ids: true }); + } + }, + }); + + owner.register('serializer:evil-minion', Serializer); + owner.register('serializer:secret-weapon', Serializer); + owner.register( + 'serializer:super-villain', + Serializer.extend(EmbeddedRecordsMixin, { + attrs: { + evilMinions: { serialize: 'records', deserialize: 'records' }, + // some relationships are not listed here, so super should be called on those + // e.g. secretWeapons: { serialize: 'ids' } + }, + }) + ); + + let homePlanet = store.createRecord('home-planet', { + name: 'Villain League', + id: '123', + }); + let secretLab = store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }); + let superVillain = store.createRecord('super-villain', { + id: '1', + firstName: 'Super', + lastName: 'Villian', + homePlanet, + secretLab, + }); + let secretWeapon = store.createRecord('secret-weapon', { + id: '1', + name: 'Secret Weapon', + superVillain, + }); + + superVillain.get('secretWeapons').pushObject(secretWeapon); + let evilMinion = store.createRecord('evil-minion', { + id: '1', + name: 'Evil Minion', + superVillain, + }); + superVillain.get('evilMinions').pushObject(evilMinion); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(superVillain._createSnapshot()); + const expectedOutput = { + firstName: 'Super', + lastName: 'Villian', + homePlanet: '123', + evilMinions: [ + { + id: '1', + name: 'Evil Minion', + superVillain: '1', + }, + ], + secretLab: '101', + // customized serializeHasMany method to generate ids for "manyToOne" relation + secretWeapons: ['1'], + }; + + assert.deepEqual(serializedRestJson, expectedOutput, 'we serialized correctly'); + assert.ok(calledSerializeBelongsTo); + assert.ok(calledSerializeHasMany); + }); + + module('Serialize hasMany', function() { + test('serialize with embedded objects (hasMany relationship)', async function(assert) { + this.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + }, + }) + ); + + let homePlanet = store.createRecord('home-planet', { + name: 'Villain League', + id: '123', + }); + store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + homePlanet, + id: '1', + }); + const serializer = store.serializerFor('home-planet'); + const serializedRestJson = serializer.serialize(homePlanet._createSnapshot()); + const expectedOutput = { + name: 'Villain League', + villains: [ + { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: null, + }, + ], + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialized the hasMany relationship into an embedded object' + ); + }); + + test('serialize with embedded objects and a custom keyForAttribute (hasMany relationship)', async function(assert) { + this.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + keyForRelationship(key) { + return key + '-custom'; + }, + attrs: { + villains: { embedded: 'always' }, + }, + }) + ); + let homePlanet = store.createRecord('home-planet', { + name: 'Villain League', + id: '123', + }); + store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + homePlanet, + id: '1', + }); + + const serializer = store.serializerFor('home-planet'); + const serializedRestJson = serializer.serialize(homePlanet._createSnapshot()); + const expectedOutput = { + name: 'Villain League', + 'villains-custom': [ + { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: null, + }, + ], + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialized the hasMany into an embedded format with a custom key' + ); + }); + + testInDebug('serialize with embedded objects (unknown hasMany relationship)', async function( + assert + ) { + this.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + }, + }) + ); + + store.push({ + data: { + type: 'home-planet', + id: '123', + attributes: { + name: 'Villain League', + }, + }, + }); + const serializer = store.serializerFor('home-planet'); + let league = store.peekRecord('home-planet', 123); + let serializedRestJson; + const expectedOutput = { + name: 'Villain League', + villains: [], + }; + + assert.expectWarning(function() { + serializedRestJson = serializer.serialize(league._createSnapshot()); + }, /The embedded relationship 'villains' is undefined for 'home-planet' with id '123'. Please include it in your original payload./); + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialize the missing hasMany to an empty array' + ); + }); + + test('serialize with embedded objects (hasMany relationship) supports serialize:false', async function(assert) { + this.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { serialize: false }, + }, + }) + ); + + let homePlanet = store.createRecord('home-planet', { + name: 'Villain League', + id: '123', + }); + store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + homePlanet, + id: '1', + }); + + const serializer = store.serializerFor('home-planet'); + const serializedRestJson = serializer.serialize(homePlanet._createSnapshot()); + const expectedOutput = { + name: 'Villain League', + }; + + assert.deepEqual(serializedRestJson, expectedOutput, 'We do not serialize the hasMany'); + }); + + test('serialize with (new) embedded objects (hasMany relationship)', async function(assert) { + this.owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always' }, + }, + }) + ); + + let homePlanet = store.createRecord('home-planet', { + name: 'Villain League', + id: '123', + }); + store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + homePlanet, + }); + const serializer = store.serializerFor('home-planet'); + const serializedRestJson = serializer.serialize(homePlanet._createSnapshot()); + const expectedOutput = { + name: 'Villain League', + villains: [ + { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: null, + }, + ], + }; + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We embed new members of a hasMany when serializing even if they do not have IDs' + ); + }); + + test('serialize with embedded objects (hasMany relationships, including related objects not embedded)', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + evilMinions: { serialize: 'records', deserialize: 'records' }, + secretWeapons: { serialize: 'ids' }, + }, + }) + ); + + let superVillain = store.createRecord('super-villain', { + id: 1, + firstName: 'Super', + lastName: 'Villian', + }); + let evilMinion = store.createRecord('evil-minion', { + id: 1, + name: 'Evil Minion', + superVillain, + }); + let secretWeapon = store.createRecord('secret-weapon', { + id: 1, + name: 'Secret Weapon', + superVillain, + }); + + superVillain.get('evilMinions').pushObject(evilMinion); + superVillain.get('secretWeapons').pushObject(secretWeapon); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(superVillain._createSnapshot()); + const expectedOutput = { + firstName: 'Super', + lastName: 'Villian', + homePlanet: null, + evilMinions: [ + { + id: '1', + name: 'Evil Minion', + superVillain: '1', + }, + ], + secretLab: null, + secretWeapons: ['1'], + }; + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We only embed relationships we are told to embed' + ); + }); + + test('serialize has many relationship using the `ids-and-types` strategy', async function(assert) { + let { owner } = this; + const NormalMinion = Model.extend({ + name: attr('string'), + }); + const YellowMinion = NormalMinion.extend(); + const RedMinion = NormalMinion.extend(); + const CommanderVillain = Model.extend({ + name: attr('string'), + minions: hasMany('normal-minion', { polymorphic: true }), + }); + + owner.register('model:commander-villain', CommanderVillain); + owner.register('model:normal-minion', NormalMinion); + owner.register('model:yellow-minion', YellowMinion); + owner.register('model:red-minion', RedMinion); + owner.register( + 'serializer:commander-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + minions: { serialize: 'ids-and-types' }, + }, + }) + ); + + let yellowMinion = store.createRecord('yellow-minion', { + id: 1, + name: 'Yellowy', + }); + let redMinion = store.createRecord('red-minion', { + id: 1, + name: 'Reddy', + }); + let commanderVillain = store.createRecord('commander-villain', { + id: 1, + name: 'Jeff', + minions: [yellowMinion, redMinion], + }); + + const serializer = store.serializerFor('commander-villain'); + const serializedRestJson = serializer.serialize(commanderVillain._createSnapshot()); + const expectedOutput = { + name: 'Jeff', + minions: [ + { + id: '1', + type: 'yellow-minion', + }, + { + id: '1', + type: 'red-minion', + }, + ], + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialized both ids and types for the hasMany' + ); + }); + + test('serializing embedded hasMany respects remapped attrs key', async function(assert) { + let { owner } = this; + owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { embedded: 'always', key: 'notable_persons' }, + }, + }) + ); + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + homePlanet: { serialize: false }, + secretLab: { serialize: false }, + }, + }) + ); + + let homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); + store.createRecord('super-villain', { + firstName: 'Ice', + lastName: 'Creature', + homePlanet: homePlanet, + }); + + const serializer = store.serializerFor('home-planet'); + const serializedRestJson = serializer.serialize(homePlanet._createSnapshot()); + const expectedOutput = { + name: 'Hoth', + notable_persons: [ + { + firstName: 'Ice', + lastName: 'Creature', + }, + ], + }; + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'we normalized to json-api and remapped the hasMany relationship' + ); + }); + + test('serializing ids hasMany respects remapped attrs key', async function(assert) { + let { owner } = this; + owner.register( + 'serializer:home-planet', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + villains: { serialize: 'ids', key: 'notable_persons' }, + }, + }) + ); + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + homePlanet: { serialize: false }, + secretLab: { serialize: false }, + }, + }) + ); + + let homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); + let superVillain = store.createRecord('super-villain', { + firstName: 'Ice', + lastName: 'Creature', + homePlanet, + }); + + const serializer = store.serializerFor('home-planet'); + const serializedRestJson = serializer.serialize(homePlanet._createSnapshot()); + const expectedOutput = { + name: 'Hoth', + notable_persons: [superVillain.id], + }; + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'we serialized respecting the custom key in attrs' + ); + }); + }); + + module('Serialize belongsTo', function() { + test('serialize with embedded object (belongsTo relationship)', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { embedded: 'always' }, + }, + }) + ); + + // records with an id, persisted + let secretLab = store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }); + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab, + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: { + id: '101', + minionCapacity: 5000, + vicinity: 'California, USA', + }, + }; + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We embed belongsTo relationships when serializing if specified' + ); + }); + + test('serialize with embedded object (polymorphic belongsTo relationship)', async function(assert) { + let { owner } = this; + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { embedded: 'always' }, + }, + }) + ); + const SuperVillain = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: true }), + secretLab: belongsTo('secret-lab', { polymorphic: true }), + secretWeapons: hasMany('secret-weapon', { async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + owner.unregister('model:super-villain'); + owner.register('model:super-villain', SuperVillain); + + let tom = store.createRecord('super-villain', { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + secretLab: store.createRecord('bat-cave', { + id: '101', + minionCapacity: 5000, + vicinity: 'California, USA', + infiltrated: true, + }), + homePlanet: store.createRecord('home-planet', { + id: '123', + name: 'Villain League', + }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLabType: 'batCave', + secretLab: { + id: '101', + minionCapacity: 5000, + vicinity: 'California, USA', + infiltrated: true, + }, + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'we serialized an embedded polymorphic relationship correctly' + ); + }); + + test('serialize with embedded object (belongsTo relationship) works with different primaryKeys', async function(assert) { + let { owner } = this; + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + primaryKey: '_id', + attrs: { + secretLab: { embedded: 'always' }, + }, + }) + ); + owner.register( + 'serializer:secret-lab', + RESTSerializer.extend(EmbeddedRecordsMixin, { + primaryKey: 'crazy_id', + }) + ); + + const superVillainSerializer = store.serializerFor('super-villain'); + + // records with an id, persisted + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab: store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializedRestJson = superVillainSerializer.serialize(tom._createSnapshot(), { + includeId: true, + }); + const expectedOutput = { + _id: '1', + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: { + crazy_id: '101', + minionCapacity: 5000, + vicinity: 'California, USA', + }, + }; + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialize the embedded belongsTo with the correct primaryKey field' + ); + }); + + test('serialize with embedded object (belongsTo relationship, new no id)', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { embedded: 'always' }, + }, + }) + ); + + const serializer = store.serializerFor('super-villain'); + + // records without ids, new + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + secretLab: store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: { + minionCapacity: 5000, + vicinity: 'California, USA', + }, + }; + + assert.deepEqual(serializedRestJson, expectedOutput); + }); + + test('serialize with embedded object (polymorphic belongsTo relationship) supports serialize:ids', async function(assert) { + let { owner } = this; + const SuperVillain = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: true }), + secretLab: belongsTo('secret-lab', { polymorphic: true }), + secretWeapons: hasMany('secret-weapon', { async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { serialize: 'ids' }, + }, + }) + ); + owner.unregister('model:super-villain'); + owner.register('model:super-villain', SuperVillain); + + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab: store.createRecord('bat-cave', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: '101', + secretLabType: 'batCave', + }; + assert.deepEqual(serializedRestJson, expectedOutput, 'We serialize the polymorphic type'); + }); + + test('serialize with embedded object (belongsTo relationship) supports serialize:id', async function(assert) { + let { owner } = this; + const SuperVillain = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: true }), + secretLab: belongsTo('secret-lab', { polymorphic: true }), + secretWeapons: hasMany('secret-weapon', { async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { serialize: 'id' }, + }, + }) + ); + owner.unregister('model:super-villain'); + owner.register('model:super-villain', SuperVillain); + + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab: store.createRecord('bat-cave', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: '101', + secretLabType: 'batCave', + }; + + assert.deepEqual(serializedRestJson, expectedOutput, 'We serialize the id'); + }); + + test('serialize with embedded object (belongsTo relationship) supports serialize:id in conjunction with deserialize:records', async function(assert) { + let { owner } = this; + const SuperVillain = Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + homePlanet: belongsTo('home-planet', { inverse: 'villains', async: true }), + secretLab: belongsTo('secret-lab', { polymorphic: true }), + secretWeapons: hasMany('secret-weapon', { async: false }), + evilMinions: hasMany('evil-minion', { async: false }), + }); + + owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { serialize: 'id', deserialize: 'records' }, + }, + }) + ); + owner.unregister('model:super-villain'); + owner.register('model:super-villain', SuperVillain); + + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab: store.createRecord('bat-cave', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: '101', + secretLabType: 'batCave', + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We support serialize:ids when deserialize:records is present' + ); + }); + + test('serialize with embedded object (belongsTo relationship) supports serialize:ids', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { serialize: 'ids' }, + }, + }) + ); + + // records with an id, persisted + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab: store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: '101', + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialized the belongsTo relationships to IDs' + ); + }); + + test('serialize with embedded object (belongsTo relationship) supports serialize:id', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { serialize: 'id' }, + }, + }) + ); + + // records with an id, persisted + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab: store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: '101', + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialized the belongsTo relationships to IDs' + ); + }); + + test('serialize with embedded object (belongsTo relationship) supports serialize:id in conjunction with deserialize:records', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { serialize: 'id', deserialize: 'records' }, + }, + }) + ); + + // records with an id, persisted + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab: store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: '101', + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialized the belongsTo relationships to IDs' + ); + }); + + test('serialize with embedded object (belongsTo relationship) supports serialize:false', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { serialize: false }, + }, + }) + ); + + // records with an id, persisted + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab: store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We do not serialize relationships that specify serialize:false' + ); + }); + + test('serialize with embedded object (belongsTo relationship) serializes the id by default if no option specified', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin) + ); + + // records with an id, persisted + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + secretLab: store.createRecord('secret-lab', { + minionCapacity: 5000, + vicinity: 'California, USA', + id: '101', + }), + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: '101', + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialized the belongsTo relationships to IDs' + ); + }); + + test('when related record is not present, serialize embedded record (with a belongsTo relationship) as null', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretLab: { embedded: 'always' }, + }, + }) + ); + + let tom = store.createRecord('super-villain', { + firstName: 'Tom', + lastName: 'Dale', + id: '1', + homePlanet: store.createRecord('home-planet', { name: 'Villain League', id: '123' }), + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(tom._createSnapshot()); + const expectedOutput = { + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '123', + secretLab: null, + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We serialized missing belongsTo relationships to null when always embedded' + ); + }); + + test('serializing belongsTo correctly removes embedded foreign key', async function(assert) { + let { owner } = this; + const SecretWeaponClass = Model.extend({ + name: attr('string'), + }); + const EvilMinionClass = Model.extend({ + secretWeapon: belongsTo('secret-weapon', { async: false }), + name: attr('string'), + }); + + owner.register( + 'serializer:evil-minion', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + secretWeapon: { embedded: 'always' }, + }, + }) + ); + owner.unregister('model:secret-weapon'); + owner.unregister('model:evil-minion'); + owner.register('model:secret-weapon', SecretWeaponClass); + owner.register('model:evil-minion', EvilMinionClass); + + let secretWeapon = store.createRecord('secret-weapon', { name: 'Secret Weapon' }); + let evilMinion = store.createRecord('evil-minion', { + name: 'Evil Minion', + secretWeapon, + }); + + const serializer = store.serializerFor('evil-minion'); + const serializedRestJson = serializer.serialize(evilMinion._createSnapshot()); + const expectedOutput = { + name: 'Evil Minion', + secretWeapon: { + name: 'Secret Weapon', + }, + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'We correctly remove the FK from the embedded inverse when serializing' + ); + }); + + test('serializing embedded belongsTo respects remapped attrs key', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + homePlanet: { embedded: 'always', key: 'favorite_place' }, + }, + }) + ); + + let homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); + let superVillain = store.createRecord('super-villain', { + firstName: 'Ice', + lastName: 'Creature', + homePlanet, + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(superVillain._createSnapshot()); + const expectedOutput = { + firstName: 'Ice', + lastName: 'Creature', + favorite_place: { + name: 'Hoth', + }, + secretLab: null, + }; + + assert.deepEqual( + serializedRestJson, + expectedOutput, + 'we respect the remapped attrs key when serializing' + ); + }); + + test('serializing id belongsTo respects remapped attrs key', async function(assert) { + this.owner.register( + 'serializer:super-villain', + RESTSerializer.extend(EmbeddedRecordsMixin, { + attrs: { + homePlanet: { serialize: 'id', key: 'favorite_place' }, + }, + }) + ); + + let homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); + let superVillain = store.createRecord('super-villain', { + firstName: 'Ice', + lastName: 'Creature', + homePlanet, + }); + + const serializer = store.serializerFor('super-villain'); + const serializedRestJson = serializer.serialize(superVillain._createSnapshot()); + const expectedOutput = { + firstName: 'Ice', + lastName: 'Creature', + favorite_place: homePlanet.id, + secretLab: null, + }; + + assert.deepEqual(serializedRestJson, expectedOutput, 'we serialized with remapped keys'); + }); + }); + }); +}); diff --git a/tests/integration/serializers/json-api-serializer-test.js b/tests/integration/serializers/json-api-serializer-test.js new file mode 100644 index 00000000000..f6fe59eedc2 --- /dev/null +++ b/tests/integration/serializers/json-api-serializer-test.js @@ -0,0 +1,724 @@ +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var env, store, serializer; + +var User, Handle, GithubHandle, TwitterHandle, Company, Project; + +module('integration/serializers/json-api-serializer - JSONAPISerializer', { + beforeEach() { + User = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + title: DS.attr('string'), + handles: DS.hasMany('handle', { async: true, polymorphic: true }), + company: DS.belongsTo('company', { async: true }), + reportsTo: DS.belongsTo('user', { async: true, inverse: null }), + }); + + Handle = DS.Model.extend({ + user: DS.belongsTo('user', { async: true }), + }); + + GithubHandle = Handle.extend({ + username: DS.attr('string'), + }); + + TwitterHandle = Handle.extend({ + nickname: DS.attr('string'), + }); + + Company = DS.Model.extend({ + name: DS.attr('string'), + employees: DS.hasMany('user', { async: true }), + }); + + Project = DS.Model.extend({ + 'company-name': DS.attr('string'), + }); + + env = setupStore({ + adapter: DS.JSONAPIAdapter, + + user: User, + handle: Handle, + 'github-handle': GithubHandle, + 'twitter-handle': TwitterHandle, + company: Company, + project: Project, + }); + + store = env.store; + serializer = env.serializer; + }, + + afterEach() { + run(env.store, 'destroy'); + }, +}); + +test('Calling pushPayload works', function(assert) { + run(function() { + serializer.pushPayload(store, { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + relationships: { + company: { + data: { type: 'companies', id: '2' }, + }, + handles: { + data: [{ type: 'github-handles', id: '3' }, { type: 'twitter-handles', id: '4' }], + }, + }, + }, + included: [ + { + type: 'companies', + id: '2', + attributes: { + name: 'Tilde Inc.', + }, + }, + { + type: 'github-handles', + id: '3', + attributes: { + username: 'wycats', + }, + }, + { + type: 'twitter-handles', + id: '4', + attributes: { + nickname: '@wycats', + }, + }, + ], + }); + + var user = store.peekRecord('user', 1); + + assert.equal(get(user, 'firstName'), 'Yehuda', 'firstName is correct'); + assert.equal(get(user, 'lastName'), 'Katz', 'lastName is correct'); + assert.equal(get(user, 'company.name'), 'Tilde Inc.', 'company.name is correct'); + assert.equal( + get(user, 'handles.firstObject.username'), + 'wycats', + 'handles.firstObject.username is correct' + ); + assert.equal( + get(user, 'handles.lastObject.nickname'), + '@wycats', + 'handles.lastObject.nickname is correct' + ); + }); +}); + +testInDebug('Warns when normalizing an unknown type', function(assert) { + var documentHash = { + data: { + type: 'UnknownType', + id: '1', + attributes: { + foo: 'bar', + }, + }, + }; + + assert.expectWarning(function() { + run(function() { + env.store + .serializerFor('user') + .normalizeResponse(env.store, User, documentHash, '1', 'findRecord'); + }); + }, /Encountered a resource object with type "UnknownType", but no model was found for model name "unknown-type"/); +}); + +testInDebug('Warns when normalizing payload with unknown type included', function(assert) { + var documentHash = { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + relationships: { + company: { + data: { type: 'unknown-types', id: '2' }, + }, + }, + }, + included: [ + { + type: 'unknown-types', + id: '2', + attributes: { + name: 'WyKittens', + }, + }, + ], + }; + + assert.expectWarning(function() { + run(function() { + env.store + .serializerFor('user') + .normalizeResponse(env.store, User, documentHash, '1', 'findRecord'); + }); + }, /Encountered a resource object with type "unknown-types", but no model was found for model name "unknown-type"/); +}); + +testInDebug('Warns but does not fail when pushing payload with unknown type included', function( + assert +) { + var documentHash = { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + }, + included: [ + { + type: 'unknown-types', + id: '2', + attributes: { + name: 'WyKittens', + }, + }, + ], + }; + + assert.expectWarning(function() { + run(function() { + env.store.pushPayload(documentHash); + }); + }, /Encountered a resource object with type "unknown-types", but no model was found for model name "unknown-type"/); + + var user = store.peekRecord('user', 1); + assert.equal(get(user, 'firstName'), 'Yehuda', 'firstName is correct'); +}); + +testInDebug('Errors when pushing payload with unknown type included in relationship', function( + assert +) { + var documentHash = { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': 'Yehuda', + 'last-name': 'Katz', + }, + relationships: { + company: { + data: { type: 'unknown-types', id: '2' }, + }, + }, + }, + }; + + assert.expectAssertion(function() { + run(function() { + env.store.pushPayload(documentHash); + }); + }, /No model was found for 'unknown-type'/); +}); + +testInDebug('Warns when normalizing with type missing', function(assert) { + var documentHash = { + data: { + id: '1', + attributes: { + foo: 'bar', + }, + }, + }; + + assert.expectAssertion(function() { + run(function() { + env.store + .serializerFor('user') + .normalizeResponse(env.store, User, documentHash, '1', 'findRecord'); + }); + }, /Encountered a resource object with an undefined type/); +}); + +test('Serializer should respect the attrs hash when extracting attributes and relationships', function(assert) { + env.owner.register( + 'serializer:user', + DS.JSONAPISerializer.extend({ + attrs: { + firstName: 'firstname_attribute_key', + title: 'title_attribute_key', + company: { key: 'company_relationship_key' }, + }, + }) + ); + + var jsonHash = { + data: { + type: 'users', + id: '1', + attributes: { + firstname_attribute_key: 'Yehuda', + title_attribute_key: 'director', + }, + relationships: { + company_relationship_key: { + data: { type: 'companies', id: '2' }, + }, + }, + }, + included: [ + { + type: 'companies', + id: '2', + attributes: { + name: 'Tilde Inc.', + }, + }, + ], + }; + + var user = env.store + .serializerFor('user') + .normalizeResponse(env.store, User, jsonHash, '1', 'findRecord'); + + assert.equal(user.data.attributes.firstName, 'Yehuda'); + assert.equal(user.data.attributes.title, 'director'); + assert.deepEqual(user.data.relationships.company.data, { id: '2', type: 'company' }); +}); + +test('Serializer should respect the attrs hash when serializing attributes and relationships', function(assert) { + env.owner.register( + 'serializer:user', + DS.JSONAPISerializer.extend({ + attrs: { + firstName: 'firstname_attribute_key', + title: 'title_attribute_key', + company: { key: 'company_relationship_key' }, + }, + }) + ); + var company, user; + + run(function() { + env.store.push({ + data: { + type: 'company', + id: '1', + attributes: { + name: 'Tilde Inc.', + }, + }, + }); + company = env.store.peekRecord('company', 1); + user = env.store.createRecord('user', { + firstName: 'Yehuda', + title: 'director', + company: company, + }); + }); + + var payload = env.store.serializerFor('user').serialize(user._createSnapshot()); + + assert.equal(payload.data.relationships['company_relationship_key'].data.id, '1'); + assert.equal(payload.data.attributes['firstname_attribute_key'], 'Yehuda'); + assert.equal(payload.data.attributes['title_attribute_key'], 'director'); +}); + +test('Serializer should respect the attrs hash when extracting attributes with not camelized keys', function(assert) { + env.owner.register( + 'serializer:project', + DS.JSONAPISerializer.extend({ + attrs: { + 'company-name': 'company_name', + }, + }) + ); + + var jsonHash = { + data: { + type: 'projects', + id: '1', + attributes: { + company_name: 'Tilde Inc.', + }, + }, + }; + + var project = env.store + .serializerFor('project') + .normalizeResponse(env.store, User, jsonHash, '1', 'findRecord'); + + assert.equal(project.data.attributes['company-name'], 'Tilde Inc.'); +}); + +test('Serializer should respect the attrs hash when serializing attributes with not camelized keys', function(assert) { + env.owner.register( + 'serializer:project', + DS.JSONAPISerializer.extend({ + attrs: { + 'company-name': 'company_name', + }, + }) + ); + + let project = env.store.createRecord('project', { 'company-name': 'Tilde Inc.' }); + let payload = env.store.serializerFor('project').serialize(project._createSnapshot()); + + assert.equal(payload.data.attributes['company_name'], 'Tilde Inc.'); +}); + +test('options are passed to transform for serialization', function(assert) { + assert.expect(1); + + env.owner.register( + 'transform:custom', + DS.Transform.extend({ + serialize: function(deserialized, options) { + assert.deepEqual(options, { custom: 'config' }); + }, + }) + ); + + User.reopen({ + myCustomField: DS.attr('custom', { + custom: 'config', + }), + }); + + let user = env.store.createRecord('user', { myCustomField: 'value' }); + + env.store.serializerFor('user').serialize(user._createSnapshot()); +}); + +testInDebug('Warns when defining extractMeta()', function(assert) { + assert.expectWarning(function() { + DS.JSONAPISerializer.extend({ + extractMeta() {}, + }).create(); + }, /You've defined 'extractMeta' in/); +}); + +test('a belongsTo relationship that is not set will not be in the relationships key', function(assert) { + run(function() { + serializer.pushPayload(store, { + data: { + type: 'handles', + id: 1, + }, + }); + + let handle = store.peekRecord('handle', 1); + + let serialized = handle.serialize({ includeId: true }); + assert.deepEqual(serialized, { + data: { + type: 'handles', + id: '1', + }, + }); + }); +}); + +test('a belongsTo relationship that is set to null will show as null in the relationships key', function(assert) { + run(function() { + serializer.pushPayload(store, { + data: { + type: 'handles', + id: 1, + }, + }); + + let handle = store.peekRecord('handle', 1); + handle.set('user', null); + + let serialized = handle.serialize({ includeId: true }); + assert.deepEqual(serialized, { + data: { + type: 'handles', + id: '1', + relationships: { + user: { + data: null, + }, + }, + }, + }); + }); +}); + +test('a belongsTo relationship set to a new record will not show in the relationships key', function(assert) { + run(function() { + serializer.pushPayload(store, { + data: { + type: 'handles', + id: 1, + }, + }); + + let handle = store.peekRecord('handle', 1); + let user = store.createRecord('user'); + handle.set('user', user); + + let serialized = handle.serialize({ includeId: true }); + assert.deepEqual(serialized, { + data: { + type: 'handles', + id: '1', + }, + }); + }); +}); + +test('it should serialize a hasMany relationship', function(assert) { + env.owner.register( + 'serializer:user', + DS.JSONAPISerializer.extend({ + attrs: { + handles: { serialize: true }, + }, + }) + ); + + run(function() { + serializer.pushPayload(store, { + data: { + type: 'users', + id: 1, + relationships: { + handles: { + data: [{ type: 'handles', id: 1 }, { type: 'handles', id: 2 }], + }, + }, + }, + included: [{ type: 'handles', id: 1 }, { type: 'handles', id: 2 }], + }); + + let user = store.peekRecord('user', 1); + + let serialized = user.serialize({ includeId: true }); + + assert.deepEqual(serialized, { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': null, + 'last-name': null, + title: null, + }, + relationships: { + handles: { + data: [{ type: 'handles', id: '1' }, { type: 'handles', id: '2' }], + }, + }, + }, + }); + }); +}); + +test('it should not include new records when serializing a hasMany relationship', function(assert) { + env.owner.register( + 'serializer:user', + DS.JSONAPISerializer.extend({ + attrs: { + handles: { serialize: true }, + }, + }) + ); + + run(function() { + serializer.pushPayload(store, { + data: { + type: 'users', + id: 1, + relationships: { + handles: { + data: [{ type: 'handles', id: 1 }, { type: 'handles', id: 2 }], + }, + }, + }, + included: [{ type: 'handles', id: 1 }, { type: 'handles', id: 2 }], + }); + + let user = store.peekRecord('user', 1); + store.createRecord('handle', { user }); + + let serialized = user.serialize({ includeId: true }); + + assert.deepEqual(serialized, { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': null, + 'last-name': null, + title: null, + }, + relationships: { + handles: { + data: [{ type: 'handles', id: '1' }, { type: 'handles', id: '2' }], + }, + }, + }, + }); + }); +}); + +test('it should not include any records when serializing a hasMany relationship if they are all new', function(assert) { + env.owner.register( + 'serializer:user', + DS.JSONAPISerializer.extend({ + attrs: { + handles: { serialize: true }, + }, + }) + ); + + run(function() { + serializer.pushPayload(store, { + data: { + type: 'users', + id: 1, + }, + }); + + let user = store.peekRecord('user', 1); + store.createRecord('handle', { user }); + + let serialized = user.serialize({ includeId: true }); + + assert.deepEqual(serialized, { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': null, + 'last-name': null, + title: null, + }, + relationships: { + handles: { + data: [], + }, + }, + }, + }); + }); +}); + +test('it should include an empty list when serializing an empty hasMany relationship', function(assert) { + env.owner.register( + 'serializer:user', + DS.JSONAPISerializer.extend({ + attrs: { + handles: { serialize: true }, + }, + }) + ); + + run(function() { + serializer.pushPayload(store, { + data: { + type: 'users', + id: 1, + relationships: { + handles: { + data: [{ type: 'handles', id: 1 }, { type: 'handles', id: 2 }], + }, + }, + }, + included: [{ type: 'handles', id: 1 }, { type: 'handles', id: 2 }], + }); + + let user = store.peekRecord('user', 1); + let handle1 = store.peekRecord('handle', 1); + let handle2 = store.peekRecord('handle', 2); + user.get('handles').removeObject(handle1); + user.get('handles').removeObject(handle2); + + let serialized = user.serialize({ includeId: true }); + + assert.deepEqual(serialized, { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': null, + 'last-name': null, + title: null, + }, + relationships: { + handles: { + data: [], + }, + }, + }, + }); + }); +}); + +testInDebug('JSON warns when combined with EmbeddedRecordsMixin', function(assert) { + assert.expectWarning(function() { + DS.JSONAPISerializer.extend(DS.EmbeddedRecordsMixin).create(); + }, /The JSONAPISerializer does not work with the EmbeddedRecordsMixin/); +}); + +testInDebug( + 'Asserts when normalized attribute key is not found in payload but original key is', + function(assert) { + var jsonHash = { + data: { + type: 'users', + id: '1', + attributes: { + firstName: 'Yehuda', + }, + }, + }; + assert.expectAssertion(function() { + env.store + .serializerFor('user') + .normalizeResponse(env.store, User, jsonHash, '1', 'findRecord'); + }, /Your payload for 'user' contains 'firstName', but your serializer is setup to look for 'first-name'/); + } +); + +testInDebug( + 'Asserts when normalized relationship key is not found in payload but original key is', + function(assert) { + var jsonHash = { + data: { + type: 'users', + id: '1', + relationships: { + reportsTo: { + data: null, + }, + }, + }, + }; + assert.expectAssertion(function() { + env.store + .serializerFor('user') + .normalizeResponse(env.store, User, jsonHash, '1', 'findRecord'); + }, /Your payload for 'user' contains 'reportsTo', but your serializer is setup to look for 'reports-to'/); + } +); diff --git a/tests/integration/serializers/json-serializer-test.js b/tests/integration/serializers/json-serializer-test.js new file mode 100644 index 00000000000..9ba5160f843 --- /dev/null +++ b/tests/integration/serializers/json-serializer-test.js @@ -0,0 +1,1133 @@ +import { underscore } from '@ember/string'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var Post, Comment, Favorite, env, serializer; + +module('integration/serializer/json - JSONSerializer', { + beforeEach() { + Post = DS.Model.extend({ + title: DS.attr('string'), + comments: DS.hasMany('comment', { inverse: null, async: false }), + }); + Comment = DS.Model.extend({ + body: DS.attr('string'), + post: DS.belongsTo('post', { inverse: null, async: false }), + }); + Favorite = DS.Model.extend({ + post: DS.belongsTo('post', { inverse: null, async: true, polymorphic: true }), + }); + env = setupStore({ + post: Post, + comment: Comment, + favorite: Favorite, + }); + env.store.modelFor('post'); + env.store.modelFor('comment'); + env.store.modelFor('favorite'); + serializer = env.store.serializerFor('-json'); + }, + + afterEach() { + run(env.store, 'destroy'); + }, +}); + +test("serialize doesn't include ID when includeId is false", function(assert) { + let post = env.store.createRecord('post', { + title: 'Rails is omakase', + comments: [], + }); + let json = serializer.serialize(post._createSnapshot(), { includeId: false }); + + assert.deepEqual(json, { + title: 'Rails is omakase', + comments: [], + }); +}); + +test("serialize doesn't include relationship if not aware of one", function(assert) { + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + let json = serializer.serialize(post._createSnapshot()); + + assert.deepEqual(json, { + title: 'Rails is omakase', + }); +}); + +test('serialize includes id when includeId is true', function(assert) { + let post = env.store.createRecord('post', { title: 'Rails is omakase', comments: [] }); + + run(() => { + post.set('id', 'test'); + }); + + let json = serializer.serialize(post._createSnapshot(), { includeId: true }); + + assert.deepEqual(json, { + id: 'test', + title: 'Rails is omakase', + comments: [], + }); +}); + +test('serializeAttribute', function(assert) { + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + let json = {}; + + serializer.serializeAttribute(post._createSnapshot(), json, 'title', { type: 'string' }); + + assert.deepEqual(json, { + title: 'Rails is omakase', + }); +}); + +test('serializeAttribute respects keyForAttribute', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + keyForAttribute(key) { + return key.toUpperCase(); + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + let json = {}; + + env.store + .serializerFor('post') + .serializeAttribute(post._createSnapshot(), json, 'title', { type: 'string' }); + + assert.deepEqual(json, { TITLE: 'Rails is omakase' }); +}); + +test('serializeBelongsTo', function(assert) { + let post = env.store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + let json = {}; + + serializer.serializeBelongsTo(comment._createSnapshot(), json, { key: 'post', options: {} }); + + assert.deepEqual(json, { post: '1' }); +}); + +test('serializeBelongsTo with null', function(assert) { + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: null }); + let json = {}; + + serializer.serializeBelongsTo(comment._createSnapshot(), json, { key: 'post', options: {} }); + + assert.deepEqual( + json, + { + post: null, + }, + 'Can set a belongsTo to a null value' + ); +}); + +test('async serializeBelongsTo with null', function(assert) { + Comment.reopen({ + post: DS.belongsTo('post', { async: true }), + }); + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: null }); + let json = {}; + + serializer.serializeBelongsTo(comment._createSnapshot(), json, { key: 'post', options: {} }); + + assert.deepEqual( + json, + { + post: null, + }, + 'Can set a belongsTo to a null value' + ); +}); + +test('serializeBelongsTo respects keyForRelationship', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + keyForRelationship(key, type) { + return key.toUpperCase(); + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + let json = {}; + + env.store + .serializerFor('post') + .serializeBelongsTo(comment._createSnapshot(), json, { key: 'post', options: {} }); + + assert.deepEqual(json, { + POST: '1', + }); +}); + +test('serializeHasMany respects keyForRelationship', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + keyForRelationship(key, type) { + return key.toUpperCase(); + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + let comment = env.store.createRecord('comment', { + body: 'Omakase is delicious', + post: post, + id: '1', + }); + + run(function() { + post.get('comments').pushObject(comment); + }); + + let json = {}; + + env.store + .serializerFor('post') + .serializeHasMany(post._createSnapshot(), json, { key: 'comments', options: {} }); + + assert.deepEqual(json, { + COMMENTS: ['1'], + }); +}); + +test('serializeHasMany omits unknown relationships on pushed record', function(assert) { + let post = run(() => + env.store.push({ + data: { + id: '1', + type: 'post', + attributes: { + title: 'Rails is omakase', + }, + }, + }) + ); + let json = {}; + + env.store + .serializerFor('post') + .serializeHasMany(post._createSnapshot(), json, { key: 'comments', options: {} }); + + assert.ok(!json.hasOwnProperty('comments'), 'Does not add the relationship key to json'); +}); + +test('shouldSerializeHasMany', function(assert) { + let post = env.store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + env.store.createRecord('comment', { body: 'Omakase is delicious', post: post, id: '1' }); + + var snapshot = post._createSnapshot(); + var relationship = snapshot.record.relationshipFor('comments'); + var key = relationship.key; + + var shouldSerialize = env.store + .serializerFor('post') + .shouldSerializeHasMany(snapshot, relationship, key); + + assert.ok( + shouldSerialize, + 'shouldSerializeHasMany correctly identifies with hasMany relationship' + ); +}); + +test('serializeIntoHash', function(assert) { + let post = env.store.createRecord('post', { title: 'Rails is omakase', comments: [] }); + let json = {}; + + serializer.serializeIntoHash(json, Post, post._createSnapshot()); + + assert.deepEqual(json, { + title: 'Rails is omakase', + comments: [], + }); +}); + +test('serializePolymorphicType sync', function(assert) { + assert.expect(1); + + env.owner.register( + 'serializer:comment', + DS.JSONSerializer.extend({ + serializePolymorphicType(record, json, relationship) { + let key = relationship.key; + let belongsTo = record.belongsTo(key); + json[relationship.key + 'TYPE'] = belongsTo.modelName; + + assert.ok( + true, + 'serializePolymorphicType is called when serialize a polymorphic belongsTo' + ); + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase', id: 1 }); + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + + env.store + .serializerFor('comment') + .serializeBelongsTo( + comment._createSnapshot(), + {}, + { key: 'post', options: { polymorphic: true } } + ); +}); + +test('serializePolymorphicType async', function(assert) { + assert.expect(1); + + Comment.reopen({ + post: DS.belongsTo('post', { async: true }), + }); + + env.owner.register( + 'serializer:comment', + DS.JSONSerializer.extend({ + serializePolymorphicType(record, json, relationship) { + assert.ok( + true, + 'serializePolymorphicType is called when serialize a polymorphic belongsTo' + ); + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase', id: 1 }); + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + + env.store + .serializerFor('comment') + .serializeBelongsTo( + comment._createSnapshot(), + {}, + { key: 'post', options: { async: true, polymorphic: true } } + ); +}); + +test('normalizeResponse normalizes each record in the array', function(assert) { + var postNormalizeCount = 0; + var posts = [{ id: '1', title: 'Rails is omakase' }, { id: '2', title: 'Another Post' }]; + + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + normalize() { + postNormalizeCount++; + return this._super.apply(this, arguments); + }, + }) + ); + + run(function() { + env.store.serializerFor('post').normalizeResponse(env.store, Post, posts, null, 'findAll'); + }); + assert.equal(postNormalizeCount, 2, 'two posts are normalized'); +}); + +test('Serializer should respect the attrs hash when extracting records', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + title: 'title_payload_key', + comments: { key: 'my_comments' }, + }, + }) + ); + + var jsonHash = { + id: '1', + title_payload_key: 'Rails is omakase', + my_comments: [1, 2], + }; + + var post = env.store + .serializerFor('post') + .normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + + assert.equal(post.data.attributes.title, 'Rails is omakase'); + assert.deepEqual(post.data.relationships.comments.data, [ + { id: '1', type: 'comment' }, + { id: '2', type: 'comment' }, + ]); +}); + +test('Serializer should map `attrs` attributes directly when keyForAttribute also has a transform', function(assert) { + Post = DS.Model.extend({ + authorName: DS.attr('string'), + }); + env = setupStore({ + post: Post, + }); + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + keyForAttribute: underscore, + attrs: { + authorName: 'author_name_key', + }, + }) + ); + + var jsonHash = { + id: '1', + author_name_key: 'DHH', + }; + + var post = env.store + .serializerFor('post') + .normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + + assert.equal(post.data.attributes.authorName, 'DHH'); +}); + +test('Serializer should respect the attrs hash when serializing records', function(assert) { + Post.reopen({ + parentPost: DS.belongsTo('post', { inverse: null, async: true }), + }); + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + title: 'title_payload_key', + parentPost: { key: 'my_parent' }, + }, + }) + ); + + let parentPost = run(() => + env.store.push({ + data: { + type: 'post', + id: '2', + attributes: { + title: 'Rails is omakase', + }, + }, + }) + ); + let post = env.store.createRecord('post', { title: 'Rails is omakase', parentPost: parentPost }); + let payload = env.store.serializerFor('post').serialize(post._createSnapshot()); + + assert.equal(payload.title_payload_key, 'Rails is omakase'); + assert.equal(payload.my_parent, '2'); +}); + +test('Serializer respects if embedded model has an attribute named "type" - #3726', function(assert) { + env.owner.register('serializer:child', DS.JSONSerializer); + env.owner.register( + 'serializer:parent', + DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, { + attrs: { + child: { embedded: 'always' }, + }, + }) + ); + env.owner.register( + 'model:parent', + DS.Model.extend({ + child: DS.belongsTo('child'), + }) + ); + env.owner.register( + 'model:child', + DS.Model.extend({ + type: DS.attr(), + }) + ); + + var jsonHash = { + id: 1, + child: { + id: 1, + type: 'first_type', + }, + }; + + var Parent = env.store.modelFor('parent'); + var payload = env.store + .serializerFor('parent') + .normalizeResponse(env.store, Parent, jsonHash, '1', 'findRecord'); + assert.deepEqual(payload.included, [ + { + id: '1', + type: 'child', + attributes: { + type: 'first_type', + }, + relationships: {}, + }, + ]); +}); + +test('Serializer respects if embedded model has a relationship named "type" - #3726', function(assert) { + env.owner.register('serializer:child', DS.JSONSerializer); + env.owner.register( + 'serializer:parent', + DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, { + attrs: { + child: { embedded: 'always' }, + }, + }) + ); + env.owner.register( + 'model:parent', + DS.Model.extend({ + child: DS.belongsTo('child'), + }) + ); + env.owner.register( + 'model:child', + DS.Model.extend({ + type: DS.belongsTo('le-type'), + }) + ); + env.owner.register('model:le-type', DS.Model.extend()); + + var jsonHash = { + id: 1, + child: { + id: 1, + type: 'my_type_id', + }, + }; + + var Parent = env.store.modelFor('parent'); + var payload = env.store + .serializerFor('parent') + .normalizeResponse(env.store, Parent, jsonHash, '1', 'findRecord'); + assert.deepEqual(payload.included, [ + { + id: '1', + type: 'child', + attributes: {}, + relationships: { + type: { + data: { + id: 'my_type_id', + type: 'le-type', + }, + }, + }, + }, + ]); +}); + +test('Serializer respects `serialize: false` on the attrs hash', function(assert) { + assert.expect(2); + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + title: { serialize: false }, + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + let payload = env.store.serializerFor('post').serialize(post._createSnapshot()); + + assert.ok(!payload.hasOwnProperty('title'), 'Does not add the key to instance'); + assert.ok( + !payload.hasOwnProperty('[object Object]'), + 'Does not add some random key like [object Object]' + ); +}); + +test('Serializer respects `serialize: false` on the attrs hash for a `hasMany` property', function(assert) { + assert.expect(1); + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + comments: { serialize: false }, + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + + var serializer = env.store.serializerFor('post'); + var serializedProperty = serializer.keyForRelationship('comments', 'hasMany'); + + var payload = serializer.serialize(post._createSnapshot()); + assert.ok(!payload.hasOwnProperty(serializedProperty), 'Does not add the key to instance'); +}); + +test('Serializer respects `serialize: false` on the attrs hash for a `belongsTo` property', function(assert) { + assert.expect(1); + env.owner.register( + 'serializer:comment', + DS.JSONSerializer.extend({ + attrs: { + post: { serialize: false }, + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + + var serializer = env.store.serializerFor('comment'); + var serializedProperty = serializer.keyForRelationship('post', 'belongsTo'); + + var payload = serializer.serialize(comment._createSnapshot()); + assert.ok(!payload.hasOwnProperty(serializedProperty), 'Does not add the key to instance'); +}); + +test('Serializer respects `serialize: false` on the attrs hash for a `hasMany` property', function(assert) { + assert.expect(1); + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + comments: { serialize: false }, + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + + var serializer = env.store.serializerFor('post'); + var serializedProperty = serializer.keyForRelationship('comments', 'hasMany'); + + var payload = serializer.serialize(post._createSnapshot()); + assert.ok(!payload.hasOwnProperty(serializedProperty), 'Does not add the key to instance'); +}); + +test('Serializer respects `serialize: false` on the attrs hash for a `belongsTo` property', function(assert) { + assert.expect(1); + env.owner.register( + 'serializer:comment', + DS.JSONSerializer.extend({ + attrs: { + post: { serialize: false }, + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + + var serializer = env.store.serializerFor('comment'); + var serializedProperty = serializer.keyForRelationship('post', 'belongsTo'); + + var payload = serializer.serialize(comment._createSnapshot()); + assert.ok(!payload.hasOwnProperty(serializedProperty), 'Does not add the key to instance'); +}); + +test('Serializer respects `serialize: true` on the attrs hash for a `hasMany` property', function(assert) { + assert.expect(1); + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + comments: { serialize: true }, + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + + run(function() { + post.get('comments').pushObject(comment); + }); + + var serializer = env.store.serializerFor('post'); + var serializedProperty = serializer.keyForRelationship('comments', 'hasMany'); + + var payload = serializer.serialize(post._createSnapshot()); + assert.ok(payload.hasOwnProperty(serializedProperty), 'Add the key to instance'); +}); + +test('Serializer respects `serialize: true` on the attrs hash for a `belongsTo` property', function(assert) { + assert.expect(1); + env.owner.register( + 'serializer:comment', + DS.JSONSerializer.extend({ + attrs: { + post: { serialize: true }, + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Rails is omakase' }); + let comment = env.store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + + var serializer = env.store.serializerFor('comment'); + var serializedProperty = serializer.keyForRelationship('post', 'belongsTo'); + + var payload = serializer.serialize(comment._createSnapshot()); + assert.ok(payload.hasOwnProperty(serializedProperty), 'Add the key to instance'); +}); + +test('Serializer should merge attrs from superclasses', function(assert) { + assert.expect(4); + Post.reopen({ + description: DS.attr('string'), + anotherString: DS.attr('string'), + }); + var BaseSerializer = DS.JSONSerializer.extend({ + attrs: { + title: 'title_payload_key', + anotherString: 'base_another_string_key', + }, + }); + env.owner.register( + 'serializer:post', + BaseSerializer.extend({ + attrs: { + description: 'description_payload_key', + anotherString: 'overwritten_another_string_key', + }, + }) + ); + + let post = env.store.createRecord('post', { + title: 'Rails is omakase', + description: 'Omakase is delicious', + anotherString: 'yet another string', + }); + let payload = env.store.serializerFor('post').serialize(post._createSnapshot()); + + assert.equal(payload.title_payload_key, 'Rails is omakase'); + assert.equal(payload.description_payload_key, 'Omakase is delicious'); + assert.equal(payload.overwritten_another_string_key, 'yet another string'); + assert.ok(!payload.base_another_string_key, 'overwritten key is not added'); +}); + +test('Serializer should respect the primaryKey attribute when extracting records', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + primaryKey: '_ID_', + }) + ); + + let jsonHash = { _ID_: 1, title: 'Rails is omakase' }; + let post = env.store + .serializerFor('post') + .normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + + assert.equal(post.data.id, '1'); + assert.equal(post.data.attributes.title, 'Rails is omakase'); +}); + +test('Serializer should respect the primaryKey attribute when serializing records', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + primaryKey: '_ID_', + }) + ); + + let post = env.store.createRecord('post', { id: '1', title: 'Rails is omakase' }); + let payload = env.store + .serializerFor('post') + .serialize(post._createSnapshot(), { includeId: true }); + + assert.equal(payload._ID_, '1'); +}); + +test('Serializer should respect keyForAttribute when extracting records', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + keyForAttribute(key) { + return key.toUpperCase(); + }, + }) + ); + + let jsonHash = { id: 1, TITLE: 'Rails is omakase' }; + let post = env.store.serializerFor('post').normalize(Post, jsonHash); + + assert.equal(post.data.id, '1'); + assert.equal(post.data.attributes.title, 'Rails is omakase'); +}); + +test('Serializer should respect keyForRelationship when extracting records', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + keyForRelationship(key, type) { + return key.toUpperCase(); + }, + }) + ); + + let jsonHash = { id: 1, title: 'Rails is omakase', COMMENTS: ['1'] }; + let post = env.store.serializerFor('post').normalize(Post, jsonHash); + + assert.deepEqual(post.data.relationships.comments.data, [{ id: '1', type: 'comment' }]); +}); + +test('Calling normalize should normalize the payload (only the passed keys)', function(assert) { + assert.expect(1); + var Person = DS.Model.extend({ + posts: DS.hasMany('post', { async: false }), + }); + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + notInHash: 'aCustomAttrNotInHash', + inHash: 'aCustomAttrInHash', + }, + }) + ); + + env.owner.register('model:person', Person); + + Post.reopen({ + content: DS.attr('string'), + author: DS.belongsTo('person', { async: false }), + notInHash: DS.attr('string'), + inHash: DS.attr('string'), + }); + + var normalizedPayload = env.store.serializerFor('post').normalize(Post, { + id: '1', + title: 'Ember rocks', + author: 1, + aCustomAttrInHash: 'blah', + }); + + assert.deepEqual(normalizedPayload, { + data: { + id: '1', + type: 'post', + attributes: { + inHash: 'blah', + title: 'Ember rocks', + }, + relationships: { + author: { + data: { id: '1', type: 'person' }, + }, + }, + }, + }); +}); + +test('serializeBelongsTo with async polymorphic', function(assert) { + var json = {}; + var expected = { post: '1', postTYPE: 'post' }; + + env.owner.register( + 'serializer:favorite', + DS.JSONSerializer.extend({ + serializePolymorphicType(snapshot, json, relationship) { + var key = relationship.key; + json[key + 'TYPE'] = snapshot.belongsTo(key).modelName; + }, + }) + ); + + let post = env.store.createRecord('post', { title: 'Kitties are omakase', id: '1' }); + let favorite = env.store.createRecord('favorite', { post: post, id: '3' }); + + env.store.serializerFor('favorite').serializeBelongsTo(favorite._createSnapshot(), json, { + key: 'post', + options: { polymorphic: true, async: true }, + }); + + assert.deepEqual(json, expected, 'returned JSON is correct'); +}); + +test('extractErrors respects custom key mappings', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + title: 'le_title', + comments: { key: 'my_comments' }, + }, + }) + ); + + var payload = { + errors: [ + { + source: { pointer: 'data/attributes/le_title' }, + detail: 'title errors', + }, + { + source: { pointer: 'data/attributes/my_comments' }, + detail: 'comments errors', + }, + ], + }; + + var errors = env.store.serializerFor('post').extractErrors(env.store, Post, payload); + + assert.deepEqual(errors, { + title: ['title errors'], + comments: ['comments errors'], + }); +}); + +test('extractErrors expects error information located on the errors property of payload', function(assert) { + env.owner.register('serializer:post', DS.JSONSerializer.extend()); + + var payload = { + attributeWhichWillBeRemovedinExtractErrors: ['true'], + errors: [ + { + source: { pointer: 'data/attributes/title' }, + detail: 'title errors', + }, + ], + }; + + var errors = env.store.serializerFor('post').extractErrors(env.store, Post, payload); + + assert.deepEqual(errors, { title: ['title errors'] }); +}); + +test('extractErrors leaves payload untouched if it has no errors property', function(assert) { + env.owner.register('serializer:post', DS.JSONSerializer.extend()); + + var payload = { + untouchedSinceNoErrorsSiblingPresent: ['true'], + }; + + var errors = env.store.serializerFor('post').extractErrors(env.store, Post, payload); + + assert.deepEqual(errors, { untouchedSinceNoErrorsSiblingPresent: ['true'] }); +}); + +test('normalizeResponse should extract meta using extractMeta', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + extractMeta(store, modelClass, payload) { + let meta = this._super(...arguments); + meta.authors.push('Tomhuda'); + return meta; + }, + }) + ); + + var jsonHash = { + id: '1', + title_payload_key: 'Rails is omakase', + my_comments: [1, 2], + meta: { + authors: ['Tomster'], + }, + }; + + var post = env.store + .serializerFor('post') + .normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + + assert.deepEqual(post.meta.authors, ['Tomster', 'Tomhuda']); +}); + +test('normalizeResponse returns empty `included` payload by default', function(assert) { + env.owner.register('serializer:post', DS.JSONSerializer.extend()); + + var jsonHash = { + id: '1', + title: 'Rails is omakase', + }; + + var post = env.store + .serializerFor('post') + .normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + + assert.deepEqual(post.included, []); +}); + +test('normalizeResponse returns empty `included` payload when relationship is undefined', function(assert) { + env.owner.register('serializer:post', DS.JSONSerializer.extend()); + + var jsonHash = { + id: '1', + title: 'Rails is omakase', + comments: null, + }; + + var post = env.store + .serializerFor('post') + .normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + + assert.deepEqual(post.included, []); +}); + +test('normalizeResponse respects `included` items (single response)', function(assert) { + env.owner.register('serializer:comment', DS.JSONSerializer); + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, { + attrs: { + comments: { embedded: 'always' }, + }, + }) + ); + + var jsonHash = { + id: '1', + title: 'Rails is omakase', + comments: [{ id: '1', body: 'comment 1' }, { id: '2', body: 'comment 2' }], + }; + + var post = env.store + .serializerFor('post') + .normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + + assert.deepEqual(post.included, [ + { id: '1', type: 'comment', attributes: { body: 'comment 1' }, relationships: {} }, + { id: '2', type: 'comment', attributes: { body: 'comment 2' }, relationships: {} }, + ]); +}); + +test('normalizeResponse respects `included` items (array response)', function(assert) { + env.owner.register('serializer:comment', DS.JSONSerializer); + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, { + attrs: { + comments: { embedded: 'always' }, + }, + }) + ); + + var payload = [ + { + id: '1', + title: 'Rails is omakase', + comments: [{ id: '1', body: 'comment 1' }], + }, + { + id: '2', + title: 'Post 2', + comments: [{ id: '2', body: 'comment 2' }, { id: '3', body: 'comment 3' }], + }, + ]; + + var post = env.store + .serializerFor('post') + .normalizeResponse(env.store, Post, payload, '1', 'findAll'); + + assert.deepEqual(post.included, [ + { id: '1', type: 'comment', attributes: { body: 'comment 1' }, relationships: {} }, + { id: '2', type: 'comment', attributes: { body: 'comment 2' }, relationships: {} }, + { id: '3', type: 'comment', attributes: { body: 'comment 3' }, relationships: {} }, + ]); +}); + +testInDebug('normalizeResponse ignores unmapped attributes', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + title: { serialize: false }, + notInMapping: { serialize: false }, + }, + }) + ); + + var jsonHash = { + id: '1', + notInMapping: 'I should be ignored', + title: 'Rails is omakase', + }; + + assert.expectWarning(function() { + var post = env.store + .serializerFor('post') + .normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + assert.equal(post.data.attributes.title, 'Rails is omakase'); + }, /There is no attribute or relationship with the name/); +}); + +test('options are passed to transform for serialization', function(assert) { + assert.expect(1); + + env.owner.register( + 'transform:custom', + DS.Transform.extend({ + serialize: function(deserialized, options) { + assert.deepEqual(options, { custom: 'config' }); + }, + }) + ); + + Post.reopen({ + custom: DS.attr('custom', { + custom: 'config', + }), + }); + + let post = env.store.createRecord('post', { custom: 'value' }); + + serializer.serialize(post._createSnapshot()); +}); + +test('options are passed to transform for normalization', function(assert) { + assert.expect(1); + + env.owner.register( + 'transform:custom', + DS.Transform.extend({ + deserialize: function(serialized, options) { + assert.deepEqual(options, { custom: 'config' }); + }, + }) + ); + + Post.reopen({ + custom: DS.attr('custom', { + custom: 'config', + }), + }); + + serializer.normalize(Post, { + custom: 'value', + }); +}); + +test('Serializer should respect the attrs hash in links', function(assert) { + env.owner.register( + 'serializer:post', + DS.JSONSerializer.extend({ + attrs: { + title: 'title_payload_key', + comments: { key: 'my_comments' }, + }, + }) + ); + + var jsonHash = { + title_payload_key: 'Rails is omakase', + links: { + my_comments: 'posts/1/comments', + }, + }; + + var post = env.container + .lookup('serializer:post') + .normalizeSingleResponse(env.store, Post, jsonHash); + + assert.equal(post.data.attributes.title, 'Rails is omakase'); + assert.equal(post.data.relationships.comments.links.related, 'posts/1/comments'); +}); diff --git a/tests/integration/serializers/rest-serializer-test.js b/tests/integration/serializers/rest-serializer-test.js new file mode 100644 index 00000000000..73aaa907c83 --- /dev/null +++ b/tests/integration/serializers/rest-serializer-test.js @@ -0,0 +1,947 @@ +import { camelize, decamelize, dasherize } from '@ember/string'; +import Inflector, { singularize } from 'ember-inflector'; +import { run, bind } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; + +let HomePlanet, + SuperVillain, + EvilMinion, + YellowMinion, + DoomsdayDevice, + Comment, + Basket, + Container, + env; + +module('integration/serializer/rest - RESTSerializer', { + beforeEach() { + HomePlanet = DS.Model.extend({ + name: DS.attr('string'), + superVillains: DS.hasMany('super-villain', { async: false }), + }); + SuperVillain = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + homePlanet: DS.belongsTo('home-planet', { async: false }), + evilMinions: DS.hasMany('evil-minion', { async: false }), + }); + EvilMinion = DS.Model.extend({ + superVillain: DS.belongsTo('super-villain', { async: false }), + name: DS.attr('string'), + doomsdayDevice: DS.belongsTo('doomsday-device', { async: false }), + }); + YellowMinion = EvilMinion.extend({ + eyes: DS.attr('number'), + }); + DoomsdayDevice = DS.Model.extend({ + name: DS.attr('string'), + evilMinion: DS.belongsTo('evil-minion', { polymorphic: true, async: true }), + }); + Comment = DS.Model.extend({ + body: DS.attr('string'), + root: DS.attr('boolean'), + children: DS.hasMany('comment', { inverse: null, async: false }), + }); + Basket = DS.Model.extend({ + type: DS.attr('string'), + size: DS.attr('number'), + }); + Container = DS.Model.extend({ + type: DS.belongsTo('basket', { async: true }), + volume: DS.attr('string'), + }); + env = setupStore({ + superVillain: SuperVillain, + homePlanet: HomePlanet, + evilMinion: EvilMinion, + yellowMinion: YellowMinion, + doomsdayDevice: DoomsdayDevice, + comment: Comment, + basket: Basket, + container: Container, + }); + env.store.modelFor('super-villain'); + env.store.modelFor('home-planet'); + env.store.modelFor('evil-minion'); + env.store.modelFor('yellow-minion'); + env.store.modelFor('doomsday-device'); + env.store.modelFor('comment'); + env.store.modelFor('basket'); + env.store.modelFor('container'); + }, + + afterEach() { + run(env.store, 'destroy'); + }, +}); + +test('modelNameFromPayloadKey returns always same modelName even for uncountable multi words keys', function(assert) { + assert.expect(2); + Inflector.inflector.uncountable('words'); + var expectedModelName = 'multi-words'; + assert.equal(env.restSerializer.modelNameFromPayloadKey('multi_words'), expectedModelName); + assert.equal(env.restSerializer.modelNameFromPayloadKey('multi-words'), expectedModelName); +}); + +test('normalizeResponse should extract meta using extractMeta', function(assert) { + env.owner.register( + 'serializer:home-planet', + DS.RESTSerializer.extend({ + extractMeta(store, modelClass, payload) { + let meta = this._super(...arguments); + meta.authors.push('Tomhuda'); + return meta; + }, + }) + ); + + var jsonHash = { + meta: { authors: ['Tomster'] }, + home_planets: [{ id: '1', name: 'Umber', superVillains: [1] }], + }; + + var json = env.container + .lookup('serializer:home-planet') + .normalizeResponse(env.store, HomePlanet, jsonHash, null, 'findAll'); + + assert.deepEqual(json.meta.authors, ['Tomster', 'Tomhuda']); +}); + +test('normalizeResponse with custom modelNameFromPayloadKey', function(assert) { + assert.expect(1); + + env.restSerializer.modelNameFromPayloadKey = function(root) { + var camelized = camelize(root); + return singularize(camelized); + }; + env.owner.register('serializer:home-planet', DS.JSONSerializer); + env.owner.register('serializer:super-villain', DS.JSONSerializer); + + var jsonHash = { + home_planets: [ + { + id: '1', + name: 'Umber', + superVillains: [1], + }, + ], + super_villains: [ + { + id: '1', + firstName: 'Tom', + lastName: 'Dale', + homePlanet: '1', + }, + ], + }; + var array; + + run(function() { + array = env.restSerializer.normalizeResponse( + env.store, + HomePlanet, + jsonHash, + '1', + 'findRecord' + ); + }); + + assert.deepEqual(array, { + data: { + id: '1', + type: 'home-planet', + attributes: { + name: 'Umber', + }, + relationships: { + superVillains: { + data: [{ id: '1', type: 'super-villain' }], + }, + }, + }, + included: [ + { + id: '1', + type: 'super-villain', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + relationships: { + homePlanet: { + data: { id: '1', type: 'home-planet' }, + }, + }, + }, + ], + }); +}); + +testInDebug('normalizeResponse with type and custom modelNameFromPayloadKey', function(assert) { + assert.expect(2); + + var homePlanetNormalizeCount = 0; + + env.restSerializer.modelNameFromPayloadKey = function(root) { + return 'home-planet'; + }; + + env.owner.register( + 'serializer:home-planet', + DS.RESTSerializer.extend({ + normalize() { + homePlanetNormalizeCount++; + return this._super.apply(this, arguments); + }, + }) + ); + + var jsonHash = { + 'my-custom-type': [{ id: '1', name: 'Umber', type: 'my-custom-type' }], + }; + var array; + + run(function() { + array = env.restSerializer.normalizeResponse(env.store, HomePlanet, jsonHash, '1', 'findAll'); + }); + + assert.deepEqual(array, { + data: [ + { + id: '1', + type: 'home-planet', + attributes: { + name: 'Umber', + }, + relationships: {}, + }, + ], + included: [], + }); + assert.equal(homePlanetNormalizeCount, 1, 'homePlanet is normalized once'); +}); + +testInDebug('normalizeResponse warning with custom modelNameFromPayloadKey', function(assert) { + var homePlanet; + var oldModelNameFromPayloadKey = env.restSerializer.modelNameFromPayloadKey; + env.owner.register('serializer:super-villain', DS.JSONSerializer); + env.owner.register('serializer:home-planet', DS.JSONSerializer); + env.restSerializer.modelNameFromPayloadKey = function(root) { + //return some garbage that won"t resolve in the container + return 'garbage'; + }; + + var jsonHash = { + home_planet: { id: '1', name: 'Umber', superVillains: [1] }, + }; + + assert.expectWarning( + bind(null, function() { + run(function() { + env.restSerializer.normalizeResponse(env.store, HomePlanet, jsonHash, '1', 'findRecord'); + }); + }), + /Encountered "home_planet" in payload, but no model was found for model name "garbage"/ + ); + + // should not warn if a model is found. + env.restSerializer.modelNameFromPayloadKey = oldModelNameFromPayloadKey; + jsonHash = { + home_planet: { id: '1', name: 'Umber', superVillains: [1] }, + }; + + assert.expectNoWarning(function() { + run(function() { + homePlanet = env.restSerializer.normalizeResponse( + env.store, + HomePlanet, + jsonHash, + 1, + 'findRecord' + ); + }); + }); + + assert.equal(homePlanet.data.attributes.name, 'Umber'); + assert.deepEqual(homePlanet.data.relationships.superVillains.data, [ + { id: '1', type: 'super-villain' }, + ]); +}); + +testInDebug('normalizeResponse warning with custom modelNameFromPayloadKey', function(assert) { + var homePlanets; + env.owner.register('serializer:super-villain', DS.JSONSerializer); + env.owner.register('serializer:home-planet', DS.JSONSerializer); + env.restSerializer.modelNameFromPayloadKey = function(root) { + //return some garbage that won"t resolve in the container + return 'garbage'; + }; + + var jsonHash = { + home_planets: [{ id: '1', name: 'Umber', superVillains: [1] }], + }; + + assert.expectWarning(function() { + env.restSerializer.normalizeResponse(env.store, HomePlanet, jsonHash, null, 'findAll'); + }, /Encountered "home_planets" in payload, but no model was found for model name "garbage"/); + + // should not warn if a model is found. + env.restSerializer.modelNameFromPayloadKey = function(root) { + return camelize(singularize(root)); + }; + + jsonHash = { + home_planets: [{ id: '1', name: 'Umber', superVillains: [1] }], + }; + + assert.expectNoWarning(function() { + run(function() { + homePlanets = env.restSerializer.normalizeResponse( + env.store, + HomePlanet, + jsonHash, + null, + 'findAll' + ); + }); + }); + + assert.equal(homePlanets.data.length, 1); + assert.equal(homePlanets.data[0].attributes.name, 'Umber'); + assert.deepEqual(homePlanets.data[0].relationships.superVillains.data, [ + { id: '1', type: 'super-villain' }, + ]); +}); + +test('serialize polymorphicType', function(assert) { + let tom = env.store.createRecord('yellow-minion', { name: 'Alex', id: '124' }); + let ray = env.store.createRecord('doomsday-device', { evilMinion: tom, name: 'DeathRay' }); + let json = env.restSerializer.serialize(ray._createSnapshot()); + + assert.deepEqual(json, { + name: 'DeathRay', + evilMinionType: 'yellowMinion', + evilMinion: '124', + }); +}); + +test('serialize polymorphicType with decamelized modelName', function(assert) { + let tom = env.store.createRecord('yellow-minion', { name: 'Alex', id: '124' }); + let ray = env.store.createRecord('doomsday-device', { evilMinion: tom, name: 'DeathRay' }); + let json = env.restSerializer.serialize(ray._createSnapshot()); + + assert.deepEqual(json['evilMinionType'], 'yellowMinion'); +}); + +test('serialize polymorphic when associated object is null', function(assert) { + let ray = env.store.createRecord('doomsday-device', { name: 'DeathRay' }); + let json = env.restSerializer.serialize(ray._createSnapshot()); + + assert.deepEqual(json['evilMinionType'], null); +}); + +test('normalizeResponse loads secondary records with correct serializer', function(assert) { + var superVillainNormalizeCount = 0; + + env.owner.register('serializer:evil-minion', DS.JSONSerializer); + env.owner.register( + 'serializer:super-villain', + DS.RESTSerializer.extend({ + normalize() { + superVillainNormalizeCount++; + return this._super.apply(this, arguments); + }, + }) + ); + + var jsonHash = { + evilMinion: { id: '1', name: 'Tom Dale', superVillain: 1 }, + superVillains: [{ id: '1', firstName: 'Yehuda', lastName: 'Katz', homePlanet: '1' }], + }; + + run(function() { + env.restSerializer.normalizeResponse(env.store, EvilMinion, jsonHash, '1', 'findRecord'); + }); + + assert.equal(superVillainNormalizeCount, 1, 'superVillain is normalized once'); +}); + +test('normalizeResponse returns null if payload contains null', function(assert) { + assert.expect(1); + + var jsonHash = { + evilMinion: null, + }; + var value; + + run(function() { + value = env.restSerializer.normalizeResponse( + env.store, + EvilMinion, + jsonHash, + null, + 'findRecord' + ); + }); + + assert.deepEqual(value, { data: null, included: [] }, 'returned value is null'); +}); + +test('normalizeResponse loads secondary records with correct serializer', function(assert) { + var superVillainNormalizeCount = 0; + + env.owner.register('serializer:evil-minion', DS.JSONSerializer); + env.owner.register( + 'serializer:super-villain', + DS.RESTSerializer.extend({ + normalize() { + superVillainNormalizeCount++; + return this._super.apply(this, arguments); + }, + }) + ); + + var jsonHash = { + evilMinions: [{ id: '1', name: 'Tom Dale', superVillain: 1 }], + superVillains: [{ id: '1', firstName: 'Yehuda', lastName: 'Katz', homePlanet: '1' }], + }; + + run(function() { + env.restSerializer.normalizeResponse(env.store, EvilMinion, jsonHash, null, 'findAll'); + }); + + assert.equal(superVillainNormalizeCount, 1, 'superVillain is normalized once'); +}); + +test('normalize should allow for different levels of normalization', function(assert) { + env.owner.register( + 'serializer:application', + DS.RESTSerializer.extend({ + attrs: { + superVillain: 'is_super_villain', + }, + keyForAttribute(attr) { + return decamelize(attr); + }, + }) + ); + + var jsonHash = { + evilMinions: [{ id: '1', name: 'Tom Dale', is_super_villain: 1 }], + }; + var array; + + run(function() { + array = env.restSerializer.normalizeResponse(env.store, EvilMinion, jsonHash, null, 'findAll'); + }); + + assert.equal(array.data[0].relationships.superVillain.data.id, 1); +}); + +test('normalize should allow for different levels of normalization - attributes', function(assert) { + env.owner.register( + 'serializer:application', + DS.RESTSerializer.extend({ + attrs: { + name: 'full_name', + }, + keyForAttribute(attr) { + return decamelize(attr); + }, + }) + ); + + var jsonHash = { + evilMinions: [{ id: '1', full_name: 'Tom Dale' }], + }; + var array; + + run(function() { + array = env.restSerializer.normalizeResponse(env.store, EvilMinion, jsonHash, null, 'findAll'); + }); + + assert.equal(array.data[0].attributes.name, 'Tom Dale'); +}); + +test('serializeIntoHash', function(assert) { + let league = env.store.createRecord('home-planet', { name: 'Umber', id: '123' }); + let json = {}; + + env.restSerializer.serializeIntoHash(json, HomePlanet, league._createSnapshot()); + + assert.deepEqual(json, { + homePlanet: { + name: 'Umber', + }, + }); +}); + +test('serializeIntoHash with decamelized modelName', function(assert) { + let league = env.store.createRecord('home-planet', { name: 'Umber', id: '123' }); + let json = {}; + + env.restSerializer.serializeIntoHash(json, HomePlanet, league._createSnapshot()); + + assert.deepEqual(json, { + homePlanet: { + name: 'Umber', + }, + }); +}); + +test('serializeBelongsTo with async polymorphic', function(assert) { + let json = {}; + let expected = { evilMinion: '1', evilMinionType: 'evilMinion' }; + let evilMinion = env.store.createRecord('evil-minion', { id: 1, name: 'Tomster' }); + let doomsdayDevice = env.store.createRecord('doomsday-device', { + id: 2, + name: 'Yehuda', + evilMinion: evilMinion, + }); + + env.restSerializer.serializeBelongsTo(doomsdayDevice._createSnapshot(), json, { + key: 'evilMinion', + options: { polymorphic: true, async: true }, + }); + + assert.deepEqual(json, expected, 'returned JSON is correct'); +}); + +test('keyForPolymorphicType can be used to overwrite how the type of a polymorphic record is serialized', function(assert) { + let json = {}; + let expected = { evilMinion: '1', typeForEvilMinion: 'evilMinion' }; + + env.restSerializer.keyForPolymorphicType = function() { + return 'typeForEvilMinion'; + }; + + let evilMinion = env.store.createRecord('evil-minion', { id: 1, name: 'Tomster' }); + let doomsdayDevice = env.store.createRecord('doomsday-device', { + id: 2, + name: 'Yehuda', + evilMinion: evilMinion, + }); + + env.restSerializer.serializeBelongsTo(doomsdayDevice._createSnapshot(), json, { + key: 'evilMinion', + options: { polymorphic: true, async: true }, + }); + + assert.deepEqual(json, expected, 'returned JSON is correct'); +}); + +test('keyForPolymorphicType can be used to overwrite how the type of a polymorphic record is looked up for normalization', function(assert) { + var json = { + doomsdayDevice: { + id: '1', + evilMinion: '2', + typeForEvilMinion: 'evilMinion', + }, + }; + + var expected = { + data: { + type: 'doomsday-device', + id: '1', + attributes: {}, + relationships: { + evilMinion: { + data: { + type: 'evil-minion', + id: '2', + }, + }, + }, + }, + included: [], + }; + + env.restSerializer.keyForPolymorphicType = function() { + return 'typeForEvilMinion'; + }; + + var normalized = env.restSerializer.normalizeResponse( + env.store, + DoomsdayDevice, + json, + null, + 'findRecord' + ); + + assert.deepEqual(normalized, expected, 'normalized JSON is correct'); +}); + +test('serializeIntoHash uses payloadKeyFromModelName to normalize the payload root key', function(assert) { + let league = env.store.createRecord('home-planet', { name: 'Umber', id: '123' }); + let json = {}; + + env.owner.register( + 'serializer:home-planet', + DS.RESTSerializer.extend({ + payloadKeyFromModelName(modelName) { + return dasherize(modelName); + }, + }) + ); + + let serializer = env.store.serializerFor('home-planet'); + + serializer.serializeIntoHash(json, HomePlanet, league._createSnapshot()); + + assert.deepEqual(json, { + 'home-planet': { + name: 'Umber', + }, + }); +}); + +test('normalizeResponse with async polymorphic belongsTo, using Type', function(assert) { + env.owner.register('serializer:application', DS.RESTSerializer.extend()); + var store = env.store; + env.adapter.findRecord = (store, type) => { + if (type.modelName === 'doomsday-device') { + return { + doomsdayDevice: { + id: 1, + name: 'DeathRay', + evilMinion: 1, + evilMinionType: 'yellowMinion', + }, + }; + } + + assert.equal(type.modelName, 'yellow-minion'); + + return { + yellowMinion: { + id: 1, + type: 'yellowMinion', + name: 'Alex', + eyes: 3, + }, + }; + }; + + run(function() { + store + .findRecord('doomsday-device', 1) + .then(deathRay => { + return deathRay.get('evilMinion'); + }) + .then(evilMinion => { + assert.equal(evilMinion.get('eyes'), 3); + }); + }); +}); + +test('normalizeResponse with async polymorphic belongsTo', function(assert) { + env.owner.register('serializer:application', DS.RESTSerializer.extend()); + var store = env.store; + env.adapter.findRecord = () => { + return { + doomsdayDevices: [ + { + id: 1, + name: 'DeathRay', + links: { + evilMinion: '/doomsday-device/1/evil-minion', + }, + }, + ], + }; + }; + + env.adapter.findBelongsTo = () => { + return { + evilMinion: { + id: 1, + type: 'yellowMinion', + name: 'Alex', + eyes: 3, + }, + }; + }; + run(function() { + store + .findRecord('doomsday-device', 1) + .then(deathRay => { + return deathRay.get('evilMinion'); + }) + .then(evilMinion => { + assert.equal(evilMinion.get('eyes'), 3); + }); + }); +}); + +test('normalizeResponse with async polymorphic hasMany', function(assert) { + SuperVillain.reopen({ + evilMinions: DS.hasMany('evil-minion', { async: true, polymorphic: true }), + }); + env.owner.register('serializer:application', DS.RESTSerializer.extend()); + var store = env.store; + env.adapter.findRecord = () => { + return { + superVillains: [ + { + id: '1', + firstName: 'Yehuda', + lastName: 'Katz', + links: { + evilMinions: '/super-villain/1/evil-minions', + }, + }, + ], + }; + }; + + env.adapter.findHasMany = () => { + return { + evilMinion: [ + { + id: 1, + type: 'yellowMinion', + name: 'Alex', + eyes: 3, + }, + ], + }; + }; + run(function() { + store + .findRecord('super-villain', 1) + .then(superVillain => { + return superVillain.get('evilMinions'); + }) + .then(evilMinions => { + assert.ok(evilMinions.get('firstObject') instanceof YellowMinion); + assert.equal(evilMinions.get('firstObject.eyes'), 3); + }); + }); +}); + +test('normalizeResponse can load secondary records of the same type without affecting the query count', function(assert) { + var jsonHash = { + comments: [{ id: '1', body: 'Parent Comment', root: true, children: [2, 3] }], + _comments: [ + { id: '2', body: 'Child Comment 1', root: false }, + { id: '3', body: 'Child Comment 2', root: false }, + ], + }; + var array; + env.owner.register('serializer:comment', DS.JSONSerializer); + + run(function() { + array = env.restSerializer.normalizeResponse(env.store, Comment, jsonHash, '1', 'findRecord'); + }); + + assert.deepEqual(array, { + data: { + id: '1', + type: 'comment', + attributes: { + body: 'Parent Comment', + root: true, + }, + relationships: { + children: { + data: [{ id: '2', type: 'comment' }, { id: '3', type: 'comment' }], + }, + }, + }, + included: [ + { + id: '2', + type: 'comment', + attributes: { + body: 'Child Comment 1', + root: false, + }, + relationships: {}, + }, + { + id: '3', + type: 'comment', + attributes: { + body: 'Child Comment 2', + root: false, + }, + relationships: {}, + }, + ], + }); +}); + +test("don't polymorphically deserialize base on the type key in payload when a type attribute exist", function(assert) { + env.owner.register('serializer:application', DS.RESTSerializer.extend()); + + run(function() { + env.store.push( + env.restSerializer.normalizeArrayResponse(env.store, Basket, { + basket: [ + { type: 'bamboo', size: 10, id: '1' }, + { type: 'yellowMinion', size: 10, id: '65536' }, + ], + }) + ); + }); + + const normalRecord = env.store.peekRecord('basket', '1'); + assert.ok(normalRecord, "payload with type that doesn't exist"); + assert.strictEqual(normalRecord.get('type'), 'bamboo'); + assert.strictEqual(normalRecord.get('size'), 10); + + const clashingRecord = env.store.peekRecord('basket', '65536'); + assert.ok(clashingRecord, 'payload with type that matches another model name'); + assert.strictEqual(clashingRecord.get('type'), 'yellowMinion'); + assert.strictEqual(clashingRecord.get('size'), 10); +}); + +test("don't polymorphically deserialize base on the type key in payload when a type attribute exist on a singular response", function(assert) { + env.owner.register('serializer:application', DS.RESTSerializer.extend()); + + run(function() { + env.store.push( + env.restSerializer.normalizeSingleResponse( + env.store, + Basket, + { + basket: { type: 'yellowMinion', size: 10, id: '65536' }, + }, + '65536' + ) + ); + }); + + const clashingRecord = env.store.peekRecord('basket', '65536'); + assert.ok(clashingRecord, 'payload with type that matches another model name'); + assert.strictEqual(clashingRecord.get('type'), 'yellowMinion'); + assert.strictEqual(clashingRecord.get('size'), 10); +}); + +test("don't polymorphically deserialize based on the type key in payload when a relationship exists named type", function(assert) { + env.owner.register('serializer:application', DS.RESTSerializer.extend()); + + env.adapter.findRecord = () => { + return { + containers: [{ id: 42, volume: '10 liters', type: 1 }], + baskets: [{ id: 1, size: 4 }], + }; + }; + + run(function() { + env.store + .findRecord('container', 42) + .then(container => { + assert.strictEqual(container.get('volume'), '10 liters'); + return container.get('type'); + }) + .then(basket => { + assert.ok(basket instanceof Basket); + assert.equal(basket.get('size'), 4); + }); + }); +}); + +test('Serializer should respect the attrs hash in links', function(assert) { + env.owner.register( + 'serializer:super-villain', + DS.RESTSerializer.extend({ + attrs: { + evilMinions: { key: 'my_minions' }, + }, + }) + ); + + var jsonHash = { + 'super-villains': [ + { + firstName: 'Tom', + lastName: 'Dale', + links: { + my_minions: 'me/minions', + }, + }, + ], + }; + + var documentHash = env.container + .lookup('serializer:super-villain') + .normalizeSingleResponse(env.store, SuperVillain, jsonHash); + + assert.equal(documentHash.data.relationships.evilMinions.links.related, 'me/minions'); +}); + +// https://github.com/emberjs/data/issues/3805 +test('normalizes sideloaded single record so that it sideloads correctly - belongsTo - GH-3805', function(assert) { + env.owner.register('serializer:evil-minion', DS.JSONSerializer); + env.owner.register('serializer:doomsday-device', DS.RESTSerializer.extend()); + let payload = { + doomsdayDevice: { + id: 1, + evilMinion: 2, + }, + evilMinion: { + id: 2, + doomsdayDevice: 1, + }, + }; + + let document = env.store + .serializerFor('doomsday-device') + .normalizeSingleResponse(env.store, DoomsdayDevice, payload); + assert.equal(document.data.relationships.evilMinion.data.id, 2); + assert.equal(document.included.length, 1); + assert.deepEqual(document.included[0], { + attributes: {}, + id: '2', + type: 'evil-minion', + relationships: { + doomsdayDevice: { + data: { + id: '1', + type: 'doomsday-device', + }, + }, + }, + }); +}); + +// https://github.com/emberjs/data/issues/3805 +test('normalizes sideloaded single record so that it sideloads correctly - hasMany - GH-3805', function(assert) { + env.owner.register('serializer:super-villain', DS.JSONSerializer); + env.owner.register('serializer:home-planet', DS.RESTSerializer.extend()); + let payload = { + homePlanet: { + id: 1, + superVillains: [2], + }, + superVillain: { + id: 2, + homePlanet: 1, + }, + }; + + let document = env.store + .serializerFor('home-planet') + .normalizeSingleResponse(env.store, HomePlanet, payload); + + assert.equal(document.data.relationships.superVillains.data.length, 1); + assert.equal(document.data.relationships.superVillains.data[0].id, 2); + assert.equal(document.included.length, 1); + assert.deepEqual(document.included[0], { + attributes: {}, + id: '2', + type: 'super-villain', + relationships: { + homePlanet: { + data: { + id: '1', + type: 'home-planet', + }, + }, + }, + }); +}); diff --git a/tests/integration/snapshot-test.js b/tests/integration/snapshot-test.js new file mode 100644 index 00000000000..5513e86c5e8 --- /dev/null +++ b/tests/integration/snapshot-test.js @@ -0,0 +1,1235 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; +const { Model, attr, hasMany, belongsTo, Snapshot } = DS; + +let env, Post, Comment; + +module('integration/snapshot - Snapshot', { + beforeEach() { + Post = Model.extend({ + author: attr(), + title: attr(), + comments: hasMany({ async: true }), + }); + Comment = Model.extend({ + body: attr(), + post: belongsTo({ async: true }), + }); + + env = setupStore({ + post: Post, + comment: Comment, + }); + }, + + afterEach() { + run(() => { + env.store.destroy(); + }); + }, +}); + +test('snapshot.attributes() includes defaultValues when appropriate', function(assert) { + const Address = Model.extend({ + street: attr(), + country: attr({ defaultValue: 'USA' }), + state: attr({ defaultValue: () => 'CA' }), + }); + + let { store } = setupStore({ + address: Address, + }); + let newAddress = store.createRecord('address', {}); + let snapshot = newAddress._createSnapshot(); + let expected = { + country: 'USA', + state: 'CA', + street: undefined, + }; + + assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); + assert.deepEqual(snapshot.attributes(), expected, 'We generated attributes with default values'); + + run(() => store.destroy()); +}); + +test('record._createSnapshot() returns a snapshot', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); + }); +}); + +test('snapshot.id, snapshot.type and snapshot.modelName returns correctly', function(assert) { + assert.expect(3); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + assert.equal(snapshot.id, '1', 'id is correct'); + assert.ok(Model.detect(snapshot.type), 'type is correct'); + assert.equal(snapshot.modelName, 'post', 'modelName is correct'); + }); +}); + +test('snapshot.type loads the class lazily', function(assert) { + assert.expect(3); + + let postClassLoaded = false; + let modelFactoryFor = env.store._modelFactoryFor; + env.store._modelFactoryFor = name => { + if (name === 'post') { + postClassLoaded = true; + } + return modelFactoryFor.call(env.store, name); + }; + + run(() => { + env.store._push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let postInternalModel = env.store._internalModelForId('post', 1); + let snapshot = postInternalModel.createSnapshot(); + + assert.equal(false, postClassLoaded, 'model class is not eagerly loaded'); + assert.equal(snapshot.type, Post, 'type is correct'); + assert.equal(true, postClassLoaded, 'model class is loaded'); + }); +}); + +test('an initial findRecord call has no record for internal-model when a snapshot is generated', function(assert) { + assert.expect(2); + env.adapter.findRecord = (store, type, id, snapshot) => { + assert.equal(snapshot._internalModel.hasRecord, false, 'We do not have a materialized record'); + assert.equal(snapshot.__attributes, null, 'attributes were not populated initially'); + return resolve({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + }; + + run(() => env.store.findRecord('post', '1')); +}); + +test('snapshots for un-materialized internal-models generate attributes lazily', function(assert) { + assert.expect(2); + + run(() => + env.store._push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }) + ); + + let postInternalModel = env.store._internalModelForId('post', 1); + let snapshot = postInternalModel.createSnapshot(); + let expected = { + author: undefined, + title: 'Hello World', + }; + + assert.equal(snapshot.__attributes, null, 'attributes were not populated initially'); + snapshot.attributes(); + assert.deepEqual(snapshot.__attributes, expected, 'attributes were populated on access'); +}); + +test('snapshots for materialized internal-models generate attributes greedily', function(assert) { + assert.expect(1); + + run(() => + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }) + ); + + let postInternalModel = env.store._internalModelForId('post', 1); + let snapshot = postInternalModel.createSnapshot(); + let expected = { + author: undefined, + title: 'Hello World', + }; + + assert.deepEqual(snapshot.__attributes, expected, 'attributes were populated initially'); +}); + +test('snapshot.attr() does not change when record changes', function(assert) { + assert.expect(2); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + assert.equal(snapshot.attr('title'), 'Hello World', 'snapshot title is correct'); + post.set('title', 'Tomster'); + assert.equal(snapshot.attr('title'), 'Hello World', 'snapshot title is still correct'); + }); +}); + +test('snapshot.attr() throws an error attribute not found', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + assert.throws( + () => { + snapshot.attr('unknown'); + }, + /has no attribute named 'unknown' defined/, + 'attr throws error' + ); + }); +}); + +test('snapshot.attributes() returns a copy of all attributes for the current snapshot', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + let attributes = snapshot.attributes(); + + assert.deepEqual( + attributes, + { author: undefined, title: 'Hello World' }, + 'attributes are returned correctly' + ); + }); +}); + +test('snapshot.changedAttributes() returns a copy of all changed attributes for the current snapshot', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + post.set('title', 'Hello World!'); + let snapshot = post._createSnapshot(); + + let changes = snapshot.changedAttributes(); + + assert.deepEqual( + changes.title, + ['Hello World', 'Hello World!'], + 'changed attributes are returned correctly' + ); + }); +}); + +test('snapshot.belongsTo() returns undefined if relationship is undefined', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'comment', + id: '1', + attributes: { + body: 'This is comment', + }, + }, + }); + let comment = env.store.peekRecord('comment', 1); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); + + assert.equal(relationship, undefined, 'relationship is undefined'); + }); +}); + +test('snapshot.belongsTo() returns null if relationship is unset', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is comment', + }, + relationships: { + post: { + data: null, + }, + }, + }, + ], + }); + let comment = env.store.peekRecord('comment', 2); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); + + assert.equal(relationship, null, 'relationship is unset'); + }); +}); + +test('snapshot.belongsTo() returns a snapshot if relationship is set', function(assert) { + assert.expect(3); + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is comment', + }, + relationships: { + post: { + data: { type: 'post', id: '1' }, + }, + }, + }, + ], + }); + let comment = env.store.peekRecord('comment', 2); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); + + assert.ok(relationship instanceof Snapshot, 'snapshot is an instance of Snapshot'); + assert.equal(relationship.id, '1', 'post id is correct'); + assert.equal(relationship.attr('title'), 'Hello World', 'post title is correct'); + }); +}); + +test('snapshot.belongsTo() returns null if relationship is deleted', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is comment', + }, + relationships: { + post: { + data: { type: 'post', id: '1' }, + }, + }, + }, + ], + }); + let post = env.store.peekRecord('post', 1); + let comment = env.store.peekRecord('comment', 2); + + post.deleteRecord(); + + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); + + assert.equal(relationship, null, 'relationship unset after deleted'); + }); +}); + +test('snapshot.belongsTo() returns undefined if relationship is a link', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'comment', + id: '2', + attributes: { + body: 'This is comment', + }, + relationships: { + post: { + links: { + related: 'post', + }, + }, + }, + }, + }); + let comment = env.store.peekRecord('comment', 2); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); + + assert.equal(relationship, undefined, 'relationship is undefined'); + }); +}); + +test("snapshot.belongsTo() throws error if relation doesn't exist", function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + assert.throws( + () => { + snapshot.belongsTo('unknown'); + }, + /has no belongsTo relationship named 'unknown'/, + 'throws error' + ); + }); +}); + +test('snapshot.belongsTo() returns a snapshot if relationship link has been fetched', function(assert) { + assert.expect(2); + + env.adapter.findBelongsTo = function(store, snapshot, link, relationship) { + return resolve({ data: { id: 1, type: 'post', attributes: { title: 'Hello World' } } }); + }; + + return run(() => { + env.store.push({ + data: { + type: 'comment', + id: '2', + attributes: { + body: 'This is comment', + }, + relationships: { + post: { + links: { + related: 'post', + }, + }, + }, + }, + }); + let comment = env.store.peekRecord('comment', 2); + + return comment.get('post').then(post => { + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); + + assert.ok(relationship instanceof Snapshot, 'snapshot is an instance of Snapshot'); + assert.equal(relationship.id, '1', 'post id is correct'); + }); + }); +}); + +test('snapshot.belongsTo() and snapshot.hasMany() returns correctly when adding an object to a hasMany relationship', function(assert) { + assert.expect(4); + + return run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is comment', + }, + }, + ], + }); + let post = env.store.peekRecord('post', 1); + let comment = env.store.peekRecord('comment', 2); + + return post.get('comments').then(comments => { + comments.addObject(comment); + + let postSnapshot = post._createSnapshot(); + let commentSnapshot = comment._createSnapshot(); + + let hasManyRelationship = postSnapshot.hasMany('comments'); + let belongsToRelationship = commentSnapshot.belongsTo('post'); + + assert.ok( + hasManyRelationship instanceof Array, + 'hasMany relationship is an instance of Array' + ); + assert.equal(hasManyRelationship.length, 1, 'hasMany relationship contains related object'); + + assert.ok( + belongsToRelationship instanceof Snapshot, + 'belongsTo relationship is an instance of Snapshot' + ); + assert.equal( + belongsToRelationship.attr('title'), + 'Hello World', + 'belongsTo relationship contains related object' + ); + }); + }); +}); + +test('snapshot.belongsTo() and snapshot.hasMany() returns correctly when setting an object to a belongsTo relationship', function(assert) { + assert.expect(4); + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is comment', + }, + }, + ], + }); + let post = env.store.peekRecord('post', 1); + let comment = env.store.peekRecord('comment', 2); + + comment.set('post', post); + + let postSnapshot = post._createSnapshot(); + let commentSnapshot = comment._createSnapshot(); + + let hasManyRelationship = postSnapshot.hasMany('comments'); + let belongsToRelationship = commentSnapshot.belongsTo('post'); + + assert.ok(hasManyRelationship instanceof Array, 'hasMany relationship is an instance of Array'); + assert.equal(hasManyRelationship.length, 1, 'hasMany relationship contains related object'); + + assert.ok( + belongsToRelationship instanceof Snapshot, + 'belongsTo relationship is an instance of Snapshot' + ); + assert.equal( + belongsToRelationship.attr('title'), + 'Hello World', + 'belongsTo relationship contains related object' + ); + }); +}); + +test('snapshot.belongsTo() returns ID if option.id is set', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is comment', + }, + relationships: { + post: { + data: { type: 'post', id: '1' }, + }, + }, + }, + ], + }); + let comment = env.store.peekRecord('comment', 2); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post', { id: true }); + + assert.equal(relationship, '1', 'relationship ID correctly returned'); + }); +}); + +test('snapshot.belongsTo() returns null if option.id is set but relationship was deleted', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is comment', + }, + relationships: { + post: { + data: { type: 'post', id: '1' }, + }, + }, + }, + ], + }); + let post = env.store.peekRecord('post', 1); + let comment = env.store.peekRecord('comment', 2); + + post.deleteRecord(); + + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post', { id: true }); + + assert.equal(relationship, null, 'relationship unset after deleted'); + }); +}); + +test('snapshot.hasMany() returns undefined if relationship is undefined', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); + + assert.equal(relationship, undefined, 'relationship is undefined'); + }); +}); + +test('snapshot.hasMany() returns empty array if relationship is empty', function(assert) { + assert.expect(2); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + relationships: { + comments: { + data: [], + }, + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); + + assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); + assert.equal(relationship.length, 0, 'relationship is empty'); + }); +}); + +test('snapshot.hasMany() returns array of snapshots if relationship is set', function(assert) { + assert.expect(5); + + run(() => { + env.store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'This is the first comment', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is the second comment', + }, + }, + { + type: 'post', + id: '3', + attributes: { + title: 'Hello World', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }, { type: 'comment', id: '2' }], + }, + }, + }, + ], + }); + let post = env.store.peekRecord('post', 3); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); + + assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); + assert.equal(relationship.length, 2, 'relationship has two items'); + + let relationship1 = relationship[0]; + + assert.ok(relationship1 instanceof Snapshot, 'relationship item is an instance of Snapshot'); + + assert.equal(relationship1.id, '1', 'relationship item id is correct'); + assert.equal( + relationship1.attr('body'), + 'This is the first comment', + 'relationship item body is correct' + ); + }); +}); + +test('snapshot.hasMany() returns empty array if relationship records are deleted', function(assert) { + assert.expect(2); + + run(() => { + env.store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'This is the first comment', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is the second comment', + }, + }, + { + type: 'post', + id: '3', + attributes: { + title: 'Hello World', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }, { type: 'comment', id: '2' }], + }, + }, + }, + ], + }); + let comment1 = env.store.peekRecord('comment', 1); + let comment2 = env.store.peekRecord('comment', 2); + let post = env.store.peekRecord('post', 3); + + comment1.deleteRecord(); + comment2.deleteRecord(); + + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); + + assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); + assert.equal(relationship.length, 0, 'relationship is empty'); + }); +}); + +test('snapshot.hasMany() returns array of IDs if option.ids is set', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '2' }, { type: 'comment', id: '3' }], + }, + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments', { ids: true }); + + assert.deepEqual(relationship, ['2', '3'], 'relationship IDs correctly returned'); + }); +}); + +test('snapshot.hasMany() returns empty array of IDs if option.ids is set but relationship records were deleted', function(assert) { + assert.expect(2); + + run(() => { + env.store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'This is the first comment', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is the second comment', + }, + }, + { + type: 'post', + id: '3', + attributes: { + title: 'Hello World', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }, { type: 'comment', id: '2' }], + }, + }, + }, + ], + }); + let comment1 = env.store.peekRecord('comment', 1); + let comment2 = env.store.peekRecord('comment', 2); + let post = env.store.peekRecord('post', 3); + + comment1.deleteRecord(); + comment2.deleteRecord(); + + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments', { ids: true }); + + assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); + assert.equal(relationship.length, 0, 'relationship is empty'); + }); +}); + +test('snapshot.hasMany() returns undefined if relationship is a link', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + relationships: { + comments: { + links: { + related: 'comments', + }, + }, + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); + + assert.equal(relationship, undefined, 'relationship is undefined'); + }); +}); + +test('snapshot.hasMany() returns array of snapshots if relationship link has been fetched', function(assert) { + assert.expect(2); + + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + return resolve({ data: [{ id: 2, type: 'comment', attributes: { body: 'This is comment' } }] }); + }; + + return run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + relationships: { + comments: { + links: { + related: 'comments', + }, + }, + }, + }, + }); + + let post = env.store.peekRecord('post', 1); + + return post.get('comments').then(comments => { + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); + + assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); + assert.equal(relationship.length, 1, 'relationship has one item'); + }); + }); +}); + +test("snapshot.hasMany() throws error if relation doesn't exist", function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + assert.throws( + () => { + snapshot.hasMany('unknown'); + }, + /has no hasMany relationship named 'unknown'/, + 'throws error' + ); + }); +}); + +test('snapshot.hasMany() respects the order of items in the relationship', function(assert) { + assert.expect(3); + + run(() => { + env.store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'This is the first comment', + }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'This is the second comment', + }, + }, + { + type: 'comment', + id: '3', + attributes: { + body: 'This is the third comment', + }, + }, + { + type: 'post', + id: '4', + attributes: { + title: 'Hello World', + }, + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + { type: 'comment', id: '3' }, + ], + }, + }, + }, + ], + }); + let comment3 = env.store.peekRecord('comment', 3); + let post = env.store.peekRecord('post', 4); + + post.get('comments').removeObject(comment3); + post.get('comments').insertAt(0, comment3); + + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); + + assert.equal(relationship[0].id, '3', 'order of comment 3 is correct'); + assert.equal(relationship[1].id, '1', 'order of comment 1 is correct'); + assert.equal(relationship[2].id, '2', 'order of comment 2 is correct'); + }); +}); + +test('snapshot.eachAttribute() proxies to record', function(assert) { + assert.expect(1); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + let attributes = []; + snapshot.eachAttribute(name => attributes.push(name)); + assert.deepEqual(attributes, ['author', 'title'], 'attributes are iterated correctly'); + }); +}); + +test('snapshot.eachRelationship() proxies to record', function(assert) { + assert.expect(2); + + let getRelationships = function(snapshot) { + let relationships = []; + snapshot.eachRelationship(name => relationships.push(name)); + return relationships; + }; + + run(() => { + env.store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'This is the first comment', + }, + }, + { + type: 'post', + id: '2', + attributes: { + title: 'Hello World', + }, + }, + ], + }); + let comment = env.store.peekRecord('comment', 1); + let post = env.store.peekRecord('post', 2); + let snapshot; + + snapshot = comment._createSnapshot(); + assert.deepEqual(getRelationships(snapshot), ['post'], 'relationships are iterated correctly'); + + snapshot = post._createSnapshot(); + assert.deepEqual( + getRelationships(snapshot), + ['comments'], + 'relationships are iterated correctly' + ); + }); +}); + +test('snapshot.belongsTo() does not trigger a call to store._scheduleFetch', function(assert) { + assert.expect(0); + + env.store._scheduleFetch = function() { + assert.ok(false, 'store._scheduleFetch should not be called'); + }; + + run(() => { + env.store.push({ + data: { + type: 'comment', + id: '1', + attributes: { + body: 'This is the first comment', + }, + relationships: { + post: { + data: { type: 'post', id: '2' }, + }, + }, + }, + }); + let comment = env.store.peekRecord('comment', 1); + let snapshot = comment._createSnapshot(); + + snapshot.belongsTo('post'); + }); +}); + +test('snapshot.hasMany() does not trigger a call to store._scheduleFetch', function(assert) { + assert.expect(0); + + env.store._scheduleFetch = function() { + assert.ok(false, 'store._scheduleFetch should not be called'); + }; + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '2' }, { type: 'comment', id: '3' }], + }, + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + snapshot.hasMany('comments'); + }); +}); + +test('snapshot.serialize() serializes itself', function(assert) { + assert.expect(2); + + run(() => { + env.store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'Hello World', + }, + }, + }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + + post.set('title', 'New Title'); + + let expected = { + data: { + attributes: { + author: undefined, + title: 'Hello World', + }, + type: 'posts', + }, + }; + assert.deepEqual(snapshot.serialize(), expected, 'shapshot serializes correctly'); + expected.data.id = '1'; + assert.deepEqual(snapshot.serialize({ includeId: true }), expected, 'serialize takes options'); + }); +}); diff --git a/tests/integration/store-test.js b/tests/integration/store-test.js new file mode 100644 index 00000000000..9ef2e293ee6 --- /dev/null +++ b/tests/integration/store-test.js @@ -0,0 +1,1124 @@ +import { Promise, resolve } from 'rsvp'; +import { run, next } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import Ember from 'ember'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import deepCopy from 'dummy/tests/helpers/deep-copy'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let store, env; + +const Person = DS.Model.extend({ + name: DS.attr('string'), + cars: DS.hasMany('car', { async: false }), +}); + +Person.reopenClass({ + toString() { + return 'Person'; + }, +}); + +const Car = DS.Model.extend({ + make: DS.attr('string'), + model: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), +}); + +Car.reopenClass({ + toString() { + return 'Car'; + }, +}); + +function initializeStore(adapter) { + env = setupStore({ + adapter: adapter, + }); + store = env.store; + + env.owner.register('model:car', Car); + env.owner.register('model:person', Person); +} + +module('integration/store - destroy', { + beforeEach() { + initializeStore(DS.Adapter.extend()); + }, + afterEach() { + store = null; + env = null; + }, +}); + +function tap(obj, methodName, callback) { + let old = obj[methodName]; + + let summary = { called: [] }; + + obj[methodName] = function() { + let result = old.apply(obj, arguments); + if (callback) { + callback.apply(obj, arguments); + } + summary.called.push(arguments); + return result; + }; + + return summary; +} + +test("destroying record during find doesn't cause error", function(assert) { + assert.expect(0); + let done = assert.async(); + + let TestAdapter = DS.Adapter.extend({ + findRecord(store, type, id, snapshot) { + return new Promise((resolve, reject) => { + next(() => { + store.unloadAll(type.modelName); + reject(); + }); + }); + }, + }); + + initializeStore(TestAdapter); + + let type = 'car'; + let id = 1; + + return run(() => store.findRecord(type, id).then(done, done)); +}); + +testInDebug('find calls do not resolve when the store is destroyed', async function(assert) { + assert.expect(2); + let done = assert.async(); + let next; + let nextPromise = new Promise(resolve => { + next = resolve; + }); + let TestAdapter = DS.Adapter.extend({ + findRecord() { + next(); + nextPromise = new Promise(resolve => { + next = resolve; + }).then(() => { + return { + data: { type: 'car', id: '1' }, + }; + }); + return nextPromise; + }, + }); + + initializeStore(TestAdapter); + + // needed for LTS 2.16 + Ember.Test.adapter.exception = e => { + throw e; + }; + + store.shouldTrackAsyncRequests = true; + store.push = function() { + assert('The test should have destroyed the store by now', store.get('isDestroyed')); + + throw new Error("We shouldn't be pushing data into the store when it is destroyed"); + }; + store.findRecord('car', '1'); + + await nextPromise; + + assert.throws(() => { + run(() => store.destroy()); + }, /Async Request leaks detected/); + + next(); + await nextPromise; + + // ensure we allow the internal store promises + // to flush, potentially pushing data into the store + setTimeout(() => { + assert.ok(true, 'We made it to the end'); + done(); + }, 0); +}); + +test('destroying the store correctly cleans everything up', function(assert) { + let car, person; + env.adapter.shouldBackgroundReloadRecord = () => false; + run(() => { + store.push({ + data: [ + { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + cars: { + data: [{ type: 'car', id: '1' }], + }, + }, + }, + ], + }); + car = store.peekRecord('car', 1); + person = store.peekRecord('person', 1); + }); + + let personWillDestroy = tap(person, 'willDestroy'); + let carWillDestroy = tap(car, 'willDestroy'); + let carsWillDestroy = run(() => tap(car.get('person.cars'), 'willDestroy')); + + env.adapter.query = function() { + return { + data: [ + { + id: 2, + type: 'person', + attributes: { name: 'Yehuda' }, + }, + ], + }; + }; + + let adapterPopulatedPeople = run(() => { + return store.query('person', { + someCrazy: 'query', + }); + }); + + let adapterPopulatedPeopleWillDestroy = tap(adapterPopulatedPeople.get('content'), 'willDestroy'); + + run(() => store.findRecord('person', 2)); + + assert.equal( + personWillDestroy.called.length, + 0, + 'expected person.willDestroy to not have been called' + ); + assert.equal(carWillDestroy.called.length, 0, 'expected car.willDestroy to not have been called'); + assert.equal( + carsWillDestroy.called.length, + 0, + 'expected cars.willDestroy to not have been called' + ); + assert.equal( + adapterPopulatedPeopleWillDestroy.called.length, + 0, + 'expected adapterPopulatedPeople.willDestroy to not have been called' + ); + assert.equal(car.get('person'), person, "expected car's person to be the correct person"); + assert.equal( + person.get('cars.firstObject'), + car, + " expected persons cars's firstRecord to be the correct car" + ); + + run(store, 'destroy'); + + assert.equal( + personWillDestroy.called.length, + 1, + 'expected person to have recieved willDestroy once' + ); + assert.equal(carWillDestroy.called.length, 1, 'expected car to recieve willDestroy once'); + assert.equal( + carsWillDestroy.called.length, + 1, + 'expected person.cars to recieve willDestroy once' + ); + assert.equal( + adapterPopulatedPeopleWillDestroy.called.length, + 1, + 'expected adapterPopulatedPeople to recieve willDestroy once' + ); +}); + +function ajaxResponse(value) { + env.adapter.ajax = function(url, verb, hash) { + return run(() => resolve(deepCopy(value))); + }; +} + +module('integration/store - findRecord'); + +test('store#findRecord fetches record from server when cached record is not present', function(assert) { + assert.expect(2); + + initializeStore(DS.RESTAdapter.extend()); + + env.owner.register('serializer:application', DS.RESTSerializer); + ajaxResponse({ + cars: [ + { + id: 20, + make: 'BMC', + model: 'Mini', + }, + ], + }); + + let cachedRecordIsPresent = store.hasRecordForId('car', 20); + assert.ok(!cachedRecordIsPresent, 'Car with id=20 should not exist'); + + return run(() => { + return store.findRecord('car', 20).then(car => { + assert.equal(car.get('make'), 'BMC', 'Car with id=20 is now loaded'); + }); + }); +}); + +test('store#findRecord returns cached record immediately and reloads record in the background', function(assert) { + assert.expect(2); + + initializeStore(DS.RESTAdapter.extend()); + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + }); + }); + + ajaxResponse({ + cars: [ + { + id: 1, + make: 'BMC', + model: 'Princess', + }, + ], + }); + + run(() => { + return store.findRecord('car', 1).then(car => { + assert.equal(car.get('model'), 'Mini', 'cached car record is returned'); + }); + }); + + run(() => { + let car = store.peekRecord('car', 1); + assert.equal(car.get('model'), 'Princess', 'car record was reloaded'); + }); +}); + +test('store#findRecord { reload: true } ignores cached record and reloads record from server', function(assert) { + assert.expect(2); + + const testAdapter = DS.RESTAdapter.extend({ + shouldReloadRecord(store, type, id, snapshot) { + assert.ok(false, 'shouldReloadRecord should not be called when { reload: true }'); + }, + }); + + initializeStore(testAdapter); + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + }); + }); + + ajaxResponse({ + cars: [ + { + id: 1, + make: 'BMC', + model: 'Princess', + }, + ], + }); + + let cachedCar = store.peekRecord('car', 1); + assert.equal(cachedCar.get('model'), 'Mini', 'cached car has expected model'); + + return run(() => { + return store.findRecord('car', 1, { reload: true }).then(car => { + assert.equal( + car.get('model'), + 'Princess', + 'cached record ignored, record reloaded via server' + ); + }); + }); +}); + +test('store#findRecord { reload: true } ignores cached record and reloads record from server even after previous findRecord', function(assert) { + assert.expect(5); + let calls = 0; + + const testAdapter = DS.JSONAPIAdapter.extend({ + shouldReloadRecord(store, type, id, snapshot) { + assert.ok(false, 'shouldReloadRecord should not be called when { reload: true }'); + }, + findRecord() { + calls++; + return resolve({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: calls === 1 ? 'Mini' : 'Princess', + }, + }, + }); + }, + }); + + initializeStore(testAdapter); + + let car = run(() => store.findRecord('car', '1')); + + assert.equal(calls, 1, 'We made one call to findRecord'); + assert.equal(car.get('model'), 'Mini', 'cached car has expected model'); + + run(() => { + let promiseCar = store.findRecord('car', 1, { reload: true }); + + assert.ok(promiseCar.get('model') === undefined, `We don't have early access to local data`); + }); + + assert.equal(calls, 2, 'We made a second call to findRecord'); + assert.equal(car.get('model'), 'Princess', 'cached record ignored, record reloaded via server'); +}); + +test('store#findRecord { backgroundReload: false } returns cached record and does not reload in the background', function(assert) { + assert.expect(2); + + let testAdapter = DS.RESTAdapter.extend({ + shouldBackgroundReloadRecord() { + assert.ok( + false, + 'shouldBackgroundReloadRecord should not be called when { backgroundReload: false }' + ); + }, + + findRecord() { + assert.ok(false, 'findRecord() should not be called when { backgroundReload: false }'); + }, + }); + + initializeStore(testAdapter); + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + }); + }); + + run(() => { + store.findRecord('car', 1, { backgroundReload: false }).then(car => { + assert.equal(car.get('model'), 'Mini', 'cached car record is returned'); + }); + }); + + run(() => { + let car = store.peekRecord('car', 1); + assert.equal(car.get('model'), 'Mini', 'car record was not reloaded'); + }); +}); + +test('store#findRecord { backgroundReload: true } returns cached record and reloads record in background', function(assert) { + assert.expect(2); + + let testAdapter = DS.RESTAdapter.extend({ + shouldBackgroundReloadRecord() { + assert.ok( + false, + 'shouldBackgroundReloadRecord should not be called when { backgroundReload: true }' + ); + }, + }); + + initializeStore(testAdapter); + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + }); + }); + + ajaxResponse({ + cars: [ + { + id: 1, + make: 'BMC', + model: 'Princess', + }, + ], + }); + + run(() => { + store.findRecord('car', 1, { backgroundReload: true }).then(car => { + assert.equal(car.get('model'), 'Mini', 'cached car record is returned'); + }); + }); + + run(() => { + let car = store.peekRecord('car', 1); + assert.equal(car.get('model'), 'Princess', 'car record was reloaded'); + }); +}); + +test('store#findRecord { backgroundReload: false } is ignored if adapter.shouldReloadRecord is true', function(assert) { + assert.expect(2); + + let testAdapter = DS.RESTAdapter.extend({ + shouldReloadRecord() { + return true; + }, + + shouldBackgroundReloadRecord() { + assert.ok( + false, + 'shouldBackgroundReloadRecord should not be called when adapter.shouldReloadRecord = true' + ); + }, + }); + + initializeStore(testAdapter); + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + }); + }); + + ajaxResponse({ + cars: [ + { + id: 1, + make: 'BMC', + model: 'Princess', + }, + ], + }); + + run(() => { + let car = store.peekRecord('car', 1); + assert.equal(car.get('model'), 'Mini', 'Car record is initially a Mini'); + }); + + run(() => { + store.findRecord('car', 1, { backgroundReload: false }).then(car => { + assert.equal( + car.get('model'), + 'Princess', + 'Car record is reloaded immediately (not in the background)' + ); + }); + }); +}); + +testInDebug( + 'store#findRecord call with `id` of type different than non-empty string or number should trigger an assertion', + assert => { + const badValues = ['', undefined, null, NaN, false]; + assert.expect(badValues.length); + + initializeStore(DS.RESTAdapter.extend()); + + run(() => { + badValues.map(item => { + assert.expectAssertion(() => { + store.findRecord('car', item); + }, '`id` passed to `findRecord()` has to be non-empty string or number'); + }); + }); + } +); + +module('integration/store - findAll', { + beforeEach() { + initializeStore(DS.RESTAdapter.extend()); + }, +}); + +test('Using store#findAll with no records triggers a query', function(assert) { + assert.expect(2); + + ajaxResponse({ + cars: [ + { + id: 1, + make: 'BMC', + model: 'Mini', + }, + { + id: 2, + make: 'BMCW', + model: 'Isetta', + }, + ], + }); + + let cars = store.peekAll('car'); + assert.ok(!cars.get('length'), 'There is no cars in the store'); + + return run(() => { + return store.findAll('car').then(cars => { + assert.equal(cars.get('length'), 2, 'Two car were fetched'); + }); + }); +}); + +test('Using store#findAll with existing records performs a query in the background, updating existing records and returning new ones', function(assert) { + assert.expect(4); + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + }); + }); + + ajaxResponse({ + cars: [ + { + id: 1, + make: 'BMC', + model: 'New Mini', + }, + { + id: 2, + make: 'BMCW', + model: 'Isetta', + }, + ], + }); + + let cars = store.peekAll('car'); + assert.equal(cars.get('length'), 1, 'There is one car in the store'); + + let waiter = run(() => { + return store.findAll('car').then(cars => { + assert.equal(cars.get('length'), 1, 'Store resolves with the existing records'); + }); + }); + + run(() => { + let cars = store.peekAll('car'); + assert.equal(cars.get('length'), 2, 'There is 2 cars in the store now'); + let mini = cars.findBy('id', '1'); + assert.equal(mini.get('model'), 'New Mini', 'Existing records have been updated'); + }); + + return waiter; +}); + +test('store#findAll { backgroundReload: false } skips shouldBackgroundReloadAll, returns cached records & does not reload in the background', function(assert) { + assert.expect(4); + + let testAdapter = DS.RESTAdapter.extend({ + shouldBackgroundReloadAll() { + assert.ok( + false, + 'shouldBackgroundReloadAll should not be called when { backgroundReload: false }' + ); + }, + + findAll() { + assert.ok(false, 'findAll() should not be called when { backgroundReload: true }'); + }, + }); + + initializeStore(testAdapter); + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + }); + }); + + run(() => { + store.findAll('car', { backgroundReload: false }).then(cars => { + assert.equal(cars.get('length'), 1, 'single cached car record is returned'); + assert.equal(cars.get('firstObject.model'), 'Mini', 'correct cached car record is returned'); + }); + }); + + run(() => { + let cars = store.peekAll('car'); + assert.equal(cars.get('length'), 1, 'single cached car record is returned again'); + assert.equal( + cars.get('firstObject.model'), + 'Mini', + 'correct cached car record is returned again' + ); + }); +}); + +test('store#findAll { backgroundReload: true } skips shouldBackgroundReloadAll, returns cached records, & reloads in background', function(assert) { + assert.expect(5); + + let testAdapter = DS.RESTAdapter.extend({ + shouldBackgroundReloadAll() { + assert.ok( + false, + 'shouldBackgroundReloadAll should not be called when { backgroundReload: true }' + ); + }, + }); + + initializeStore(testAdapter); + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + }); + }); + + ajaxResponse({ + cars: [ + { + id: 1, + make: 'BMC', + model: 'New Mini', + }, + { + id: 2, + make: 'BMCW', + model: 'Isetta', + }, + ], + }); + + run(() => { + store.findAll('car', { backgroundReload: true }).then(cars => { + assert.equal(cars.get('length'), 1, 'single cached car record is returned'); + assert.equal(cars.get('firstObject.model'), 'Mini', 'correct cached car record is returned'); + }); + }); + + run(() => { + let cars = store.peekAll('car'); + assert.equal(cars.get('length'), 2, 'multiple cars now in the store'); + assert.equal(cars.get('firstObject.model'), 'New Mini', 'existing record updated correctly'); + assert.equal(cars.get('lastObject.model'), 'Isetta', 'new record added to the store'); + }); +}); + +test('store#findAll { backgroundReload: false } is ignored if adapter.shouldReloadAll is true', function(assert) { + assert.expect(5); + + let testAdapter = DS.RESTAdapter.extend({ + shouldReloadAll() { + return true; + }, + + shouldBackgroundReloadAll() { + assert.ok( + false, + 'shouldBackgroundReloadAll should not be called when adapter.shouldReloadAll = true' + ); + }, + }); + + initializeStore(testAdapter); + + run(() => { + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + }); + }); + + ajaxResponse({ + cars: [ + { + id: 1, + make: 'BMC', + model: 'New Mini', + }, + { + id: 2, + make: 'BMCW', + model: 'Isetta', + }, + ], + }); + + run(() => { + let cars = store.peekAll('car'); + assert.equal(cars.get('length'), 1, 'one car in the store'); + assert.equal(cars.get('firstObject.model'), 'Mini', 'correct car is in the store'); + }); + + return run(() => { + return store.findAll('car', { backgroundReload: false }).then(cars => { + assert.equal(cars.get('length'), 2, 'multiple car records are returned'); + assert.equal(cars.get('firstObject.model'), 'New Mini', 'initial car record was updated'); + assert.equal(cars.get('lastObject.model'), 'Isetta', 'second car record was loaded'); + }); + }); +}); + +test('store#findAll should eventually return all known records even if they are not in the adapter response', function(assert) { + assert.expect(5); + + run(() => { + store.push({ + data: [ + { + type: 'car', + id: '1', + attributes: { + make: 'BMC', + model: 'Mini', + }, + }, + { + type: 'car', + id: '2', + attributes: { + make: 'BMCW', + model: 'Isetta', + }, + }, + ], + }); + }); + + ajaxResponse({ + cars: [ + { + id: 1, + make: 'BMC', + model: 'New Mini', + }, + ], + }); + + let cars = store.peekAll('car'); + assert.equal(cars.get('length'), 2, 'There is two cars in the store'); + + let waiter = run(() => { + return store.findAll('car').then(cars => { + assert.equal(cars.get('length'), 2, 'It returns all cars'); + + let carsInStore = store.peekAll('car'); + assert.equal(carsInStore.get('length'), 2, 'There is 2 cars in the store'); + }); + }); + + run(() => { + let cars = store.peekAll('car'); + let mini = cars.findBy('id', '1'); + assert.equal(mini.get('model'), 'New Mini', 'Existing records have been updated'); + + let carsInStore = store.peekAll('car'); + assert.equal(carsInStore.get('length'), 2, 'There is 2 cars in the store'); + }); + + return waiter; +}); + +test('Using store#fetch on an empty record calls find', function(assert) { + assert.expect(2); + + ajaxResponse({ + cars: [ + { + id: 20, + make: 'BMCW', + model: 'Mini', + }, + ], + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + cars: { + data: [{ type: 'car', id: '20' }], + }, + }, + }, + }); + }); + + let car = store.recordForId('car', 20); + assert.ok(car.get('isEmpty'), 'Car with id=20 should be empty'); + + return run(() => { + return store.findRecord('car', 20, { reload: true }).then(car => { + assert.equal(car.get('make'), 'BMCW', 'Car with id=20 is now loaded'); + }); + }); +}); + +test('Using store#adapterFor should not throw an error when looking up the application adapter', function(assert) { + assert.expect(1); + + run(() => { + let applicationAdapter = store.adapterFor('application'); + assert.ok(applicationAdapter); + }); +}); + +test('Using store#serializerFor should not throw an error when looking up the application serializer', function(assert) { + assert.expect(1); + + run(() => { + let applicationSerializer = store.serializerFor('application'); + assert.ok(applicationSerializer); + }); +}); + +module('integration/store - deleteRecord', { + beforeEach() { + initializeStore(DS.RESTAdapter.extend()); + }, +}); + +test('Using store#deleteRecord should mark the model for removal', function(assert) { + assert.expect(3); + let person; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }); + person = store.peekRecord('person', 1); + }); + + assert.ok(store.hasRecordForId('person', 1), 'expected the record to be in the store'); + + let personDeleteRecord = tap(person, 'deleteRecord'); + + run(() => store.deleteRecord(person)); + + assert.equal( + personDeleteRecord.called.length, + 1, + 'expected person.deleteRecord to have been called' + ); + assert.ok(person.get('isDeleted'), 'expect person to be isDeleted'); +}); + +test('Store should accept a null value for `data`', function(assert) { + assert.expect(0); + + run(() => { + store.push({ + data: null, + }); + }); +}); + +testInDebug('store#findRecord that returns an array should assert', assert => { + initializeStore( + DS.JSONAPIAdapter.extend({ + findRecord() { + return { data: [] }; + }, + }) + ); + + assert.expectAssertion(() => { + run(() => { + store.findRecord('car', 1); + }); + }, /expected the primary data returned from a 'findRecord' response to be an object but instead it found an array/); +}); + +testInDebug( + 'store#didSaveRecord should assert when the response to a save does not include the id', + function(assert) { + env.adapter.createRecord = function() { + return {}; + }; + + assert.expectAssertion(() => { + run(() => { + let car = store.createRecord('car'); + car.save(); + }); + }, /Your car record was saved to the server, but the response does not have an id and no id has been set client side. Records must have ids. Please update the server response to provide an id in the response or generate the id on the client side either before saving the record or while normalizing the response./); + } +); + +module('integration/store - queryRecord', { + beforeEach() { + initializeStore(DS.Adapter.extend()); + }, +}); + +testInDebug( + 'store#queryRecord should assert when normalized payload of adapter has an array an data', + function(assert) { + env.adapter.queryRecord = function() { + return { + cars: [{ id: 1 }], + }; + }; + + env.serializer.normalizeQueryRecordResponse = function() { + return { + data: [{ id: 1, type: 'car' }], + }; + }; + + assert.expectAssertion(() => { + run(() => store.queryRecord('car', {})); + }, /Expected the primary data returned by the serializer for a 'queryRecord' response to be a single object or null but instead it was an array./); + } +); + +test('The store should trap exceptions that are thrown from adapter#findRecord', function(assert) { + assert.expect(1); + env.adapter.findRecord = function() { + throw new Error('Refusing to find record'); + }; + + run(() => { + store.findRecord('car', 1).catch(error => { + assert.equal(error.message, 'Refusing to find record'); + }); + }); +}); + +test('The store should trap exceptions that are thrown from adapter#findAll', function(assert) { + assert.expect(1); + env.adapter.findAll = function() { + throw new Error('Refusing to find all records'); + }; + + run(() => { + store.findAll('car').catch(error => { + assert.equal(error.message, 'Refusing to find all records'); + }); + }); +}); + +test('The store should trap exceptions that are thrown from adapter#query', function(assert) { + assert.expect(1); + env.adapter.query = function() { + throw new Error('Refusing to query records'); + }; + + run(() => { + store.query('car', {}).catch(error => { + assert.equal(error.message, 'Refusing to query records'); + }); + }); +}); + +test('The store should trap exceptions that are thrown from adapter#queryRecord', function(assert) { + assert.expect(1); + env.adapter.queryRecord = function() { + throw new Error('Refusing to query record'); + }; + + run(() => { + store.queryRecord('car', {}).catch(error => { + assert.equal(error.message, 'Refusing to query record'); + }); + }); +}); + +test('The store should trap exceptions that are thrown from adapter#createRecord', function(assert) { + assert.expect(1); + env.adapter.createRecord = function() { + throw new Error('Refusing to serialize'); + }; + + run(() => { + let car = store.createRecord('car'); + + car.save().catch(error => { + assert.equal(error.message, 'Refusing to serialize'); + }); + }); +}); diff --git a/tests/integration/store/adapter-for-test.js b/tests/integration/store/adapter-for-test.js new file mode 100644 index 00000000000..56b1ee64265 --- /dev/null +++ b/tests/integration/store/adapter-for-test.js @@ -0,0 +1,329 @@ +import { setupTest } from 'ember-qunit'; +import { module, test } from 'qunit'; +import Store from 'ember-data/store'; +import { run } from '@ember/runloop'; + +class TestAdapter { + constructor(args) { + Object.assign(this, args); + this.didInit(); + } + + didInit() {} + + static create(args) { + return new this(args); + } +} + +module('integration/store - adapterFor', function(hooks) { + setupTest(hooks); + let store; + + hooks.beforeEach(function() { + let { owner } = this; + store = owner.lookup('service:store'); + }); + + test('when no adapter is available we throw an error', async function(assert) { + let { owner } = this; + /* + ensure our store instance does not specify a fallback + we use an empty string as that would cause `owner.lookup` to blow up if not guarded properly + whereas `null` `undefined` `false` would not. + */ + store.adapter = ''; + /* + adapter:-json-api is the "last chance" fallback and is + registered automatically. + unregistering it will cause adapterFor to return `undefined`. + */ + owner.unregister('adapter:-json-api'); + + assert.expectAssertion(() => { + store.adapterFor('person'); + }, /No adapter was found for 'person' and no 'application', store\.adapter = 'adapter-fallback-name', or '-json-api' adapter were found as fallbacks\./); + }); + + test('we find and instantiate the application adapter', async function(assert) { + let { owner } = this; + let didInstantiate = false; + + class AppAdapter extends TestAdapter { + didInit() { + didInstantiate = true; + } + } + + owner.register('adapter:application', AppAdapter); + + let adapter = store.adapterFor('application'); + + assert.ok(adapter instanceof AppAdapter, 'We found the correct adapter'); + assert.ok(didInstantiate, 'We instantiated the adapter'); + didInstantiate = false; + + let adapterAgain = store.adapterFor('application'); + + assert.ok(adapterAgain instanceof AppAdapter, 'We found the correct adapter'); + assert.ok(!didInstantiate, 'We did not instantiate the adapter again'); + assert.ok(adapter === adapterAgain, 'Repeated calls to adapterFor return the same instance'); + }); + + test('multiple stores do not share adapters', async function(assert) { + let { owner } = this; + let didInstantiate = false; + + class AppAdapter extends TestAdapter { + didInit() { + didInstantiate = true; + } + } + + owner.register('adapter:application', AppAdapter); + owner.register('service:other-store', Store); + + let otherStore = owner.lookup('service:other-store'); + let adapter = store.adapterFor('application'); + + assert.ok(adapter instanceof AppAdapter, 'We found the correct adapter'); + assert.ok(didInstantiate, 'We instantiated the adapter'); + didInstantiate = false; + + let otherAdapter = otherStore.adapterFor('application'); + assert.ok(otherAdapter instanceof AppAdapter, 'We found the correct adapter again'); + assert.ok(didInstantiate, 'We instantiated the other adapter'); + assert.ok(otherAdapter !== adapter, 'We have a different adapter instance'); + + // Ember 2.18 requires us to wrap destroy in a run. Use `await settled()` for newer versions. + run(() => otherStore.destroy()); + }); + + test('we can find and instantiate per-type adapters', async function(assert) { + let { owner } = this; + let didInstantiateAppAdapter = false; + let didInstantiatePersonAdapter = false; + + class AppAdapter extends TestAdapter { + didInit() { + didInstantiateAppAdapter = true; + } + } + + class PersonAdapter extends TestAdapter { + didInit() { + didInstantiatePersonAdapter = true; + } + } + + owner.register('adapter:application', AppAdapter); + owner.register('adapter:person', PersonAdapter); + + let adapter = store.adapterFor('person'); + + assert.ok(adapter instanceof PersonAdapter, 'We found the correct adapter'); + assert.ok(didInstantiatePersonAdapter, 'We instantiated the person adapter'); + assert.ok(!didInstantiateAppAdapter, 'We did not instantiate the application adapter'); + + let appAdapter = store.adapterFor('application'); + assert.ok(appAdapter instanceof AppAdapter, 'We found the correct adapter'); + assert.ok(didInstantiateAppAdapter, 'We instantiated the application adapter'); + assert.ok(appAdapter !== adapter, 'We have separate adapters'); + }); + + test('we fallback to the application adapter when a per-type adapter is not found', async function(assert) { + let { owner } = this; + let didInstantiateAppAdapter = false; + + class AppAdapter extends TestAdapter { + didInit() { + didInstantiateAppAdapter = true; + } + } + + owner.register('adapter:application', AppAdapter); + + let adapter = store.adapterFor('person'); + + assert.ok(adapter instanceof AppAdapter, 'We found the adapter'); + assert.ok(didInstantiateAppAdapter, 'We instantiated the adapter'); + didInstantiateAppAdapter = false; + + let appAdapter = store.adapterFor('application'); + assert.ok(appAdapter instanceof AppAdapter, 'We found the correct adapter'); + assert.ok(!didInstantiateAppAdapter, 'We did not instantiate the adapter again'); + assert.ok(appAdapter === adapter, 'We fell back to the application adapter instance'); + }); + + test('we can specify a fallback adapter by name in place of the application adapter', async function(assert) { + store.adapter = '-rest'; + let { owner } = this; + + let didInstantiateRestAdapter = false; + + class RestAdapter extends TestAdapter { + didInit() { + didInstantiateRestAdapter = true; + } + } + owner.register('adapter:-rest', RestAdapter); + + let adapter = store.adapterFor('person'); + + assert.ok(adapter instanceof RestAdapter, 'We found the fallback -rest adapter for person'); + assert.ok(didInstantiateRestAdapter, 'We instantiated the adapter'); + didInstantiateRestAdapter = false; + + let appAdapter = store.adapterFor('application'); + + assert.ok( + appAdapter instanceof RestAdapter, + 'We found the fallback -rest adapter for application' + ); + assert.ok(!didInstantiateRestAdapter, 'We did not instantiate the adapter again'); + didInstantiateRestAdapter = false; + + let restAdapter = store.adapterFor('-rest'); + assert.ok(restAdapter instanceof RestAdapter, 'We found the correct adapter'); + assert.ok(!didInstantiateRestAdapter, 'We did not instantiate the adapter again'); + assert.ok( + restAdapter === adapter, + 'We fell back to the -rest adapter instance for the person adapters' + ); + assert.ok( + restAdapter === appAdapter, + 'We fell back to the -rest adapter instance for the application adapter' + ); + }); + + test('the application adapter has higher precedence than a fallback adapter defined via store.adapter', async function(assert) { + store.adapter = '-rest'; + let { owner } = this; + + let didInstantiateAppAdapter = false; + let didInstantiateRestAdapter = false; + + class AppAdapter extends TestAdapter { + didInit() { + didInstantiateAppAdapter = true; + } + } + + class RestAdapter extends TestAdapter { + didInit() { + didInstantiateRestAdapter = true; + } + } + + owner.register('adapter:application', AppAdapter); + owner.register('adapter:-rest', RestAdapter); + + let adapter = store.adapterFor('person'); + + assert.ok(adapter instanceof AppAdapter, 'We found the store specified fallback adapter'); + assert.ok( + !didInstantiateRestAdapter, + 'We did not instantiate the store.adapter (-rest) adapter' + ); + assert.ok(didInstantiateAppAdapter, 'We instantiated the application adapter'); + didInstantiateRestAdapter = false; + didInstantiateAppAdapter = false; + + let appAdapter = store.adapterFor('application'); + assert.ok(appAdapter instanceof AppAdapter, 'We found the correct adapter for application'); + assert.ok(!didInstantiateRestAdapter, 'We did not instantiate the store fallback adapter'); + assert.ok(!didInstantiateAppAdapter, 'We did not instantiate the application adapter again'); + assert.ok(appAdapter === adapter, 'We used the application adapter as the person adapter'); + didInstantiateRestAdapter = false; + didInstantiateAppAdapter = false; + + let restAdapter = store.adapterFor('-rest'); + assert.ok(restAdapter instanceof RestAdapter, 'We found the correct adapter for -rest'); + assert.ok(!didInstantiateAppAdapter, 'We did not instantiate the application adapter again'); + assert.ok(didInstantiateRestAdapter, 'We instantiated the fallback adapter'); + assert.ok(restAdapter !== appAdapter, `We did not use the application adapter instance`); + }); + + test('we can specify a fallback adapter by name in place of the application adapter', async function(assert) { + store.adapter = '-rest'; + let { owner } = this; + + let didInstantiateRestAdapter = false; + + class RestAdapter extends TestAdapter { + didInit() { + didInstantiateRestAdapter = true; + } + } + owner.register('adapter:-rest', RestAdapter); + + let adapter = store.adapterFor('application'); + + assert.ok(adapter instanceof RestAdapter, 'We found the adapter'); + assert.ok(didInstantiateRestAdapter, 'We instantiated the adapter'); + didInstantiateRestAdapter = false; + + let restAdapter = store.adapterFor('-rest'); + assert.ok(restAdapter instanceof RestAdapter, 'We found the correct adapter'); + assert.ok(!didInstantiateRestAdapter, 'We did not instantiate the adapter again'); + assert.ok( + restAdapter === adapter, + 'We fell back to the -rest adapter instance for the application adapter' + ); + }); + + test('When the per-type, application and specified fallback adapters do not exist, we fallback to the -json-api adapter', async function(assert) { + store.adapter = '-not-a-real-adapter'; + let { owner } = this; + + let didInstantiateAdapter = false; + + class JsonApiAdapter extends TestAdapter { + didInit() { + didInstantiateAdapter = true; + } + } + owner.unregister('adapter:-json-api'); + owner.register('adapter:-json-api', JsonApiAdapter); + + let adapter = store.adapterFor('person'); + + assert.ok(adapter instanceof JsonApiAdapter, 'We found the adapter'); + assert.ok(didInstantiateAdapter, 'We instantiated the adapter'); + didInstantiateAdapter = false; + + let appAdapter = store.adapterFor('application'); + + assert.ok( + appAdapter instanceof JsonApiAdapter, + 'We found the fallback -json-api adapter for application' + ); + assert.ok(!didInstantiateAdapter, 'We did not instantiate the adapter again'); + didInstantiateAdapter = false; + + let fallbackAdapter = store.adapterFor('-not-a-real-adapter'); + + assert.ok( + fallbackAdapter instanceof JsonApiAdapter, + 'We found the fallback -json-api adapter for application' + ); + assert.ok(!didInstantiateAdapter, 'We did not instantiate the adapter again'); + didInstantiateAdapter = false; + + let jsonApiAdapter = store.adapterFor('-json-api'); + assert.ok(jsonApiAdapter instanceof JsonApiAdapter, 'We found the correct adapter'); + assert.ok(!didInstantiateAdapter, 'We did not instantiate the adapter again'); + assert.ok( + jsonApiAdapter === appAdapter, + 'We fell back to the -json-api adapter instance for application' + ); + assert.ok( + jsonApiAdapter === fallbackAdapter, + 'We fell back to the -json-api adapter instance for the fallback -not-a-real-adapter' + ); + assert.ok( + jsonApiAdapter === adapter, + 'We fell back to the -json-api adapter instance for the per-type adapter' + ); + }); +}); diff --git a/tests/integration/store/json-api-validation-test.js b/tests/integration/store/json-api-validation-test.js new file mode 100644 index 00000000000..583a246de1c --- /dev/null +++ b/tests/integration/store/json-api-validation-test.js @@ -0,0 +1,237 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import QUnit, { module } from 'qunit'; +import DS from 'ember-data'; + +var Person, store, env; + +function payloadError(payload, expectedError, assert) { + env.owner.register( + 'serializer:person', + DS.Serializer.extend({ + normalizeResponse(store, type, pld) { + return pld; + }, + }) + ); + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return resolve(payload); + }, + }) + ); + this.expectAssertion( + function() { + run(function() { + store.findRecord('person', 1); + }); + }, + expectedError, + `Payload ${JSON.stringify(payload)} should throw error ${expectedError}` + ); + env.owner.unregister('serializer:person'); + env.owner.unregister('adapter:person'); +} + +module('integration/store/json-validation', { + beforeEach() { + QUnit.assert.payloadError = payloadError.bind(QUnit.assert); + + Person = DS.Model.extend({ + updatedAt: DS.attr('string'), + name: DS.attr('string'), + firstName: DS.attr('string'), + lastName: DS.attr('string'), + }); + + env = setupStore({ + person: Person, + }); + store = env.store; + }, + + afterEach() { + QUnit.assert.payloadError = null; + run(store, 'destroy'); + }, +}); + +testInDebug( + "when normalizeResponse returns undefined (or doesn't return), throws an error", + function(assert) { + env.owner.register( + 'serializer:person', + DS.Serializer.extend({ + normalizeResponse() {}, + }) + ); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return resolve({ data: {} }); + }, + }) + ); + + assert.expectAssertion(function() { + run(function() { + store.findRecord('person', 1); + }); + }, /Top level of a JSON API document must be an object/); + } +); + +testInDebug('when normalizeResponse returns null, throws an error', function(assert) { + env.owner.register( + 'serializer:person', + DS.Serializer.extend({ + normalizeResponse() { + return null; + }, + }) + ); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return resolve({ data: {} }); + }, + }) + ); + + assert.expectAssertion(function() { + run(function() { + store.findRecord('person', 1); + }); + }, /Top level of a JSON API document must be an object/); +}); + +testInDebug('when normalizeResponse returns an empty object, throws an error', function(assert) { + env.owner.register( + 'serializer:person', + DS.Serializer.extend({ + normalizeResponse() { + return {}; + }, + }) + ); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return resolve({ data: {} }); + }, + }) + ); + + assert.expectAssertion(function() { + run(function() { + store.findRecord('person', 1); + }); + }, /One or more of the following keys must be present/); +}); + +testInDebug( + 'when normalizeResponse returns a document with both data and errors, throws an error', + function(assert) { + env.owner.register( + 'serializer:person', + DS.Serializer.extend({ + normalizeResponse() { + return { + data: [], + errors: [], + }; + }, + }) + ); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord() { + return resolve({ data: {} }); + }, + }) + ); + + assert.expectAssertion(function() { + run(function() { + store.findRecord('person', 1); + }); + }, /cannot both be present/); + } +); + +testInDebug( + "normalizeResponse 'data' cannot be undefined, a number, a string or a boolean", + function(assert) { + assert.payloadError({ data: undefined }, /data must be/); + assert.payloadError({ data: 1 }, /data must be/); + assert.payloadError({ data: 'lollerskates' }, /data must be/); + assert.payloadError({ data: true }, /data must be/); + } +); + +testInDebug( + "normalizeResponse 'meta' cannot be an array, undefined, a number, a string or a boolean", + function(assert) { + assert.payloadError({ meta: undefined }, /meta must be an object/); + assert.payloadError({ meta: [] }, /meta must be an object/); + assert.payloadError({ meta: 1 }, /meta must be an object/); + assert.payloadError({ meta: 'lollerskates' }, /meta must be an object/); + assert.payloadError({ meta: true }, /meta must be an object/); + } +); + +testInDebug( + "normalizeResponse 'links' cannot be an array, undefined, a number, a string or a boolean", + function(assert) { + assert.payloadError({ data: [], links: undefined }, /links must be an object/); + assert.payloadError({ data: [], links: [] }, /links must be an object/); + assert.payloadError({ data: [], links: 1 }, /links must be an object/); + assert.payloadError({ data: [], links: 'lollerskates' }, /links must be an object/); + assert.payloadError({ data: [], links: true }, /links must be an object/); + } +); + +testInDebug( + "normalizeResponse 'jsonapi' cannot be an array, undefined, a number, a string or a boolean", + function(assert) { + assert.payloadError({ data: [], jsonapi: undefined }, /jsonapi must be an object/); + assert.payloadError({ data: [], jsonapi: [] }, /jsonapi must be an object/); + assert.payloadError({ data: [], jsonapi: 1 }, /jsonapi must be an object/); + assert.payloadError({ data: [], jsonapi: 'lollerskates' }, /jsonapi must be an object/); + assert.payloadError({ data: [], jsonapi: true }, /jsonapi must be an object/); + } +); + +testInDebug( + "normalizeResponse 'included' cannot be an object, undefined, a number, a string or a boolean", + function(assert) { + assert.payloadError({ included: undefined }, /included must be an array/); + assert.payloadError({ included: {} }, /included must be an array/); + assert.payloadError({ included: 1 }, /included must be an array/); + assert.payloadError({ included: 'lollerskates' }, /included must be an array/); + assert.payloadError({ included: true }, /included must be an array/); + } +); + +testInDebug( + "normalizeResponse 'errors' cannot be an object, undefined, a number, a string or a boolean", + function(assert) { + assert.payloadError({ errors: undefined }, /errors must be an array/); + assert.payloadError({ errors: {} }, /errors must be an array/); + assert.payloadError({ errors: 1 }, /errors must be an array/); + assert.payloadError({ errors: 'lollerskates' }, /errors must be an array/); + assert.payloadError({ errors: true }, /errors must be an array/); + } +); diff --git a/tests/integration/store/query-record-test.js b/tests/integration/store/query-record-test.js new file mode 100644 index 00000000000..9eec0051e44 --- /dev/null +++ b/tests/integration/store/query-record-test.js @@ -0,0 +1,116 @@ +import { resolve, reject } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var Person, store, env; + +module('integration/store/query-record - Query one record with a query hash', { + beforeEach() { + Person = DS.Model.extend({ + updatedAt: DS.attr('string'), + name: DS.attr('string'), + firstName: DS.attr('string'), + lastName: DS.attr('string'), + }); + + env = setupStore({ + person: Person, + }); + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +testInDebug('It raises an assertion when no type is passed', function(assert) { + assert.expectAssertion(function() { + store.queryRecord(); + }, "You need to pass a model name to the store's queryRecord method"); +}); + +testInDebug('It raises an assertion when no query hash is passed', function(assert) { + assert.expectAssertion(function() { + store.queryRecord('person'); + }, "You need to pass a query hash to the store's queryRecord method"); +}); + +test("When a record is requested, the adapter's queryRecord method should be called.", function(assert) { + assert.expect(1); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + queryRecord(store, type, query) { + assert.equal(type, Person, 'the query method is called with the correct type'); + return resolve({ data: { id: 1, type: 'person', attributes: { name: 'Peter Wagenet' } } }); + }, + }) + ); + + run(function() { + store.queryRecord('person', { related: 'posts' }); + }); +}); + +test('When a record is requested, and the promise is rejected, .queryRecord() is rejected.', function(assert) { + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + queryRecord(store, type, query) { + return reject(); + }, + }) + ); + + run(function() { + store.queryRecord('person', {}).catch(function(reason) { + assert.ok(true, 'The rejection handler was called'); + }); + }); +}); + +test("When a record is requested, the serializer's normalizeQueryRecordResponse method should be called.", function(assert) { + assert.expect(1); + + env.owner.register( + 'serializer:person', + DS.JSONAPISerializer.extend({ + normalizeQueryRecordResponse(store, primaryModelClass, payload, id, requestType) { + assert.equal( + payload.data.id, + '1', + 'the normalizeQueryRecordResponse method was called with the right payload' + ); + return this._super(...arguments); + }, + }) + ); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + queryRecord(store, type, query) { + return resolve({ + data: { + id: '1', + type: 'person', + attributes: { + name: 'Peter Wagenet', + }, + }, + }); + }, + }) + ); + + run(function() { + store.queryRecord('person', { related: 'posts' }); + }); +}); diff --git a/tests/integration/store/query-test.js b/tests/integration/store/query-test.js new file mode 100644 index 00000000000..d99b943d8ac --- /dev/null +++ b/tests/integration/store/query-test.js @@ -0,0 +1,51 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import RSVP from 'rsvp'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var Person, store, env; + +module('integration/store/query', { + beforeEach() { + Person = DS.Model.extend(); + + env = setupStore({ + person: Person, + }); + + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +test('meta is proxied correctly on the PromiseArray', function(assert) { + let defered = RSVP.defer(); + + env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + query(store, type, query) { + return defered.promise; + }, + }) + ); + + let result; + run(function() { + result = store.query('person', {}); + }); + + assert.notOk(result.get('meta.foo'), 'precond: meta is not yet set'); + + run(function() { + defered.resolve({ data: [], meta: { foo: 'bar' } }); + }); + + assert.equal(result.get('meta.foo'), 'bar'); +}); diff --git a/tests/integration/store/serializer-for-test.js b/tests/integration/store/serializer-for-test.js new file mode 100644 index 00000000000..01878d67046 --- /dev/null +++ b/tests/integration/store/serializer-for-test.js @@ -0,0 +1,462 @@ +import { setupTest } from 'ember-qunit'; +import { module, test } from 'qunit'; +import Store from 'ember-data/store'; +import { run } from '@ember/runloop'; + +class TestAdapter { + constructor(args) { + Object.assign(this, args); + this.didInit(); + } + + didInit() {} + + static create(args) { + return new this(args); + } +} + +class TestSerializer { + constructor(args) { + Object.assign(this, args); + this.didInit(); + } + + didInit() {} + + static create(args) { + return new this(args); + } +} + +/* + Serializer Fallback Rules + + 1. per-type + 2. application + 3. Adapter.defaultSerializer + 4. serializer:-default (json-api serializer) + */ +module('integration/store - serializerFor', function(hooks) { + setupTest(hooks); + let store; + + hooks.beforeEach(function() { + let { owner } = this; + + store = owner.lookup('service:store'); + }); + + test('when no serializer is available we throw an error', async function(assert) { + let { owner } = this; + /* + serializer:-default is the "last chance" fallback and is + registered automatically as the json-api serializer. + unregistering it will cause serializerFor to return `undefined`. + */ + owner.unregister('serializer:-default'); + /* + we fallback to -json-api adapter by default when no other adapter is present. + This adapter specifies a defaultSerializer. We register our own to ensure + that this does not occur. + */ + class AppAdapter extends TestAdapter { + constructor() { + super(...arguments); + // ensure our adapter instance does not specify a fallback + // we use an empty string as that would cause `owner.lookup` to blow up if not guarded properly + // whereas `null` `undefined` `false` would not. + this.defaultSerializer = ''; + } + } + owner.register('adapter:application', AppAdapter); + + assert.expectAssertion(() => { + store.serializerFor('person'); + }, /No serializer was found for 'person' and no 'application', Adapter\.defaultSerializer, or '-default' serializer were found as fallbacks\./); + }); + + test('we find and instantiate the application serializer', async function(assert) { + let { owner } = this; + let didInstantiate = false; + + class AppSerializer extends TestSerializer { + didInit() { + didInstantiate = true; + } + } + + owner.register('serializer:application', AppSerializer); + + let serializer = store.serializerFor('application'); + + assert.ok(serializer instanceof AppSerializer, 'We found the correct serializer'); + assert.ok(didInstantiate, 'We instantiated the serializer'); + didInstantiate = false; + + let serializerAgain = store.serializerFor('application'); + + assert.ok(serializerAgain instanceof AppSerializer, 'We found the correct serializer'); + assert.ok(!didInstantiate, 'We did not instantiate the serializer again'); + assert.ok( + serializer === serializerAgain, + 'Repeated calls to serializerFor return the same instance' + ); + }); + + test('multiple stores do not share serializers', async function(assert) { + let { owner } = this; + let didInstantiate = false; + + class AppSerializer extends TestSerializer { + didInit() { + didInstantiate = true; + } + } + + owner.register('serializer:application', AppSerializer); + owner.register('service:other-store', Store); + + let otherStore = owner.lookup('service:other-store'); + let serializer = store.serializerFor('application'); + + assert.ok(serializer instanceof AppSerializer, 'We found the correct serializer'); + assert.ok(didInstantiate, 'We instantiated the serializer'); + didInstantiate = false; + + let otherSerializer = otherStore.serializerFor('application'); + assert.ok(otherSerializer instanceof AppSerializer, 'We found the correct serializer again'); + assert.ok(didInstantiate, 'We instantiated the other serializer'); + assert.ok(otherSerializer !== serializer, 'We have a different serializer instance'); + + // Ember 2.18 requires us to wrap destroy in a run. Use `await settled()` for newer versions. + run(() => otherStore.destroy()); + }); + + test('we can find and instantiate per-type serializers', async function(assert) { + let { owner } = this; + let didInstantiateAppSerializer = false; + let didInstantiatePersonSerializer = false; + + class AppSerializer extends TestSerializer { + didInit() { + didInstantiateAppSerializer = true; + } + } + + class PersonSerializer extends TestSerializer { + didInit() { + didInstantiatePersonSerializer = true; + } + } + + owner.register('serializer:application', AppSerializer); + owner.register('serializer:person', PersonSerializer); + + let serializer = store.serializerFor('person'); + + assert.ok(serializer instanceof PersonSerializer, 'We found the correct serializer'); + assert.ok(didInstantiatePersonSerializer, 'We instantiated the person serializer'); + assert.ok(!didInstantiateAppSerializer, 'We did not instantiate the application serializer'); + + let appSerializer = store.serializerFor('application'); + assert.ok(appSerializer instanceof AppSerializer, 'We found the correct serializer'); + assert.ok(didInstantiateAppSerializer, 'We instantiated the application serializer'); + assert.ok(appSerializer !== serializer, 'We have separate serializers'); + }); + + test('we fallback to the application serializer when a per-type serializer is not found', async function(assert) { + let { owner } = this; + let didInstantiateAppSerializer = false; + + class AppSerializer extends TestSerializer { + didInit() { + didInstantiateAppSerializer = true; + } + } + + owner.register('serializer:application', AppSerializer); + + let serializer = store.serializerFor('person'); + + assert.ok(serializer instanceof AppSerializer, 'We found the serializer'); + assert.ok(didInstantiateAppSerializer, 'We instantiated the serializer'); + didInstantiateAppSerializer = false; + + let appSerializer = store.serializerFor('application'); + assert.ok(appSerializer instanceof AppSerializer, 'We found the correct serializer'); + assert.ok(!didInstantiateAppSerializer, 'We did not instantiate the serializer again'); + assert.ok(appSerializer === serializer, 'We fell back to the application serializer instance'); + }); + + module('Adapter Fallback', function() { + test('we can specify a fallback serializer on the adapter when there is no application serializer', async function(assert) { + let { owner } = this; + let personAdapterDidInit = false; + let fallbackSerializerDidInit = false; + + class PersonAdapter extends TestAdapter { + constructor() { + super(...arguments); + this.defaultSerializer = '-fallback'; + } + + didInit() { + personAdapterDidInit = true; + } + } + class FallbackSerializer extends TestSerializer { + didInit() { + fallbackSerializerDidInit = true; + } + } + + owner.register('adapter:person', PersonAdapter); + owner.register('serializer:-fallback', FallbackSerializer); + + let serializer = store.serializerFor('person'); + + assert.ok(serializer instanceof FallbackSerializer, 'We found the serializer'); + assert.ok(personAdapterDidInit, 'We instantiated the adapter'); + assert.ok(fallbackSerializerDidInit, 'We instantiated the serializer'); + personAdapterDidInit = false; + fallbackSerializerDidInit = false; + + let fallbackSerializer = store.serializerFor('-fallback'); + assert.ok( + fallbackSerializer instanceof FallbackSerializer, + 'We found the correct serializer' + ); + assert.ok(!fallbackSerializerDidInit, 'We did not instantiate the serializer again'); + assert.ok(!personAdapterDidInit, 'We did not instantiate the adapter again'); + assert.ok( + fallbackSerializer === serializer, + 'We fell back to the fallback-serializer instance' + ); + }); + + test('specifying defaultSerializer on application serializer when there is a per-type serializer does not work', async function(assert) { + let { owner } = this; + let appAdapterDidInit = false; + let personAdapterDidInit = false; + let fallbackSerializerDidInit = false; + let defaultSerializerDidInit = false; + + class AppAdapter extends TestAdapter { + constructor() { + super(...arguments); + this.defaultSerializer = '-fallback'; + } + + didInit() { + appAdapterDidInit = true; + } + } + class PersonAdapter extends TestAdapter { + constructor() { + super(...arguments); + this.defaultSerializer = null; + } + + didInit() { + personAdapterDidInit = true; + } + } + class FallbackSerializer extends TestSerializer { + didInit() { + fallbackSerializerDidInit = true; + } + } + class DefaultSerializer extends TestSerializer { + didInit() { + defaultSerializerDidInit = true; + } + } + + owner.register('adapter:application', AppAdapter); + owner.register('adapter:person', PersonAdapter); + owner.register('serializer:-fallback', FallbackSerializer); + /* + serializer:-default is the "last chance" fallback and is + registered automatically as the json-api serializer. + */ + owner.unregister('serializer:-default'); + owner.register('serializer:-default', DefaultSerializer); + + let serializer = store.serializerFor('person'); + + assert.ok(serializer instanceof DefaultSerializer, 'We found the serializer'); + assert.ok(personAdapterDidInit, 'We instantiated the person adapter'); + assert.ok(!appAdapterDidInit, 'We did not instantiate the application adapter'); + assert.ok( + !fallbackSerializerDidInit, + 'We did not instantiate the application adapter fallback serializer' + ); + assert.ok(defaultSerializerDidInit, 'We instantiated the `-default` fallback serializer'); + personAdapterDidInit = false; + appAdapterDidInit = false; + fallbackSerializerDidInit = false; + defaultSerializerDidInit = false; + + let defaultSerializer = store.serializerFor('-default'); + assert.ok(defaultSerializer instanceof DefaultSerializer, 'We found the correct serializer'); + assert.ok(!defaultSerializerDidInit, 'We did not instantiate the serializer again'); + assert.ok(!appAdapterDidInit, 'We did not instantiate the application adapter'); + assert.ok( + !fallbackSerializerDidInit, + 'We did not instantiate the application adapter fallback serializer' + ); + assert.ok(!personAdapterDidInit, 'We did not instantiate the adapter again'); + assert.ok( + defaultSerializer === serializer, + 'We fell back to the fallback-serializer instance' + ); + }); + + test('specifying defaultSerializer on a fallback serializer when there is no per-type serializer does work', async function(assert) { + let { owner } = this; + let appAdapterDidInit = false; + let fallbackSerializerDidInit = false; + let defaultSerializerDidInit = false; + + class AppAdapter extends TestAdapter { + constructor() { + super(...arguments); + this.defaultSerializer = '-fallback'; + } + + didInit() { + appAdapterDidInit = true; + } + } + class FallbackSerializer extends TestSerializer { + didInit() { + fallbackSerializerDidInit = true; + } + } + class DefaultSerializer extends TestSerializer { + didInit() { + defaultSerializerDidInit = true; + } + } + + owner.register('adapter:application', AppAdapter); + owner.register('serializer:-fallback', FallbackSerializer); + /* + serializer:-default is the "last chance" fallback and is + registered automatically as the json-api serializer. + */ + owner.unregister('serializer:-default'); + owner.register('serializer:-default', DefaultSerializer); + + let serializer = store.serializerFor('person'); + + assert.ok(serializer instanceof FallbackSerializer, 'We found the serializer'); + assert.ok(appAdapterDidInit, 'We instantiated the fallback application adapter'); + assert.ok( + fallbackSerializerDidInit, + 'We instantiated the application adapter fallback defaultSerializer' + ); + assert.ok( + !defaultSerializerDidInit, + 'We did not instantiate the `-default` fallback serializer' + ); + appAdapterDidInit = false; + fallbackSerializerDidInit = false; + defaultSerializerDidInit = false; + + let fallbackSerializer = store.serializerFor('-fallback'); + assert.ok( + fallbackSerializer instanceof FallbackSerializer, + 'We found the correct serializer' + ); + assert.ok(!defaultSerializerDidInit, 'We did not instantiate the default serializer'); + assert.ok(!appAdapterDidInit, 'We did not instantiate the application adapter again'); + assert.ok( + !fallbackSerializerDidInit, + 'We did not instantiate the application adapter fallback serializer again' + ); + assert.ok( + fallbackSerializer === serializer, + 'We fell back to the fallback-serializer instance' + ); + }); + }); + + test('When the per-type, application and adapter specified fallback serializer do not exist, we fallback to the -default serializer', async function(assert) { + let { owner } = this; + let appAdapterDidInit = false; + let defaultSerializerDidInit = false; + + class AppAdapter extends TestAdapter { + constructor() { + super(...arguments); + this.defaultSerializer = '-not-a-real-fallback'; + } + + didInit() { + appAdapterDidInit = true; + } + } + class DefaultSerializer extends TestSerializer { + didInit() { + defaultSerializerDidInit = true; + } + } + + owner.register('adapter:application', AppAdapter); + /* + serializer:-default is the "last chance" fallback and is + registered automatically as the json-api serializer. + */ + owner.unregister('serializer:-default'); + owner.register('serializer:-default', DefaultSerializer); + + let serializer = store.serializerFor('person'); + + assert.ok(serializer instanceof DefaultSerializer, 'We found the serializer'); + assert.ok(appAdapterDidInit, 'We instantiated the fallback application adapter'); + assert.ok(defaultSerializerDidInit, 'We instantiated the `-default` fallback serializer'); + appAdapterDidInit = false; + defaultSerializerDidInit = false; + + let appSerializer = store.serializerFor('application'); + + assert.ok(appSerializer instanceof DefaultSerializer, 'We found the serializer'); + assert.ok(!appAdapterDidInit, 'We did not instantiate the application adapter again'); + assert.ok( + !defaultSerializerDidInit, + 'We did not instantiate the `-default` fallback serializer again' + ); + appAdapterDidInit = false; + defaultSerializerDidInit = false; + + let fallbackSerializer = store.serializerFor('-not-a-real-fallback'); + + assert.ok(fallbackSerializer instanceof DefaultSerializer, 'We found the serializer'); + assert.ok(!appAdapterDidInit, 'We did not instantiate the application adapter again'); + assert.ok( + !defaultSerializerDidInit, + 'We did not instantiate the `-default` fallback serializer again' + ); + appAdapterDidInit = false; + defaultSerializerDidInit = false; + + let defaultSerializer = store.serializerFor('-default'); + assert.ok(defaultSerializer instanceof DefaultSerializer, 'We found the correct serializer'); + assert.ok(!defaultSerializerDidInit, 'We did not instantiate the default serializer again'); + assert.ok(!appAdapterDidInit, 'We did not instantiate the application adapter again'); + assert.ok( + defaultSerializer === serializer, + 'We fell back to the -default serializer instance for the per-type serializer' + ); + assert.ok( + defaultSerializer === appSerializer, + 'We fell back to the -default serializer instance for the application serializer' + ); + assert.ok( + defaultSerializer === fallbackSerializer, + 'We fell back to the -default serializer instance for the adapter defaultSerializer' + ); + }); +}); diff --git a/tests/test-helper.js b/tests/test-helper.js new file mode 100644 index 00000000000..07bd3a07333 --- /dev/null +++ b/tests/test-helper.js @@ -0,0 +1,66 @@ +import RSVP from 'rsvp'; +import resolver from './helpers/resolver'; +import { setResolver } from '@ember/test-helpers'; +import { start } from 'ember-qunit'; + +import QUnit from 'qunit'; +import DS from 'ember-data'; +import { wait, asyncEqual, invokeAsync } from 'dummy/tests/helpers/async'; + +// TODO get us to a setApplication world instead +// seems to require killing off createStore +setResolver(resolver); + +const { assert } = QUnit; +const transforms = { + boolean: DS.BooleanTransform.create(), + date: DS.DateTransform.create(), + number: DS.NumberTransform.create(), + string: DS.StringTransform.create(), +}; + +QUnit.begin(() => { + RSVP.configure('onerror', reason => { + // only print error messages if they're exceptions; + // otherwise, let a future turn of the event loop + // handle the error. + if (reason && reason instanceof Error) { + throw reason; + } + }); + + // Prevent all tests involving serialization to require a container + // TODO kill the need for this + DS.JSONSerializer.reopen({ + transformFor(attributeType) { + return this._super(attributeType, true) || transforms[attributeType]; + }, + }); +}); + +assert.wait = wait; +assert.asyncEqual = asyncEqual; +assert.invokeAsync = invokeAsync; +assert.assertClean = function(promise) { + return promise.then( + this.wait(record => { + this.equal(record.get('hasDirtyAttributes'), false, 'The record is now clean'); + return record; + }) + ); +}; + +assert.contains = function(array, item) { + this.ok(array.indexOf(item) !== -1, `array contains ${item}`); +}; + +assert.without = function(array, item) { + this.ok(array.indexOf(item) === -1, `array doesn't contain ${item}`); +}; + +QUnit.config.testTimeout = 2000; +QUnit.config.urlConfig.push({ + id: 'enableoptionalfeatures', + label: 'Enable Opt Features', +}); +start({ setupTestIsolationValidation: true }); diff --git a/tests/unit/.gitkeep b/tests/unit/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/adapter-errors-test.js b/tests/unit/adapter-errors-test.js new file mode 100644 index 00000000000..aac6600afe4 --- /dev/null +++ b/tests/unit/adapter-errors-test.js @@ -0,0 +1,182 @@ +import EmberError from '@ember/error'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +module('unit/adapter-errors - DS.AdapterError'); + +test('DS.AdapterError', function(assert) { + let error = new DS.AdapterError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof EmberError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'Adapter operation failed'); +}); + +test('DS.InvalidError', function(assert) { + let error = new DS.InvalidError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof DS.AdapterError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'The adapter rejected the commit because it was invalid'); +}); + +test('DS.TimeoutError', function(assert) { + let error = new DS.TimeoutError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof DS.AdapterError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'The adapter operation timed out'); +}); + +test('DS.AbortError', function(assert) { + let error = new DS.AbortError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof DS.AdapterError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'The adapter operation was aborted'); +}); + +test('DS.UnauthorizedError', function(assert) { + let error = new DS.UnauthorizedError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof DS.AdapterError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'The adapter operation is unauthorized'); +}); + +test('DS.ForbiddenError', function(assert) { + let error = new DS.ForbiddenError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof DS.AdapterError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'The adapter operation is forbidden'); +}); + +test('DS.NotFoundError', function(assert) { + let error = new DS.NotFoundError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof DS.AdapterError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'The adapter could not find the resource'); +}); + +test('DS.ConflictError', function(assert) { + let error = new DS.ConflictError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof DS.AdapterError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'The adapter operation failed due to a conflict'); +}); + +test('DS.ServerError', function(assert) { + let error = new DS.ServerError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof DS.AdapterError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'The adapter operation failed due to a server error'); +}); + +test('CustomAdapterError', function(assert) { + let CustomAdapterError = DS.AdapterError.extend(); + let error = new CustomAdapterError(); + + assert.ok(error instanceof Error); + assert.ok(error instanceof DS.AdapterError); + assert.ok(error.isAdapterError); + assert.equal(error.message, 'Adapter operation failed'); +}); + +test('CustomAdapterError with default message', function(assert) { + let CustomAdapterError = DS.AdapterError.extend({ message: 'custom error!' }); + let error = new CustomAdapterError(); + + assert.equal(error.message, 'custom error!'); +}); + +const errorsHash = { + name: ['is invalid', 'must be a string'], + age: ['must be a number'], +}; + +const errorsArray = [ + { + title: 'Invalid Attribute', + detail: 'is invalid', + source: { pointer: '/data/attributes/name' }, + }, + { + title: 'Invalid Attribute', + detail: 'must be a string', + source: { pointer: '/data/attributes/name' }, + }, + { + title: 'Invalid Attribute', + detail: 'must be a number', + source: { pointer: '/data/attributes/age' }, + }, +]; + +const errorsPrimaryHash = { + base: ['is invalid', 'error message'], +}; + +const errorsPrimaryArray = [ + { + title: 'Invalid Document', + detail: 'is invalid', + source: { pointer: '/data' }, + }, + { + title: 'Invalid Document', + detail: 'error message', + source: { pointer: '/data' }, + }, +]; + +test('errorsHashToArray', function(assert) { + let result = DS.errorsHashToArray(errorsHash); + assert.deepEqual(result, errorsArray); +}); + +test('errorsHashToArray for primary data object', function(assert) { + let result = DS.errorsHashToArray(errorsPrimaryHash); + assert.deepEqual(result, errorsPrimaryArray); +}); + +test('errorsArrayToHash', function(assert) { + let result = DS.errorsArrayToHash(errorsArray); + assert.deepEqual(result, errorsHash); +}); + +test('errorsArrayToHash without trailing slash', function(assert) { + let result = DS.errorsArrayToHash([ + { + detail: 'error message', + source: { pointer: 'data/attributes/name' }, + }, + ]); + assert.deepEqual(result, { name: ['error message'] }); +}); + +test('errorsArrayToHash for primary data object', function(assert) { + let result = DS.errorsArrayToHash(errorsPrimaryArray); + assert.deepEqual(result, errorsPrimaryHash); +}); + +testInDebug('DS.InvalidError will normalize errors hash will assert', function(assert) { + assert.expectAssertion(function() { + new DS.InvalidError({ name: ['is invalid'] }); + }, /expects json-api formatted errors/); +}); diff --git a/tests/unit/adapters/build-url-mixin/build-url-test.js b/tests/unit/adapters/build-url-mixin/build-url-test.js new file mode 100644 index 00000000000..98fdacfb172 --- /dev/null +++ b/tests/unit/adapters/build-url-mixin/build-url-test.js @@ -0,0 +1,161 @@ +import setupStore from 'dummy/tests/helpers/store'; +import DS from 'ember-data'; + +import { module, test } from 'qunit'; + +let adapter, env; + +module('unit/adapters/build-url-mixin/build-url - DS.BuildURLMixin#buildURL', { + beforeEach() { + const customPathForType = { + pathForType(type) { + if (type === 'rootModel') { + return ''; + } + return this._super(type); + }, + }; + + const Adapter = DS.Adapter.extend(DS.BuildURLMixin, customPathForType); + + env = setupStore({ + adapter: Adapter, + }); + + adapter = env.adapter; + }, +}); + +test('buildURL - works with empty paths', function(assert) { + assert.equal(adapter.buildURL('rootModel', 1), '/1'); +}); + +test('buildURL - find requestType delegates to urlForFindRecord', function(assert) { + assert.expect(4); + let snapshotStub = { snapshot: true }; + let originalMethod = adapter.urlForFindRecord; + adapter.urlForFindRecord = function(id, type, snapshot) { + assert.equal(id, 1); + assert.equal(type, 'super-user'); + assert.equal(snapshot, snapshotStub); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', 1, snapshotStub, 'findRecord'), '/superUsers/1'); +}); + +test('buildURL - findAll requestType delegates to urlForFindAll', function(assert) { + assert.expect(3); + let originalMethod = adapter.urlForFindAll; + let snapshotStub = { snapshot: true }; + adapter.urlForFindAll = function(type, snapshot) { + assert.equal(type, 'super-user'); + assert.equal(snapshot, snapshotStub); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', null, snapshotStub, 'findAll'), '/superUsers'); +}); + +test('buildURL - query requestType delegates to urlForQuery', function(assert) { + assert.expect(3); + let originalMethod = adapter.urlForQuery; + let queryStub = { limit: 10 }; + adapter.urlForQuery = function(query, type) { + assert.equal(query, queryStub); + assert.equal(type, 'super-user'); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', null, null, 'query', queryStub), '/superUsers'); +}); + +test('buildURL - queryRecord requestType delegates to urlForQueryRecord', function(assert) { + assert.expect(3); + let originalMethod = adapter.urlForQueryRecord; + let queryStub = { companyId: 10 }; + adapter.urlForQueryRecord = function(query, type) { + assert.equal(query, queryStub); + assert.equal(type, 'super-user'); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', null, null, 'queryRecord', queryStub), '/superUsers'); +}); + +test('buildURL - findMany requestType delegates to urlForFindMany', function(assert) { + assert.expect(3); + let originalMethod = adapter.urlForFindMany; + let idsStub = [1, 2, 3]; + adapter.urlForFindMany = function(ids, type) { + assert.equal(ids, idsStub); + assert.equal(type, 'super-user'); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', idsStub, null, 'findMany'), '/superUsers'); +}); + +test('buildURL - findHasMany requestType delegates to urlForFindHasMany', function(assert) { + assert.expect(4); + let originalMethod = adapter.urlForFindHasMany; + let snapshotStub = { snapshot: true }; + adapter.urlForFindHasMany = function(id, type, snapshot) { + assert.equal(id, 1); + assert.equal(type, 'super-user'); + assert.equal(snapshot, snapshotStub); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', 1, snapshotStub, 'findHasMany'), '/superUsers/1'); +}); + +test('buildURL - findBelongsTo requestType delegates to urlForFindBelongsTo', function(assert) { + assert.expect(4); + let originalMethod = adapter.urlForFindBelongsTo; + let snapshotStub = { snapshot: true }; + adapter.urlForFindBelongsTo = function(id, type, snapshot) { + assert.equal(id, 1); + assert.equal(type, 'super-user'); + assert.equal(snapshot, snapshotStub); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', 1, snapshotStub, 'findBelongsTo'), '/superUsers/1'); +}); + +test('buildURL - createRecord requestType delegates to urlForCreateRecord', function(assert) { + assert.expect(3); + let snapshotStub = { snapshot: true }; + let originalMethod = adapter.urlForCreateRecord; + adapter.urlForCreateRecord = function(type, snapshot) { + assert.equal(type, 'super-user'); + assert.equal(snapshot, snapshotStub); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', null, snapshotStub, 'createRecord'), '/superUsers'); +}); + +test('buildURL - updateRecord requestType delegates to urlForUpdateRecord', function(assert) { + assert.expect(4); + let snapshotStub = { snapshot: true }; + let originalMethod = adapter.urlForUpdateRecord; + adapter.urlForUpdateRecord = function(id, type, snapshot) { + assert.equal(id, 1); + assert.equal(type, 'super-user'); + assert.equal(snapshot, snapshotStub); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', 1, snapshotStub, 'updateRecord'), '/superUsers/1'); +}); + +test('buildURL - deleteRecord requestType delegates to urlForDeleteRecord', function(assert) { + assert.expect(4); + let snapshotStub = { snapshot: true }; + let originalMethod = adapter.urlForDeleteRecord; + adapter.urlForDeleteRecord = function(id, type, snapshot) { + assert.equal(id, 1); + assert.equal(type, 'super-user'); + assert.equal(snapshot, snapshotStub); + return originalMethod.apply(this, arguments); + }; + assert.equal(adapter.buildURL('super-user', 1, snapshotStub, 'deleteRecord'), '/superUsers/1'); +}); + +test('buildURL - unknown requestType', function(assert) { + assert.equal(adapter.buildURL('super-user', 1, null, 'unknown'), '/superUsers/1'); + assert.equal(adapter.buildURL('super-user', null, null, 'unknown'), '/superUsers'); +}); diff --git a/tests/unit/adapters/build-url-mixin/path-for-type-test.js b/tests/unit/adapters/build-url-mixin/path-for-type-test.js new file mode 100644 index 00000000000..701bb729787 --- /dev/null +++ b/tests/unit/adapters/build-url-mixin/path-for-type-test.js @@ -0,0 +1,45 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import DS from 'ember-data'; + +import { module, test } from 'qunit'; + +let env, adapter; + +module('unit/adapters/build-url-mixin/path-for-type - DS.BuildURLMixin#pathForType', { + beforeEach() { + // test for overriden pathForType methods which return null path values + let customPathForType = { + pathForType(type) { + if (type === 'rootModel') { + return ''; + } + return this._super(type); + }, + }; + + let Adapter = DS.Adapter.extend(DS.BuildURLMixin, customPathForType); + + env = setupStore({ + adapter: Adapter, + }); + + adapter = env.adapter; + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +test('pathForType - works with camelized types', function(assert) { + assert.equal(adapter.pathForType('superUser'), 'superUsers'); +}); + +test('pathForType - works with dasherized types', function(assert) { + assert.equal(adapter.pathForType('super-user'), 'superUsers'); +}); + +test('pathForType - works with underscored types', function(assert) { + assert.equal(adapter.pathForType('super_user'), 'superUsers'); +}); diff --git a/tests/unit/adapters/json-api-adapter/ajax-test.js b/tests/unit/adapters/json-api-adapter/ajax-test.js new file mode 100644 index 00000000000..6f497553b52 --- /dev/null +++ b/tests/unit/adapters/json-api-adapter/ajax-test.js @@ -0,0 +1,86 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let Person, Place, store, adapter, env; + +function alphabetize(headers) { + return headers.sort((a, b) => (a[0] > b[0] ? 1 : -1)); +} + +module('unit/adapters/json-api-adapter/ajax - building requests', { + beforeEach() { + Person = { modelName: 'person' }; + Place = { modelName: 'place' }; + env = setupStore({ adapter: DS.JSONAPIAdapter, person: Person, place: Place }); + store = env.store; + adapter = env.adapter; + }, + + afterEach() { + run(() => { + store.destroy(); + env.container.destroy(); + }); + }, +}); + +test('ajaxOptions() adds Accept when no other headers exist', function(assert) { + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + let receivedHeaders = []; + let fakeXHR = { + setRequestHeader(key, value) { + receivedHeaders.push([key, value]); + }, + }; + ajaxOptions.beforeSend(fakeXHR); + assert.deepEqual( + alphabetize(receivedHeaders), + [['Accept', 'application/vnd.api+json']], + 'headers assigned' + ); +}); + +test('ajaxOptions() adds Accept header to existing headers', function(assert) { + adapter.headers = { 'Other-key': 'Other Value' }; + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + let receivedHeaders = []; + let fakeXHR = { + setRequestHeader(key, value) { + receivedHeaders.push([key, value]); + }, + }; + ajaxOptions.beforeSend(fakeXHR); + assert.deepEqual( + alphabetize(receivedHeaders), + [['Accept', 'application/vnd.api+json'], ['Other-key', 'Other Value']], + 'headers assigned' + ); +}); + +test('ajaxOptions() adds Accept header to existing computed properties headers', function(assert) { + adapter.headers = { 'Other-key': 'Other Value' }; + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + let receivedHeaders = []; + let fakeXHR = { + setRequestHeader(key, value) { + receivedHeaders.push([key, value]); + }, + }; + ajaxOptions.beforeSend(fakeXHR); + + assert.deepEqual( + alphabetize(receivedHeaders), + [['Accept', 'application/vnd.api+json'], ['Other-key', 'Other Value']], + 'headers assigned' + ); +}); diff --git a/tests/unit/adapters/json-api-adapter/fetch-test.js b/tests/unit/adapters/json-api-adapter/fetch-test.js new file mode 100644 index 00000000000..01ae37e23a3 --- /dev/null +++ b/tests/unit/adapters/json-api-adapter/fetch-test.js @@ -0,0 +1,75 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let Person, Place, store, adapter, env; + +module('unit/adapters/json-api-adapter/fetch - building requests', { + beforeEach() { + Person = { modelName: 'person' }; + Place = { modelName: 'place' }; + env = setupStore({ adapter: DS.JSONAPIAdapter, person: Person, place: Place }); + store = env.store; + adapter = env.adapter; + adapter.set('useFetch', true); + }, + + afterEach() { + run(() => { + store.destroy(); + env.container.destroy(); + }); + }, +}); + +test('ajaxOptions() adds Accept when no other headers exist', function(assert) { + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + let receivedHeaders = ajaxOptions.headers; + + assert.deepEqual( + receivedHeaders, + { + Accept: 'application/vnd.api+json', + }, + 'headers assigned' + ); +}); + +test('ajaxOptions() adds Accept header to existing headers', function(assert) { + adapter.headers = { 'Other-key': 'Other Value' }; + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + let receivedHeaders = ajaxOptions.headers; + + assert.deepEqual( + receivedHeaders, + { + Accept: 'application/vnd.api+json', + 'Other-key': 'Other Value', + }, + 'headers assigned' + ); +}); + +test('ajaxOptions() adds Accept header to existing computed properties headers', function(assert) { + adapter.headers = { 'Other-key': 'Other Value' }; + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + let receivedHeaders = ajaxOptions.headers; + + assert.deepEqual( + receivedHeaders, + { + Accept: 'application/vnd.api+json', + 'Other-key': 'Other Value', + }, + 'headers assigned' + ); +}); diff --git a/tests/unit/adapters/rest-adapter/ajax-test.js b/tests/unit/adapters/rest-adapter/ajax-test.js new file mode 100644 index 00000000000..2581b635a0c --- /dev/null +++ b/tests/unit/adapters/rest-adapter/ajax-test.js @@ -0,0 +1,139 @@ +import { resolve, Promise as EmberPromise } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var Person, Place, store, adapter, env; + +module('unit/adapters/rest-adapter/ajax - building requests', { + beforeEach() { + Person = { modelName: 'person' }; + Place = { modelName: 'place' }; + env = setupStore({ adapter: DS.RESTAdapter, person: Person, place: Place }); + store = env.store; + adapter = env.adapter; + }, + + afterEach() { + run(() => { + store.destroy(); + env.container.destroy(); + }); + }, +}); + +test('When an id is searched, the correct url should be generated', function(assert) { + assert.expect(2); + + let count = 0; + + adapter.ajax = function(url, method) { + if (count === 0) { + assert.equal(url, '/people/1', 'should create the correct url'); + } + if (count === 1) { + assert.equal(url, '/places/1', 'should create the correct url'); + } + count++; + return resolve(); + }; + + return run(() => { + return EmberPromise.all([ + adapter.findRecord(store, Person, 1, {}), + adapter.findRecord(store, Place, 1, {}), + ]); + }); +}); + +test(`id's should be sanatized`, function(assert) { + assert.expect(1); + + adapter.ajax = function(url, method) { + assert.equal(url, '/people/..%2Fplace%2F1', 'should create the correct url'); + return resolve(); + }; + + return run(() => adapter.findRecord(store, Person, '../place/1', {})); +}); + +test('ajaxOptions() headers are set', function(assert) { + adapter.headers = { + 'Content-Type': 'application/json', + 'Other-key': 'Other Value', + }; + + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + let receivedHeaders = []; + let fakeXHR = { + setRequestHeader(key, value) { + receivedHeaders.push([key, value]); + }, + }; + ajaxOptions.beforeSend(fakeXHR); + assert.deepEqual( + receivedHeaders, + [['Content-Type', 'application/json'], ['Other-key', 'Other Value']], + 'headers assigned' + ); +}); + +test('ajaxOptions() do not serializes data when GET', function(assert) { + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, { data: { key: 'value' } }); + delete ajaxOptions.beforeSend; + + assert.deepEqual(ajaxOptions, { + context: adapter, + data: { + key: 'value', + }, + dataType: 'json', + type: 'GET', + method: 'GET', + headers: {}, + url: 'example.com', + }); +}); + +test('ajaxOptions() serializes data when not GET', function(assert) { + let url = 'example.com'; + let type = 'POST'; + let ajaxOptions = adapter.ajaxOptions(url, type, { data: { key: 'value' } }); + delete ajaxOptions.beforeSend; + + assert.deepEqual(ajaxOptions, { + contentType: 'application/json; charset=utf-8', + context: adapter, + data: '{"key":"value"}', + dataType: 'json', + type: 'POST', + method: 'POST', + headers: { + 'content-type': 'application/json; charset=utf-8', + }, + url: 'example.com', + }); +}); + +test('ajaxOptions() empty data', function(assert) { + let url = 'example.com'; + let type = 'POST'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + delete ajaxOptions.beforeSend; + + assert.deepEqual(ajaxOptions, { + context: adapter, + dataType: 'json', + type: 'POST', + method: 'POST', + headers: {}, + url: 'example.com', + }); +}); diff --git a/tests/unit/adapters/rest-adapter/build-query-test.js b/tests/unit/adapters/rest-adapter/build-query-test.js new file mode 100644 index 00000000000..f8b6f64f5f7 --- /dev/null +++ b/tests/unit/adapters/rest-adapter/build-query-test.js @@ -0,0 +1,29 @@ +import { module, test } from 'qunit'; +import DS from 'ember-data'; + +module('unit/adapters/rest-adapter/build-query - building queries'); + +test('buildQuery() returns an empty query when snapshot has no query params', function(assert) { + const adapter = DS.RESTAdapter.create(); + const snapshotStub = {}; + + const query = adapter.buildQuery(snapshotStub); + + assert.deepEqual(query, {}, 'query is empty'); +}); + +test(`buildQuery - doesn't fail without a snapshot`, function(assert) { + const adapter = DS.RESTAdapter.create(); + const query = adapter.buildQuery(); + + assert.deepEqual(query, {}, 'returns an empty query'); +}); + +test('buildQuery() returns query with `include` from snapshot', function(assert) { + const adapter = DS.RESTAdapter.create(); + const snapshotStub = { include: 'comments' }; + + const query = adapter.buildQuery(snapshotStub); + + assert.deepEqual(query, { include: 'comments' }, 'query includes `include`'); +}); diff --git a/tests/unit/adapters/rest-adapter/detailed-message-test.js b/tests/unit/adapters/rest-adapter/detailed-message-test.js new file mode 100644 index 00000000000..3971e3b85b8 --- /dev/null +++ b/tests/unit/adapters/rest-adapter/detailed-message-test.js @@ -0,0 +1,61 @@ +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let adapter, env; + +module( + 'unit/adapters/rest_adapter/detailed_message_test - DS.RESTAdapter#generatedDetailedMessage', + { + beforeEach() { + env = setupStore({ adapter: DS.RESTAdapter }); + adapter = env.adapter; + }, + } +); + +test('generating a wonderfully friendly error message should work', function(assert) { + assert.expect(1); + + let friendlyMessage = adapter.generatedDetailedMessage( + 418, + { 'content-type': 'text/plain' }, + "I'm a little teapot, short and stout", + { + url: '/teapots/testing', + method: 'GET', + } + ); + + assert.equal( + friendlyMessage, + [ + 'Ember Data Request GET /teapots/testing returned a 418', + 'Payload (text/plain)', + `I'm a little teapot, short and stout`, + ].join('\n') + ); +}); + +test('generating a friendly error message with a missing content-type header should work', function(assert) { + let friendlyMessage = adapter.generatedDetailedMessage( + 418, + {}, + `I'm a little teapot, short and stout`, + { + url: '/teapots/testing', + method: 'GET', + } + ); + + assert.equal( + friendlyMessage, + [ + 'Ember Data Request GET /teapots/testing returned a 418', + 'Payload (Empty Content-Type)', + `I'm a little teapot, short and stout`, + ].join('\n') + ); +}); diff --git a/tests/unit/adapters/rest-adapter/fetch-test.js b/tests/unit/adapters/rest-adapter/fetch-test.js new file mode 100644 index 00000000000..4e11f58772e --- /dev/null +++ b/tests/unit/adapters/rest-adapter/fetch-test.js @@ -0,0 +1,135 @@ +import { resolve, Promise as EmberPromise } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +var Person, Place, store, adapter, env; + +module('unit/adapters/rest-adapter/fetch - building requests', { + beforeEach() { + Person = { modelName: 'person' }; + Place = { modelName: 'place' }; + env = setupStore({ adapter: DS.RESTAdapter, person: Person, place: Place }); + store = env.store; + adapter = env.adapter; + adapter.set('useFetch', true); + }, + + afterEach() { + run(() => { + store.destroy(); + env.container.destroy(); + }); + }, +}); + +test('When an id is searched, the correct url should be generated', function(assert) { + assert.expect(2); + + let count = 0; + + adapter.ajax = function(url, method) { + if (count === 0) { + assert.equal(url, '/people/1', 'should create the correct url'); + } + if (count === 1) { + assert.equal(url, '/places/1', 'should create the correct url'); + } + count++; + return resolve(); + }; + + return run(() => { + return EmberPromise.all([ + adapter.findRecord(store, Person, 1, {}), + adapter.findRecord(store, Place, 1, {}), + ]); + }); +}); + +test(`id's should be sanatized`, function(assert) { + assert.expect(1); + + adapter.ajax = function(url, method) { + assert.equal(url, '/people/..%2Fplace%2F1', 'should create the correct url'); + return resolve(); + }; + + return run(() => adapter.findRecord(store, Person, '../place/1', {})); +}); + +test('ajaxOptions() headers are set', function(assert) { + adapter.headers = { + 'Content-Type': 'application/json', + 'Other-key': 'Other Value', + }; + + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + let receivedHeaders = ajaxOptions.headers; + + assert.deepEqual( + receivedHeaders, + { + 'Content-Type': 'application/json', + 'Other-key': 'Other Value', + }, + 'headers assigned' + ); +}); + +test('ajaxOptions() do not serializes data when GET', function(assert) { + let url = 'example.com'; + let type = 'GET'; + let ajaxOptions = adapter.ajaxOptions(url, type, { data: { key: 'value' } }); + delete ajaxOptions.beforeSend; + + assert.deepEqual(ajaxOptions, { + credentials: 'same-origin', + data: { + key: 'value', + }, + type: 'GET', + method: 'GET', + headers: {}, + url: 'example.com?key=value', + }); +}); + +test('ajaxOptions() serializes data when not GET', function(assert) { + let url = 'example.com'; + let type = 'POST'; + let ajaxOptions = adapter.ajaxOptions(url, type, { data: { key: 'value' } }); + delete ajaxOptions.beforeSend; + + assert.deepEqual(ajaxOptions, { + credentials: 'same-origin', + data: { key: 'value' }, + body: '{"key":"value"}', + type: 'POST', + method: 'POST', + headers: { + 'content-type': 'application/json; charset=utf-8', + }, + url: 'example.com', + }); +}); + +test('ajaxOptions() empty data', function(assert) { + let url = 'example.com'; + let type = 'POST'; + let ajaxOptions = adapter.ajaxOptions(url, type, {}); + delete ajaxOptions.beforeSend; + + assert.deepEqual(ajaxOptions, { + credentials: 'same-origin', + type: 'POST', + method: 'POST', + headers: {}, + url: 'example.com', + }); +}); diff --git a/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js b/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js new file mode 100644 index 00000000000..083f04929e6 --- /dev/null +++ b/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js @@ -0,0 +1,95 @@ +import { run } from '@ember/runloop'; +import { Promise as EmberPromise } from 'rsvp'; +import { createStore } from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let GroupsAdapter, store, requests; +let maxLength; +let lengths; + +module( + 'unit/adapters/rest_adapter/group_records_for_find_many_test - DS.RESTAdapter#groupRecordsForFindMany', + { + beforeEach() { + maxLength = -1; + requests = []; + lengths = []; + + GroupsAdapter = DS.RESTAdapter.extend({ + coalesceFindRequests: true, + + findRecord(store, type, id, snapshot) { + return { id }; + }, + }); + + GroupsAdapter.reopen({ + ajax(url, type, options) { + requests.push({ + url, + ids: options.data.ids, + }); + + let queryString = options.data.ids + .map(i => { + return encodeURIComponent('ids[]') + '=' + encodeURIComponent(i); + }) + .join('&'); + let fullUrl = url + '?' + queryString; + + maxLength = this.get('maxURLLength'); + lengths.push(fullUrl.length); + + let testRecords = options.data.ids.map(id => ({ id })); + return EmberPromise.resolve({ testRecords: testRecords }); + }, + }); + + store = createStore({ + adapter: GroupsAdapter, + testRecord: DS.Model.extend(), + }); + }, + afterEach() { + run(store, 'destroy'); + }, + } +); + +test('groupRecordsForFindMany - findMany', function(assert) { + let wait = []; + run(() => { + for (var i = 1; i <= 1024; i++) { + wait.push(store.findRecord('testRecord', i)); + } + }); + + assert.ok(lengths.every(len => len <= maxLength), `Some URLs are longer than ${maxLength} chars`); + return EmberPromise.all(wait); +}); + +test('groupRecordsForFindMany works for encodeURIComponent-ified ids', function(assert) { + let wait = []; + run(() => { + wait.push(store.findRecord('testRecord', 'my-id:1')); + wait.push(store.findRecord('testRecord', 'my-id:2')); + }); + + assert.equal(requests.length, 1); + assert.equal(requests[0].url, '/testRecords'); + assert.deepEqual(requests[0].ids, ['my-id:1', 'my-id:2']); + + return EmberPromise.all(wait); +}); + +test('_stripIDFromURL works with id being encoded - #4190', function(assert) { + let record = store.createRecord('testRecord', { id: 'id:123' }); + let adapter = store.adapterFor('testRecord'); + let snapshot = record._internalModel.createSnapshot(); + let strippedUrl = adapter._stripIDFromURL(store, snapshot); + + assert.equal(strippedUrl, '/testRecords/'); +}); diff --git a/tests/unit/debug-test.js b/tests/unit/debug-test.js new file mode 100644 index 00000000000..937ced7dbf9 --- /dev/null +++ b/tests/unit/debug-test.js @@ -0,0 +1,113 @@ +import { computed } from '@ember/object'; +import { createStore } from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +const TestAdapter = DS.Adapter.extend(); + +module('Debug'); + +test('_debugInfo groups the attributes and relationships correctly', function(assert) { + const MaritalStatus = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Post = DS.Model.extend({ + title: DS.attr('string'), + }); + + const User = DS.Model.extend({ + name: DS.attr('string'), + isDrugAddict: DS.attr('boolean'), + maritalStatus: DS.belongsTo('marital-status', { async: false }), + posts: DS.hasMany('post', { async: false }), + }); + + let store = createStore({ + adapter: TestAdapter.extend(), + maritalStatus: MaritalStatus, + post: Post, + user: User, + }); + + let record = store.createRecord('user'); + + let propertyInfo = record._debugInfo().propertyInfo; + + assert.equal(propertyInfo.groups.length, 4); + assert.deepEqual(propertyInfo.groups[0].properties, ['id', 'name', 'isDrugAddict']); + assert.deepEqual(propertyInfo.groups[1].properties, ['maritalStatus']); + assert.deepEqual(propertyInfo.groups[2].properties, ['posts']); +}); + +test('_debugInfo supports arbitray relationship types', function(assert) { + const MaritalStatus = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Post = DS.Model.extend({ + title: DS.attr('string'), + }); + + const User = DS.Model.extend({ + name: DS.attr('string'), + isDrugAddict: DS.attr('boolean'), + maritalStatus: DS.belongsTo('marital-status', { async: false }), + posts: computed(() => [1, 2, 3]) + .readOnly() + .meta({ + options: { inverse: null }, + isRelationship: true, + kind: 'customRelationship', + name: 'posts', + type: 'post', + }), + }); + + let store = createStore({ + adapter: TestAdapter.extend(), + maritalStatus: MaritalStatus, + post: Post, + user: User, + }); + + let record = store.createRecord('user'); + + let propertyInfo = record._debugInfo().propertyInfo; + + assert.deepEqual(propertyInfo, { + includeOtherProperties: true, + groups: [ + { + name: 'Attributes', + properties: ['id', 'name', 'isDrugAddict'], + expand: true, + }, + { + name: 'maritalStatus', + properties: ['maritalStatus'], + expand: true, + }, + { + name: 'posts', + properties: ['posts'], + expand: true, + }, + { + name: 'Flags', + properties: [ + 'isLoaded', + 'hasDirtyAttributes', + 'isSaving', + 'isDeleted', + 'isError', + 'isNew', + 'isValid', + ], + }, + ], + expensiveProperties: ['maritalStatus', 'posts'], + }); +}); diff --git a/tests/unit/diff-array-test.js b/tests/unit/diff-array-test.js new file mode 100644 index 00000000000..791c710fc56 --- /dev/null +++ b/tests/unit/diff-array-test.js @@ -0,0 +1,487 @@ +import { module, test } from 'qunit'; + +import { diffArray } from 'ember-data/-private'; + +module('unit/diff-array Diff Array tests', {}); + +const a = 'aaa'; +const b = 'bbb'; +const c = 'ccc'; +const d = 'ddd'; +const e = 'eee'; +const f = 'fff'; +const g = 'ggg'; +const h = 'hhh'; +const w = 'www'; +const x = 'xxx'; +const y = 'yyy'; +const z = 'zzz'; + +test('diff array returns no change given two empty arrays', function(assert) { + const result = diffArray([], []); + assert.strictEqual(result.firstChangeIndex, null); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns no change given two identical arrays length 1', function(assert) { + const result = diffArray([a], [a]); + assert.strictEqual(result.firstChangeIndex, null); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns no change given two identical arrays length 3', function(assert) { + const result = diffArray([a, b, c], [a, b, c]); + assert.strictEqual(result.firstChangeIndex, null); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given one appended item with old length 0', function(assert) { + const result = diffArray([], [a]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given one appended item with old length 1', function(assert) { + const result = diffArray([a], [a, b]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given one appended item with old length 2', function(assert) { + const result = diffArray([a, b], [a, b, c]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given 3 appended items with old length 0', function(assert) { + const result = diffArray([], [a, b, c]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given 3 appended items with old length 1', function(assert) { + const result = diffArray([a], [a, b, c, d]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given 3 appended items with old length 2', function(assert) { + const result = diffArray([a, b], [a, b, c, d, e]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given one item removed from end with old length 1', function(assert) { + const result = diffArray([a], []); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item removed from end with old length 2', function(assert) { + const result = diffArray([a, b], [a]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item removed from end with old length 3', function(assert) { + const result = diffArray([a, b, c], [a, b]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given 3 items removed from end with old length 3', function(assert) { + const result = diffArray([a, b, c], []); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items removed from end with old length 4', function(assert) { + const result = diffArray([a, b, c, d], [a]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items removed from end with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [a, b]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given one item removed from beginning with old length 2', function(assert) { + const result = diffArray([a, b], [b]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item removed from beginning with old length 3', function(assert) { + const result = diffArray([a, b, c], [b, c]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given 3 items removed from beginning with old length 4', function(assert) { + const result = diffArray([a, b, c, d], [d]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items removed from beginning with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [d, e]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given one item removed from middle with old length 3', function(assert) { + const result = diffArray([a, b, c], [a, c]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item removed from middle with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [a, b, d, e]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given 3 items removed from middle with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [a, e]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items removed from middle with old length 7', function(assert) { + const result = diffArray([a, b, c, d, e, f, g], [a, b, f, g]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 0); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given one item added to middle with old length 2', function(assert) { + const result = diffArray([a, c], [a, b, c]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given one item added to middle with old length 4', function(assert) { + const result = diffArray([a, b, d, e], [a, b, c, d, e]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given 3 items added to middle with old length 2', function(assert) { + const result = diffArray([a, e], [a, b, c, d, e]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given 3 items added to middle with old length 4', function(assert) { + const result = diffArray([a, b, f, g], [a, b, c, d, e, f, g]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 0); +}); + +test('diff array returns correctly given complete replacement with length 1', function(assert) { + const result = diffArray([a], [b]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given complete replacement with length 3', function(assert) { + const result = diffArray([a, b, c], [x, y, z]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given complete replacement with longer length', function(assert) { + const result = diffArray([a, b], [x, y, z]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 2); +}); + +test('diff array returns correctly given one item replaced in middle with old length 3', function(assert) { + const result = diffArray([a, b, c], [a, x, c]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item replaced in middle with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [a, b, x, d, e]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given 3 items replaced in middle with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [a, x, y, z, e]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items replaced in middle with old length 7', function(assert) { + const result = diffArray([a, b, c, d, e, f, g], [a, b, x, y, z, f, g]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given one item replaced at beginning with old length 2', function(assert) { + const result = diffArray([a, b], [x, b]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item replaced at beginning with old length 3', function(assert) { + const result = diffArray([a, b, c], [x, b, c]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given 3 items replaced at beginning with old length 4', function(assert) { + const result = diffArray([a, b, c, d], [x, y, z, d]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items replaced at beginning with old length 6', function(assert) { + const result = diffArray([a, b, c, d, e, f], [x, y, z, d, e, f]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given one item replaced at end with old length 2', function(assert) { + const result = diffArray([a, b], [a, x]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item replaced at end with old length 3', function(assert) { + const result = diffArray([a, b, c], [a, b, x]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given 3 items replaced at end with old length 4', function(assert) { + const result = diffArray([a, b, c, d], [a, x, y, z]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items replaced at end with old length 6', function(assert) { + const result = diffArray([a, b, c, d, e, f], [a, b, c, x, y, z]); + assert.equal(result.firstChangeIndex, 3); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given one item replaced with two in middle with old length 3', function(assert) { + const result = diffArray([a, b, c], [a, x, y, c]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 2); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item replaced with two in middle with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [a, b, x, y, d, e]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 2); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given 3 items replaced with 4 in middle with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [a, w, x, y, z, e]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 4); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items replaced with 4 in middle with old length 7', function(assert) { + const result = diffArray([a, b, c, d, e, f, g], [a, b, w, x, y, z, f, g]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 4); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given one item replaced with two at beginning with old length 2', function(assert) { + const result = diffArray([a, b], [x, y, b]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 2); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item replaced with two at beginning with old length 3', function(assert) { + const result = diffArray([a, b, c], [x, y, b, c]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 2); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given 3 items replaced with 4 at beginning with old length 4', function(assert) { + const result = diffArray([a, b, c, d], [w, x, y, z, d]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 4); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items replaced with 4 at beginning with old length 6', function(assert) { + const result = diffArray([a, b, c, d, e, f], [w, x, y, z, d, e, f]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 4); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given one item replaced with two at end with old length 2', function(assert) { + const result = diffArray([a, b], [a, x, y]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 2); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given one item replaced with two at end with old length 3', function(assert) { + const result = diffArray([a, b, c], [a, b, x, y]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 2); + assert.equal(result.removedCount, 1); +}); + +test('diff array returns correctly given 3 items replaced with 4 at end with old length 4', function(assert) { + const result = diffArray([a, b, c, d], [a, w, x, y, z]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 4); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given 3 items replaced with 4 at end with old length 6', function(assert) { + const result = diffArray([a, b, c, d, e, f], [a, b, c, w, x, y, z]); + assert.equal(result.firstChangeIndex, 3); + assert.equal(result.addedCount, 4); + assert.equal(result.removedCount, 3); +}); + +test('diff array returns correctly given two items replaced with one in middle with old length 4', function(assert) { + const result = diffArray([a, b, c, d], [a, x, d]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 2); +}); + +test('diff array returns correctly given two items replaced with one in middle with old length 6', function(assert) { + const result = diffArray([a, b, c, d, e, f], [a, b, x, e, f]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 2); +}); + +test('diff array returns correctly given 4 items replaced with 3 in middle with old length 6', function(assert) { + const result = diffArray([a, b, c, d, e, f], [a, x, y, z, f]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 4); +}); + +test('diff array returns correctly given 4 items replaced with 3 in middle with old length 8', function(assert) { + const result = diffArray([a, b, c, d, e, f, g, h], [a, b, x, y, z, g, h]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 4); +}); + +test('diff array returns correctly given two items replaced with one at beginning with old length 3', function(assert) { + const result = diffArray([a, b, c], [x, c]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 2); +}); + +test('diff array returns correctly given two items replaced with one at beginning with old length 4', function(assert) { + const result = diffArray([a, b, c, d], [x, c, d]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 2); +}); + +test('diff array returns correctly given 4 items replaced with 3 at beginning with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [x, y, z, e]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 4); +}); + +test('diff array returns correctly given 4 items replaced with 3 at beginning with old length 6', function(assert) { + const result = diffArray([a, b, c, d, e, f], [x, y, z, e, f]); + assert.equal(result.firstChangeIndex, 0); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 4); +}); + +test('diff array returns correctly given two items replaced with one at end with old length 3', function(assert) { + const result = diffArray([a, b, c], [a, x]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 2); +}); + +test('diff array returns correctly given two items replaced with one at end with old length 4', function(assert) { + const result = diffArray([a, b, c, d], [a, b, x]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 1); + assert.equal(result.removedCount, 2); +}); + +test('diff array returns correctly given 4 items replaced with 3 at end with old length 5', function(assert) { + const result = diffArray([a, b, c, d, e], [a, x, y, z]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 4); +}); + +test('diff array returns correctly given 4 items replaced with 3 at end with old length 6', function(assert) { + const result = diffArray([a, b, c, d, e, f], [a, b, x, y, z]); + assert.equal(result.firstChangeIndex, 2); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 4); +}); + +test('diff array returns correctly given non-contiguous insertion', function(assert) { + const result = diffArray([a, c, e], [a, b, c, d, e]); + assert.equal(result.firstChangeIndex, 1); + assert.equal(result.addedCount, 3); + assert.equal(result.removedCount, 1); +}); diff --git a/tests/unit/many-array-test.js b/tests/unit/many-array-test.js new file mode 100644 index 00000000000..c80465b2853 --- /dev/null +++ b/tests/unit/many-array-test.js @@ -0,0 +1,185 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let env, store, Post, Tag; + +const { attr, hasMany, belongsTo } = DS; + +module('unit/many_array - DS.ManyArray', { + beforeEach() { + Post = DS.Model.extend({ + title: attr('string'), + tags: hasMany('tag', { async: false }), + }); + + Post.reopenClass({ + toString() { + return 'Post'; + }, + }); + + Tag = DS.Model.extend({ + name: attr('string'), + post: belongsTo('post', { async: false }), + }); + + Tag.reopenClass({ + toString() { + return 'Tag'; + }, + }); + + env = setupStore({ + post: Post, + tag: Tag, + }); + + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +test('manyArray.save() calls save() on all records', function(assert) { + assert.expect(3); + + Tag.reopen({ + save() { + assert.ok(true, 'record.save() was called'); + return resolve(); + }, + }); + + return run(() => { + store.push({ + data: [ + { + type: 'tag', + id: '1', + attributes: { + name: 'Ember.js', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'Tomster', + }, + }, + { + type: 'post', + id: '3', + attributes: { + title: 'A framework for creating ambitious web applications', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '1' }, { type: 'tag', id: '2' }], + }, + }, + }, + ], + }); + + let post = store.peekRecord('post', 3); + + return post + .get('tags') + .save() + .then(() => { + assert.ok(true, 'manyArray.save() promise resolved'); + }); + }); +}); + +test('manyArray trigger arrayContentChange functions with the correct values', function(assert) { + assert.expect(6); + + let willChangeStartIdx; + let willChangeRemoveAmt; + let willChangeAddAmt; + + let originalArrayContentWillChange = DS.ManyArray.proto().arrayContentWillChange; + let originalArrayContentDidChange = DS.ManyArray.proto().arrayContentDidChange; + + // override DS.ManyArray temp (cleanup occures in afterTest); + + DS.ManyArray.proto().arrayContentWillChange = function(startIdx, removeAmt, addAmt) { + willChangeStartIdx = startIdx; + willChangeRemoveAmt = removeAmt; + willChangeAddAmt = addAmt; + + return originalArrayContentWillChange.apply(this, arguments); + }; + + DS.ManyArray.proto().arrayContentDidChange = function(startIdx, removeAmt, addAmt) { + assert.equal(startIdx, willChangeStartIdx, 'WillChange and DidChange startIdx should match'); + assert.equal(removeAmt, willChangeRemoveAmt, 'WillChange and DidChange removeAmt should match'); + assert.equal(addAmt, willChangeAddAmt, 'WillChange and DidChange addAmt should match'); + + return originalArrayContentDidChange.apply(this, arguments); + }; + + try { + run(() => { + store.push({ + data: [ + { + type: 'tag', + id: '1', + attributes: { + name: 'Ember.js', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'Tomster', + }, + }, + { + type: 'post', + id: '3', + attributes: { + title: 'A framework for creating ambitious web applications', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '1' }], + }, + }, + }, + ], + }); + + store.peekRecord('post', 3).get('tags'); + + store.push({ + data: { + type: 'post', + id: '3', + attributes: { + title: 'A framework for creating ambitious web applications', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '1' }, { type: 'tag', id: '2' }], + }, + }, + }, + }); + }); + } finally { + DS.ManyArray.proto().arrayContentWillChange = originalArrayContentWillChange; + DS.ManyArray.proto().arrayContentDidChange = originalArrayContentDidChange; + } +}); diff --git a/tests/unit/model-test.js b/tests/unit/model-test.js new file mode 100644 index 00000000000..e81a271faf9 --- /dev/null +++ b/tests/unit/model-test.js @@ -0,0 +1,1479 @@ +import { guidFor } from '@ember/object/internals'; +import { resolve, reject } from 'rsvp'; +import { set, get, observer, computed } from '@ember/object'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; +import { settled } from '@ember/test-helpers'; +import { setupTest } from 'ember-qunit'; +import Model from 'ember-data/model'; +import { InvalidError } from 'ember-data/adapters/errors'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import JSONSerializer from 'ember-data/serializers/json'; +import { attr, hasMany, belongsTo } from '@ember-decorators/data'; +import DSattr from 'ember-data/attr'; +import { recordDataFor } from 'ember-data/-private'; + +module('unit/model - Model', function(hooks) { + setupTest(hooks); + let store, adapter; + + hooks.beforeEach(function() { + let { owner } = this; + + class Person extends Model { + @attr('string') + name; + @attr('boolean') + isDrugAddict; + @attr() + isArchived; + } + + owner.register('model:person', Person); + owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + shouldBackgroundReloadRecord: () => false, + }) + ); + owner.register('serializer:-default', JSONAPISerializer); + + store = owner.lookup('service:store'); + adapter = store.adapterFor('application'); + }); + + module('currentState', function() { + test('supports pushedData in root.deleted.uncommitted', async function(assert) { + let record = store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + record.deleteRecord(); + + store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + assert.equal( + get(record, 'currentState.stateName'), + 'root.deleted.uncommitted', + 'record accepts pushedData is in root.deleted.uncommitted state' + ); + }); + + test('supports canonical updates via pushedData in root.deleted.saved', async function(assert) { + adapter.deleteRecord = () => { + return resolve({ data: null }); + }; + + let record = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + isArchived: false, + }, + }, + }); + + await record.destroyRecord(); + + let currentState = record._internalModel.currentState; + + assert.ok( + currentState.stateName === 'root.deleted.saved', + 'record is in a persisted deleted state' + ); + assert.equal(get(record, 'isDeleted'), true); + assert.ok( + store.peekRecord('person', '1') !== null, + 'the deleted person is not removed from store (no unload called)' + ); + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + isArchived: true, + }, + }, + }); + + currentState = record._internalModel.currentState; + + assert.ok( + currentState.stateName === 'root.deleted.saved', + 'record is still in a persisted deleted state' + ); + assert.ok(get(record, 'isDeleted') === true, 'The record is still deleted'); + assert.ok( + get(record, 'isArchived') === true, + 'The record reflects the update to canonical state' + ); + }); + + test('Does not support dirtying in root.deleted.saved', async function(assert) { + adapter.deleteRecord = () => { + return resolve({ data: null }); + }; + + let record = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + isArchived: false, + }, + }, + }); + + await record.destroyRecord(); + + let currentState = record._internalModel.currentState; + + assert.ok( + currentState.stateName === 'root.deleted.saved', + 'record is in a persisted deleted state' + ); + assert.equal(get(record, 'isDeleted'), true); + assert.ok( + store.peekRecord('person', '1') !== null, + 'the deleted person is not removed from store (no unload called)' + ); + + assert.expectAssertion(() => { + set(record, 'isArchived', true); + }, /Attempted to set 'isArchived' to 'true' on the deleted record /); + + currentState = record._internalModel.currentState; + + assert.ok( + currentState.stateName === 'root.deleted.saved', + 'record is still in a persisted deleted state' + ); + assert.ok(get(record, 'isDeleted') === true, 'The record is still deleted'); + assert.ok(get(record, 'isArchived') === false, 'The record reflects canonical state'); + }); + + test('currentState is accessible when the record is created', async function(assert) { + let record = store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + assert.equal( + get(record, 'currentState.stateName'), + 'root.loaded.saved', + 'records pushed into the store start in the loaded state' + ); + }); + }); + + module('ID', function() { + test('a record reports its unique id via the `id` property', async function(assert) { + store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + let record = await store.findRecord('person', '1'); + + assert.equal(get(record, 'id'), 1, 'reports id as id by default'); + }); + + test("a record's id is included in its toString representation", async function(assert) { + let person = store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + assert.equal( + person.toString(), + ``, + 'reports id in toString' + ); + }); + + testInDebug('trying to use `id` as an attribute should raise', async function(assert) { + class TestModel extends Model { + @attr('number') + id; + @attr('string') + name; + } + + this.owner.register('model:test-model', TestModel); + + assert.expectAssertion(() => { + let ModelClass = store.modelFor('test-model'); + get(ModelClass, 'attributes'); + }, /You may not set `id` as an attribute on your model/); + + assert.expectAssertion(() => { + store.push({ + data: { + id: '1', + type: 'test-model', + attributes: { + id: 'foo', + name: 'bar', + }, + }, + }); + }, /You may not set 'id' as an attribute on your model/); + }); + + test(`a collision of a record's id with object function's name`, async function(assert) { + // see https://github.com/emberjs/ember.js/issues/4792 for an explanation of this test + // and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/watch + // this effectively tests that our identityMap does not choke on IDs that are method names + // such as `watch` which is particularly problematic + assert.expect(1); + + let hasWatchMethod = Object.prototype.watch; + try { + if (!hasWatchMethod) { + Object.prototype.watch = function() {}; + } + + store.push({ + data: { + type: 'person', + id: 'watch', + }, + }); + + let record = await store.findRecord('person', 'watch'); + + assert.equal( + get(record, 'id'), + 'watch', + 'record is successfully created and could be found by its id' + ); + } finally { + if (!hasWatchMethod) { + delete Object.prototype.watch; + } + } + }); + + test('can ask if record with a given id is loaded', async function(assert) { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn', + }, + }, + ], + }); + + assert.equal(store.hasRecordForId('person', 1), true, 'should have person with id 1'); + assert.equal(store.hasRecordForId('person', 1), true, 'should have person with id 1'); + assert.equal(store.hasRecordForId('person', 4), false, 'should not have person with id 4'); + assert.equal(store.hasRecordForId('person', 4), false, 'should not have person with id 4'); + }); + + test('setting the id during createRecord should correctly update the id', async function(assert) { + let person = store.createRecord('person', { id: 'john' }); + + assert.equal(person.get('id'), 'john', 'new id should be correctly set.'); + + let record = store.peekRecord('person', 'john'); + + assert.ok(person === record, 'The cache has an entry for john'); + }); + + test('setting the id after createRecord should correctly update the id', async function(assert) { + let person = store.createRecord('person'); + + assert.equal(person.get('id'), null, 'initial created model id should be null'); + + person.set('id', 'john'); + + assert.equal(person.get('id'), 'john', 'new id should be correctly set.'); + + let record = store.peekRecord('person', 'john'); + + assert.ok(person === record, 'The cache has an entry for john'); + }); + + test('updating the id with store.setRecordId should work correctly when the id property is watched', async function(assert) { + const OddPerson = Model.extend({ + name: DSattr('string'), + idComputed: computed('id', function() { + return this.get('id'); + }), + }); + this.owner.register('model:odd-person', OddPerson); + + let person = store.createRecord('odd-person'); + let oddId = person.get('idComputed'); + + assert.equal(oddId, null, 'initial computed get is null'); + // test .get access of id + assert.equal(person.get('id'), null, 'initial created model id should be null'); + + store.setRecordId('odd-person', 'john', person._internalModel.clientId); + + oddId = person.get('idComputed'); + assert.equal(oddId, 'john', 'computed get is correct'); + // test direct access of id + assert.equal(person.id, 'john', 'new id should be correctly set.'); + }); + + test('ID mutation (complicated)', async function(assert) { + let idChange = 0; + const OddPerson = Model.extend({ + name: DSattr('string'), + idComputed: computed('id', function() {}), + idDidChange: observer('id', () => idChange++), + }); + this.owner.register('model:odd-person', OddPerson); + + let person = store.createRecord('odd-person'); + person.get('idComputed'); + assert.equal(idChange, 0); + + assert.equal(person.get('id'), null, 'initial created model id should be null'); + assert.equal(idChange, 0); + store._setRecordId(person._internalModel, 'john'); + assert.equal(idChange, 1); + assert.equal(person.get('id'), 'john', 'new id should be correctly set.'); + }); + + test('an ID of 0 is allowed', async function(assert) { + store.push({ + data: { + type: 'person', + id: 0, // explicit number 0 to make this as risky as possible + attributes: { + name: 'Tom Dale', + }, + }, + }); + + // we peek it instead of getting the return of push to make sure + // we can locate it in the identity map + let record = store.peekRecord('person', 0); + + assert.equal(record.get('name'), 'Tom Dale', 'found record with id 0'); + }); + }); + + module('@attr()', function() { + test('a Model does not require an attribute type', async function(assert) { + class NativeTag extends Model { + @attr() + name; + } + const LegacyTag = Model.extend({ + name: DSattr(), + }); + + this.owner.register('model:native-tag', NativeTag); + this.owner.register('model:legacy-tag', LegacyTag); + + let nativeTag = store.createRecord('native-tag', { name: 'test native' }); + let legacyTag = store.createRecord('legacy-tag', { name: 'test legacy' }); + + assert.equal(get(nativeTag, 'name'), 'test native', 'the value is persisted'); + assert.equal(get(legacyTag, 'name'), 'test legacy', 'the value is persisted'); + }); + + test('a Model can have a defaultValue without an attribute type', async function(assert) { + class NativeTag extends Model { + @attr({ defaultValue: 'unknown native tag' }) + name; + } + const LegacyTag = Model.extend({ + name: DSattr({ defaultValue: 'unknown legacy tag' }), + }); + + this.owner.register('model:native-tag', NativeTag); + this.owner.register('model:legacy-tag', LegacyTag); + + let nativeTag = store.createRecord('native-tag'); + let legacyTag = store.createRecord('legacy-tag'); + + assert.equal(get(nativeTag, 'name'), 'unknown native tag', 'the default value is found'); + assert.equal(get(legacyTag, 'name'), 'unknown legacy tag', 'the default value is found'); + }); + + test('a defaultValue for an attribute can be a function', async function(assert) { + class Tag extends Model { + @attr('string', { + defaultValue() { + return 'le default value'; + }, + }) + createdAt; + } + this.owner.register('model:tag', Tag); + + let tag = store.createRecord('tag'); + assert.equal( + get(tag, 'createdAt'), + 'le default value', + 'the defaultValue function is evaluated' + ); + }); + + test('a defaultValue function gets the record, options, and key', async function(assert) { + assert.expect(2); + class Tag extends Model { + @attr('string', { + defaultValue(record, options, key) { + assert.deepEqual(record, tag, 'the record is passed in properly'); + assert.equal(key, 'createdAt', 'the attribute being defaulted is passed in properly'); + return 'le default value'; + }, + }) + createdAt; + } + this.owner.register('model:tag', Tag); + + let tag = store.createRecord('tag'); + + get(tag, 'createdAt'); + }); + + testInDebug('We assert when defaultValue is a constant non-primitive instance', async function( + assert + ) { + class Tag extends Model { + @attr({ defaultValue: [] }) + tagInfo; + } + this.owner.register('model:tag', Tag); + + let tag = store.createRecord('tag'); + + assert.expectAssertion(() => { + get(tag, 'tagInfo'); + }, /Non primitive defaultValues are not supported/); + }); + }); + + module('Attribute Transforms', function() { + function converts(testName, type, provided, expected, options = {}) { + test(testName, async function(assert) { + let { owner } = this; + class TestModel extends Model { + @attr(type, options) + name; + } + + owner.register('model:model', TestModel); + owner.register('serializer:model', JSONSerializer); + store.push(store.normalize('model', { id: 1, name: provided })); + store.push(store.normalize('model', { id: 2 })); + + let record = store.peekRecord('model', 1); + + assert.deepEqual( + get(record, 'name'), + expected, + type + ' coerces ' + provided + ' to ' + expected + ); + }); + } + + function convertsFromServer(testName, type, provided, expected) { + test(testName, async function(assert) { + let { owner } = this; + class TestModel extends Model { + @attr(type) + name; + } + + owner.register('model:model', TestModel); + owner.register('serializer:model', JSONSerializer); + + let record = store.push( + store.normalize('model', { + id: '1', + name: provided, + }) + ); + + assert.deepEqual( + get(record, 'name'), + expected, + type + ' coerces ' + provided + ' to ' + expected + ); + }); + } + + function convertsWhenSet(testName, type, provided, expected) { + test(testName, async function(assert) { + let { owner } = this; + class TestModel extends Model { + @attr(type) + name; + } + + owner.register('model:model', TestModel); + owner.register('serializer:model', JSONSerializer); + + let record = store.push({ + data: { + type: 'model', + id: '2', + }, + }); + + set(record, 'name', provided); + assert.deepEqual( + record.serialize().name, + expected, + type + ' saves ' + provided + ' as ' + expected + ); + }); + } + + module('String', function() { + converts('string-to-string', 'string', 'Scumbag Tom', 'Scumbag Tom'); + converts('number-to-string', 'string', 1, '1'); + converts('empty-string-to-empty-string', 'string', '', ''); + converts('null-to-null', 'string', null, null); + }); + + module('Number', function() { + converts('string-1-to-number-1', 'number', '1', 1); + converts('string-0-to-number-0', 'number', '0', 0); + converts('1-to-1', 'number', 1, 1); + converts('0-to-0', 'number', 0, 0); + converts('empty-string-to-null', 'number', '', null); + converts('null-to-null', 'number', null, null); + converts('boolean-true-to-1', 'number', true, 1); + converts('boolean-false-to-0', 'number', false, 0); + }); + + module('Boolean', function() { + converts('string-1-to-true', 'boolean', '1', true); + converts('empty-string-to-false', 'boolean', '', false); + converts('number-1-to-true', 'boolean', 1, true); + converts('number-0-to-false', 'boolean', 0, false); + + converts('null-to-null { allowNull: true }', 'boolean', null, null, { allowNull: true }); + converts('null-to-false { allowNull: false }', 'boolean', null, false, { allowNull: false }); + converts('null-to-false', 'boolean', null, false); + + converts('boolean-true-to-true', 'boolean', true, true); + converts('boolean-false-to-false', 'boolean', false, false); + }); + + module('Date', function() { + converts('null-to-null', 'date', null, null); + converts('undefined-to-undefined', 'date', undefined, undefined); + + let dateString = '2011-12-31T00:08:16.000Z'; + let date = new Date(dateString); + + convertsFromServer('string-to-Date', 'date', dateString, date); + convertsWhenSet('Date-to-string', 'date', date, dateString); + }); + }); + + module('Evented', function() { + test('an event listener can be added to a record', async function(assert) { + let count = 0; + let F = function() { + count++; + }; + + let record = store.createRecord('person'); + + record.on('event!', F); + record.trigger('event!'); + + await settled(); + + assert.equal(count, 1, 'the event was triggered'); + record.trigger('event!'); + + await settled(); + + assert.equal(count, 2, 'the event was triggered'); + }); + + test('when an event is triggered on a record the method with the same name is invoked with arguments', async function(assert) { + let count = 0; + let F = function() { + count++; + }; + let record = store.createRecord('person'); + + record.eventNamedMethod = F; + + record.trigger('eventNamedMethod'); + + await settled(); + + assert.equal(count, 1, 'the corresponding method was called'); + }); + + test('when a method is invoked from an event with the same name the arguments are passed through', async function(assert) { + let eventMethodArgs = null; + let F = function() { + eventMethodArgs = arguments; + }; + let record = store.createRecord('person'); + + record.eventThatTriggersMethod = F; + record.trigger('eventThatTriggersMethod', 1, 2); + + await settled(); + + assert.equal(eventMethodArgs[0], 1); + assert.equal(eventMethodArgs[1], 2); + }); + }); + + module('Reserved Props', function() { + testInDebug(`don't allow setting of readOnly state props`, async function(assert) { + let record = store.createRecord('person'); + + assert.expectAssertion(() => { + record.set('isLoaded', true); + }, /Cannot set read-only property "isLoaded"/); + }); + + class NativePostWithInternalModel extends Model { + @attr('string') + _internalModel; + @attr('string') + name; + } + class NativePostWithRecordData extends Model { + @attr('string', { defaultValue: 'hello' }) + recordData; + @attr('string') + name; + } + class NativePostWithCurrentState extends Model { + @attr('string') + currentState; + @attr('string') + name; + } + const PROP_MAP = { + _internalModel: NativePostWithInternalModel, + recordData: NativePostWithRecordData, + currentState: NativePostWithCurrentState, + }; + + function testReservedProperty(prop) { + let testName = `A subclass of Model cannot use the reserved property '${prop}'`; + + testInDebug(testName, async function(assert) { + const NativePost = PROP_MAP[prop]; + const LegacyPost = Model.extend({ + [prop]: DSattr('string'), + name: DSattr('string'), + }); + this.owner.register('model:native-post', NativePost); + this.owner.register('model:legacy-post', LegacyPost); + + const msg = `'${prop}' is a reserved property name on instances of classes extending Model.`; + + assert.throws( + () => { + store.createRecord('native-post', { name: 'TomHuda' }); + }, + function(e) { + return e.message.indexOf(msg) === 0; + }, + 'We throw for native-style classes' + ); + + assert.throws( + () => { + store.createRecord('legacy-post', { name: 'TomHuda' }); + }, + function(e) { + return e.message.indexOf(msg) === 0; + }, + 'We throw for legacy-style classes' + ); + }); + } + + ['recordData', '_internalModel', 'currentState'].forEach(testReservedProperty); + + testInDebug( + 'A subclass of Model throws an error when calling create() directly', + async function(assert) { + class NativePerson extends Model {} + const LegacyPerson = Model.extend({}); + + assert.throws( + () => { + NativePerson.create(); + }, + /You should not call `create` on a model/, + 'Throws an error when calling create() on model' + ); + + assert.throws( + () => { + new NativePerson(); + }, + /You should not call `create` on a model/, + 'Throws an error when calling instantiating via new Model' + ); + + assert.throws( + () => { + LegacyPerson.create(); + }, + /You should not call `create` on a model/, + 'Throws an error when calling create() on model' + ); + + assert.throws( + () => { + new LegacyPerson(); + }, + /You should not call `create` on a model/, + 'Throws an error when calling instantiating view new Model()' + ); + } + ); + }); + + module('init()', function() { + test('ensure model exits loading state, materializes data and fulfills promise only after data is available', async function(assert) { + assert.expect(2); + adapter.findRecord = () => + resolve({ + data: { + id: 1, + type: 'person', + attributes: { name: 'John' }, + }, + }); + + let person = await store.findRecord('person', 1); + + assert.equal( + get(person, 'currentState.stateName'), + 'root.loaded.saved', + 'model is in loaded state' + ); + assert.equal(get(person, 'isLoaded'), true, 'model is loaded'); + }); + + test('Pushing a record into the store should transition new records to the loaded state', async function(assert) { + let person = store.createRecord('person', { id: 1, name: 'TomHuda' }); + + assert.equal(person.get('isNew'), true, 'createRecord should put records into the new state'); + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'TomHuda', + }, + }, + }); + + assert.equal( + person.get('isNew'), + false, + 'push should put move the record into the loaded state' + ); + // TODO either this is a bug or being able to push a record with the same ID as a client created one is a bug + // probably the bug is the former + assert.equal( + get(person, 'currentState.stateName'), + 'root.loaded.updated.uncommitted', + 'model is in loaded state' + ); + }); + + test('internalModel is ready by `init`', async function(assert) { + let nameDidChange = 0; + + class OddNativePerson extends Model { + @attr('string') + name; + init() { + super.init(...arguments); + this.set('name', 'my-name-set-in-init'); + } + } + const OddLegacyPerson = Model.extend({ + name: DSattr('string'), + + init() { + this._super(...arguments); + this.set('name', 'my-name-set-in-init'); + }, + + nameDidChange: observer('name', () => nameDidChange++), + }); + this.owner.register('model:native-person', OddNativePerson); + this.owner.register('model:legacy-person', OddLegacyPerson); + + assert.equal(nameDidChange, 0, 'observer should not trigger on create'); + let person = store.createRecord('legacy-person'); + assert.equal(nameDidChange, 0, 'observer should not trigger on create'); + assert.equal(person.get('name'), 'my-name-set-in-init'); + + person = store.createRecord('native-person'); + assert.equal(person.get('name'), 'my-name-set-in-init'); + }); + + test('accessing attributes during init should not throw an error', async function(assert) { + const Person = Model.extend({ + name: DSattr('string'), + + init() { + this._super(...arguments); + assert.ok(this.get('name') === 'bam!', 'We all good here'); + }, + }); + this.owner.register('model:odd-person', Person); + + store.createRecord('odd-person', { name: 'bam!' }); + }); + }); + + module('toJSON()', function(hooks) { + test('A Model can be JSONified', async function(assert) { + let record = store.createRecord('person', { name: 'TomHuda' }); + + assert.deepEqual(record.toJSON(), { + data: { + type: 'people', + attributes: { + name: 'TomHuda', + 'is-archived': undefined, + 'is-drug-addict': false, + }, + }, + }); + }); + + test('toJSON looks up the JSONSerializer using the store instead of using JSONSerializer.create', async function(assert) { + class Author extends Model { + @hasMany('post', { async: false, inverse: 'author' }) + posts; + } + class Post extends Model { + @belongsTo('author', { async: false, inverse: 'posts' }) + author; + } + this.owner.register('model:author', Author); + this.owner.register('model:post', Post); + + // Loading the person without explicitly + // loading its relationships seems to trigger the + // original bug where `this.store` was not + // present on the serializer due to using .create + // instead of `store.serializerFor`. + let person = store.push({ + data: { + type: 'author', + id: '1', + }, + }); + + let errorThrown = false; + let json; + try { + json = person.toJSON(); + } catch (e) { + errorThrown = true; + } + + assert.ok(!errorThrown, 'error not thrown due to missing store'); + assert.deepEqual(json, { data: { type: 'authors' } }); + }); + }); + + module('Updating', function() { + test('a Model can update its attributes', async function(assert) { + assert.expect(1); + + let person = store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz', + }, + }, + }); + + set(person, 'name', 'Brohuda Katz'); + assert.equal(get(person, 'name'), 'Brohuda Katz', 'setting took hold'); + }); + + test(`clearing the value when a Model's defaultValue was in use works`, async function(assert) { + class Tag extends Model { + @attr('string', { defaultValue: 'unknown' }) + name; + } + + this.owner.register('model:tag', Tag); + + let tag = store.createRecord('tag'); + assert.equal(get(tag, 'name'), 'unknown', 'the default value is found'); + + set(tag, 'name', null); + assert.equal(get(tag, 'name'), null, `null doesn't shadow defaultValue`); + }); + + test(`a Model can define 'setUnknownProperty'`, async function(assert) { + class NativeTag extends Model { + @attr('string') + name; + + setUnknownProperty(key, value) { + if (key === 'title') { + this.set('name', value); + } + } + } + const LegacyTag = Model.extend({ + name: DSattr('string'), + + setUnknownProperty(key, value) { + if (key === 'title') { + this.set('name', value); + } + }, + }); + this.owner.register('model:native-tag', NativeTag); + this.owner.register('model:legacy-tag', LegacyTag); + + let legacyTag = store.createRecord('legacy-tag', { name: 'old' }); + assert.equal(get(legacyTag, 'name'), 'old', 'precond - name is correct'); + + set(legacyTag, 'name', 'edited'); + assert.equal(get(legacyTag, 'name'), 'edited', 'setUnknownProperty was not triggered'); + + set(legacyTag, 'title', 'new'); + assert.equal(get(legacyTag, 'name'), 'new', 'setUnknownProperty was triggered'); + + let nativeTag = store.createRecord('native-tag', { name: 'old' }); + assert.equal(get(nativeTag, 'name'), 'old', 'precond - name is correct'); + + set(nativeTag, 'name', 'edited'); + assert.equal(get(nativeTag, 'name'), 'edited', 'setUnknownProperty was not triggered'); + + set(nativeTag, 'title', 'new'); + assert.equal(get(nativeTag, 'name'), 'new', 'setUnknownProperty was triggered'); + }); + + test('setting a property to undefined on a newly created record should not impact the current state', async function(assert) { + class Tag extends Model { + @attr('string') + tagInfo; + } + this.owner.register('model:tag', Tag); + + let tag = store.createRecord('tag'); + + set(tag, 'name', 'testing'); + + assert.equal(get(tag, 'currentState.stateName'), 'root.loaded.created.uncommitted'); + + set(tag, 'name', undefined); + + assert.equal(get(tag, 'currentState.stateName'), 'root.loaded.created.uncommitted'); + + tag = store.createRecord('tag', { name: undefined }); + + assert.equal(get(tag, 'currentState.stateName'), 'root.loaded.created.uncommitted'); + }); + + test('setting a property back to its original value removes the property from the `_attributes` hash', async function(assert) { + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale', + }, + }, + }); + + let recordData = recordDataFor(person); + assert.equal(recordData._attributes.name, undefined, 'the `_attributes` hash is clean'); + + set(person, 'name', 'Niceguy Dale'); + + assert.equal( + recordData._attributes.name, + 'Niceguy Dale', + 'the `_attributes` hash contains the changed value' + ); + + set(person, 'name', 'Scumbag Dale'); + + assert.equal(recordData._attributes.name, undefined, 'the `_attributes` hash is reset'); + }); + }); + + module('Mutation', function() { + test('can have properties and non-specified properties set on it', async function(assert) { + let record = store.createRecord('person', { isDrugAddict: false, notAnAttr: 'my value' }); + set(record, 'name', 'bar'); + set(record, 'anotherNotAnAttr', 'my other value'); + + assert.equal(get(record, 'notAnAttr'), 'my value', 'property was set on the record'); + assert.equal( + get(record, 'anotherNotAnAttr'), + 'my other value', + 'property was set on the record' + ); + assert.strictEqual(get(record, 'isDrugAddict'), false, 'property was set on the record'); + assert.equal(get(record, 'name'), 'bar', 'property was set on the record'); + }); + + test('setting a property on a record that has not changed does not cause it to become dirty', async function(assert) { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Peter', + isDrugAddict: true, + }, + }, + }); + + let person = await store.findRecord('person', '1'); + + assert.equal( + person.get('hasDirtyAttributes'), + false, + 'precond - person record should not be dirty' + ); + + person.set('name', 'Peter'); + person.set('isDrugAddict', true); + + assert.equal( + person.get('hasDirtyAttributes'), + false, + 'record does not become dirty after setting property to old value' + ); + }); + + test('resetting a property on a record cause it to become clean again', async function(assert) { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Peter', + isDrugAddict: true, + }, + }, + }); + + let person = await store.findRecord('person', '1'); + + assert.equal( + person.get('hasDirtyAttributes'), + false, + 'precond - person record should not be dirty' + ); + + person.set('isDrugAddict', false); + + assert.equal( + person.get('hasDirtyAttributes'), + true, + 'record becomes dirty after setting property to a new value' + ); + + person.set('isDrugAddict', true); + + assert.equal( + person.get('hasDirtyAttributes'), + false, + 'record becomes clean after resetting property to the old value' + ); + }); + + test('resetting a property to the current in-flight value causes it to become clean when the save completes', async function(assert) { + adapter.updateRecord = function() { + return resolve(); + }; + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom', + }, + }, + }); + + let person = store.peekRecord('person', 1); + person.set('name', 'Thomas'); + + let saving = person.save(); + + assert.equal(person.get('name'), 'Thomas'); + + person.set('name', 'Tomathy'); + assert.equal(person.get('name'), 'Tomathy'); + + person.set('name', 'Thomas'); + assert.equal(person.get('name'), 'Thomas'); + + await saving; + + assert.equal(person.get('hasDirtyAttributes'), false, 'The person is now clean'); + }); + + test('a record becomes clean again only if all changed properties are reset', async function(assert) { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Peter', + isDrugAddict: true, + }, + }, + }); + + let person = await store.findRecord('person', 1); + + assert.equal( + person.get('hasDirtyAttributes'), + false, + 'precond - person record should not be dirty' + ); + person.set('isDrugAddict', false); + assert.equal( + person.get('hasDirtyAttributes'), + true, + 'record becomes dirty after setting one property to a new value' + ); + person.set('name', 'Mark'); + assert.equal( + person.get('hasDirtyAttributes'), + true, + 'record stays dirty after setting another property to a new value' + ); + person.set('isDrugAddict', true); + assert.equal( + person.get('hasDirtyAttributes'), + true, + 'record stays dirty after resetting only one property to the old value' + ); + person.set('name', 'Peter'); + assert.equal( + person.get('hasDirtyAttributes'), + false, + 'record becomes clean after resetting both properties to the old value' + ); + }); + + test('an invalid record becomes clean again if changed property is reset', async function(assert) { + adapter.updateRecord = () => { + return reject(new InvalidError([{ name: 'not valid' }])); + }; + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Peter', + isDrugAddict: true, + }, + }, + }); + + let person = store.peekRecord('person', 1); + + assert.equal( + person.get('hasDirtyAttributes'), + false, + 'precond - person record should not be dirty' + ); + person.set('name', 'Wolf'); + assert.equal( + person.get('hasDirtyAttributes'), + true, + 'record becomes dirty after setting one property to a new value' + ); + + await person + .save() + .then(() => { + assert.ok(false, 'We should reject the save'); + }) + .catch(() => { + assert.equal(person.get('isValid'), false, 'record is not valid'); + assert.equal(person.get('hasDirtyAttributes'), true, 'record still has dirty attributes'); + + person.set('name', 'Peter'); + + assert.equal( + person.get('isValid'), + true, + 'record is valid after resetting attribute to old value' + ); + assert.equal( + person.get('hasDirtyAttributes'), + false, + 'record becomes clean after resetting property to the old value' + ); + }); + }); + + test('an invalid record stays dirty if only invalid property is reset', async function(assert) { + adapter.updateRecord = () => { + return reject(new InvalidError([{ name: 'not valid' }])); + }; + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Peter', + isDrugAddict: true, + }, + }, + }); + + let person = store.peekRecord('person', 1); + + assert.equal( + person.get('hasDirtyAttributes'), + false, + 'precond - person record should not be dirty' + ); + person.set('name', 'Wolf'); + person.set('isDrugAddict', false); + assert.equal( + person.get('hasDirtyAttributes'), + true, + 'record becomes dirty after setting one property to a new value' + ); + + await person + .save() + .then(() => { + assert.ok(false, 'save should have rejected'); + }) + .catch(() => { + assert.equal(person.get('isValid'), false, 'record is not valid'); + assert.equal(person.get('hasDirtyAttributes'), true, 'record still has dirty attributes'); + + person.set('name', 'Peter'); + + assert.equal( + person.get('isValid'), + true, + 'record is valid after resetting invalid attribute to old value' + ); + assert.equal(person.get('hasDirtyAttributes'), true, 'record still has dirty attributes'); + }); + }); + + test('it should cache attributes', async function(assert) { + class Post extends Model { + @attr('string') + updatedAt; + } + this.owner.register('model:post', Post); + + let dateString = 'Sat, 31 Dec 2011 00:08:16 GMT'; + let date = new Date(dateString); + + store.push({ + data: { + type: 'post', + id: '1', + }, + }); + + let record = await store.findRecord('post', '1'); + + record.set('updatedAt', date); + + assert.deepEqual(date, get(record, 'updatedAt'), 'setting a date returns the same date'); + assert.strictEqual( + get(record, 'updatedAt'), + get(record, 'updatedAt'), + 'second get still returns the same object' + ); + }); + + test('changedAttributes() return correct values', async function(assert) { + class Mascot extends Model { + @attr('string') + name; + @attr('string') + likes; + @attr('boolean') + isMascot; + } + + this.owner.register('model:mascot', Mascot); + + let mascot = store.push({ + data: { + type: 'mascot', + id: '1', + attributes: { + likes: 'JavaScript', + isMascot: true, + }, + }, + }); + + assert.equal( + Object.keys(mascot.changedAttributes()).length, + 0, + 'there are no initial changes' + ); + + mascot.set('name', 'Tomster'); // new value + mascot.set('likes', 'Ember.js'); // changed value + mascot.set('isMascot', true); // same value + + let changedAttributes = mascot.changedAttributes(); + + assert.deepEqual(changedAttributes.name, [undefined, 'Tomster']); + assert.deepEqual(changedAttributes.likes, ['JavaScript', 'Ember.js']); + + mascot.rollbackAttributes(); + + assert.equal( + Object.keys(mascot.changedAttributes()).length, + 0, + 'after rollback attributes there are no changes' + ); + }); + + test('changedAttributes() works while the record is being saved', async function(assert) { + assert.expect(1); + class Mascot extends Model { + @attr('string') + name; + @attr('string') + likes; + @attr('boolean') + isMascot; + } + + this.owner.register('model:mascot', Mascot); + adapter.createRecord = function() { + assert.deepEqual(cat.changedAttributes(), { + name: [undefined, 'Argon'], + likes: [undefined, 'Cheese'], + }); + + return resolve({ data: { id: 1, type: 'mascot' } }); + }; + + let cat; + + cat = store.createRecord('mascot'); + cat.setProperties({ + name: 'Argon', + likes: 'Cheese', + }); + + await cat.save(); + }); + + test('changedAttributes() works while the record is being updated', async function(assert) { + assert.expect(1); + let cat; + + class Mascot extends Model { + @attr('string') + name; + @attr('string') + likes; + @attr('boolean') + isMascot; + } + + this.owner.register('model:mascot', Mascot); + adapter.updateRecord = function() { + assert.deepEqual(cat.changedAttributes(), { + name: ['Argon', 'Helia'], + likes: ['Cheese', 'Mussels'], + }); + + return { data: { id: '1', type: 'mascot' } }; + }; + + cat = store.push({ + data: { + type: 'mascot', + id: '1', + attributes: { + name: 'Argon', + likes: 'Cheese', + }, + }, + }); + + cat.setProperties({ + name: 'Helia', + likes: 'Mussels', + }); + + await cat.save(); + }); + }); + + module('Misc', function() { + testInDebug('Calling record.attr() asserts', async function(assert) { + let person = store.createRecord('person', { id: 1, name: 'TomHuda' }); + + assert.expectAssertion(() => { + person.attr(); + }, /Assertion Failed: The `attr` method is not available on DS\.Model, a DS\.Snapshot was probably expected\. Are you passing a DS\.Model instead of a DS\.Snapshot to your serializer\?/); + }); + }); +}); diff --git a/tests/unit/model/errors-test.js b/tests/unit/model/errors-test.js new file mode 100644 index 00000000000..a341f349d5f --- /dev/null +++ b/tests/unit/model/errors-test.js @@ -0,0 +1,106 @@ +import DS from 'ember-data'; +import QUnit, { module } from 'qunit'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; + +const AssertPrototype = QUnit.assert; + +let errors; + +module('unit/model/errors', { + beforeEach() { + errors = DS.Errors.create(); + }, +}); + +AssertPrototype.becameInvalid = function becameInvalid(eventName) { + if (eventName === 'becameInvalid') { + this.ok(true, 'becameInvalid send'); + } else { + this.ok(false, eventName + ' is send instead of becameInvalid'); + } +}.bind(AssertPrototype); + +AssertPrototype.becameValid = function becameValid(eventName) { + if (eventName === 'becameValid') { + this.ok(true, 'becameValid send'); + } else { + this.ok(false, eventName + ' is send instead of becameValid'); + } +}.bind(AssertPrototype); + +AssertPrototype.unexpectedSend = function unexpectedSend(eventName) { + this.ok(false, 'unexpected send : ' + eventName); +}.bind(AssertPrototype); + +testInDebug('add error', function(assert) { + errors.trigger = assert.becameInvalid; + errors.add('firstName', 'error'); + errors.trigger = assert.unexpectedSend; + assert.ok(errors.has('firstName'), 'it has firstName errors'); + assert.equal(errors.get('length'), 1, 'it has 1 error'); + errors.add('firstName', ['error1', 'error2']); + assert.equal(errors.get('length'), 3, 'it has 3 errors'); + assert.ok(!errors.get('isEmpty'), 'it is not empty'); + errors.add('lastName', 'error'); + errors.add('lastName', 'error'); + assert.equal(errors.get('length'), 4, 'it has 4 errors'); +}); + +testInDebug('get error', function(assert) { + assert.ok(errors.get('firstObject') === undefined, 'returns undefined'); + errors.trigger = assert.becameInvalid; + errors.add('firstName', 'error'); + errors.trigger = assert.unexpectedSend; + assert.ok(errors.get('firstName').length === 1, 'returns errors'); + assert.deepEqual(errors.get('firstObject'), { attribute: 'firstName', message: 'error' }); + errors.add('firstName', 'error2'); + assert.ok(errors.get('firstName').length === 2, 'returns errors'); + errors.add('lastName', 'error3'); + assert.deepEqual(errors.toArray(), [ + { attribute: 'firstName', message: 'error' }, + { attribute: 'firstName', message: 'error2' }, + { attribute: 'lastName', message: 'error3' }, + ]); + assert.deepEqual(errors.get('firstName'), [ + { attribute: 'firstName', message: 'error' }, + { attribute: 'firstName', message: 'error2' }, + ]); + assert.deepEqual(errors.get('messages'), ['error', 'error2', 'error3']); +}); + +testInDebug('remove error', function(assert) { + errors.trigger = assert.becameInvalid; + errors.add('firstName', 'error'); + errors.trigger = assert.becameValid; + errors.remove('firstName'); + errors.trigger = assert.unexpectedSend; + assert.ok(!errors.has('firstName'), 'it has no firstName errors'); + assert.equal(errors.get('length'), 0, 'it has 0 error'); + assert.ok(errors.get('isEmpty'), 'it is empty'); + errors.remove('firstName'); +}); + +testInDebug('remove same errors fromm different attributes', function(assert) { + errors.trigger = assert.becameInvalid; + errors.add('firstName', 'error'); + errors.add('lastName', 'error'); + errors.trigger = assert.unexpectedSend; + assert.equal(errors.get('length'), 2, 'it has 2 error'); + errors.remove('firstName'); + assert.equal(errors.get('length'), 1, 'it has 1 error'); + errors.trigger = assert.becameValid; + errors.remove('lastName'); + assert.ok(errors.get('isEmpty'), 'it is empty'); +}); + +testInDebug('clear errors', function(assert) { + errors.trigger = assert.becameInvalid; + errors.add('firstName', ['error', 'error1']); + assert.equal(errors.get('length'), 2, 'it has 2 errors'); + errors.trigger = assert.becameValid; + errors.clear(); + errors.trigger = assert.unexpectedSend; + assert.ok(!errors.has('firstName'), 'it has no firstName errors'); + assert.equal(errors.get('length'), 0, 'it has 0 error'); + errors.clear(); +}); diff --git a/tests/unit/model/init-properties-test.js b/tests/unit/model/init-properties-test.js new file mode 100644 index 00000000000..02524f0d1bf --- /dev/null +++ b/tests/unit/model/init-properties-test.js @@ -0,0 +1,285 @@ +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; +import { resolve } from 'rsvp'; +import setupStore from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; + +const { JSONAPIAdapter, Model, attr, belongsTo, hasMany } = DS; + +function setupModels(testState) { + let types; + const Comment = Model.extend({ + text: attr(), + post: belongsTo('post', { async: false, inverse: 'comments' }), + }); + const Author = Model.extend({ + name: attr(), + post: belongsTo('post', { async: false, inverse: 'author' }), + }); + const Post = Model.extend({ + title: attr(), + author: belongsTo('author', { async: false, inverse: 'post' }), + comments: hasMany('comment', { async: false, inverse: 'post' }), + init() { + this._super(...arguments); + testState(types, this); + }, + }); + types = { + Author, + Comment, + Post, + }; + + return setupStore({ + adapter: JSONAPIAdapter.extend(), + post: Post, + comment: Comment, + author: Author, + }); +} + +module('unit/model - init properties', {}); + +test('createRecord(properties) makes properties available during record init', function(assert) { + assert.expect(4); + let comment; + let author; + + function testState(types, record) { + assert.ok(get(record, 'title') === 'My Post', 'Attrs are available as expected'); + assert.ok( + get(record, 'randomProp') === 'An unknown prop', + 'Unknown properties are available as expected' + ); + assert.ok( + get(record, 'author') instanceof types.Author, + 'belongsTo relationships are available as expected' + ); + assert.ok( + get(record, 'comments.firstObject') instanceof types.Comment, + 'hasMany relationships are available as expected' + ); + } + + let { store } = setupModels(testState); + + run(() => { + comment = store.push({ + data: { + type: 'comment', + id: '1', + attributes: { + text: 'Hello darkness my old friend', + }, + }, + }); + author = store.push({ + data: { + type: 'author', + id: '1', + attributes: { + name: '@runspired', + }, + }, + }); + }); + + run(() => { + store.createRecord('post', { + title: 'My Post', + randomProp: 'An unknown prop', + comments: [comment], + author, + }); + }); +}); + +test('store.push() makes properties available during record init', function(assert) { + assert.expect(3); + + function testState(types, record) { + assert.ok(get(record, 'title') === 'My Post', 'Attrs are available as expected'); + assert.ok( + get(record, 'author') instanceof types.Author, + 'belongsTo relationships are available as expected' + ); + assert.ok( + get(record, 'comments.firstObject') instanceof types.Comment, + 'hasMany relationships are available as expected' + ); + } + + let { store } = setupModels(testState); + + run(() => + store.push({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'My Post', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], + }, + author: { + data: { type: 'author', id: '1' }, + }, + }, + }, + included: [ + { + type: 'comment', + id: '1', + attributes: { + text: 'Hello darkness my old friend', + }, + }, + { + type: 'author', + id: '1', + attributes: { + name: '@runspired', + }, + }, + ], + }) + ); +}); + +test('store.findRecord(type, id) makes properties available during record init', function(assert) { + assert.expect(3); + + function testState(types, record) { + assert.ok(get(record, 'title') === 'My Post', 'Attrs are available as expected'); + assert.ok( + get(record, 'author') instanceof types.Author, + 'belongsTo relationships are available as expected' + ); + assert.ok( + get(record, 'comments.firstObject') instanceof types.Comment, + 'hasMany relationships are available as expected' + ); + } + + let { adapter, store } = setupModels(testState); + + adapter.findRecord = () => { + return resolve({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'My Post', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], + }, + author: { + data: { type: 'author', id: '1' }, + }, + }, + }, + included: [ + { + type: 'comment', + id: '1', + attributes: { + text: 'Hello darkness my old friend', + }, + }, + { + type: 'author', + id: '1', + attributes: { + name: '@runspired', + }, + }, + ], + }); + }; + + run(() => store.findRecord('post', '1')); +}); + +test('store.queryRecord(type, query) makes properties available during record init', function(assert) { + assert.expect(3); + + function testState(types, record) { + assert.ok(get(record, 'title') === 'My Post', 'Attrs are available as expected'); + assert.ok( + get(record, 'author') instanceof types.Author, + 'belongsTo relationships are available as expected' + ); + assert.ok( + get(record, 'comments.firstObject') instanceof types.Comment, + 'hasMany relationships are available as expected' + ); + } + + let { adapter, store } = setupModels(testState); + + adapter.queryRecord = () => { + return resolve({ + data: { + type: 'post', + id: '1', + attributes: { + title: 'My Post', + }, + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], + }, + author: { + data: { type: 'author', id: '1' }, + }, + }, + }, + included: [ + { + type: 'comment', + id: '1', + attributes: { + text: 'Hello darkness my old friend', + }, + }, + { + type: 'author', + id: '1', + attributes: { + name: '@runspired', + }, + }, + ], + }); + }; + + run(() => store.queryRecord('post', { id: '1' })); +}); + +test('Model class does not get properties passed to setUknownProperty accidentally', function(assert) { + assert.expect(2); + // If we end up passing additional properties to init in modelClasses, we will need to come up with a strategy for + // how to get setUnknownProperty to continue working + let { store } = setupStore({ + adapter: JSONAPIAdapter.extend(), + post: Model.extend({ + title: attr(), + setUnknownProperty: function(key, value) { + assert.equal(key, 'randomProp', 'Passed the correct key to setUknownProperty'); + assert.equal(value, 'An unknown prop', 'Passed the correct value to setUknownProperty'); + }, + }), + }); + run(() => { + store.createRecord('post', { + title: 'My Post', + randomProp: 'An unknown prop', + }); + }); +}); diff --git a/tests/unit/model/lifecycle-callbacks-test.js b/tests/unit/model/lifecycle-callbacks-test.js new file mode 100644 index 00000000000..ac3aab1ada3 --- /dev/null +++ b/tests/unit/model/lifecycle-callbacks-test.js @@ -0,0 +1,298 @@ +import { resolve, reject } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +module('unit/model/lifecycle_callbacks - Lifecycle Callbacks'); + +test('a record receives a didLoad callback when it has finished loading', function(assert) { + assert.expect(3); + + const Person = DS.Model.extend({ + name: DS.attr(), + didLoad() { + assert.ok('The didLoad callback was called'); + }, + }); + + const Adapter = DS.Adapter.extend({ + findRecord(store, type, id, snapshot) { + return { data: { id: 1, type: 'person', attributes: { name: 'Foo' } } }; + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + + return run(() => { + return store.findRecord('person', 1).then(person => { + assert.equal(person.get('id'), '1', `The person's ID is available`); + assert.equal(person.get('name'), 'Foo', `The person's properties are availablez`); + }); + }); +}); + +test(`TEMPORARY: a record receives a didLoad callback once it materializes if it wasn't materialized when loaded`, function(assert) { + assert.expect(2); + let didLoadCalled = 0; + const Person = DS.Model.extend({ + name: DS.attr(), + didLoad() { + didLoadCalled++; + }, + }); + + let store = createStore({ + person: Person, + }); + + run(() => { + store._pushInternalModel({ id: 1, type: 'person' }); + assert.equal(didLoadCalled, 0, 'didLoad was not called'); + }); + run(() => store.peekRecord('person', 1)); + assert.equal(didLoadCalled, 1, 'didLoad was called'); +}); + +test('a record receives a didUpdate callback when it has finished updating', function(assert) { + assert.expect(5); + + let callCount = 0; + + const Person = DS.Model.extend({ + bar: DS.attr('string'), + name: DS.attr('string'), + + didUpdate() { + callCount++; + assert.equal(get(this, 'isSaving'), false, 'record should be saving'); + assert.equal(get(this, 'hasDirtyAttributes'), false, 'record should not be dirty'); + }, + }); + + const Adapter = DS.Adapter.extend({ + findRecord(store, type, id, snapshot) { + return { data: { id: 1, type: 'person', attributes: { name: 'Foo' } } }; + }, + + updateRecord(store, type, snapshot) { + assert.equal(callCount, 0, 'didUpdate callback was not called until didSaveRecord is called'); + + return resolve(); + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + + let asyncPerson = run(() => store.findRecord('person', 1)); + + assert.equal(callCount, 0, 'precond - didUpdate callback was not called yet'); + + return run(() => { + return asyncPerson + .then(person => { + return run(() => { + person.set('bar', 'Bar'); + return person.save(); + }); + }) + .then(() => { + assert.equal(callCount, 1, 'didUpdate called after update'); + }); + }); +}); + +test('a record receives a didCreate callback when it has finished updating', function(assert) { + assert.expect(5); + + let callCount = 0; + + const Person = DS.Model.extend({ + didCreate() { + callCount++; + assert.equal(get(this, 'isSaving'), false, 'record should not be saving'); + assert.equal(get(this, 'hasDirtyAttributes'), false, 'record should not be dirty'); + }, + }); + + const Adapter = DS.Adapter.extend({ + createRecord(store, type, snapshot) { + assert.equal(callCount, 0, 'didCreate callback was not called until didSaveRecord is called'); + + return resolve(); + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + + assert.equal(callCount, 0, 'precond - didCreate callback was not called yet'); + let person = store.createRecord('person', { id: 69, name: 'Newt Gingrich' }); + + return run(() => { + return person.save().then(() => { + assert.equal(callCount, 1, 'didCreate called after commit'); + }); + }); +}); + +test('a record receives a didDelete callback when it has finished deleting', function(assert) { + assert.expect(5); + + let callCount = 0; + + const Person = DS.Model.extend({ + bar: DS.attr('string'), + name: DS.attr('string'), + + didDelete() { + callCount++; + + assert.equal(get(this, 'isSaving'), false, 'record should not be saving'); + assert.equal(get(this, 'hasDirtyAttributes'), false, 'record should not be dirty'); + }, + }); + + const Adapter = DS.Adapter.extend({ + findRecord(store, type, id, snapshot) { + return { data: { id: 1, type: 'person', attributes: { name: 'Foo' } } }; + }, + + deleteRecord(store, type, snapshot) { + assert.equal(callCount, 0, 'didDelete callback was not called until didSaveRecord is called'); + + return resolve(); + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + let asyncPerson = run(() => store.findRecord('person', 1)); + + assert.equal(callCount, 0, 'precond - didDelete callback was not called yet'); + + return run(() => { + return asyncPerson + .then(person => { + return run(() => { + person.deleteRecord(); + return person.save(); + }); + }) + .then(() => { + assert.equal(callCount, 1, 'didDelete called after delete'); + }); + }); +}); + +test('an uncommited record also receives a didDelete callback when it is deleted', function(assert) { + assert.expect(4); + + let callCount = 0; + + const Person = DS.Model.extend({ + bar: DS.attr('string'), + name: DS.attr('string'), + + didDelete() { + callCount++; + assert.equal(get(this, 'isSaving'), false, 'record should not be saving'); + assert.equal(get(this, 'hasDirtyAttributes'), false, 'record should not be dirty'); + }, + }); + + let store = createStore({ + adapter: DS.Adapter.extend(), + person: Person, + }); + + let person = store.createRecord('person', { name: 'Tomster' }); + + assert.equal(callCount, 0, 'precond - didDelete callback was not called yet'); + + run(() => person.deleteRecord()); + + assert.equal(callCount, 1, 'didDelete called after delete'); +}); + +test('a record receives a becameInvalid callback when it became invalid', function(assert) { + assert.expect(8); + + let callCount = 0; + + const Person = DS.Model.extend({ + bar: DS.attr('string'), + name: DS.attr('string'), + + becameInvalid() { + callCount++; + + assert.equal(get(this, 'isSaving'), false, 'record should not be saving'); + assert.equal(get(this, 'hasDirtyAttributes'), true, 'record should be dirty'); + }, + }); + + const Adapter = DS.Adapter.extend({ + findRecord(store, type, id, snapshot) { + return { data: { id: 1, type: 'person', attributes: { name: 'Foo' } } }; + }, + + updateRecord(store, type, snapshot) { + assert.equal( + callCount, + 0, + 'becameInvalid callback was not called until recordWasInvalid is called' + ); + + return reject( + new DS.InvalidError([ + { + title: 'Invalid Attribute', + detail: 'error', + source: { + pointer: '/data/attributes/bar', + }, + }, + ]) + ); + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + + let asyncPerson = run(() => store.findRecord('person', 1)); + assert.equal(callCount, 0, 'precond - becameInvalid callback was not called yet'); + + // Make sure that the error handler has a chance to attach before + // save fails. + return run(() => { + return asyncPerson.then(person => { + return run(() => { + person.set('bar', 'Bar'); + return person.save().catch(reason => { + assert.ok(reason.isAdapterError, 'reason should have been an adapter error'); + + assert.equal(reason.errors.length, 1, 'reason should have one error'); + assert.equal(reason.errors[0].title, 'Invalid Attribute'); + assert.equal(callCount, 1, 'becameInvalid called after invalidating'); + }); + }); + }); + }); +}); diff --git a/tests/unit/model/merge-test.js b/tests/unit/model/merge-test.js new file mode 100644 index 00000000000..f75315f2cc3 --- /dev/null +++ b/tests/unit/model/merge-test.js @@ -0,0 +1,327 @@ +import { resolve, Promise as EmberPromise } from 'rsvp'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let Person; + +module('unit/model/merge - Merging', { + beforeEach() { + Person = DS.Model.extend({ + name: DS.attr(), + city: DS.attr(), + }); + }, +}); + +test('When a record is in flight, changes can be made', function(assert) { + assert.expect(3); + + const Adapter = DS.Adapter.extend({ + createRecord(store, type, snapshot) { + return { data: { id: 1, type: 'person', attributes: { name: 'Tom Dale' } } }; + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + + let person = store.createRecord('person', { name: 'Tom Dale' }); + + // Make sure saving isn't resolved synchronously + return run(() => { + let save = person.save(); + + assert.equal(person.get('name'), 'Tom Dale'); + + person.set('name', 'Thomas Dale'); + + return save.then(person => { + assert.equal(person.get('hasDirtyAttributes'), true, 'The person is still dirty'); + assert.equal(person.get('name'), 'Thomas Dale', 'The changes made still apply'); + }); + }); +}); + +test('Make sure snapshot is created at save time not at flush time', function(assert) { + assert.expect(5); + + const Adapter = DS.Adapter.extend({ + updateRecord(store, type, snapshot) { + assert.equal(snapshot.attr('name'), 'Thomas Dale'); + + return resolve(); + }, + }); + + let store = createStore({ adapter: Adapter, person: Person }); + + let person; + run(() => { + person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom', + }, + }, + }); + person.set('name', 'Thomas Dale'); + }); + + return run(() => { + let promise = person.save(); + + assert.equal(person.get('name'), 'Thomas Dale'); + + person.set('name', 'Tomasz Dale'); + + assert.equal(person.get('name'), 'Tomasz Dale', 'the local changes applied on top'); + + return promise.then(person => { + assert.equal(person.get('hasDirtyAttributes'), true, 'The person is still dirty'); + assert.equal(person.get('name'), 'Tomasz Dale', 'The local changes apply'); + }); + }); +}); + +test('When a record is in flight, pushes are applied underneath the in flight changes', function(assert) { + assert.expect(6); + + const Adapter = DS.Adapter.extend({ + updateRecord(store, type, snapshot) { + // Make sure saving isn't resolved synchronously + return new EmberPromise(resolve => { + run.next(null, resolve, { + data: { + id: 1, + type: 'person', + attributes: { name: 'Senor Thomas Dale, Esq.', city: 'Portland' }, + }, + }); + }); + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + let person; + + run(() => { + person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom', + }, + }, + }); + person.set('name', 'Thomas Dale'); + }); + + return run(() => { + var promise = person.save(); + + assert.equal(person.get('name'), 'Thomas Dale'); + + person.set('name', 'Tomasz Dale'); + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tommy Dale', + city: 'PDX', + }, + }, + }); + + assert.equal(person.get('name'), 'Tomasz Dale', 'the local changes applied on top'); + assert.equal(person.get('city'), 'PDX', 'the pushed change is available'); + + return promise.then(person => { + assert.equal(person.get('hasDirtyAttributes'), true, 'The person is still dirty'); + assert.equal(person.get('name'), 'Tomasz Dale', 'The local changes apply'); + assert.equal( + person.get('city'), + 'Portland', + 'The updates from the server apply on top of the previous pushes' + ); + }); + }); +}); + +test('When a record is dirty, pushes are overridden by local changes', function(assert) { + let store = createStore({ + adapter: DS.Adapter, + person: Person, + }); + let person; + + run(() => { + person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + city: 'San Francisco', + }, + }, + }); + person.set('name', 'Tomasz Dale'); + }); + + assert.equal(person.get('hasDirtyAttributes'), true, 'the person is currently dirty'); + assert.equal(person.get('name'), 'Tomasz Dale', 'the update was effective'); + assert.equal(person.get('city'), 'San Francisco', 'the original data applies'); + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Thomas Dale', + city: 'Portland', + }, + }, + }); + }); + + assert.equal(person.get('hasDirtyAttributes'), true, 'the local changes are reapplied'); + assert.equal(person.get('name'), 'Tomasz Dale', 'the local changes are reapplied'); + assert.equal( + person.get('city'), + 'Portland', + 'if there are no local changes, the new data applied' + ); +}); + +test('When a record is invalid, pushes are overridden by local changes', function(assert) { + let store = createStore({ + adapter: DS.Adapter, + person: Person, + }); + let person; + + run(() => { + person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Brendan McLoughlin', + city: 'Boston', + }, + }, + }); + person.set('name', 'Brondan McLoughlin'); + person.send('becameInvalid'); + }); + + assert.equal(person.get('hasDirtyAttributes'), true, 'the person is currently dirty'); + assert.equal(person.get('isValid'), false, 'the person is currently invalid'); + assert.equal(person.get('name'), 'Brondan McLoughlin', 'the update was effective'); + assert.equal(person.get('city'), 'Boston', 'the original data applies'); + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'bmac', + city: 'Prague', + }, + }, + }); + }); + + assert.equal(person.get('hasDirtyAttributes'), true, 'the local changes are reapplied'); + assert.equal(person.get('isValid'), false, 'record is still invalid'); + assert.equal(person.get('name'), 'Brondan McLoughlin', 'the local changes are reapplied'); + assert.equal(person.get('city'), 'Prague', 'if there are no local changes, the new data applied'); +}); + +test('A record with no changes can still be saved', function(assert) { + assert.expect(1); + + const Adapter = DS.Adapter.extend({ + updateRecord(store, type, snapshot) { + return { data: { id: 1, type: 'person', attributes: { name: 'Thomas Dale' } } }; + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + let person = run(() => { + return store.push({ + data: { + type: 'person', + id: '1', + attributeS: { + name: 'Tom Dale', + }, + }, + }); + }); + + return run(() => { + return person.save().then(() => { + assert.equal(person.get('name'), 'Thomas Dale', 'the updates occurred'); + }); + }); +}); + +test('A dirty record can be reloaded', function(assert) { + assert.expect(3); + + const Adapter = DS.Adapter.extend({ + findRecord(store, type, id, snapshot) { + return { + data: { id: 1, type: 'person', attributes: { name: 'Thomas Dale', city: 'Portland' } }, + }; + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + + let person; + + run(() => { + person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }); + person.set('name', 'Tomasz Dale'); + }); + + return run(() => { + return person.reload().then(() => { + assert.equal(person.get('hasDirtyAttributes'), true, 'the person is dirty'); + assert.equal(person.get('name'), 'Tomasz Dale', 'the local changes remain'); + assert.equal(person.get('city'), 'Portland', 'the new changes apply'); + }); + }); +}); diff --git a/tests/unit/model/relationships-test.js b/tests/unit/model/relationships-test.js new file mode 100644 index 00000000000..c355489e6e2 --- /dev/null +++ b/tests/unit/model/relationships-test.js @@ -0,0 +1,117 @@ +import { get } from '@ember/object'; +import { createStore } from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let Occupation, Person, store; + +module('unit/model/relationships - DS.Model', { + beforeEach() { + Occupation = DS.Model.extend(); + + Person = DS.Model.extend({ + occupations: DS.hasMany('occupation', { async: false }), + people: DS.hasMany('person', { inverse: 'parent', async: false }), + parent: DS.belongsTo('person', { inverse: 'people', async: false }), + }); + + store = createStore({ + occupation: Occupation, + person: Person, + }); + + Person = store.modelFor('person'); + }, +}); + +test('exposes a hash of the relationships on a model', function(assert) { + let Person = store.modelFor('person'); + + let relationships = get(Person, 'relationships'); + function extractDetails(key) { + let descs = relationships.get(key); + + return descs.map(desc => { + return { + kind: desc.kind, + name: desc.name, + options: desc.options, + }; + }); + } + + assert.deepEqual(extractDetails('person'), [ + { name: 'people', kind: 'hasMany', options: { async: false, inverse: 'parent' } }, + { name: 'parent', kind: 'belongsTo', options: { async: false, inverse: 'people' } }, + ]); + assert.deepEqual(extractDetails('occupation'), [ + { name: 'occupations', kind: 'hasMany', options: { async: false } }, + ]); +}); + +test('relationshipNames a hash of the relationships on a model with type as a key', function(assert) { + assert.deepEqual(get(Person, 'relationshipNames'), { + hasMany: ['occupations', 'people'], + belongsTo: ['parent'], + }); +}); + +test('eachRelatedType() iterates over relations without duplication', function(assert) { + let relations = []; + + Person.eachRelatedType(modelName => relations.push(modelName)); + + assert.deepEqual(relations, ['occupation', 'person']); +}); + +test('normalizing belongsTo relationship names', function(assert) { + const UserProfile = DS.Model.extend({ + user: DS.belongsTo(), + }); + + let User = DS.Model.extend({ + userProfile: DS.belongsTo(), + }); + + store = createStore({ + user: User, + userProfile: UserProfile, + }); + + User = store.modelFor('user'); + + const relationships = get(User, 'relationships'); + + assert.ok(relationships.has('user-profile'), 'relationship key has been normalized'); + + const relationship = relationships.get('user-profile')[0]; + + assert.equal(relationship.meta.name, 'userProfile', 'relationship name has not been changed'); +}); + +test('normalizing hasMany relationship names', function(assert) { + const StreamItem = DS.Model.extend({ + user: DS.belongsTo(), + }); + + let User = DS.Model.extend({ + streamItems: DS.hasMany(), + }); + + store = createStore({ + user: User, + streamItem: StreamItem, + }); + + User = store.modelFor('user'); + + const relationships = get(User, 'relationships'); + + assert.ok(relationships.has('stream-item'), 'relationship key has been normalized'); + + const relationship = relationships.get('stream-item')[0]; + + assert.equal(relationship.meta.name, 'streamItems', 'relationship name has not been changed'); +}); diff --git a/tests/unit/model/relationships/belongs-to-test.js b/tests/unit/model/relationships/belongs-to-test.js new file mode 100644 index 00000000000..ee494ee7f92 --- /dev/null +++ b/tests/unit/model/relationships/belongs-to-test.js @@ -0,0 +1,823 @@ +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import { Promise } from 'rsvp'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +module('unit/model/relationships - DS.belongsTo'); + +test('belongsTo lazily loads relationships as needed', function(assert) { + assert.expect(5); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: [ + { + type: 'tag', + id: '5', + attributes: { + name: 'friendly', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'smarmy', + }, + }, + { + type: 'tag', + id: '12', + attributes: { + name: 'oohlala', + }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tag: { + data: { type: 'tag', id: '5' }, + }, + }, + }, + ], + }); + }); + + return run(() => { + return store.findRecord('person', 1).then(person => { + assert.equal(get(person, 'name'), 'Tom Dale', 'precond - retrieves person record from store'); + + assert.equal(get(person, 'tag') instanceof Tag, true, 'the tag property should return a tag'); + assert.equal(get(person, 'tag.name'), 'friendly', 'the tag shuld have name'); + + assert.strictEqual( + get(person, 'tag'), + get(person, 'tag'), + 'the returned object is always the same' + ); + assert.asyncEqual( + get(person, 'tag'), + store.findRecord('tag', 5), + 'relationship object is the same as object retrieved directly' + ); + }); + }); +}); + +test('belongsTo does not notify when it is initially reified', function(assert) { + assert.expect(1); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + Tag.toString = () => 'Tag'; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + Person.toString = () => 'Person'; + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: [ + { + type: 'tag', + id: 1, + attributes: { + name: 'whatever', + }, + }, + { + type: 'person', + id: 2, + attributes: { + name: 'David J. Hamilton', + }, + relationships: { + tag: { + data: { + type: 'tag', + id: '1', + }, + }, + }, + }, + ], + }); + }); + + return run(() => { + let person = store.peekRecord('person', 2); + person.addObserver('tag', () => { + assert.ok(false, 'observer is not called'); + }); + + assert.equal(person.get('tag.name'), 'whatever', 'relationship is correct'); + }); +}); + +test('async belongsTo relationships work when the data hash has not been loaded', function(assert) { + assert.expect(5); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: true }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.findRecord = function(store, type, id, snapshot) { + if (type === Person) { + assert.equal(id, 1, 'id should be 1'); + + return { + data: { + id: 1, + type: 'person', + attributes: { name: 'Tom Dale' }, + relationships: { tag: { data: { id: 2, type: 'tag' } } }, + }, + }; + } else if (type === Tag) { + assert.equal(id, 2, 'id should be 2'); + + return { data: { id: 2, type: 'tag', attributes: { name: 'friendly' } } }; + } + }; + + return run(() => { + return store + .findRecord('person', 1) + .then(person => { + assert.equal(get(person, 'name'), 'Tom Dale', 'The person is now populated'); + + return run(() => { + return get(person, 'tag'); + }); + }) + .then(tag => { + assert.equal(get(tag, 'name'), 'friendly', 'Tom Dale is now friendly'); + assert.equal(get(tag, 'isLoaded'), true, 'Tom Dale is now loaded'); + }); + }); +}); + +test('async belongsTo relationships are not grouped with coalesceFindRequests=false', async function(assert) { + assert.expect(6); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: true }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.coalesceFindRequests = false; + + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tag: { + data: { type: 'tag', id: '3' }, + }, + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Bob Dylan', + }, + relationships: { + tag: { + data: { type: 'tag', id: '4' }, + }, + }, + }, + ], + }); + + env.adapter.findMany = function() { + throw new Error('findMany should not be called'); + }; + + env.adapter.findRecord = function(store, type, id) { + assert.equal(type.modelName, 'tag', 'modelName is tag'); + + if (id === '3') { + return Promise.resolve({ + data: { + id: '3', + type: 'tag', + attributes: { name: 'friendly' }, + }, + }); + } else if (id === '4') { + return Promise.resolve({ + data: { + id: '4', + type: 'tag', + attributes: { name: 'nice' }, + }, + }); + } + }; + + let persons = [store.peekRecord('person', '1'), store.peekRecord('person', '2')]; + let [tag1, tag2] = await Promise.all(persons.map(person => get(person, 'tag'))); + + assert.equal(get(tag1, 'name'), 'friendly', 'Tom Dale is now friendly'); + assert.equal(get(tag1, 'isLoaded'), true, "Tom Dale's tag is now loaded"); + + assert.equal(get(tag2, 'name'), 'nice', 'Bob Dylan is now nice'); + assert.equal(get(tag2, 'isLoaded'), true, "Bob Dylan's tag is now loaded"); +}); + +test('async belongsTo relationships are grouped with coalesceFindRequests=true', async function(assert) { + assert.expect(6); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: true }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.coalesceFindRequests = true; + + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tag: { + data: { type: 'tag', id: '3' }, + }, + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Bob Dylan', + }, + relationships: { + tag: { + data: { type: 'tag', id: '4' }, + }, + }, + }, + ], + }); + + env.adapter.findMany = function(store, type, ids, snapshots) { + assert.equal(type.modelName, 'tag', 'modelName is tag'); + assert.deepEqual(ids, ['3', '4'], 'it coalesces the find requests correctly'); + + return Promise.resolve({ + data: [ + { + id: '3', + type: 'tag', + attributes: { name: 'friendly' }, + }, + { + id: '4', + type: 'tag', + attributes: { name: 'nice' }, + }, + ], + }); + }; + + env.adapter.findRecord = function() { + throw new Error('findRecord should not be called'); + }; + + let persons = [store.peekRecord('person', '1'), store.peekRecord('person', '2')]; + let [tag1, tag2] = await Promise.all(persons.map(person => get(person, 'tag'))); + + assert.equal(get(tag1, 'name'), 'friendly', 'Tom Dale is now friendly'); + assert.equal(get(tag1, 'isLoaded'), true, "Tom Dale's tag is now loaded"); + + assert.equal(get(tag2, 'name'), 'nice', 'Bob Dylan is now nice'); + assert.equal(get(tag2, 'isLoaded'), true, "Bob Dylan's tag is now loaded"); +}); + +test('async belongsTo relationships work when the data hash has already been loaded', function(assert) { + assert.expect(3); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: true }), + }); + + var env = setupStore({ tag: Tag, person: Person }); + var store = env.store; + + run(() => { + store.push({ + data: [ + { + type: 'tag', + id: '2', + attributes: { + name: 'friendly', + }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tag: { + data: { type: 'tag', id: '2' }, + }, + }, + }, + ], + }); + }); + + return run(() => { + let person = store.peekRecord('person', 1); + assert.equal(get(person, 'name'), 'Tom Dale', 'The person is now populated'); + return run(() => { + return get(person, 'tag'); + }).then(tag => { + assert.equal(get(tag, 'name'), 'friendly', 'Tom Dale is now friendly'); + assert.equal(get(tag, 'isLoaded'), true, 'Tom Dale is now loaded'); + }); + }); +}); + +test('when response to saving a belongsTo is a success but includes changes that reset the users change', function(assert) { + const Tag = DS.Model.extend(); + const User = DS.Model.extend({ tag: DS.belongsTo() }); + let env = setupStore({ user: User, tag: Tag }); + let { store } = env; + + run(() => { + store.push({ + data: [ + { + type: 'user', + id: '1', + relationships: { + tag: { + data: { type: 'tag', id: '1' }, + }, + }, + }, + { type: 'tag', id: '1' }, + { type: 'tag', id: '2' }, + ], + }); + }); + + let user = store.peekRecord('user', '1'); + + run(() => user.set('tag', store.peekRecord('tag', '2'))); + + env.adapter.updateRecord = function() { + return { + data: { + type: 'user', + id: '1', + relationships: { + tag: { + data: { + id: '1', + type: 'tag', + }, + }, + }, + }, + }; + }; + + return run(() => { + return user.save().then(user => { + assert.equal(user.get('tag.id'), '1', 'expected new server state to be applied'); + }); + }); +}); + +test('calling createRecord and passing in an undefined value for a relationship should be treated as if null', function(assert) { + assert.expect(1); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + env.adapter.shouldBackgroundReloadRecord = () => false; + + store.createRecord('person', { id: '1', tag: undefined }); + + return run(() => { + return store.findRecord('person', '1').then(person => { + assert.strictEqual( + person.get('tag'), + null, + 'undefined values should return null relationships' + ); + }); + }); +}); + +test('When finding a hasMany relationship the inverse belongsTo relationship is available immediately', function(assert) { + const Occupation = DS.Model.extend({ + description: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + occupations: DS.hasMany('occupation', { async: true }), + }); + + let env = setupStore({ occupation: Occupation, person: Person }); + let { store } = env; + env.adapter.shouldBackgroundReloadRecord = () => false; + + env.adapter.findMany = function(store, type, ids, snapshots) { + assert.equal(snapshots[0].belongsTo('person').id, '1'); + return { + data: [ + { id: 5, type: 'occupation', attributes: { description: 'fifth' } }, + { id: 2, type: 'occupation', attributes: { description: 'second' } }, + ], + }; + }; + + env.adapter.coalesceFindRequests = true; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + occupations: { + data: [{ type: 'occupation', id: '5' }, { type: 'occupation', id: '2' }], + }, + }, + }, + }); + }); + + return run(() => { + return store + .findRecord('person', 1) + .then(person => { + assert.equal(get(person, 'isLoaded'), true, 'isLoaded should be true'); + assert.equal(get(person, 'name'), 'Tom Dale', 'the person is still Tom Dale'); + + return get(person, 'occupations'); + }) + .then(occupations => { + assert.equal( + get(occupations, 'length'), + 2, + 'the list of occupations should have the correct length' + ); + + assert.equal( + get(occupations.objectAt(0), 'description'), + 'fifth', + 'the occupation is the fifth' + ); + assert.equal( + get(occupations.objectAt(0), 'isLoaded'), + true, + 'the occupation is now loaded' + ); + }); + }); +}); + +test('When finding a belongsTo relationship the inverse belongsTo relationship is available immediately', function(assert) { + assert.expect(1); + + const Occupation = DS.Model.extend({ + description: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + occupation: DS.belongsTo('occupation', { async: true }), + }); + + let env = setupStore({ occupation: Occupation, person: Person }); + let store = env.store; + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(snapshot.belongsTo('person').id, '1'); + return { data: { id: 5, type: 'occupation', attributes: { description: 'fifth' } } }; + }; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + occupation: { + data: { type: 'occupation', id: '5' }, + }, + }, + }, + }); + }); + + run(() => store.peekRecord('person', 1).get('occupation')); +}); + +test('belongsTo supports relationships to models with id 0', function(assert) { + assert.expect(5); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let store = env.store; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: [ + { + type: 'tag', + id: '0', + attributes: { + name: 'friendly', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'smarmy', + }, + }, + { + type: 'tag', + id: '12', + attributes: { + name: 'oohlala', + }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tag: { + data: { type: 'tag', id: '0' }, + }, + }, + }, + ], + }); + }); + + return run(() => { + return store.findRecord('person', 1).then(person => { + assert.equal(get(person, 'name'), 'Tom Dale', 'precond - retrieves person record from store'); + + assert.equal(get(person, 'tag') instanceof Tag, true, 'the tag property should return a tag'); + assert.equal(get(person, 'tag.name'), 'friendly', 'the tag should have name'); + + assert.strictEqual( + get(person, 'tag'), + get(person, 'tag'), + 'the returned object is always the same' + ); + assert.asyncEqual( + get(person, 'tag'), + store.findRecord('tag', 0), + 'relationship object is the same as object retrieved directly' + ); + }); + }); +}); + +testInDebug('belongsTo gives a warning when provided with a serialize option', function(assert) { + const Hobby = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + hobby: DS.belongsTo('hobby', { serialize: true, async: true }), + }); + + let env = setupStore({ hobby: Hobby, person: Person }); + let store = env.store; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: [ + { + type: 'hobby', + id: '1', + attributes: { + name: 'fishing', + }, + }, + { + type: 'hobby', + id: '2', + attributes: { + name: 'coding', + }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + hobby: { + data: { type: 'hobby', id: '1' }, + }, + }, + }, + ], + }); + }); + + return run(() => { + return store.findRecord('person', 1).then(person => { + assert.expectWarning(() => { + get(person, 'hobby'); + }, /You provided a serialize option on the "hobby" property in the "person" class, this belongs in the serializer. See DS.Serializer and it's implementations/); + }); + }); +}); + +testInDebug('belongsTo gives a warning when provided with an embedded option', function(assert) { + const Hobby = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + hobby: DS.belongsTo('hobby', { embedded: true, async: true }), + }); + + let env = setupStore({ hobby: Hobby, person: Person }); + let { store } = env; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: [ + { + type: 'hobby', + id: '1', + attributes: { + name: 'fishing', + }, + }, + { + type: 'hobby', + id: '2', + attributes: { + name: 'coding', + }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + hobby: { + data: { type: 'hobby', id: '1' }, + }, + }, + }, + ], + }); + }); + + return run(() => { + return store.findRecord('person', 1).then(person => { + assert.expectWarning(() => { + get(person, 'hobby'); + }, /You provided an embedded option on the "hobby" property in the "person" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin/); + }); + }); +}); + +test('DS.belongsTo should be async by default', function(assert) { + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag'), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + let person = store.createRecord('person'); + + assert.ok(person.get('tag') instanceof DS.PromiseObject, 'tag should be an async relationship'); +}); diff --git a/tests/unit/model/relationships/has-many-test.js b/tests/unit/model/relationships/has-many-test.js new file mode 100644 index 00000000000..422c081968a --- /dev/null +++ b/tests/unit/model/relationships/has-many-test.js @@ -0,0 +1,2580 @@ +import { hash, Promise as EmberPromise } from 'rsvp'; +import { get, observer } from '@ember/object'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; +import todo from '../../../helpers/todo'; + +let env; + +module('unit/model/relationships - DS.hasMany', { + beforeEach() { + env = setupStore(); + }, +}); + +test('hasMany handles pre-loaded relationships', function(assert) { + assert.expect(13); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Pet = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: false }), + pets: DS.hasMany('pet', { async: false }), + }); + + env.owner.register('model:tag', Tag); + env.owner.register('model:pet', Pet); + env.owner.register('model:person', Person); + + env.adapter.findRecord = function(store, type, id, snapshot) { + if (type === Tag && id === '12') { + return { id: 12, name: 'oohlala' }; + } else { + assert.ok(false, 'findRecord() should not be called with these values'); + } + }; + env.adapter.shouldBackgroundReloadRecord = () => false; + + let { store } = env; + + run(() => { + store.push({ + data: [ + { + type: 'tag', + id: '5', + attributes: { + name: 'friendly', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'smarmy', + }, + }, + { + type: 'pet', + id: '4', + attributes: { + name: 'fluffy', + }, + }, + { + type: 'pet', + id: '7', + attributes: { + name: 'snowy', + }, + }, + { + type: 'pet', + id: '12', + attributes: { + name: 'cerberus', + }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '5' }], + }, + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Yehuda Katz', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '12' }], + }, + }, + }, + ], + }); + }); + + return run(() => { + return store + .findRecord('person', 1) + .then(person => { + assert.equal( + get(person, 'name'), + 'Tom Dale', + 'precond - retrieves person record from store' + ); + + let tags = get(person, 'tags'); + assert.equal(get(tags, 'length'), 1, 'the list of tags should have the correct length'); + assert.equal(get(tags.objectAt(0), 'name'), 'friendly', 'the first tag should be a Tag'); + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '5' }, { type: 'tag', id: '2' }], + }, + }, + }, + }); + }); + + assert.equal( + tags, + get(person, 'tags'), + 'a relationship returns the same object every time' + ); + assert.equal( + get(get(person, 'tags'), 'length'), + 2, + 'the length is updated after new data is loaded' + ); + + assert.strictEqual( + get(person, 'tags').objectAt(0), + get(person, 'tags').objectAt(0), + 'the returned object is always the same' + ); + assert.equal( + get(person, 'tags').objectAt(0), + store.peekRecord('tag', 5), + 'relationship objects are the same as objects retrieved directly' + ); + + run(() => { + store.push({ + data: { + type: 'person', + id: '3', + attributes: { + name: 'KSelden', + }, + }, + }); + }); + + return store.findRecord('person', 3); + }) + .then(kselden => { + assert.equal( + get(get(kselden, 'tags'), 'length'), + 0, + 'a relationship that has not been supplied returns an empty array' + ); + + run(() => { + store.push({ + data: { + type: 'person', + id: '4', + attributes: { + name: 'Cyvid Hamluck', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '4' }], + }, + }, + }, + }); + }); + return store.findRecord('person', 4); + }) + .then(cyvid => { + assert.equal( + get(cyvid, 'name'), + 'Cyvid Hamluck', + 'precond - retrieves person record from store' + ); + + let pets = get(cyvid, 'pets'); + assert.equal(get(pets, 'length'), 1, 'the list of pets should have the correct length'); + assert.equal(get(pets.objectAt(0), 'name'), 'fluffy', 'the first pet should be correct'); + + run(() => { + store.push({ + data: { + type: 'person', + id: '4', + attributes: { + name: 'Cyvid Hamluck', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '4' }, { type: 'pet', id: '12' }], + }, + }, + }, + }); + }); + + assert.equal(pets, get(cyvid, 'pets'), 'a relationship returns the same object every time'); + assert.equal( + get(get(cyvid, 'pets'), 'length'), + 2, + 'the length is updated after new data is loaded' + ); + }); + }); +}); + +test('hasMany does not notify when it is initially reified', function(assert) { + assert.expect(1); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + Tag.toString = () => 'Tag'; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + Person.toString = () => 'Person'; + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: [ + { + type: 'tag', + id: 1, + attributes: { + name: 'whatever', + }, + relationships: { + people: { + data: [ + { + id: 2, + type: 'person', + }, + ], + }, + }, + }, + { + type: 'person', + id: 2, + attributes: { + name: 'David J. Hamilton', + }, + }, + ], + }); + }); + + return run(() => { + let tag = store.peekRecord('tag', 1); + tag.addObserver('people', () => { + assert.ok(false, 'observer is not called'); + }); + tag.addObserver('people.[]', () => { + assert.ok(false, 'observer is not called'); + }); + + assert.equal(tag.get('people').mapBy('name'), 'David J. Hamilton', 'relationship is correct'); + }); +}); + +test('hasMany can be initially reified with null', function(assert) { + assert.expect(1); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: { + type: 'tag', + id: 1, + attributes: { + name: 'whatever', + }, + relationships: { + people: { + data: null, + }, + }, + }, + }); + }); + + return run(() => { + let tag = store.peekRecord('tag', 1); + + assert.equal(tag.get('people.length'), 0, 'relationship is correct'); + }); +}); + +test('hasMany with explicit initial null works even when the inverse was set to not null', function(assert) { + assert.expect(2); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + // first we push in data with the relationship + store.push({ + data: { + type: 'person', + id: 1, + attributes: { + name: 'David J. Hamilton', + }, + relationships: { + tag: { + data: { + type: 'tag', + id: 1, + }, + }, + }, + }, + included: [ + { + type: 'tag', + id: 1, + attributes: { + name: 'whatever', + }, + relationships: { + people: { + data: [ + { + type: 'person', + id: 1, + }, + ], + }, + }, + }, + ], + }); + + // now we push in data for that record which says it has no relationships + store.push({ + data: { + type: 'tag', + id: 1, + attributes: { + name: 'whatever', + }, + relationships: { + people: { + data: null, + }, + }, + }, + }); + }); + + return run(() => { + let tag = store.peekRecord('tag', 1); + let person = store.peekRecord('person', 1); + + assert.equal(person.get('tag'), null, 'relationship is empty'); + assert.equal(tag.get('people.length'), 0, 'relationship is correct'); + }); +}); + +test('hasMany with duplicates from payload', function(assert) { + assert.expect(1); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + + Tag.reopenClass({ + toString() { + return 'tag'; + }, + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + Person.reopenClass({ + toString() { + return 'person'; + }, + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + run(() => { + // first we push in data with the relationship + store.push({ + data: { + type: 'person', + id: 1, + attributes: { + name: 'David J. Hamilton', + }, + relationships: { + tag: { + data: { + type: 'tag', + id: 1, + }, + }, + }, + }, + included: [ + { + type: 'tag', + id: 1, + attributes: { + name: 'whatever', + }, + relationships: { + people: { + data: [ + { + type: 'person', + id: 1, + }, + { + type: 'person', + id: 1, + }, + ], + }, + }, + }, + ], + }); + }); + + run(() => { + let tag = store.peekRecord('tag', 1); + assert.equal(tag.get('people.length'), 1, 'relationship does not contain duplicates'); + }); +}); + +test('many2many loads both sides #5140', function(assert) { + assert.expect(3); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + + Tag.reopenClass({ + toString() { + return 'tag'; + }, + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tags', { async: false }), + }); + + Person.reopenClass({ + toString() { + return 'person'; + }, + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + run(() => { + // first we push in data with the relationship + store.push({ + data: [ + { + type: 'person', + id: 1, + attributes: { + name: 'David J. Hamilton', + }, + relationships: { + tags: [ + { + data: { + type: 'tag', + id: 1, + }, + }, + { + data: { + type: 'tag', + id: 2, + }, + }, + ], + }, + }, + { + type: 'person', + id: 2, + attributes: { + name: 'Gerald Dempsey Posey', + }, + relationships: { + tags: [ + { + data: { + type: 'tag', + id: 1, + }, + }, + { + data: { + type: 'tag', + id: 2, + }, + }, + ], + }, + }, + { + type: 'tag', + id: 1, + attributes: { + name: 'whatever', + }, + relationships: { + people: { + data: [ + { + type: 'person', + id: 1, + }, + { + type: 'person', + id: 2, + }, + ], + }, + }, + }, + { + type: 'tag', + id: 2, + attributes: { + name: 'nothing', + }, + relationships: { + people: { + data: [ + { + type: 'person', + id: 1, + }, + { + type: 'person', + id: 2, + }, + ], + }, + }, + }, + ], + }); + }); + + run(() => { + let tag = store.peekRecord('tag', 1); + assert.equal(tag.get('people.length'), 2, 'relationship does contain all data'); + let person1 = store.peekRecord('person', 1); + assert.equal(person1.get('tags.length'), 2, 'relationship does contain all data'); + let person2 = store.peekRecord('person', 2); + assert.equal(person2.get('tags.length'), 2, 'relationship does contain all data'); + }); +}); + +test('hasMany with explicit null works even when the inverse was set to not null', function(assert) { + assert.expect(3); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + // first we push in data with the relationship + store.push({ + data: { + type: 'person', + id: 1, + attributes: { + name: 'David J. Hamilton', + }, + relationships: { + tag: { + data: { + type: 'tag', + id: 1, + }, + }, + }, + }, + included: [ + { + type: 'tag', + id: 1, + attributes: { + name: 'whatever', + }, + relationships: { + people: { + data: [ + { + type: 'person', + id: 1, + }, + ], + }, + }, + }, + ], + }); + }); + + run(() => { + let person = store.peekRecord('person', 1); + let tag = store.peekRecord('tag', 1); + + assert.equal(person.get('tag'), tag, 'relationship is not empty'); + }); + + run(() => { + // now we push in data for that record which says it has no relationships + store.push({ + data: { + type: 'tag', + id: 1, + attributes: { + name: 'whatever', + }, + relationships: { + people: { + data: null, + }, + }, + }, + }); + }); + + return run(() => { + let person = store.peekRecord('person', 1); + let tag = store.peekRecord('tag', 1); + + assert.equal(person.get('tag'), null, 'relationship is now empty'); + assert.equal(tag.get('people.length'), 0, 'relationship is correct'); + }); +}); + +test('hasMany tolerates reflexive self-relationships', function(assert) { + assert.expect(1); + + const Person = DS.Model.extend({ + name: DS.attr(), + trueFriends: DS.hasMany('person', { async: false }), + }); + + let env = setupStore({ person: Person }); + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + env.store.push({ + data: { + id: '1', + type: 'person', + attributes: { + name: 'Edward II', + }, + relationships: { + trueFriends: { + data: [ + { + id: '1', + type: 'person', + }, + ], + }, + }, + }, + }); + }); + + let eddy = env.store.peekRecord('person', 1); + assert.deepEqual( + eddy.get('trueFriends').mapBy('name'), + ['Edward II'], + 'hasMany supports reflexive self-relationships' + ); +}); + +test('hasMany lazily loads async relationships', function(assert) { + assert.expect(5); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Pet = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: true }), + pets: DS.hasMany('pet', { async: false }), + }); + + env.owner.register('model:tag', Tag); + env.owner.register('model:pet', Pet); + env.owner.register('model:person', Person); + + env.adapter.findRecord = function(store, type, id, snapshot) { + if (type === Tag && id === '12') { + return { data: { id: 12, type: 'tag', attributes: { name: 'oohlala' } } }; + } else { + assert.ok(false, 'findRecord() should not be called with these values'); + } + }; + env.adapter.shouldBackgroundReloadRecord = () => false; + + let { store } = env; + + run(() => { + store.push({ + data: [ + { + type: 'tag', + id: '5', + attributes: { + name: 'friendly', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'smarmy', + }, + }, + { + type: 'pet', + id: '4', + attributes: { + name: 'fluffy', + }, + }, + { + type: 'pet', + id: '7', + attributes: { + name: 'snowy', + }, + }, + { + type: 'pet', + id: '12', + attributes: { + name: 'cerberus', + }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '5' }], + }, + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Yehuda Katz', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '12' }], + }, + }, + }, + ], + }); + }); + + return run(() => { + let wycats; + store + .findRecord('person', 2) + .then(function(person) { + wycats = person; + + assert.equal( + get(wycats, 'name'), + 'Yehuda Katz', + 'precond - retrieves person record from store' + ); + + return hash({ + wycats, + tags: wycats.get('tags'), + }); + }) + .then(records => { + assert.equal( + get(records.tags, 'length'), + 1, + 'the list of tags should have the correct length' + ); + assert.equal( + get(records.tags.objectAt(0), 'name'), + 'oohlala', + 'the first tag should be a Tag' + ); + + assert.strictEqual( + records.tags.objectAt(0), + records.tags.objectAt(0), + 'the returned object is always the same' + ); + assert.equal( + records.tags.objectAt(0), + store.peekRecord('tag', 12), + 'relationship objects are the same as objects retrieved directly' + ); + + return get(wycats, 'tags'); + }) + .then(tags => { + let newTag = store.createRecord('tag'); + tags.pushObject(newTag); + }); + }); +}); + +test('should be able to retrieve the type for a hasMany relationship without specifying a type from its metadata', function(assert) { + const Tag = DS.Model.extend({}); + + const Person = DS.Model.extend({ + tags: DS.hasMany('tag', { async: false }), + }); + + let env = setupStore({ + tag: Tag, + person: Person, + }); + + assert.equal( + env.store.modelFor('person').typeForRelationship('tags', env.store), + Tag, + 'returns the relationship type' + ); +}); + +test('should be able to retrieve the type for a hasMany relationship specified using a string from its metadata', function(assert) { + const Tag = DS.Model.extend({}); + + const Person = DS.Model.extend({ + tags: DS.hasMany('tag', { async: false }), + }); + + let env = setupStore({ + tag: Tag, + person: Person, + }); + + assert.equal( + env.store.modelFor('person').typeForRelationship('tags', env.store), + Tag, + 'returns the relationship type' + ); +}); + +test('should be able to retrieve the type for a belongsTo relationship without specifying a type from its metadata', function(assert) { + const Tag = DS.Model.extend({}); + + const Person = DS.Model.extend({ + tag: DS.belongsTo('tag', { async: false }), + }); + + let env = setupStore({ + tag: Tag, + person: Person, + }); + + assert.equal( + env.store.modelFor('person').typeForRelationship('tag', env.store), + Tag, + 'returns the relationship type' + ); +}); + +test('should be able to retrieve the type for a belongsTo relationship specified using a string from its metadata', function(assert) { + const Tag = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Person = DS.Model.extend({ + tags: DS.belongsTo('tag', { async: false }), + }); + + let env = setupStore({ + tag: Tag, + person: Person, + }); + + assert.equal( + env.store.modelFor('person').typeForRelationship('tags', env.store), + Tag, + 'returns the relationship type' + ); +}); + +test('relationships work when declared with a string path', function(assert) { + assert.expect(2); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: false }), + }); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + }); + + let env = setupStore({ + person: Person, + tag: Tag, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + env.store.push({ + data: [ + { + type: 'tag', + id: '5', + attributes: { + name: 'friendly', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'smarmy', + }, + }, + { + type: 'tag', + id: '12', + attributes: { + name: 'oohlala', + }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '5' }, { type: 'tag', id: '2' }], + }, + }, + }, + ], + }); + }); + + return run(() => { + return env.store.findRecord('person', 1).then(person => { + assert.equal(get(person, 'name'), 'Tom Dale', 'precond - retrieves person record from store'); + assert.equal( + get(person, 'tags.length'), + 2, + 'the list of tags should have the correct length' + ); + }); + }); +}); + +test('hasMany relationships work when the data hash has not been loaded', function(assert) { + assert.expect(8); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: true }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.coalesceFindRequests = true; + env.adapter.findMany = function(store, type, ids, snapshots) { + assert.equal(type, Tag, 'type should be Tag'); + assert.deepEqual(ids, ['5', '2'], 'ids should be 5 and 2'); + + return { + data: [ + { id: 5, type: 'tag', attributes: { name: 'friendly' } }, + { id: 2, type: 'tag', attributes: { name: 'smarmy' } }, + ], + }; + }; + + env.adapter.findRecord = function(store, type, id, snapshot) { + assert.equal(type, Person, 'type should be Person'); + assert.equal(id, 1, 'id should be 1'); + + return { + data: { + id: 1, + type: 'person', + attributes: { name: 'Tom Dale' }, + relationships: { + tags: { + data: [{ id: 5, type: 'tag' }, { id: 2, type: 'tag' }], + }, + }, + }, + }; + }; + + return run(() => { + return store + .findRecord('person', 1) + .then(person => { + assert.equal(get(person, 'name'), 'Tom Dale', 'The person is now populated'); + + return run(() => person.get('tags')); + }) + .then(tags => { + assert.equal(get(tags, 'length'), 2, 'the tags object still exists'); + assert.equal(get(tags.objectAt(0), 'name'), 'friendly', 'Tom Dale is now friendly'); + assert.equal(get(tags.objectAt(0), 'isLoaded'), true, 'Tom Dale is now loaded'); + }); + }); +}); + +test('it is possible to add a new item to a relationship', function(assert) { + assert.expect(2); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: false }), + }); + + let env = setupStore({ + tag: Tag, + person: Person, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + + let { store } = env; + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '1' }], + }, + }, + }, + { + type: 'tag', + id: '1', + attributes: { + name: 'ember', + }, + }, + ], + }); + }); + + return run(() => { + return store.findRecord('person', 1).then(person => { + let tag = get(person, 'tags').objectAt(0); + + assert.equal(get(tag, 'name'), 'ember', 'precond - relationships work'); + + tag = store.createRecord('tag', { name: 'js' }); + get(person, 'tags').pushObject(tag); + + assert.equal(get(person, 'tags').objectAt(1), tag, 'newly added relationship works'); + }); + }); +}); + +test('new items added to a hasMany relationship are not cleared by a delete', function(assert) { + assert.expect(4); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + pets: DS.hasMany('pet', { async: false, inverse: null }), + }); + + const Pet = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false, inverse: null }), + }); + + let env = setupStore({ + person: Person, + pet: Pet, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.deleteRecord = () => { + return EmberPromise.resolve({ data: null }); + }; + + let { store } = env; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + }, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'pet', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + { + type: 'pet', + id: '3', + attributes: { + name: 'Rebel', + }, + }, + ], + }); + }); + + const person = store.peekRecord('person', '1'); + const pets = run(() => person.get('pets')); + + const shen = pets.objectAt(0); + const rambo = store.peekRecord('pet', '2'); + const rebel = store.peekRecord('pet', '3'); + + assert.equal(get(shen, 'name'), 'Shenanigans', 'precond - relationships work'); + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1'], + 'precond - relationship has the correct pets to start' + ); + + run(() => { + pets.pushObjects([rambo, rebel]); + }); + + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1', '2', '3'], + 'precond2 - relationship now has the correct three pets' + ); + + run(() => { + return shen.destroyRecord({}).then(() => { + shen.unloadRecord(); + }); + }); + + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['2', '3'], + 'relationship now has the correct two pets' + ); +}); + +todo( + '[push hasMany] new items added to a hasMany relationship are not cleared by a store.push', + function(assert) { + assert.expect(5); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + pets: DS.hasMany('pet', { async: false, inverse: null }), + }); + + const Pet = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false, inverse: null }), + }); + + let env = setupStore({ + person: Person, + pet: Pet, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.deleteRecord = () => { + return EmberPromise.resolve({ data: null }); + }; + + let { store } = env; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + }, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'pet', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + { + type: 'pet', + id: '3', + attributes: { + name: 'Rebel', + }, + }, + ], + }); + }); + + const person = store.peekRecord('person', '1'); + const pets = run(() => person.get('pets')); + + const shen = pets.objectAt(0); + const rebel = store.peekRecord('pet', '3'); + + assert.equal(get(shen, 'name'), 'Shenanigans', 'precond - relationships work'); + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1'], + 'precond - relationship has the correct pets to start' + ); + + run(() => { + pets.pushObjects([rebel]); + }); + + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1', '3'], + 'precond2 - relationship now has the correct two pets' + ); + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '2' }], + }, + }, + }, + }); + }); + + let hasManyCanonical = person.hasMany('pets').hasManyRelationship.canonicalMembers.list; + + assert.todo.deepEqual( + pets.map(p => get(p, 'id')), + ['2', '3'], + 'relationship now has the correct current pets' + ); + assert.deepEqual( + hasManyCanonical.map(p => get(p, 'id')), + ['2'], + 'relationship now has the correct canonical pets' + ); + } +); + +todo( + '[push hasMany] items removed from a hasMany relationship are not cleared by a store.push', + function(assert) { + assert.expect(5); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + pets: DS.hasMany('pet', { async: false, inverse: null }), + }); + + const Pet = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false, inverse: null }), + }); + + let env = setupStore({ + person: Person, + pet: Pet, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.deleteRecord = () => { + return EmberPromise.resolve({ data: null }); + }; + + let { store } = env; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }, { type: 'pet', id: '3' }], + }, + }, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'pet', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + { + type: 'pet', + id: '3', + attributes: { + name: 'Rebel', + }, + }, + ], + }); + }); + + const person = store.peekRecord('person', '1'); + const pets = run(() => person.get('pets')); + + const shen = pets.objectAt(0); + const rebel = store.peekRecord('pet', '3'); + + assert.equal(get(shen, 'name'), 'Shenanigans', 'precond - relationships work'); + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1', '3'], + 'precond - relationship has the correct pets to start' + ); + + run(() => { + pets.removeObject(rebel); + }); + + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1'], + 'precond2 - relationship now has the correct pet' + ); + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '2' }, { type: 'pet', id: '3' }], + }, + }, + }, + }); + }); + + let hasManyCanonical = person.hasMany('pets').hasManyRelationship.canonicalMembers.list; + + assert.todo.deepEqual( + pets.map(p => get(p, 'id')), + ['2'], + 'relationship now has the correct current pets' + ); + assert.deepEqual( + hasManyCanonical.map(p => get(p, 'id')), + ['2', '3'], + 'relationship now has the correct canonical pets' + ); + } +); + +test('new items added to an async hasMany relationship are not cleared by a delete', function(assert) { + assert.expect(7); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + pets: DS.hasMany('pet', { async: true, inverse: null }), + }); + + const Pet = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false, inverse: null }), + }); + + let env = setupStore({ + person: Person, + pet: Pet, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.deleteRecord = () => { + return EmberPromise.resolve({ data: null }); + }; + + let { store } = env; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + }, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'pet', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + { + type: 'pet', + id: '3', + attributes: { + name: 'Rebel', + }, + }, + ], + }); + }); + + return run(() => { + const person = store.peekRecord('person', '1'); + const petsProxy = run(() => person.get('pets')); + + return petsProxy.then(pets => { + const shen = pets.objectAt(0); + const rambo = store.peekRecord('pet', '2'); + const rebel = store.peekRecord('pet', '3'); + + assert.equal(get(shen, 'name'), 'Shenanigans', 'precond - relationships work'); + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1'], + 'precond - relationship has the correct pet to start' + ); + assert.equal(get(petsProxy, 'length'), 1, 'precond - proxy has only one pet to start'); + + pets.pushObjects([rambo, rebel]); + + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1', '2', '3'], + 'precond2 - relationship now has the correct three pets' + ); + assert.equal(get(petsProxy, 'length'), 3, 'precond2 - proxy now reflects three pets'); + + return shen.destroyRecord({}).then(() => { + shen.unloadRecord(); + + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['2', '3'], + 'relationship now has the correct two pets' + ); + assert.equal(get(petsProxy, 'length'), 2, 'proxy now reflects two pets'); + }); + }); + }); +}); + +test('new items added to a belongsTo relationship are not cleared by a delete', function(assert) { + assert.expect(4); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + dog: DS.belongsTo('dog', { async: false, inverse: null }), + }); + + const Dog = DS.Model.extend({ + name: DS.attr('string'), + }); + + let env = setupStore({ + person: Person, + dog: Dog, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.deleteRecord = () => { + return EmberPromise.resolve({ data: null }); + }; + + let { store } = env; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + dog: { + data: { type: 'dog', id: '1' }, + }, + }, + }, + included: [ + { + type: 'dog', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'dog', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + ], + }); + }); + + const person = store.peekRecord('person', '1'); + let dog = run(() => person.get('dog')); + const shen = store.peekRecord('dog', '1'); + const rambo = store.peekRecord('dog', '2'); + + assert.ok(dog === shen, 'precond - the belongsTo points to the correct dog'); + assert.equal(get(dog, 'name'), 'Shenanigans', 'precond - relationships work'); + + run(() => { + person.set('dog', rambo); + }); + + dog = person.get('dog'); + assert.equal(dog, rambo, 'precond2 - relationship was updated'); + + return run(() => { + return shen.destroyRecord({}).then(() => { + shen.unloadRecord(); + + dog = person.get('dog'); + assert.equal(dog, rambo, 'The currentState of the belongsTo was preserved after the delete'); + }); + }); +}); + +test('new items added to an async belongsTo relationship are not cleared by a delete', function(assert) { + assert.expect(4); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + dog: DS.belongsTo('dog', { async: true, inverse: null }), + }); + + const Dog = DS.Model.extend({ + name: DS.attr('string'), + }); + + let env = setupStore({ + person: Person, + dog: Dog, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.deleteRecord = () => { + return EmberPromise.resolve({ data: null }); + }; + + let { store } = env; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + dog: { + data: { type: 'dog', id: '1' }, + }, + }, + }, + included: [ + { + type: 'dog', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'dog', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + ], + }); + }); + + return run(() => { + const person = store.peekRecord('person', '1'); + const shen = store.peekRecord('dog', '1'); + const rambo = store.peekRecord('dog', '2'); + + return person.get('dog').then(dog => { + assert.ok(dog === shen, 'precond - the belongsTo points to the correct dog'); + assert.equal(get(dog, 'name'), 'Shenanigans', 'precond - relationships work'); + + person.set('dog', rambo); + + dog = person.get('dog.content'); + + assert.ok(dog === rambo, 'precond2 - relationship was updated'); + + return shen.destroyRecord({}).then(() => { + shen.unloadRecord(); + + dog = person.get('dog.content'); + assert.ok( + dog === rambo, + 'The currentState of the belongsTo was preserved after the delete' + ); + }); + }); + }); +}); + +test('deleting an item that is the current state of a belongsTo clears currentState', function(assert) { + assert.expect(4); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + dog: DS.belongsTo('dog', { async: false, inverse: null }), + }); + + const Dog = DS.Model.extend({ + name: DS.attr('string'), + }); + + let env = setupStore({ + person: Person, + dog: Dog, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.deleteRecord = () => { + return EmberPromise.resolve({ data: null }); + }; + + let { store } = env; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + dog: { + data: { type: 'dog', id: '1' }, + }, + }, + }, + included: [ + { + type: 'dog', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'dog', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + ], + }); + }); + + const person = store.peekRecord('person', '1'); + let dog = run(() => person.get('dog')); + const shen = store.peekRecord('dog', '1'); + const rambo = store.peekRecord('dog', '2'); + + assert.ok(dog === shen, 'precond - the belongsTo points to the correct dog'); + assert.equal(get(dog, 'name'), 'Shenanigans', 'precond - relationships work'); + + run(() => { + person.set('dog', rambo); + }); + + dog = person.get('dog'); + assert.equal(dog, rambo, 'precond2 - relationship was updated'); + + return run(() => { + return rambo.destroyRecord({}).then(() => { + rambo.unloadRecord(); + + dog = person.get('dog'); + assert.equal(dog, null, 'The current state of the belongsTo was clearer'); + }); + }); +}); + +test('hasMany.firstObject.unloadRecord should not break that hasMany', function(assert) { + const Person = DS.Model.extend({ + cars: DS.hasMany('car', { async: false }), + name: DS.attr(), + }); + + Person.reopenClass({ + toString() { + return 'person'; + }, + }); + + const Car = DS.Model.extend({ + name: DS.attr(), + }); + + Car.reopenClass({ + toString() { + return 'car'; + }, + }); + + let env = setupStore({ + person: Person, + car: Car, + }); + + run(() => { + env.store.push({ + data: [ + { + type: 'person', + id: 1, + attributes: { + name: 'marvin', + }, + relationships: { + cars: { + data: [{ type: 'car', id: 1 }, { type: 'car', id: 2 }], + }, + }, + }, + { type: 'car', id: 1, attributes: { name: 'a' } }, + { type: 'car', id: 2, attributes: { name: 'b' } }, + ], + }); + }); + + let person = env.store.peekRecord('person', 1); + let cars = person.get('cars'); + + assert.equal(cars.get('length'), 2); + + run(() => { + cars.get('firstObject').unloadRecord(); + assert.equal(cars.get('length'), 1); // unload now.. + assert.equal(person.get('cars.length'), 1); // unload now.. + }); + + assert.equal(cars.get('length'), 1); // unload now.. + assert.equal(person.get('cars.length'), 1); // unload now.. +}); + +/* + This test, when passing, affirms that a known limitation of ember-data still exists. + + When pushing new data into the store, ember-data is currently incapable of knowing whether + a relationship has been persisted. In order to update relationship state effectively, ember-data + blindly "flushes canonical" state, removing any `currentState` changes. A delete that sideloads + the parent record's hasMany is a situation in which this limitation will be encountered should other + local changes to the relationship still exist. + */ +test('[ASSERTS KNOWN LIMITATION STILL EXISTS] returning new hasMany relationship info from a delete clears local state', function(assert) { + assert.expect(4); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + pets: DS.hasMany('pet', { async: false, inverse: null }), + }); + + const Pet = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false, inverse: null }), + }); + + let env = setupStore({ + person: Person, + pet: Pet, + }); + env.adapter.shouldBackgroundReloadRecord = () => false; + env.adapter.deleteRecord = () => { + return EmberPromise.resolve({ + data: null, + included: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '2' }], + }, + }, + }, + ], + }); + }; + + let { store } = env; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }, { type: 'pet', id: '2' }], + }, + }, + }, + included: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'pet', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + { + type: 'pet', + id: '3', + attributes: { + name: 'Rebel', + }, + }, + ], + }); + }); + + const person = store.peekRecord('person', '1'); + const pets = run(() => person.get('pets')); + + const shen = store.peekRecord('pet', '1'); + const rebel = store.peekRecord('pet', '3'); + + assert.equal(get(shen, 'name'), 'Shenanigans', 'precond - relationships work'); + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1', '2'], + 'precond - relationship has the correct pets to start' + ); + + run(() => { + pets.pushObjects([rebel]); + }); + + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['1', '2', '3'], + 'precond2 - relationship now has the correct three pets' + ); + + return run(() => { + return shen.destroyRecord({}).then(() => { + shen.unloadRecord(); + + // were ember-data to now preserve local edits during a relationship push, this would be '2' + assert.deepEqual( + pets.map(p => get(p, 'id')), + ['2'], + 'relationship now has only one pet, we lost the local change' + ); + }); + }); +}); + +test('possible to replace items in a relationship using setObjects w/ Ember Enumerable Array/Object as the argument (GH-2533)', function(assert) { + assert.expect(2); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '1' }], + }, + }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Sylvain Mina', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '2' }], + }, + }, + }, + { + type: 'tag', + id: '1', + attributes: { + name: 'ember', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'ember-data', + }, + }, + ], + }); + }); + + let tom, sylvain; + + run(() => { + tom = store.peekRecord('person', '1'); + sylvain = store.peekRecord('person', '2'); + // Test that since sylvain.get('tags') instanceof DS.ManyArray, + // addInternalModels on Relationship iterates correctly. + tom.get('tags').setObjects(sylvain.get('tags')); + }); + + assert.equal(tom.get('tags.length'), 1); + assert.equal(tom.get('tags.firstObject'), store.peekRecord('tag', 2)); +}); + +test('Replacing `has-many` with non-array will throw assertion', function(assert) { + assert.expect(1); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '1' }], + }, + }, + }, + { + type: 'tag', + id: '1', + attributes: { + name: 'ember', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'ember-data', + }, + }, + ], + }); + }); + + let tom; + + run(() => { + tom = store.peekRecord('person', '1'); + assert.expectAssertion(() => { + tom.get('tags').setObjects(store.peekRecord('tag', '2')); + }, /The third argument to replace needs to be an array./); + }); +}); + +test('it is possible to remove an item from a relationship', function(assert) { + assert.expect(2); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tags: { + data: [{ type: 'tag', id: '1' }], + }, + }, + }, + { + type: 'tag', + id: '1', + attributes: { + name: 'ember', + }, + }, + ], + }); + }); + + return run(() => { + return store.findRecord('person', 1).then(person => { + let tag = get(person, 'tags').objectAt(0); + + assert.equal(get(tag, 'name'), 'ember', 'precond - relationships work'); + + run(() => get(person, 'tags').removeObject(tag)); + + assert.equal(get(person, 'tags.length'), 0, 'object is removed from the relationship'); + }); + }); +}); + +test('it is possible to add an item to a relationship, remove it, then add it again', function(assert) { + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + let person = store.createRecord('person'); + let tag1 = store.createRecord('tag'); + let tag2 = store.createRecord('tag'); + let tag3 = store.createRecord('tag'); + let tags = get(person, 'tags'); + + run(() => { + tags.pushObjects([tag1, tag2, tag3]); + tags.removeObject(tag2); + }); + + assert.equal(tags.objectAt(0), tag1); + assert.equal(tags.objectAt(1), tag3); + assert.equal(get(person, 'tags.length'), 2, 'object is removed from the relationship'); + + run(() => { + tags.insertAt(0, tag2); + }); + + assert.equal(get(person, 'tags.length'), 3, 'object is added back to the relationship'); + assert.equal(tags.objectAt(0), tag2); + assert.equal(tags.objectAt(1), tag1); + assert.equal(tags.objectAt(2), tag3); +}); + +test('DS.hasMany is async by default', function(assert) { + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person'), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let { store } = setupStore({ tag: Tag, person: Person }); + let tag = store.createRecord('tag'); + + assert.ok(tag.get('people') instanceof DS.PromiseArray, 'people should be an async relationship'); +}); + +test('DS.hasMany is stable', function(assert) { + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person'), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let { store } = setupStore({ tag: Tag, person: Person }); + + let tag = store.createRecord('tag'); + let people = tag.get('people'); + let peopleCached = tag.get('people'); + + assert.equal(people, peopleCached); + + tag.notifyPropertyChange('people'); + let notifiedPeople = tag.get('people'); + + assert.equal(people, notifiedPeople); + + return EmberPromise.all([people]); +}); + +test('DS.hasMany proxy is destroyed', function(assert) { + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person'), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let { store } = setupStore({ tag: Tag, person: Person }); + + let tag = store.createRecord('tag'); + let peopleProxy = tag.get('people'); + + return peopleProxy.then(people => { + run(() => { + let isRecordDataBuild = people.recordData !== undefined; + tag.unloadRecord(); + // TODO Check all unloading behavior + assert.equal(people.isDestroying, false, 'people is NOT destroying sync after unloadRecord'); + assert.equal(people.isDestroyed, false, 'people is NOT destroyed sync after unloadRecord'); + + // unload is not the same as destroy, and we may cancel + // prior to RecordData, this was coupled to the destroy + // of the relationship, which was async and possibly could + // be cancelled were an unload to be aborted. + assert.equal( + peopleProxy.isDestroying, + isRecordDataBuild, + 'peopleProxy is not destroying sync after unloadRecord' + ); + assert.equal( + peopleProxy.isDestroyed, + false, + 'peopleProxy is NOT YET destroyed sync after unloadRecord' + ); + }); + + assert.equal( + peopleProxy.isDestroying, + true, + 'peopleProxy is destroying after the run post unloadRecord' + ); + assert.equal( + peopleProxy.isDestroyed, + true, + 'peopleProxy is destroyed after the run post unloadRecord' + ); + }); +}); + +test('DS.ManyArray is lazy', function(assert) { + let peopleDidChange = 0; + const Tag = DS.Model.extend({ + name: DS.attr('string'), + people: DS.hasMany('person'), + peopleDidChange: observer('people', function() { + peopleDidChange++; + }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tag: DS.belongsTo('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let tag = env.store.createRecord('tag'); + // TODO replace with a test that checks for wherever the new ManyArray location is + //let hasManyRelationship = tag.hasMany('people').hasManyRelationship; + + //assert.ok(!hasManyRelationship._manyArray); + + run(() => { + assert.equal( + peopleDidChange, + 0, + 'expect people hasMany to not emit a change event (before access)' + ); + tag.get('people'); + assert.equal( + peopleDidChange, + 0, + 'expect people hasMany to not emit a change event (sync after access)' + ); + }); + + assert.equal( + peopleDidChange, + 0, + 'expect people hasMany to not emit a change event (after access, but after the current run loop)' + ); + //assert.ok(hasManyRelationship._manyArray instanceof DS.ManyArray); + + let person = env.store.createRecord('person'); + + run(() => { + assert.equal( + peopleDidChange, + 0, + 'expect people hasMany to not emit a change event (before access)' + ); + tag.get('people').addObject(person); + assert.equal(peopleDidChange, 1, 'expect people hasMany to have changed exactly once'); + }); +}); + +test('fetch hasMany loads full relationship after a parent and child have been loaded', function(assert) { + assert.expect(4); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: true, inverse: 'tags' }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: true, inverse: 'person' }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.findHasMany = function(store, snapshot, url, relationship) { + assert.equal(relationship.key, 'tags', 'relationship should be tags'); + + return { + data: [ + { id: 1, type: 'tag', attributes: { name: 'first' } }, + { id: 2, type: 'tag', attributes: { name: 'second' } }, + { id: 3, type: 'tag', attributes: { name: 'third' } }, + ], + }; + }; + + env.adapter.findRecord = function(store, type, id, snapshot) { + if (type === Person) { + return { + data: { + id: 1, + type: 'person', + attributes: { name: 'Watson' }, + relationships: { + tags: { links: { related: 'person/1/tags' } }, + }, + }, + }; + } else if (type === Tag) { + return { + data: { + id: 2, + type: 'tag', + attributes: { name: 'second' }, + relationships: { + person: { + data: { id: 1, type: 'person' }, + }, + }, + }, + }; + } else { + assert.true(false, 'wrong type'); + } + }; + + return run(() => { + return store.findRecord('person', 1).then(person => { + assert.equal(get(person, 'name'), 'Watson', 'The person is now loaded'); + + // when I remove this findRecord the test passes + return store.findRecord('tag', 2).then(tag => { + assert.equal(get(tag, 'name'), 'second', 'The tag is now loaded'); + + return run(() => + person.get('tags').then(tags => { + assert.equal(get(tags, 'length'), 3, 'the tags are all loaded'); + }) + ); + }); + }); + }); +}); + +testInDebug('throws assertion if of not set with an array', function(assert) { + const Person = DS.Model.extend(); + const Tag = DS.Model.extend({ + people: DS.hasMany('person'), + }); + + let { store } = setupStore({ tag: Tag, person: Person }); + let tag = store.createRecord('tag'); + let person = store.createRecord('person'); + + run(() => { + assert.expectAssertion(() => { + tag.set('people', person); + }, /You must pass an array of records to set a hasMany relationship/); + }); +}); + +testInDebug('checks if passed array only contains instances of DS.Model', function(assert) { + const Person = DS.Model.extend(); + const Tag = DS.Model.extend({ + people: DS.hasMany('person'), + }); + + let env = setupStore({ tag: Tag, person: Person }); + + env.adapter.findRecord = function() { + return { + data: { + type: 'person', + id: 1, + }, + }; + }; + + let tag = env.store.createRecord('tag'); + let person = run(() => env.store.findRecord('person', 1)); + + run(() => { + assert.expectAssertion(() => { + tag.set('people', [person]); + }, /All elements of a hasMany relationship must be instances of DS.Model/); + }); +}); diff --git a/tests/unit/model/relationships/record-array-test.js b/tests/unit/model/relationships/record-array-test.js new file mode 100644 index 00000000000..e9711270821 --- /dev/null +++ b/tests/unit/model/relationships/record-array-test.js @@ -0,0 +1,109 @@ +import { A } from '@ember/array'; +import { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +module('unit/model/relationships - RecordArray'); + +test('updating the content of a RecordArray updates its content', function(assert) { + let Tag = DS.Model.extend({ + name: DS.attr('string'), + }); + + let env = setupStore({ tag: Tag }); + let store = env.store; + let tags; + let internalModels; + + run(() => { + internalModels = store._push({ + data: [ + { + type: 'tag', + id: '5', + attributes: { + name: 'friendly', + }, + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'smarmy', + }, + }, + { + type: 'tag', + id: '12', + attributes: { + name: 'oohlala', + }, + }, + ], + }); + tags = DS.RecordArray.create({ + content: A(internalModels.slice(0, 2)), + store: store, + modelName: 'tag', + }); + }); + + let tag = tags.objectAt(0); + assert.equal(get(tag, 'name'), 'friendly', `precond - we're working with the right tags`); + + run(() => set(tags, 'content', A(internalModels.slice(1, 3)))); + + tag = tags.objectAt(0); + assert.equal(get(tag, 'name'), 'smarmy', 'the lookup was updated'); +}); + +test('can create child record from a hasMany relationship', function(assert) { + assert.expect(3); + + const Tag = DS.Model.extend({ + name: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + tags: DS.hasMany('tag', { async: false }), + }); + + let env = setupStore({ tag: Tag, person: Person }); + let { store } = env; + + env.adapter.shouldBackgroundReloadRecord = () => false; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }); + }); + + return run(() => { + return store.findRecord('person', 1).then(person => { + person.get('tags').createRecord({ name: 'cool' }); + + assert.equal(get(person, 'name'), 'Tom Dale', 'precond - retrieves person record from store'); + assert.equal(get(person, 'tags.length'), 1, 'tag is added to the parent record'); + assert.equal( + get(person, 'tags') + .objectAt(0) + .get('name'), + 'cool', + 'tag values are passed along' + ); + }); + }); +}); diff --git a/tests/unit/model/rollback-attributes-test.js b/tests/unit/model/rollback-attributes-test.js new file mode 100644 index 00000000000..13aa1f365c1 --- /dev/null +++ b/tests/unit/model/rollback-attributes-test.js @@ -0,0 +1,570 @@ +import { isPresent } from '@ember/utils'; +import { addObserver } from '@ember/object/observers'; +import { Promise as EmberPromise, reject } from 'rsvp'; +import { run, later } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let env, store, Person; + +module('unit/model/rollbackAttributes - model.rollbackAttributes()', { + beforeEach() { + Person = DS.Model.extend({ + firstName: DS.attr(), + lastName: DS.attr(), + rolledBackCount: 0, + rolledBack() { + this.incrementProperty('rolledBackCount'); + }, + }); + Person.reopenClass({ + toString() { + return 'Person'; + }, + }); + + env = setupStore({ person: Person }); + store = env.store; + }, +}); + +test('changes to attributes can be rolled back', function(assert) { + let person; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + }, + }); + person = store.peekRecord('person', 1); + person.set('firstName', 'Thomas'); + return person; + }); + + assert.equal(person.get('firstName'), 'Thomas'); + assert.equal(person.get('rolledBackCount'), 0); + + run(() => person.rollbackAttributes()); + + assert.equal(person.get('firstName'), 'Tom'); + assert.equal(person.get('hasDirtyAttributes'), false); + assert.equal(person.get('rolledBackCount'), 1); +}); + +test('changes to unassigned attributes can be rolled back', function(assert) { + let person; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + lastName: 'Dale', + }, + }, + }); + person = store.peekRecord('person', 1); + person.set('firstName', 'Thomas'); + + return person; + }); + + assert.equal(person.get('firstName'), 'Thomas'); + assert.equal(person.get('rolledBackCount'), 0); + + run(() => person.rollbackAttributes()); + + assert.strictEqual(person.get('firstName'), undefined); + assert.equal(person.get('hasDirtyAttributes'), false); + assert.equal(person.get('rolledBackCount'), 1); +}); + +test('changes to attributes made after a record is in-flight only rolls back the local changes', function(assert) { + env.adapter.updateRecord = function(store, type, snapshot) { + // Make sure the save is async + return new EmberPromise(resolve => later(null, resolve, 15)); + }; + + let person = run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + }, + }); + + let person = store.peekRecord('person', 1); + person.set('firstName', 'Thomas'); + + return person; + }); + + return run(() => { + let saving = person.save(); + + assert.equal(person.get('firstName'), 'Thomas'); + + person.set('lastName', 'Dolly'); + + assert.equal(person.get('lastName'), 'Dolly'); + assert.equal(person.get('rolledBackCount'), 0); + + person.rollbackAttributes(); + + assert.equal(person.get('firstName'), 'Thomas'); + assert.equal(person.get('lastName'), 'Dale'); + assert.equal(person.get('isSaving'), true); + + return saving.then(() => { + assert.equal(person.get('rolledBackCount'), 1); + assert.equal(person.get('hasDirtyAttributes'), false, 'The person is now clean'); + }); + }); +}); + +test("a record's changes can be made if it fails to save", function(assert) { + env.adapter.updateRecord = function(store, type, snapshot) { + return reject(); + }; + + let person = run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + }, + }); + + let person = store.peekRecord('person', 1); + person.set('firstName', 'Thomas'); + + return person; + }); + + assert.deepEqual(person.changedAttributes().firstName, ['Tom', 'Thomas']); + + run(function() { + person.save().then(null, function() { + assert.equal(person.get('isError'), true); + assert.deepEqual(person.changedAttributes().firstName, ['Tom', 'Thomas']); + assert.equal(person.get('rolledBackCount'), 0); + + run(function() { + person.rollbackAttributes(); + }); + + assert.equal(person.get('firstName'), 'Tom'); + assert.equal(person.get('isError'), false); + assert.equal(Object.keys(person.changedAttributes()).length, 0); + assert.equal(person.get('rolledBackCount'), 1); + }); + }); +}); + +test(`a deleted record's attributes can be rollbacked if it fails to save, record arrays are updated accordingly`, function(assert) { + assert.expect(10); + env.adapter.deleteRecord = function(store, type, snapshot) { + return reject(); + }; + + let person, people; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Tom', + lastName: 'Dale', + }, + }, + }); + person = store.peekRecord('person', 1); + people = store.peekAll('person'); + }); + + run(() => person.deleteRecord()); + + assert.equal( + people.get('length'), + 1, + 'a deleted record appears in record array until it is saved' + ); + assert.equal( + people.objectAt(0), + person, + 'a deleted record appears in record array until it is saved' + ); + + return run(() => { + return person + .save() + .catch(() => { + assert.equal(person.get('isError'), true); + assert.equal(person.get('isDeleted'), true); + assert.equal(person.get('rolledBackCount'), 0); + + run(() => person.rollbackAttributes()); + + assert.equal(person.get('isDeleted'), false); + assert.equal(person.get('isError'), false); + assert.equal(person.get('hasDirtyAttributes'), false, 'must be not dirty'); + assert.equal(person.get('rolledBackCount'), 1); + }) + .then(() => { + assert.equal( + people.get('length'), + 1, + 'the underlying record array is updated accordingly in an asynchronous way' + ); + }); + }); +}); + +test(`new record's attributes can be rollbacked`, function(assert) { + let person = store.createRecord('person', { id: 1 }); + + assert.equal(person.get('isNew'), true, 'must be new'); + assert.equal(person.get('hasDirtyAttributes'), true, 'must be dirty'); + assert.equal(person.get('rolledBackCount'), 0); + + run(person, 'rollbackAttributes'); + + assert.equal(person.get('isNew'), false, 'must not be new'); + assert.equal(person.get('hasDirtyAttributes'), false, 'must not be dirty'); + assert.equal(person.get('isDeleted'), true, 'must be deleted'); + assert.equal(person.get('rolledBackCount'), 1); +}); + +test(`invalid new record's attributes can be rollbacked`, function(assert) { + let error = new DS.InvalidError([ + { + detail: 'is invalid', + source: { pointer: 'data/attributes/name' }, + }, + ]); + + let adapter = DS.RESTAdapter.extend({ + ajax(url, type, hash) { + return reject(error); + }, + }); + + env = setupStore({ person: Person, adapter: adapter }); + + let person = env.store.createRecord('person', { id: 1 }); + + assert.equal(person.get('isNew'), true, 'must be new'); + assert.equal(person.get('hasDirtyAttributes'), true, 'must be dirty'); + + return run(() => { + return person.save().catch(reason => { + assert.equal(error, reason); + assert.equal(person.get('isValid'), false); + + run(() => person.rollbackAttributes()); + + assert.equal(person.get('isNew'), false, 'must not be new'); + assert.equal(person.get('hasDirtyAttributes'), false, 'must not be dirty'); + assert.equal(person.get('isDeleted'), true, 'must be deleted'); + assert.equal(person.get('rolledBackCount'), 1); + }); + }); +}); + +test(`invalid record's attributes can be rollbacked after multiple failed calls - #3677`, function(assert) { + let adapter = DS.RESTAdapter.extend({ + ajax(url, type, hash) { + let error = new DS.InvalidError(); + return reject(error); + }, + }); + + env = setupStore({ person: Person, adapter: adapter }); + + let person; + run(() => { + person = env.store.push({ + data: { + type: 'person', + id: 1, + attributes: { + firstName: 'original name', + }, + }, + }); + + person.set('firstName', 'updated name'); + }); + + return run(() => { + assert.equal(person.get('firstName'), 'updated name', 'precondition: firstName is changed'); + + return person + .save() + .catch(() => { + assert.equal(person.get('hasDirtyAttributes'), true, 'has dirty attributes'); + assert.equal(person.get('firstName'), 'updated name', 'firstName is still changed'); + + return person.save(); + }) + .catch(() => { + run(() => person.rollbackAttributes()); + + assert.equal(person.get('hasDirtyAttributes'), false, 'has no dirty attributes'); + assert.equal( + person.get('firstName'), + 'original name', + 'after rollbackAttributes() firstName has the original value' + ); + assert.equal(person.get('rolledBackCount'), 1); + }); + }); +}); + +test(`deleted record's attributes can be rollbacked`, function(assert) { + let person, people; + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + }, + }); + person = store.peekRecord('person', 1); + people = store.peekAll('person'); + person.deleteRecord(); + }); + + assert.equal( + people.get('length'), + 1, + 'a deleted record appears in the record array until it is saved' + ); + assert.equal( + people.objectAt(0), + person, + 'a deleted record appears in the record array until it is saved' + ); + + assert.equal(person.get('isDeleted'), true, 'must be deleted'); + + run(() => person.rollbackAttributes()); + + assert.equal( + people.get('length'), + 1, + 'the rollbacked record should appear again in the record array' + ); + assert.equal(person.get('isDeleted'), false, 'must not be deleted'); + assert.equal(person.get('hasDirtyAttributes'), false, 'must not be dirty'); +}); + +test("invalid record's attributes can be rollbacked", function(assert) { + assert.expect(12); + const Dog = DS.Model.extend({ + name: DS.attr(), + rolledBackCount: 0, + rolledBack() { + this.incrementProperty('rolledBackCount'); + }, + }); + + let error = new DS.InvalidError([ + { + detail: 'is invalid', + source: { pointer: 'data/attributes/name' }, + }, + ]); + + let adapter = DS.RESTAdapter.extend({ + ajax(url, type, hash) { + return reject(error); + }, + }); + + env = setupStore({ dog: Dog, adapter: adapter }); + let dog; + run(() => { + env.store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'Pluto', + }, + }, + }); + dog = env.store.peekRecord('dog', 1); + dog.set('name', 'is a dwarf planet'); + }); + + return run(() => { + addObserver(dog, 'errors.name', function() { + assert.ok(true, 'errors.name did change'); + }); + + dog.get('errors').addArrayObserver( + {}, + { + willChange() { + assert.ok(true, 'errors will change'); + }, + didChange() { + assert.ok(true, 'errors did change'); + }, + } + ); + + return dog.save().catch(reason => { + assert.equal(reason, error); + + run(() => { + dog.rollbackAttributes(); + }); + + assert.equal(dog.get('hasDirtyAttributes'), false, 'must not be dirty'); + assert.equal(dog.get('name'), 'Pluto'); + assert.notOk(dog.get('errors.name')); + assert.ok(dog.get('isValid')); + assert.equal(dog.get('rolledBackCount'), 1); + }); + }); +}); + +test(`invalid record's attributes rolled back to correct state after set`, function(assert) { + assert.expect(14); + const Dog = DS.Model.extend({ + name: DS.attr(), + breed: DS.attr(), + }); + + let error = new DS.InvalidError([ + { + detail: 'is invalid', + source: { pointer: 'data/attributes/name' }, + }, + ]); + + let adapter = DS.RESTAdapter.extend({ + ajax(url, type, hash) { + return reject(error); + }, + }); + + env = setupStore({ dog: Dog, adapter: adapter }); + let dog; + run(() => { + env.store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'Pluto', + breed: 'Disney', + }, + }, + }); + dog = env.store.peekRecord('dog', 1); + dog.set('name', 'is a dwarf planet'); + dog.set('breed', 'planet'); + }); + + return run(() => { + addObserver(dog, 'errors.name', function() { + assert.ok(true, 'errors.name did change'); + }); + + return dog.save().catch(reason => { + assert.equal(reason, error); + assert.equal(dog.get('name'), 'is a dwarf planet'); + assert.equal(dog.get('breed'), 'planet'); + assert.ok(isPresent(dog.get('errors.name'))); + assert.equal(dog.get('errors.name.length'), 1); + + run(() => dog.set('name', 'Seymour Asses')); + + assert.equal(dog.get('name'), 'Seymour Asses'); + assert.equal(dog.get('breed'), 'planet'); + + run(() => dog.rollbackAttributes()); + + assert.equal(dog.get('name'), 'Pluto'); + assert.equal(dog.get('breed'), 'Disney'); + assert.equal(dog.get('hasDirtyAttributes'), false, 'must not be dirty'); + assert.notOk(dog.get('errors.name')); + assert.ok(dog.get('isValid')); + }); + }); +}); + +test(`when destroying a record setup the record state to invalid, the record's attributes can be rollbacked`, function(assert) { + const Dog = DS.Model.extend({ + name: DS.attr(), + }); + + let error = new DS.InvalidError([ + { + detail: 'is invalid', + source: { pointer: 'data/attributes/name' }, + }, + ]); + + let adapter = DS.RESTAdapter.extend({ + ajax(url, type, hash) { + return reject(error); + }, + }); + + env = setupStore({ dog: Dog, adapter: adapter }); + let dog = run(() => { + env.store.push({ + data: { + type: 'dog', + id: '1', + attributes: { + name: 'Pluto', + }, + }, + }); + return env.store.peekRecord('dog', 1); + }); + + return run(() => { + return dog.destroyRecord().catch(reason => { + assert.equal(reason, error); + + assert.equal(dog.get('isError'), false, 'must not be error'); + assert.equal(dog.get('isDeleted'), true, 'must be deleted'); + assert.equal(dog.get('isValid'), false, 'must not be valid'); + assert.ok(dog.get('errors.length') > 0, 'must have errors'); + + dog.rollbackAttributes(); + + assert.equal(dog.get('isError'), false, 'must not be error after `rollbackAttributes`'); + assert.equal(dog.get('isDeleted'), false, 'must not be deleted after `rollbackAttributes`'); + assert.equal(dog.get('isValid'), true, 'must be valid after `rollbackAttributes`'); + assert.ok(dog.get('errors.length') === 0, 'must not have errors'); + }); + }); +}); diff --git a/tests/unit/modules-test.js b/tests/unit/modules-test.js new file mode 100644 index 00000000000..9f92525aa3f --- /dev/null +++ b/tests/unit/modules-test.js @@ -0,0 +1,83 @@ +import { module, test } from 'qunit'; + +import Transform from 'ember-data/transform'; + +import Adapter from 'ember-data/adapter'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import RESTAdapter from 'ember-data/adapters/rest'; + +import Store from 'ember-data/store'; + +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +import { belongsTo, hasMany } from 'ember-data/relationships'; + +import Serializer from 'ember-data/serializer'; +import JSONSerializer from 'ember-data/serializers/json'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import RESTSerializer from 'ember-data/serializers/rest'; +import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin'; + +import { AdapterError, InvalidError, TimeoutError, AbortError } from 'ember-data/adapters/errors'; + +module('unit/modules - public modules'); + +test('ember-data/transform', function(assert) { + assert.ok(Transform); +}); + +test('ember-data/adapter', function(assert) { + assert.ok(Adapter); +}); + +test('ember-data/adapters/json-api', function(assert) { + assert.ok(JSONAPIAdapter); +}); + +test('ember-data/adapters/rest', function(assert) { + assert.ok(RESTAdapter); +}); + +test('ember-data/attr', function(assert) { + assert.ok(attr); +}); + +test('ember-data/relationships', function(assert) { + assert.ok(belongsTo); + assert.ok(hasMany); +}); + +test('ember-data/store', function(assert) { + assert.ok(Store); +}); + +test('ember-data/model', function(assert) { + assert.ok(Model); +}); + +test('ember-data/mixins/embedded-records', function(assert) { + assert.ok(EmbeddedRecordsMixin); +}); + +test('ember-data/serializer', function(assert) { + assert.ok(Serializer); +}); + +test('ember-data/serializers/json-api', function(assert) { + assert.ok(JSONAPISerializer); +}); + +test('ember-data/serializers/json', function(assert) { + assert.ok(JSONSerializer); +}); + +test('ember-data/serializers/rest', function(assert) { + assert.ok(RESTSerializer); +}); + +test('ember-data/adapters/errors', function(assert) { + assert.ok(AdapterError); + assert.ok(InvalidError); + assert.ok(TimeoutError); + assert.ok(AbortError); +}); diff --git a/tests/unit/private-test.js b/tests/unit/private-test.js new file mode 100644 index 00000000000..95b1b7e0431 --- /dev/null +++ b/tests/unit/private-test.js @@ -0,0 +1,12 @@ +import { module, test } from 'qunit'; +import { InternalModel, RootState } from 'ember-data/-private'; + +module('-private'); + +test('`InternalModel` is accessible via private import', function(assert) { + assert.ok(!!InternalModel); +}); + +test('`RootState` is accessible via private import', function(assert) { + assert.ok(!!RootState); +}); diff --git a/tests/unit/promise-proxies-test.js b/tests/unit/promise-proxies-test.js new file mode 100644 index 00000000000..26930f9b6bc --- /dev/null +++ b/tests/unit/promise-proxies-test.js @@ -0,0 +1,112 @@ +import { Promise as EmberPromise } from 'rsvp'; +import { A } from '@ember/array'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +module('PromiseManyArray'); + +test('.reload should NOT leak the internal promise, rather return another promiseArray', function(assert) { + assert.expect(2); + + let content = A(); + + content.reload = () => EmberPromise.resolve(content); + + let array = DS.PromiseManyArray.create({ + content, + }); + + let reloaded = array.reload(); + + assert.ok(reloaded instanceof DS.PromiseManyArray); + + return reloaded.then(value => assert.equal(content, value)); +}); + +test('.reload should be stable', function(assert) { + assert.expect(19); + + let content = A(); + + content.reload = () => EmberPromise.resolve(content); + let promise = EmberPromise.resolve(content); + + let array = DS.PromiseManyArray.create({ + promise, + }); + + assert.equal(array.get('isRejected'), false, 'should NOT be rejected'); + assert.equal(array.get('isPending'), true, 'should be pending'); + assert.equal(array.get('isSettled'), false, 'should NOT be settled'); + assert.equal(array.get('isFulfilled'), false, 'should NOT be fulfilled'); + + return array.then(() => { + assert.equal(array.get('isRejected'), false, 'should NOT be rejected'); + assert.equal(array.get('isPending'), false, 'should NOT be pending'); + assert.equal(array.get('isSettled'), true, 'should be settled'); + assert.equal(array.get('isFulfilled'), true, 'should be fulfilled'); + + let reloaded = array.reload(); + + assert.equal(array.get('isRejected'), false, 'should NOT be rejected'); + assert.equal(array.get('isPending'), true, 'should be pending'); + assert.equal(array.get('isSettled'), false, 'should NOT be settled'); + assert.equal(array.get('isFulfilled'), false, 'should NOT be fulfilled'); + + assert.ok(reloaded instanceof DS.PromiseManyArray); + assert.equal(reloaded, array); + + return reloaded.then(value => { + assert.equal(array.get('isRejected'), false, 'should NOT be rejected'); + assert.equal(array.get('isPending'), false, 'should NOT be pending'); + assert.equal(array.get('isSettled'), true, 'should be settled'); + assert.equal(array.get('isFulfilled'), true, 'should be fulfilled'); + + assert.equal(content, value); + }); + }); +}); + +test('.set to new promise should be like reload', function(assert) { + assert.expect(18); + + let content = A([1, 2, 3]); + + let promise = EmberPromise.resolve(content); + + let array = DS.PromiseManyArray.create({ + promise, + }); + + assert.equal(array.get('isRejected'), false, 'should NOT be rejected'); + assert.equal(array.get('isPending'), true, 'should be pending'); + assert.equal(array.get('isSettled'), false, 'should NOT be settled'); + assert.equal(array.get('isFulfilled'), false, 'should NOT be fulfilled'); + + return array.then(() => { + assert.equal(array.get('isRejected'), false, 'should NOT be rejected'); + assert.equal(array.get('isPending'), false, 'should NOT be pending'); + assert.equal(array.get('isSettled'), true, 'should be settled'); + assert.equal(array.get('isFulfilled'), true, 'should be fulfilled'); + + array.set('promise', EmberPromise.resolve(content)); + + assert.equal(array.get('isRejected'), false, 'should NOT be rejected'); + assert.equal(array.get('isPending'), true, 'should be pending'); + assert.equal(array.get('isSettled'), false, 'should NOT be settled'); + assert.equal(array.get('isFulfilled'), false, 'should NOT be fulfilled'); + + assert.ok(array instanceof DS.PromiseManyArray); + + return array.then(value => { + assert.equal(array.get('isRejected'), false, 'should NOT be rejected'); + assert.equal(array.get('isPending'), false, 'should NOT be pending'); + assert.equal(array.get('isSettled'), true, 'should be settled'); + assert.equal(array.get('isFulfilled'), true, 'should be fulfilled'); + + assert.equal(content, value); + }); + }); +}); diff --git a/tests/unit/record-arrays/adapter-populated-record-array-test.js b/tests/unit/record-arrays/adapter-populated-record-array-test.js new file mode 100644 index 00000000000..a9db12d8068 --- /dev/null +++ b/tests/unit/record-arrays/adapter-populated-record-array-test.js @@ -0,0 +1,280 @@ +import { A } from '@ember/array'; +import RSVP from 'rsvp'; +import { run } from '@ember/runloop'; +import DS from 'ember-data'; +import { module, test } from 'qunit'; +const { AdapterPopulatedRecordArray, RecordArrayManager } = DS; + +module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedRecordArray'); + +function internalModelFor(record) { + let _internalModel = { + get id() { + return record.id; + }, + getRecord() { + return record; + }, + }; + + record._internalModel = _internalModel; + return _internalModel; +} + +test('default initial state', function(assert) { + let recordArray = AdapterPopulatedRecordArray.create({ modelName: 'recordType' }); + + assert.equal(recordArray.get('isLoaded'), false, 'expected isLoaded to be false'); + assert.equal(recordArray.get('modelName'), 'recordType'); + assert.deepEqual(recordArray.get('content'), []); + assert.strictEqual(recordArray.get('query'), null); + assert.strictEqual(recordArray.get('store'), null); + assert.strictEqual(recordArray.get('links'), null); +}); + +test('custom initial state', function(assert) { + let content = A([]); + let store = {}; + let recordArray = AdapterPopulatedRecordArray.create({ + modelName: 'apple', + isLoaded: true, + isUpdating: true, + content, + store, + query: 'some-query', + links: 'foo', + }); + assert.equal(recordArray.get('isLoaded'), true); + assert.equal(recordArray.get('isUpdating'), false); + assert.equal(recordArray.get('modelName'), 'apple'); + assert.equal(recordArray.get('content'), content); + assert.equal(recordArray.get('store'), store); + assert.equal(recordArray.get('query'), 'some-query'); + assert.strictEqual(recordArray.get('links'), 'foo'); +}); + +test('#replace() throws error', function(assert) { + let recordArray = AdapterPopulatedRecordArray.create({ modelName: 'recordType' }); + + assert.throws( + () => { + recordArray.replace(); + }, + Error('The result of a server query (on recordType) is immutable.'), + 'throws error' + ); +}); + +test('#update uses _update enabling query specific behavior', function(assert) { + let queryCalled = 0; + let deferred = RSVP.defer(); + + const store = { + _query(modelName, query, array) { + queryCalled++; + assert.equal(modelName, 'recordType'); + assert.equal(query, 'some-query'); + assert.equal(array, recordArray); + + return deferred.promise; + }, + }; + + let recordArray = AdapterPopulatedRecordArray.create({ + modelName: 'recordType', + store, + query: 'some-query', + }); + + assert.equal(recordArray.get('isUpdating'), false, 'should not yet be updating'); + + assert.equal(queryCalled, 0); + + let updateResult = recordArray.update(); + + assert.equal(queryCalled, 1); + + deferred.resolve('return value'); + + assert.equal(recordArray.get('isUpdating'), true, 'should be updating'); + + return updateResult.then(result => { + assert.equal(result, 'return value'); + assert.equal(recordArray.get('isUpdating'), false, 'should no longer be updating'); + }); +}); + +// TODO: is this method required, i suspect store._query should be refactor so this is not needed +test('#_setInternalModels', function(assert) { + let didAddRecord = 0; + function add(array) { + didAddRecord++; + assert.equal(array, recordArray); + } + + let recordArray = AdapterPopulatedRecordArray.create({ + query: 'some-query', + manager: new RecordArrayManager({}), + }); + + let model1 = internalModelFor({ id: 1 }); + let model2 = internalModelFor({ id: 2 }); + + model1._recordArrays = { add }; + model2._recordArrays = { add }; + + assert.equal(didAddRecord, 0, 'no records should have been added yet'); + + let didLoad = 0; + recordArray.on('didLoad', function() { + didLoad++; + }); + + let links = { foo: 1 }; + let meta = { bar: 2 }; + + run(() => { + assert.equal( + recordArray._setInternalModels([model1, model2], { + links, + meta, + }), + undefined, + '_setInternalModels should have no return value' + ); + + assert.equal(didAddRecord, 2, 'two records should have been added'); + + assert.deepEqual( + recordArray.toArray(), + [model1, model2].map(x => x.getRecord()), + 'should now contain the loaded records' + ); + + assert.equal(didLoad, 0, 'didLoad event should not have fired'); + assert.equal(recordArray.get('links').foo, 1); + assert.equal(recordArray.get('meta').bar, 2); + }); + assert.equal(didLoad, 1, 'didLoad event should have fired once'); +}); + +test('change events when receiving a new query payload', function(assert) { + assert.expect(37); + + let arrayDidChange = 0; + let contentDidChange = 0; + let didAddRecord = 0; + + function add(array) { + didAddRecord++; + assert.equal(array, recordArray); + } + + function del(array) { + assert.equal(array, recordArray); + } + + let recordArray = AdapterPopulatedRecordArray.create({ + query: 'some-query', + manager: new RecordArrayManager({}), + }); + + let model1 = internalModelFor({ id: '1', name: 'Scumbag Dale' }); + let model2 = internalModelFor({ id: '2', name: 'Scumbag Katz' }); + + model1._recordArrays = { add, delete: del }; + model2._recordArrays = { add, delete: del }; + + run(() => { + recordArray._setInternalModels([model1, model2], {}); + }); + + assert.equal(didAddRecord, 2, 'expected 2 didAddRecords'); + assert.deepEqual(recordArray.map(x => x.name), ['Scumbag Dale', 'Scumbag Katz']); + + assert.equal(arrayDidChange, 0, 'array should not yet have emitted a change event'); + assert.equal(contentDidChange, 0, 'recordArray.content should not have changed'); + + recordArray.addObserver('content', function() { + contentDidChange++; + }); + + recordArray.one('@array:change', function(array, startIdx, removeAmt, addAmt) { + arrayDidChange++; + + // first time invoked + assert.equal(array, recordArray, 'should be same record array as above'); + assert.equal(startIdx, 0, 'expected startIdx'); + assert.equal(removeAmt, 2, 'expcted removeAmt'); + assert.equal(addAmt, 2, 'expected addAmt'); + }); + + assert.equal(recordArray.get('isLoaded'), true, 'should be considered loaded'); + assert.equal(recordArray.get('isUpdating'), false, 'should not yet be updating'); + + assert.equal(arrayDidChange, 0); + assert.equal(contentDidChange, 0, 'recordArray.content should not have changed'); + + arrayDidChange = 0; + contentDidChange = 0; + didAddRecord = 0; + + let model3 = internalModelFor({ id: '3', name: 'Scumbag Penner' }); + let model4 = internalModelFor({ id: '4', name: 'Scumbag Hamilton' }); + + model3._recordArrays = { add, delete: del }; + model4._recordArrays = { add, delete: del }; + + run(() => { + // re-query + recordArray._setInternalModels([model3, model4], {}); + }); + + assert.equal(didAddRecord, 2, 'expected 2 didAddRecords'); + assert.equal(recordArray.get('isLoaded'), true, 'should be considered loaded'); + assert.equal(recordArray.get('isUpdating'), false, 'should no longer be updating'); + + assert.equal(arrayDidChange, 1, 'record array should have omitted ONE change event'); + assert.equal(contentDidChange, 0, 'recordArray.content should not have changed'); + + assert.deepEqual(recordArray.map(x => x.name), ['Scumbag Penner', 'Scumbag Hamilton']); + + arrayDidChange = 0; // reset change event counter + contentDidChange = 0; // reset change event counter + didAddRecord = 0; + + recordArray.one('@array:change', function(array, startIdx, removeAmt, addAmt) { + arrayDidChange++; + + // first time invoked + assert.equal(array, recordArray, 'should be same recordArray as above'); + assert.equal(startIdx, 0, 'expected startIdx'); + assert.equal(removeAmt, 2, 'expcted removeAmt'); + assert.equal(addAmt, 1, 'expected addAmt'); + }); + + // re-query + assert.equal(recordArray.get('isLoaded'), true, 'should be considered loaded'); + assert.equal(recordArray.get('isUpdating'), false, 'should not yet be updating'); + + assert.equal(arrayDidChange, 0, 'record array should not yet have omitted a change event'); + assert.equal(contentDidChange, 0, 'recordArray.content should not have changed'); + + let model5 = internalModelFor({ id: '3', name: 'Scumbag Penner' }); + + model5._recordArrays = { add, delete: del }; + + run(() => { + recordArray._setInternalModels([model5], {}); + }); + + assert.equal(didAddRecord, 1, 'expected 0 didAddRecord'); + + assert.equal(recordArray.get('isLoaded'), true, 'should be considered loaded'); + assert.equal(recordArray.get('isUpdating'), false, 'should not longer be updating'); + + assert.equal(arrayDidChange, 1, 'record array should have emitted one change event'); + assert.equal(contentDidChange, 0, 'recordArray.content should not have changed'); + + assert.deepEqual(recordArray.map(x => x.name), ['Scumbag Penner']); +}); diff --git a/tests/unit/record-arrays/record-array-test.js b/tests/unit/record-arrays/record-array-test.js new file mode 100644 index 00000000000..4a26f37b6ab --- /dev/null +++ b/tests/unit/record-arrays/record-array-test.js @@ -0,0 +1,472 @@ +import { A } from '@ember/array'; +import { get } from '@ember/object'; +import RSVP from 'rsvp'; +import { run } from '@ember/runloop'; +import DS from 'ember-data'; +import { module, test } from 'qunit'; + +const { RecordArray } = DS; + +module('unit/record-arrays/record-array - DS.RecordArray'); + +test('default initial state', function(assert) { + let recordArray = RecordArray.create({ modelName: 'recordType' }); + + assert.equal(get(recordArray, 'isLoaded'), false); + assert.equal(get(recordArray, 'isUpdating'), false); + assert.equal(get(recordArray, 'modelName'), 'recordType'); + assert.strictEqual(get(recordArray, 'content'), null); + assert.strictEqual(get(recordArray, 'store'), null); +}); + +test('custom initial state', function(assert) { + let content = A(); + let store = {}; + let recordArray = RecordArray.create({ + modelName: 'apple', + isLoaded: true, + isUpdating: true, + content, + store, + }); + assert.equal(get(recordArray, 'isLoaded'), true); + assert.equal(get(recordArray, 'isUpdating'), false); // cannot set as default value: + assert.equal(get(recordArray, 'modelName'), 'apple'); + assert.equal(get(recordArray, 'content'), content); + assert.equal(get(recordArray, 'store'), store); +}); + +test('#replace() throws error', function(assert) { + let recordArray = RecordArray.create({ modelName: 'recordType' }); + + assert.throws( + () => { + recordArray.replace(); + }, + Error( + 'The result of a server query (for all recordType types) is immutable. To modify contents, use toArray()' + ), + 'throws error' + ); +}); + +test('#objectAtContent', function(assert) { + let content = A([ + { + getRecord() { + return 'foo'; + }, + }, + { + getRecord() { + return 'bar'; + }, + }, + { + getRecord() { + return 'baz'; + }, + }, + ]); + + let recordArray = RecordArray.create({ + modelName: 'recordType', + content, + }); + + assert.equal(get(recordArray, 'length'), 3); + assert.equal(recordArray.objectAtContent(0), 'foo'); + assert.equal(recordArray.objectAtContent(1), 'bar'); + assert.equal(recordArray.objectAtContent(2), 'baz'); + assert.strictEqual(recordArray.objectAtContent(3), undefined); +}); + +test('#update', function(assert) { + let findAllCalled = 0; + let deferred = RSVP.defer(); + + const store = { + findAll(modelName, options) { + findAllCalled++; + assert.equal(modelName, 'recordType'); + assert.equal(options.reload, true, 'options should contain reload: true'); + return deferred.promise; + }, + }; + + let recordArray = RecordArray.create({ + modelName: 'recordType', + store, + }); + + assert.equal(get(recordArray, 'isUpdating'), false, 'should not yet be updating'); + + assert.equal(findAllCalled, 0); + + let updateResult = recordArray.update(); + + assert.equal(findAllCalled, 1); + + deferred.resolve('return value'); + + assert.equal(get(recordArray, 'isUpdating'), true, 'should be updating'); + + return updateResult.then(result => { + assert.equal(result, 'return value'); + assert.equal(get(recordArray, 'isUpdating'), false, 'should no longer be updating'); + }); +}); + +test('#update while updating', function(assert) { + let findAllCalled = 0; + let deferred = RSVP.defer(); + const store = { + findAll(modelName, options) { + findAllCalled++; + return deferred.promise; + }, + }; + + let recordArray = RecordArray.create({ + modelName: { modelName: 'recordType' }, + store, + }); + + assert.equal(get(recordArray, 'isUpdating'), false, 'should not be updating'); + assert.equal(findAllCalled, 0); + + let updateResult1 = recordArray.update(); + + assert.equal(findAllCalled, 1); + + let updateResult2 = recordArray.update(); + + assert.equal(findAllCalled, 1); + + assert.equal(updateResult1, updateResult2); + + deferred.resolve('return value'); + + assert.equal(get(recordArray, 'isUpdating'), true, 'should be updating'); + + return updateResult1.then(result => { + assert.equal(result, 'return value'); + assert.equal(get(recordArray, 'isUpdating'), false, 'should no longer be updating'); + }); +}); + +test('#_pushInternalModels', function(assert) { + let content = A(); + let recordArray = RecordArray.create({ + content, + }); + + let model1 = { + id: 1, + getRecord() { + return 'model-1'; + }, + }; + let model2 = { + id: 2, + getRecord() { + return 'model-2'; + }, + }; + let model3 = { + id: 3, + getRecord() { + return 'model-3'; + }, + }; + + assert.equal( + recordArray._pushInternalModels([model1]), + undefined, + '_pushInternalModels has no return value' + ); + assert.deepEqual(content, [model1], 'now contains model1'); + + recordArray._pushInternalModels([model1]); + assert.deepEqual( + content, + [model1, model1], + 'allows duplicates, because record-array-manager via internalModel._recordArrays ensures no duplicates, this layer should not double check' + ); + + recordArray._removeInternalModels([model1]); + recordArray._pushInternalModels([model1]); + + // can add multiple models at once + recordArray._pushInternalModels([model2, model3]); + assert.deepEqual(content, [model1, model2, model3], 'now contains model1, model2, model3'); +}); + +test('#_removeInternalModels', function(assert) { + let content = A(); + let recordArray = RecordArray.create({ + content, + }); + + let model1 = { + id: 1, + getRecord() { + return 'model-1'; + }, + }; + let model2 = { + id: 2, + getRecord() { + return 'model-2'; + }, + }; + let model3 = { + id: 3, + getRecord() { + return 'model-3'; + }, + }; + + assert.equal(content.length, 0); + assert.equal( + recordArray._removeInternalModels([model1]), + undefined, + '_removeInternalModels has no return value' + ); + assert.deepEqual(content, [], 'now contains no models'); + + recordArray._pushInternalModels([model1, model2]); + + assert.deepEqual(content, [model1, model2], 'now contains model1, model2,'); + assert.equal( + recordArray._removeInternalModels([model1]), + undefined, + '_removeInternalModels has no return value' + ); + assert.deepEqual(content, [model2], 'now only contains model2'); + assert.equal( + recordArray._removeInternalModels([model2]), + undefined, + '_removeInternalModels has no return value' + ); + assert.deepEqual(content, [], 'now contains no models'); + + recordArray._pushInternalModels([model1, model2, model3]); + + assert.equal( + recordArray._removeInternalModels([model1, model3]), + undefined, + '_removeInternalModels has no return value' + ); + + assert.deepEqual(content, [model2], 'now contains model2'); + assert.equal( + recordArray._removeInternalModels([model2]), + undefined, + '_removeInternalModels has no return value' + ); + assert.deepEqual(content, [], 'now contains no models'); +}); + +class FakeInternalModel { + constructor(record) { + this._record = record; + this.__recordArrays = null; + } + + get _recordArrays() { + return this.__recordArrays; + } + + getRecord() { + return this._record; + } + + createSnapshot() { + return this._record; + } +} + +function internalModelFor(record) { + return new FakeInternalModel(record); +} + +test('#save', function(assert) { + let model1 = { + save() { + model1Saved++; + return this; + }, + }; + let model2 = { + save() { + model2Saved++; + return this; + }, + }; + let content = A([internalModelFor(model1), internalModelFor(model2)]); + + let recordArray = RecordArray.create({ + content, + }); + + let model1Saved = 0; + let model2Saved = 0; + + assert.equal(model1Saved, 0); + assert.equal(model2Saved, 0); + + let result = recordArray.save(); + + assert.equal(model1Saved, 1); + assert.equal(model2Saved, 1); + + return result.then(result => { + assert.equal(result, result, 'save promise should fulfill with the original recordArray'); + }); +}); + +test('#destroy', function(assert) { + let didUnregisterRecordArray = 0; + let didDissociatieFromOwnRecords = 0; + let model1 = {}; + let internalModel1 = internalModelFor(model1); + + // TODO: this will be removed once we fix ownership related memory leaks. + internalModel1.__recordArrays = { + delete(array) { + didDissociatieFromOwnRecords++; + assert.equal(array, recordArray); + }, + }; + // end TODO: + + let recordArray = RecordArray.create({ + content: A([internalModel1]), + manager: { + unregisterRecordArray(_recordArray) { + didUnregisterRecordArray++; + assert.equal(recordArray, _recordArray); + }, + }, + }); + + assert.equal(get(recordArray, 'isDestroyed'), false, 'should not be destroyed'); + assert.equal(get(recordArray, 'isDestroying'), false, 'should not be destroying'); + + run(() => { + assert.equal(get(recordArray, 'length'), 1, 'before destroy, length should be 1'); + assert.equal( + didUnregisterRecordArray, + 0, + 'before destroy, we should not yet have unregisterd the record array' + ); + assert.equal( + didDissociatieFromOwnRecords, + 0, + 'before destroy, we should not yet have dissociated from own record array' + ); + recordArray.destroy(); + }); + + assert.equal( + didUnregisterRecordArray, + 1, + 'after destroy we should have unregistered the record array' + ); + assert.equal( + didDissociatieFromOwnRecords, + 1, + 'after destroy, we should have dissociated from own record array' + ); + recordArray.destroy(); + + assert.strictEqual(get(recordArray, 'content'), null); + assert.equal(get(recordArray, 'length'), 0, 'after destroy we should have no length'); + assert.equal(get(recordArray, 'isDestroyed'), true, 'should be destroyed'); +}); + +test('#_createSnapshot', function(assert) { + let model1 = { + id: 1, + }; + + let model2 = { + id: 2, + }; + + let content = A([internalModelFor(model1), internalModelFor(model2)]); + + let recordArray = RecordArray.create({ + content, + }); + + let snapshot = recordArray._createSnapshot(); + let snapshots = snapshot.snapshots(); + + assert.deepEqual( + snapshots, + [model1, model2], + 'record array snapshot should contain the internalModel.createSnapshot result' + ); +}); + +test('#destroy', function(assert) { + let didUnregisterRecordArray = 0; + let didDissociatieFromOwnRecords = 0; + let model1 = {}; + let internalModel1 = internalModelFor(model1); + + // TODO: this will be removed once we fix ownership related memory leaks. + internalModel1.__recordArrays = { + delete(array) { + didDissociatieFromOwnRecords++; + assert.equal(array, recordArray); + }, + }; + // end TODO: + + let recordArray = RecordArray.create({ + content: A([internalModel1]), + manager: { + unregisterRecordArray(_recordArray) { + didUnregisterRecordArray++; + assert.equal(recordArray, _recordArray); + }, + }, + }); + + assert.equal(get(recordArray, 'isDestroyed'), false, 'should not be destroyed'); + assert.equal(get(recordArray, 'isDestroying'), false, 'should not be destroying'); + + run(() => { + assert.equal(get(recordArray, 'length'), 1, 'before destroy, length should be 1'); + assert.equal( + didUnregisterRecordArray, + 0, + 'before destroy, we should not yet have unregisterd the record array' + ); + assert.equal( + didDissociatieFromOwnRecords, + 0, + 'before destroy, we should not yet have dissociated from own record array' + ); + recordArray.destroy(); + }); + + assert.equal( + didUnregisterRecordArray, + 1, + 'after destroy we should have unregistered the record array' + ); + assert.equal( + didDissociatieFromOwnRecords, + 1, + 'after destroy, we should have dissociated from own record array' + ); + recordArray.destroy(); + + assert.strictEqual(get(recordArray, 'content'), null); + assert.equal(get(recordArray, 'length'), 0, 'after destroy we should have no length'); + assert.equal(get(recordArray, 'isDestroyed'), true, 'should be destroyed'); +}); diff --git a/tests/unit/states-test.js b/tests/unit/states-test.js new file mode 100644 index 00000000000..dd01674ee90 --- /dev/null +++ b/tests/unit/states-test.js @@ -0,0 +1,101 @@ +import { get } from '@ember/object'; +import QUnit, { module, test } from 'qunit'; +import DS from 'ember-data'; + +const { assert } = QUnit; + +let rootState, stateName; + +module('unit/states - Flags for record states', { + beforeEach() { + rootState = DS.RootState; + }, +}); + +assert.flagIsTrue = function flagIsTrue(flag) { + this.equal( + get(rootState, stateName + '.' + flag), + true, + stateName + '.' + flag + ' should be true' + ); +}; + +assert.flagIsFalse = function flagIsFalse(flag) { + this.equal( + get(rootState, stateName + '.' + flag), + false, + stateName + '.' + flag + ' should be false' + ); +}; + +test('the empty state', function(assert) { + stateName = 'empty'; + assert.flagIsFalse('isLoading'); + assert.flagIsFalse('isLoaded'); + assert.flagIsFalse('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsFalse('isDeleted'); +}); + +test('the loading state', function(assert) { + stateName = 'loading'; + assert.flagIsTrue('isLoading'); + assert.flagIsFalse('isLoaded'); + assert.flagIsFalse('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsFalse('isDeleted'); +}); + +test('the loaded state', function(assert) { + stateName = 'loaded'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsFalse('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsFalse('isDeleted'); +}); + +test('the updated state', function(assert) { + stateName = 'loaded.updated'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsTrue('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsFalse('isDeleted'); +}); + +test('the saving state', function(assert) { + stateName = 'loaded.updated.inFlight'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsTrue('isDirty'); + assert.flagIsTrue('isSaving'); + assert.flagIsFalse('isDeleted'); +}); + +test('the deleted state', function(assert) { + stateName = 'deleted'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsTrue('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsTrue('isDeleted'); +}); + +test('the deleted.saving state', function(assert) { + stateName = 'deleted.inFlight'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsTrue('isDirty'); + assert.flagIsTrue('isSaving'); + assert.flagIsTrue('isDeleted'); +}); + +test('the deleted.saved state', function(assert) { + stateName = 'deleted.saved'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsFalse('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsTrue('isDeleted'); +}); diff --git a/tests/unit/store/adapter-interop-test.js b/tests/unit/store/adapter-interop-test.js new file mode 100644 index 00000000000..5e753025617 --- /dev/null +++ b/tests/unit/store/adapter-interop-test.js @@ -0,0 +1,1401 @@ +import { A } from '@ember/array'; +import { resolve, all, Promise as EmberPromise } from 'rsvp'; +import { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let TestAdapter, store; + +module('unit/store/adapter-interop - DS.Store working with a DS.Adapter', { + beforeEach() { + TestAdapter = DS.Adapter.extend(); + }, + + afterEach() { + run(() => { + if (store) { + store.destroy(); + } + }); + }, +}); + +test('Adapter can be set as a factory', function(assert) { + store = createStore({ adapter: TestAdapter }); + + assert.ok(store.get('defaultAdapter') instanceof TestAdapter); +}); + +test('Adapter can be set as a name', function(assert) { + store = createStore({ adapter: '-rest' }); + + assert.ok(store.get('defaultAdapter') instanceof DS.RESTAdapter); +}); + +testInDebug('Adapter can not be set as an instance', function(assert) { + assert.expect(1); + + store = DS.Store.create({ + adapter: DS.Adapter.create(), + }); + assert.expectAssertion(() => store.get('defaultAdapter')); +}); + +test('Calling Store#find invokes its adapter#find', function(assert) { + assert.expect(5); + + let currentStore; + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + assert.ok(true, 'Adapter#find was called'); + assert.equal(store, currentStore, 'Adapter#find was called with the right store'); + assert.equal( + type, + store.modelFor('test'), + 'Adapter#find was called with the type passed into Store#find' + ); + assert.equal(id, 1, 'Adapter#find was called with the id passed into Store#find'); + assert.equal( + snapshot.id, + '1', + 'Adapter#find was called with the record created from Store#find' + ); + + return resolve({ + data: { + id: 1, + type: 'test', + }, + }); + }, + }); + + const Type = DS.Model.extend(); + + currentStore = createStore({ + adapter: Adapter, + test: Type, + }); + + return run(() => currentStore.findRecord('test', 1)); +}); + +test('Calling Store#findRecord multiple times coalesces the calls into a adapter#findMany call', function(assert) { + assert.expect(2); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + assert.ok(false, 'Adapter#findRecord was not called'); + }, + findMany(store, type, ids, snapshots) { + assert.ok(true, 'Adapter#findMany was called'); + assert.deepEqual(ids, ['1', '2'], 'Correct ids were passed in to findMany'); + return resolve({ data: [{ id: 1, type: 'test' }, { id: 2, type: 'test' }] }); + }, + coalesceFindRequests: true, + }); + + const Type = DS.Model.extend(); + let store = createStore({ + adapter: Adapter, + test: Type, + }); + + return run(() => { + return all([store.findRecord('test', 1), store.findRecord('test', 2)]); + }); +}); + +test('Returning a promise from `findRecord` asynchronously loads data', function(assert) { + assert.expect(1); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + return resolve({ data: { id: 1, type: 'test', attributes: { name: 'Scumbag Dale' } } }); + }, + }); + + const Type = DS.Model.extend({ + name: DS.attr('string'), + }); + + let store = createStore({ + adapter: Adapter, + test: Type, + }); + + return run(() => { + return store.findRecord('test', 1).then(object => { + assert.strictEqual(get(object, 'name'), 'Scumbag Dale', 'the data was pushed'); + }); + }); +}); + +test('IDs provided as numbers are coerced to strings', function(assert) { + assert.expect(5); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + assert.equal(typeof id, 'string', 'id has been normalized to a string'); + return resolve({ data: { id, type: 'test', attributes: { name: 'Scumbag Sylvain' } } }); + }, + }); + + const Type = DS.Model.extend({ + name: DS.attr('string'), + }); + + let store = createStore({ + adapter: Adapter, + test: Type, + }); + + return run(() => { + return store + .findRecord('test', 1) + .then(object => { + assert.equal(typeof object.get('id'), 'string', 'id was coerced to a string'); + run(() => { + store.push({ + data: { + type: 'test', + id: '2', + attributes: { + name: 'Scumbag Sam Saffron', + }, + }, + }); + }); + + return store.findRecord('test', 2); + }) + .then(object => { + assert.ok(object, 'object was found'); + assert.equal( + typeof object.get('id'), + 'string', + 'id is a string despite being supplied and searched for as a number' + ); + }); + }); +}); + +test('can load data for the same record if it is not dirty', function(assert) { + assert.expect(3); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + let store = createStore({ + person: Person, + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord() { + return false; + }, + }), + }); + + return run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }); + + return store.findRecord('person', 1).then(tom => { + assert.equal(get(tom, 'hasDirtyAttributes'), false, 'precond - record is not dirty'); + assert.equal(get(tom, 'name'), 'Tom Dale', 'returns the correct name'); + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Captain Underpants', + }, + }, + }); + assert.equal(get(tom, 'name'), 'Captain Underpants', 'updated record with new date'); + }); + }); +}); + +test('loadMany takes an optional Object and passes it on to the Adapter', function(assert) { + assert.expect(2); + + let passedQuery = { page: 1 }; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Adapter = TestAdapter.extend({ + query(store, type, query) { + assert.equal(type, store.modelFor('person'), 'The type was Person'); + assert.equal(query, passedQuery, 'The query was passed in'); + return resolve({ data: [] }); + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + + run(() => store.query('person', passedQuery)); +}); + +test('Find with query calls the correct normalizeResponse', function(assert) { + let passedQuery = { page: 1 }; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const Adapter = TestAdapter.extend({ + query(store, type, query) { + return resolve([]); + }, + }); + + let callCount = 0; + + const ApplicationSerializer = DS.JSONSerializer.extend({ + normalizeQueryResponse() { + callCount++; + return this._super(...arguments); + }, + }); + + let env = setupStore({ + adapter: Adapter, + person: Person, + }); + + let { store } = env; + + env.owner.register('serializer:application', ApplicationSerializer); + + run(() => store.query('person', passedQuery)); + assert.equal(callCount, 1, 'normalizeQueryResponse was called'); +}); + +test('peekAll(type) returns a record array of all records of a specific type', function(assert) { + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + let store = createStore({ + person: Person, + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + }, + }); + }); + + let results = store.peekAll('person'); + + assert.equal(get(results, 'length'), 1, 'record array should have the original object'); + assert.equal(get(results.objectAt(0), 'name'), 'Tom Dale', 'record has the correct information'); + + run(() => { + store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'Yehuda Katz', + }, + }, + }); + }); + + assert.equal(get(results, 'length'), 2, 'record array should have the new object'); + assert.equal( + get(results.objectAt(1), 'name'), + 'Yehuda Katz', + 'record has the correct information' + ); + + assert.strictEqual( + results, + store.peekAll('person'), + 'subsequent calls to peekAll return the same recordArray)' + ); +}); + +test('a new record of a particular type is created via store.createRecord(type)', function(assert) { + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + let store = createStore({ + person: Person, + }); + + let person = store.createRecord('person'); + + assert.equal(get(person, 'isLoaded'), true, 'A newly created record is loaded'); + assert.equal(get(person, 'isNew'), true, 'A newly created record is new'); + assert.equal(get(person, 'hasDirtyAttributes'), true, 'A newly created record is dirty'); + + run(() => set(person, 'name', 'Braaahm Dale')); + + assert.equal( + get(person, 'name'), + 'Braaahm Dale', + 'Even if no hash is supplied, `set` still worked' + ); +}); + +testInDebug( + "a new record with a specific id can't be created if this id is already used in the store", + function(assert) { + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + Person.reopenClass({ + toString() { + return 'Person'; + }, + }); + + let store = createStore({ + person: Person, + }); + + store.createRecord('person', { id: 5 }); + + assert.expectAssertion(() => { + store.createRecord('person', { id: 5 }); + }, /The id 5 has already been used with another record for modelClass 'person'/); + } +); + +test('an initial data hash can be provided via store.createRecord(type, hash)', function(assert) { + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + let store = createStore({ + person: Person, + }); + + let person = store.createRecord('person', { name: 'Brohuda Katz' }); + + assert.equal(get(person, 'isLoaded'), true, 'A newly created record is loaded'); + assert.equal(get(person, 'isNew'), true, 'A newly created record is new'); + assert.equal(get(person, 'hasDirtyAttributes'), true, 'A newly created record is dirty'); + + assert.equal(get(person, 'name'), 'Brohuda Katz', 'The initial data hash is provided'); +}); + +test('if an id is supplied in the initial data hash, it can be looked up using `store.find`', function(assert) { + assert.expect(1); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + let store = createStore({ + person: Person, + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false, + }), + }); + + return run(() => { + let person = store.createRecord('person', { id: 1, name: 'Brohuda Katz' }); + + return store.findRecord('person', 1).then(again => { + assert.strictEqual(person, again, 'the store returns the loaded object'); + }); + }); +}); + +test('initial values of attributes can be passed in as the third argument to find', function(assert) { + assert.expect(1); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + assert.equal(snapshot.attr('name'), 'Test', 'Preloaded attribtue set'); + return { data: { id: '1', type: 'test', attributes: { name: 'Test' } } }; + }, + }); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + let store = createStore({ + adapter: Adapter, + test: Person, + }); + + return run(() => store.findRecord('test', 1, { preload: { name: 'Test' } })); +}); + +test('initial values of belongsTo can be passed in as the third argument to find as records', function(assert) { + assert.expect(1); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + assert.equal(snapshot.belongsTo('friend').attr('name'), 'Tom', 'Preloaded belongsTo set'); + return { data: { id, type: 'person' } }; + }, + }); + + let env = setupStore({ + adapter: Adapter, + }); + + let { store } = env; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + friend: DS.belongsTo('person', { inverse: null, async: true }), + }); + + env.owner.register('model:person', Person); + + return run(() => { + store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'Tom', + }, + }, + }); + + let tom = store.peekRecord('person', 2); + return store.findRecord('person', 1, { preload: { friend: tom } }); + }); +}); + +test('initial values of belongsTo can be passed in as the third argument to find as ids', function(assert) { + assert.expect(1); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + return { data: { id, type: 'person' } }; + }, + }); + + let env = setupStore({ + adapter: Adapter, + }); + let { store } = env; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + friend: DS.belongsTo('person', { async: true, inverse: null }), + }); + + env.owner.register('model:person', Person); + + return run(() => { + return store.findRecord('person', 1, { preload: { friend: 2 } }).then(() => { + return store + .peekRecord('person', 1) + .get('friend') + .then(friend => { + assert.equal(friend.get('id'), '2', 'Preloaded belongsTo set'); + }); + }); + }); +}); + +test('initial values of hasMany can be passed in as the third argument to find as records', function(assert) { + assert.expect(1); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + assert.equal(snapshot.hasMany('friends')[0].attr('name'), 'Tom', 'Preloaded hasMany set'); + return { data: { id, type: 'person' } }; + }, + }); + + let env = setupStore({ + adapter: Adapter, + }); + + let { store } = env; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + friends: DS.hasMany('person', { inverse: null, async: true }), + }); + + env.owner.register('model:person', Person); + + return run(() => { + store.push({ + data: { + type: 'person', + id: '2', + attributes: { + name: 'Tom', + }, + }, + }); + + let tom = store.peekRecord('person', 2); + return store.findRecord('person', 1, { preload: { friends: [tom] } }); + }); +}); + +test('initial values of hasMany can be passed in as the third argument to find as ids', function(assert) { + assert.expect(1); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + assert.equal(snapshot.hasMany('friends')[0].id, '2', 'Preloaded hasMany set'); + return { data: { id, type: 'person' } }; + }, + }); + + let env = setupStore({ + adapter: Adapter, + }); + let { store } = env; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + friends: DS.hasMany('person', { async: true, inverse: null }), + }); + + env.owner.register('model:person', Person); + + return run(() => store.findRecord('person', 1, { preload: { friends: [2] } })); +}); + +test('initial empty values of hasMany can be passed in as the third argument to find as records', function(assert) { + assert.expect(1); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + assert.equal(snapshot.hasMany('friends').length, 0, 'Preloaded hasMany set'); + return { data: { id, type: 'person' } }; + }, + }); + + let env = setupStore({ + adapter: Adapter, + }); + + let { store } = env; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + friends: DS.hasMany('person', { inverse: null, async: true }), + }); + + env.owner.register('model:person', Person); + + return run(() => { + return store.findRecord('person', 1, { preload: { friends: [] } }); + }); +}); + +test('initial values of hasMany can be passed in as the third argument to find as ids', function(assert) { + assert.expect(1); + + const Adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + assert.equal(snapshot.hasMany('friends').length, 0, 'Preloaded hasMany set'); + return { data: { id, type: 'person' } }; + }, + }); + + let env = setupStore({ + adapter: Adapter, + }); + let { store } = env; + + const Person = DS.Model.extend({ + name: DS.attr('string'), + friends: DS.hasMany('person', { async: true, inverse: null }), + }); + + env.owner.register('model:person', Person); + + return run(() => store.findRecord('person', 1, { preload: { friends: [] } })); +}); + +test('records should have their ids updated when the adapter returns the id data', function(assert) { + assert.expect(2); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + let idCounter = 1; + const Adapter = TestAdapter.extend({ + createRecord(store, type, snapshot) { + return { + data: { + id: idCounter++, + type: 'person', + attributes: { + name: snapshot.attr('name'), + }, + }, + }; + }, + }); + + let store = createStore({ + adapter: Adapter, + person: Person, + }); + + let people = store.peekAll('person'); + let tom = store.createRecord('person', { name: 'Tom Dale' }); + let yehuda = store.createRecord('person', { name: 'Yehuda Katz' }); + + return run(() => { + return all([tom.save(), yehuda.save()]).then(() => { + people.forEach((person, index) => { + assert.equal(person.get('id'), index + 1, `The record's id should be correct.`); + }); + }); + }); +}); + +test('store.fetchMany should always return a promise', function(assert) { + assert.expect(3); + + const Person = DS.Model.extend(); + let store = createStore({ + adapter: TestAdapter.extend(), + person: Person, + }); + + store.createRecord('person'); + + let records = []; + let results = run(() => store._scheduleFetchMany(records)); + + assert.ok(results, 'A call to store._scheduleFetchMany() should return a result'); + assert.ok(results.then, 'A call to store._scheduleFetchMany() should return a promise'); + + return results.then(returnedRecords => { + assert.deepEqual(returnedRecords, [], 'The correct records are returned'); + }); +}); + +test('store._scheduleFetchMany should not resolve until all the records are resolved', function(assert) { + assert.expect(1); + + const Person = DS.Model.extend(); + const Phone = DS.Model.extend(); + + const adapter = TestAdapter.extend({ + findRecord(store, type, id, snapshot) { + let record = { id, type: type.modelName }; + + return new EmberPromise(resolve => { + run.later(() => resolve({ data: record }), 5); + }); + }, + + findMany(store, type, ids, snapshots) { + let records = ids.map(id => ({ id, type: type.modelName })); + + return new EmberPromise(resolve => { + run.later(() => { + resolve({ data: records }); + }, 15); + }); + }, + }); + + let store = createStore({ + adapter: adapter, + test: Person, + phone: Phone, + }); + + store.createRecord('test'); + + let internalModels = [ + store._internalModelForId('test', 10), + store._internalModelForId('phone', 20), + store._internalModelForId('phone', 21), + ]; + + return run(() => { + return store._scheduleFetchMany(internalModels).then(() => { + let unloadedRecords = A(internalModels.map(r => r.getRecord())).filterBy('isEmpty'); + + assert.equal(get(unloadedRecords, 'length'), 0, 'All unloaded records should be loaded'); + }); + }); +}); + +test('the store calls adapter.findMany according to groupings returned by adapter.groupRecordsForFindMany', function(assert) { + assert.expect(3); + + const Person = DS.Model.extend(); + + const Adapter = TestAdapter.extend({ + groupRecordsForFindMany(store, snapshots) { + return [[snapshots[0]], [snapshots[1], snapshots[2]]]; + }, + + findRecord(store, type, id, snapshot) { + assert.equal(id, '10', 'The first group is passed to find'); + return { data: { id, type: 'test' } }; + }, + + findMany(store, type, ids, snapshots) { + let records = ids.map(id => ({ id, type: 'test' })); + + assert.deepEqual(ids, ['20', '21'], 'The second group is passed to findMany'); + + return { data: records }; + }, + }); + + let store = createStore({ + adapter: Adapter, + test: Person, + }); + + let internalModels = [ + store._internalModelForId('test', 10), + store._internalModelForId('test', 20), + store._internalModelForId('test', 21), + ]; + + return run(() => { + return store._scheduleFetchMany(internalModels).then(() => { + let ids = internalModels.map(x => x.id); + assert.deepEqual(ids, ['10', '20', '21'], 'The promise fulfills with the records'); + }); + }); +}); + +test('the promise returned by `_scheduleFetch`, when it resolves, does not depend on the promises returned to other calls to `_scheduleFetch` that are in the same run loop, but different groups', function(assert) { + assert.expect(2); + + let davidResolved = false; + + const Person = DS.Model.extend(); + const Adapter = TestAdapter.extend({ + groupRecordsForFindMany(store, snapshots) { + return [[snapshots[0]], [snapshots[1]]]; + }, + + findRecord(store, type, id, snapshot) { + let record = { id, type: 'test' }; + + return new EmberPromise(function(resolve, reject) { + if (id === 'igor') { + resolve({ data: record }); + } else { + run.later(function() { + davidResolved = true; + resolve({ data: record }); + }, 5); + } + }); + }, + }); + + let store = createStore({ + adapter: Adapter, + test: Person, + }); + + return run(() => { + let david = store.findRecord('test', 'david'); + let igor = store.findRecord('test', 'igor'); + let wait = []; + + wait.push( + igor.then(() => { + assert.equal(davidResolved, false, 'Igor did not need to wait for David'); + }) + ); + + wait.push( + david.then(() => { + assert.equal(davidResolved, true, 'David resolved'); + }) + ); + + return all(wait); + }); +}); + +test('the promise returned by `_scheduleFetch`, when it rejects, does not depend on the promises returned to other calls to `_scheduleFetch` that are in the same run loop, but different groups', function(assert) { + assert.expect(2); + + let davidResolved = false; + + const Person = DS.Model.extend(); + const Adapter = TestAdapter.extend({ + groupRecordsForFindMany(store, snapshots) { + return [[snapshots[0]], [snapshots[1]]]; + }, + + findRecord(store, type, id, snapshot) { + let record = { id, type: 'test' }; + + return new EmberPromise((resolve, reject) => { + if (id === 'igor') { + reject({ data: record }); + } else { + run.later(() => { + davidResolved = true; + resolve({ data: record }); + }, 5); + } + }); + }, + }); + + let store = createStore({ + adapter: Adapter, + test: Person, + }); + + return run(() => { + let david = store.findRecord('test', 'david'); + let igor = store.findRecord('test', 'igor'); + let wait = []; + + wait.push( + igor.catch(() => { + assert.equal(davidResolved, false, 'Igor did not need to wait for David'); + }) + ); + + wait.push( + david.then(() => { + assert.equal(davidResolved, true, 'David resolved'); + }) + ); + + return EmberPromise.all(wait); + }); +}); + +testInDebug( + 'store._fetchRecord reject records that were not found, even when those requests were coalesced with records that were found', + function(assert) { + assert.expect(3); + + const Person = DS.Model.extend(); + + const Adapter = TestAdapter.extend({ + findMany(store, type, ids, snapshots) { + let records = ids.map(id => ({ id, type: 'test' })); + return { data: [records[0]] }; + }, + }); + + let store = createStore({ + adapter: Adapter, + test: Person, + }); + + let wait = []; + assert.expectWarning(() => { + run(() => { + let david = store.findRecord('test', 'david'); + let igor = store.findRecord('test', 'igor'); + + wait.push(david.then(() => assert.ok(true, 'David resolved'))); + wait.push(igor.catch(() => assert.ok(true, 'Igor rejected'))); + }); + }, /expected to find records with the following ids/); + + return EmberPromise.all(wait); + } +); + +testInDebug('store._fetchRecord warns when records are missing', function(assert) { + const Person = DS.Model.extend(); + + const Adapter = TestAdapter.extend({ + findMany(store, type, ids, snapshots) { + let records = ids.map(id => ({ id, type: 'test' })).filter(({ id }) => id === 'david'); + + return { data: [records[0]] }; + }, + }); + + let store = createStore({ + adapter: Adapter, + test: Person, + }); + + let wait = []; + let igorDidReject = true; + + assert.expectWarning(() => { + run(() => { + wait.push(store.findRecord('test', 'david')); + wait.push( + store.findRecord('test', 'igor').catch(e => { + igorDidReject = true; + assert.equal( + e.message, + `Expected: '' to be present in the adapter provided payload, but it was not found.` + ); + }) + ); + }); + }, /expected to find records with the following ids in the adapter response but they were missing/); + + return EmberPromise.all(wait).then(() => { + assert.ok( + igorDidReject, + 'expected rejection that could not be found in the payload, but no such rejection occured' + ); + }); +}); + +test('store should not call shouldReloadRecord when the record is not in the store', function(assert) { + assert.expect(1); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldReloadRecord(store, type, id, snapshot) { + assert.ok(false, 'shouldReloadRecord should not be called when the record is not loaded'); + return false; + }, + findRecord() { + assert.ok(true, 'find is always called when the record is not in the store'); + return { data: { id: 1, type: 'person' } }; + }, + }); + + let store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + return run(() => store.findRecord('person', 1)); +}); + +test('store should not reload record when shouldReloadRecord returns false', function(assert) { + assert.expect(1); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldReloadRecord(store, type, id, snapshot) { + assert.ok(true, 'shouldReloadRecord should be called when the record is in the store'); + return false; + }, + shouldBackgroundReloadRecord() { + return false; + }, + findRecord() { + assert.ok(false, 'find should not be called when shouldReloadRecord returns false'); + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + return run(() => { + store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + return store.findRecord('person', 1); + }); +}); + +test('store should reload record when shouldReloadRecord returns true', function(assert) { + assert.expect(3); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldReloadRecord(store, type, id, snapshot) { + assert.ok(true, 'shouldReloadRecord should be called when the record is in the store'); + return true; + }, + findRecord() { + assert.ok(true, 'find should not be called when shouldReloadRecord returns false'); + return { data: { id: 1, type: 'person', attributes: { name: 'Tom' } } }; + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + return run(() => { + store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + return store.findRecord('person', 1).then(record => { + assert.equal(record.get('name'), 'Tom'); + }); + }); +}); + +test('store should not call shouldBackgroundReloadRecord when the store is already loading the record', function(assert) { + assert.expect(2); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldReloadRecord(store, type, id, snapshot) { + return true; + }, + shouldBackgroundReloadRecord(store, type, id, snapshot) { + assert.ok( + false, + 'shouldBackgroundReloadRecord is not called when shouldReloadRecord returns true' + ); + }, + findRecord() { + assert.ok(true, 'find should be called'); + return { data: { id: 1, type: 'person', attributes: { name: 'Tom' } } }; + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + return run(() => { + store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + return store.findRecord('person', 1).then(record => { + assert.equal(record.get('name'), 'Tom'); + }); + }); +}); + +test('store should not reload a record when `shouldBackgroundReloadRecord` is false', function(assert) { + assert.expect(2); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldBackgroundReloadRecord(store, type, id, snapshot) { + assert.ok( + true, + 'shouldBackgroundReloadRecord is called when record is loaded form the cache' + ); + return false; + }, + findRecord() { + assert.ok(false, 'find should not be called'); + return { data: { id: 1, type: 'person', attributes: { name: 'Tom' } } }; + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + return run(() => { + store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + return store.findRecord('person', 1).then(record => { + assert.strictEqual(record.get('name'), undefined); + }); + }); +}); + +test('store should reload the record in the background when `shouldBackgroundReloadRecord` is true', function(assert) { + assert.expect(4); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldBackgroundReloadRecord(store, type, id, snapshot) { + assert.ok( + true, + 'shouldBackgroundReloadRecord is called when record is loaded form the cache' + ); + return true; + }, + findRecord() { + assert.ok(true, 'find should not be called'); + return { data: { id: 1, type: 'person', attributes: { name: 'Tom' } } }; + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + let done = run(() => { + store.push({ + data: { + type: 'person', + id: '1', + }, + }); + + return store.findRecord('person', 1).then(record => { + assert.strictEqual(record.get('name'), undefined); + }); + }); + + assert.equal(store.peekRecord('person', 1).get('name'), 'Tom'); + + return done; +}); + +test('store should not reload record array when shouldReloadAll returns false', function(assert) { + assert.expect(1); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldReloadAll(store, snapshot) { + assert.ok(true, 'shouldReloadAll should be called when the record is in the store'); + return false; + }, + shouldBackgroundReloadAll(store, snapshot) { + return false; + }, + findAll() { + assert.ok(false, 'findAll should not be called when shouldReloadAll returns false'); + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + return run(() => store.findAll('person')); +}); + +test('store should reload all records when shouldReloadAll returns true', function(assert) { + assert.expect(3); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldReloadAll(store, type, id, snapshot) { + assert.ok(true, 'shouldReloadAll should be called when the record is in the store'); + return true; + }, + findAll() { + assert.ok(true, 'findAll should be called when shouldReloadAll returns true'); + return { data: [{ id: 1, type: 'person', attributes: { name: 'Tom' } }] }; + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + return run(() => { + return store.findAll('person').then(records => { + assert.equal(records.get('firstObject.name'), 'Tom'); + }); + }); +}); + +test('store should not call shouldBackgroundReloadAll when the store is already loading all records', function(assert) { + assert.expect(2); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldReloadAll(store, type, id, snapshot) { + return true; + }, + shouldBackgroundReloadAll(store, type, id, snapshot) { + assert.ok( + false, + 'shouldBackgroundReloadRecord is not called when shouldReloadRecord returns true' + ); + }, + findAll() { + assert.ok(true, 'find should be called'); + return { data: [{ id: 1, type: 'person', attributes: { name: 'Tom' } }] }; + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + return run(() => { + return store.findAll('person').then(records => { + assert.equal(records.get('firstObject.name'), 'Tom'); + }); + }); +}); + +test('store should not reload all records when `shouldBackgroundReloadAll` is false', function(assert) { + assert.expect(3); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldReloadAll(store, type, id, snapshot) { + assert.ok(true, 'shouldReloadAll is called when record is loaded form the cache'); + return false; + }, + shouldBackgroundReloadAll(store, type, id, snapshot) { + assert.ok(true, 'shouldBackgroundReloadAll is called when record is loaded form the cache'); + return false; + }, + findAll() { + assert.ok(false, 'findAll should not be called'); + return { data: [{ id: 1, type: 'person', attributes: { name: 'Tom' } }] }; + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + return run(() => { + return store.findAll('person').then(records => { + assert.strictEqual(records.get('firstObject'), undefined); + }); + }); +}); + +test('store should reload all records in the background when `shouldBackgroundReloadAll` is true', function(assert) { + assert.expect(5); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + const TestAdapter = DS.Adapter.extend({ + shouldReloadAll() { + assert.ok(true, 'shouldReloadAll is called'); + return false; + }, + shouldBackgroundReloadAll(store, snapshot) { + assert.ok(true, 'shouldBackgroundReloadAll is called when record is loaded form the cache'); + return true; + }, + findAll() { + assert.ok(true, 'find should not be called'); + return { data: [{ id: 1, type: 'person', attributes: { name: 'Tom' } }] }; + }, + }); + + store = createStore({ + adapter: TestAdapter, + person: Person, + }); + + let done = run(() => { + return store.findAll('person').then(records => { + assert.strictEqual(records.get('firstObject.name'), undefined); + }); + }); + + assert.equal(store.peekRecord('person', 1).get('name'), 'Tom'); + + return done; +}); + +testInDebug('store should assert of the user tries to call store.filter', function(assert) { + assert.expect(1); + + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + store = createStore({ + person: Person, + }); + + assert.expectAssertion(() => { + run(() => store.filter('person', {})); + }, /The filter API has been moved to a plugin/); +}); + +testInDebug('Calling adapterFor with a model class should assert', function(assert) { + const Person = DS.Model.extend({ + name: DS.attr('string'), + }); + + store = createStore({ + person: Person, + }); + + assert.expectAssertion(() => { + store.adapterFor(Person); + }, /Passing classes to store.adapterFor has been removed/); +}); diff --git a/tests/unit/store/asserts-test.js b/tests/unit/store/asserts-test.js new file mode 100644 index 00000000000..b3032c36934 --- /dev/null +++ b/tests/unit/store/asserts-test.js @@ -0,0 +1,113 @@ +import { module } from 'qunit'; +import test from 'dummy/tests/helpers/test-in-debug'; +import { run } from '@ember/runloop'; +import { setupTest } from 'ember-qunit'; +import Store from 'ember-data/store'; +import Model from 'ember-data/model'; + +module('unit/store/asserts - DS.Store methods produce useful assertion messages', function(hooks) { + let store; + + setupTest(hooks); + hooks.beforeEach(function() { + let { owner } = this; + owner.register('model:foo', Model.extend()); + owner.register('service:store', Store); + store = owner.lookup('service:store'); + }); + + const MODEL_NAME_METHODS = [ + 'createRecord', + 'findRecord', + 'findByIds', + 'peekRecord', + 'hasRecordForId', + 'recordForId', + 'query', + 'queryRecord', + 'findAll', + 'peekAll', + 'modelFor', + '_modelFactoryFor', + 'normalize', + 'adapterFor', + 'serializerFor', + ]; + + test('Calling Store methods with no modelName asserts', function(assert) { + assert.expect(MODEL_NAME_METHODS.length); + + MODEL_NAME_METHODS.forEach(methodName => { + assert.expectAssertion(() => { + store[methodName](null); + }, new RegExp(`You need to pass a model name to the store's ${methodName} method`)); + }); + }); + + const STORE_ENTRY_METHODS = [ + 'createRecord', + 'deleteRecord', + 'unloadRecord', + 'find', + 'findRecord', + 'findByIds', + 'getReference', + 'peekRecord', + 'hasRecordForId', + 'recordForId', + 'findMany', + 'findHasMany', + 'findBelongsTo', + 'query', + 'queryRecord', + 'findAll', + 'peekAll', + 'unloadAll', + 'didSaveRecord', + 'recordWasInvalid', + 'recordWasError', + 'modelFor', + '_modelFactoryFor', + '_hasModelFor', + 'push', + '_push', + 'pushPayload', + 'normalize', + 'recordWasLoaded', + 'adapterFor', + 'serializerFor', + ]; + + test('Calling Store methods after the store has been destroyed asserts', function(assert) { + store.shouldAssertMethodCallsOnDestroyedStore = true; + assert.expect(STORE_ENTRY_METHODS.length); + run(() => store.destroy()); + + STORE_ENTRY_METHODS.forEach(methodName => { + assert.expectAssertion(() => { + store[methodName](); + }, `Attempted to call store.${methodName}(), but the store instance has already been destroyed.`); + }); + }); + + const STORE_TEARDOWN_METHODS = ['unloadAll', 'modelFor', '_modelFactoryFor']; + + test('Calling Store teardown methods during destroy does not assert, but calling other methods does', function(assert) { + store.shouldAssertMethodCallsOnDestroyedStore = true; + assert.expect(STORE_ENTRY_METHODS.length - STORE_TEARDOWN_METHODS.length); + + run(() => { + store.destroy(); + + STORE_ENTRY_METHODS.forEach(methodName => { + if (STORE_TEARDOWN_METHODS.indexOf(methodName) !== -1) { + store[methodName]('foo'); + } else { + assert.expectAssertion(() => { + store[methodName](); + }, `Attempted to call store.${methodName}(), but the store instance has already been destroyed.`); + } + }); + }); + }); +}); diff --git a/tests/unit/store/async-leak-test.js b/tests/unit/store/async-leak-test.js new file mode 100644 index 00000000000..814beec3c80 --- /dev/null +++ b/tests/unit/store/async-leak-test.js @@ -0,0 +1,361 @@ +import { module } from 'qunit'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import { setupTest } from 'ember-qunit'; +import Store from 'ember-data/store'; +import Model from 'ember-data/model'; +import { Promise } from 'rsvp'; +import { attr } from '@ember-decorators/data'; +import { run } from '@ember/runloop'; +import Ember from 'ember'; +import test from '../../helpers/test-in-debug'; + +class Person extends Model { + @attr + name; +} + +module('unit/store async-waiter and leak detection', function(hooks) { + let store; + setupTest(hooks); + + hooks.beforeEach(function() { + let { owner } = this; + owner.register('service:store', Store); + owner.register('model:person', Person); + owner.register( + 'serializer:application', + JSONAPISerializer.extend({ + normalizeResponse(_, __, jsonApiPayload) { + return jsonApiPayload; + }, + }) + ); + store = owner.lookup('service:store'); + store.shouldTrackAsyncRequests = true; + }); + + test('the waiter properly waits for pending requests', async function(assert) { + let findRecordWasInvoked; + let findRecordWasInvokedPromise = new Promise(resolveStep => { + findRecordWasInvoked = resolveStep; + }); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + return new Promise(resolve => { + findRecordWasInvoked(); + + setTimeout(() => { + resolve({ data: { type: 'person', id: '1' } }); + }, 50); // intentionally longer than the 10ms polling interval of `wait()` + }); + }, + }) + ); + + let request = store.findRecord('person', '1'); + let waiter = store.__asyncWaiter; + + assert.equal( + waiter(), + true, + 'We return true when no requests have been initiated yet (pending queue flush is async)' + ); + + await findRecordWasInvokedPromise; + + assert.equal(waiter(), false, 'We return false to keep waiting while requests are pending'); + + await request; + + assert.equal(waiter(), true, 'We return true to end waiting when no requests are pending'); + }); + + test('waiter can be turned off', async function(assert) { + let findRecordWasInvoked; + let findRecordWasInvokedPromise = new Promise(resolveStep => { + findRecordWasInvoked = resolveStep; + }); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + return new Promise(resolve => { + findRecordWasInvoked(); + + setTimeout(() => { + resolve({ data: { type: 'person', id: '1' } }); + }, 50); // intentionally longer than the 10ms polling interval of `wait()` + }); + }, + }) + ); + + // turn off the waiter + store.shouldTrackAsyncRequests = false; + + let request = store.findRecord('person', '1'); + let waiter = store.__asyncWaiter; + + assert.equal( + waiter(), + true, + 'We return true when no requests have been initiated yet (pending queue flush is async)' + ); + + await findRecordWasInvokedPromise; + + assert.equal( + store._trackedAsyncRequests.length, + 1, + 'We return true even though a request is pending' + ); + assert.equal(waiter(), true, 'We return true even though a request is pending'); + + await request; + + assert.equal(waiter(), true, 'We return true to end waiting when no requests are pending'); + }); + + test('waiter works even when the adapter rejects', async function(assert) { + assert.expect(4); + let findRecordWasInvoked; + let findRecordWasInvokedPromise = new Promise(resolveStep => { + findRecordWasInvoked = resolveStep; + }); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + return new Promise((resolve, reject) => { + findRecordWasInvoked(); + + setTimeout(() => { + reject({ errors: [] }); + }, 50); // intentionally longer than the 10ms polling interval of `wait()` + }); + }, + }) + ); + + let request = store.findRecord('person', '1'); + let waiter = store.__asyncWaiter; + + assert.equal( + waiter(), + true, + 'We return true when no requests have been initiated yet (pending queue flush is async)' + ); + + await findRecordWasInvokedPromise; + + assert.equal(waiter(), false, 'We return false to keep waiting while requests are pending'); + + await assert.rejects(request); + + assert.equal(waiter(), true, 'We return true to end waiting when no requests are pending'); + }); + + test('waiter works even when the adapter throws', async function(assert) { + assert.expect(4); + let waiter = store.__asyncWaiter; + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + assert.equal( + waiter(), + false, + 'We return false to keep waiting while requests are pending' + ); + throw new Error('Invalid Request!'); + }, + }) + ); + + let request = store.findRecord('person', '1'); + + assert.equal( + waiter(), + true, + 'We return true when no requests have been initiated yet (pending queue flush is async)' + ); + + await assert.rejects(request); + + assert.equal(waiter(), true, 'We return true to end waiting when no requests are pending'); + }); + + test('when the store is torn down too early, we throw an error', async function(assert) { + let next; + let stepPromise = new Promise(resolveStep => { + next = resolveStep; + }); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + next(); + stepPromise = new Promise(resolveStep => { + next = resolveStep; + }).then(() => { + return { data: { type: 'person', id: '1' } }; + }); + return stepPromise; + }, + }) + ); + + store.findRecord('person', '1'); + let waiter = store.__asyncWaiter; + + assert.equal( + waiter(), + true, + 'We return true when no requests have been initiated yet (pending queue flush is async)' + ); + + await stepPromise; + + assert.equal(waiter(), false, 'We return false to keep waiting while requests are pending'); + + // needed for LTS 2.16 + Ember.Test.adapter.exception = e => { + throw e; + }; + + assert.throws(() => { + run(() => store.destroy()); + }, /Async Request leaks detected/); + + assert.equal(waiter(), false, 'We return false because we still have a pending request'); + + // make the waiter complete + run(() => next()); + assert.equal(store._trackedAsyncRequests.length, 0, 'Our pending request is cleaned up'); + assert.equal(waiter(), true, 'We return true because the waiter is cleared'); + }); + + test('when the store is torn down too early, but the waiter behavior is turned off, we emit a warning', async function(assert) { + let next; + let stepPromise = new Promise(resolveStep => { + next = resolveStep; + }); + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + next(); + stepPromise = new Promise(resolveStep => { + next = resolveStep; + }).then(() => { + return { data: { type: 'person', id: '1' } }; + }); + return stepPromise; + }, + }) + ); + + // turn off the waiter + store.shouldTrackAsyncRequests = false; + + store.findRecord('person', '1'); + let waiter = store.__asyncWaiter; + + assert.equal(store._trackedAsyncRequests.length, 0, 'We have no requests yet'); + assert.equal( + waiter(), + true, + 'We return true when no requests have been initiated yet (pending queue flush is async)' + ); + + await stepPromise; + + assert.equal(store._trackedAsyncRequests.length, 1, 'We have a pending request'); + assert.equal(waiter(), true, 'We return true because the waiter is turned off'); + assert.expectWarning(() => { + run(() => { + store.destroy(); + }); + }, /Async Request leaks detected/); + + assert.equal(waiter(), true, 'We return true because the waiter is turned off'); + + // make the waiter complete + run(() => next()); + assert.equal(store._trackedAsyncRequests.length, 0, 'Our pending request is cleaned up'); + assert.equal(waiter(), true, 'We return true because the waiter is cleared'); + }); + + test('when configured, pending requests have useful stack traces', async function(assert) { + let stepResolve; + let stepPromise = new Promise(resolveStep => { + stepResolve = resolveStep; + }); + let fakeId = 1; + this.owner.register( + 'adapter:application', + JSONAPIAdapter.extend({ + findRecord() { + return new Promise(resolve => { + stepResolve(); + + setTimeout(() => { + resolve({ data: { type: 'person', id: `${fakeId++}` } }); + }, 50); // intentionally longer than the 10ms polling interval of `wait()` + }); + }, + }) + ); + let request = store.findRecord('person', '1'); + let waiter = store.__asyncWaiter; + + assert.equal( + waiter(), + true, + 'We return true when no requests have been initiated yet (pending queue flush is async)' + ); + + await stepPromise; + + assert.equal(waiter(), false, 'We return false to keep waiting while requests are pending'); + assert.equal( + store._trackedAsyncRequests[0].trace, + 'set `store.generateStackTracesForTrackedRequests = true;` to get a detailed trace for where this request originated', + 'We provide a useful default message in place of a trace' + ); + + await request; + + assert.equal(waiter(), true, 'We return true to end waiting when no requests are pending'); + + store.generateStackTracesForTrackedRequests = true; + request = store.findRecord('person', '2'); + + assert.equal( + waiter(), + true, + 'We return true when no requests have been initiated yet (pending queue flush is async)' + ); + + await stepPromise; + + assert.equal(waiter(), false, 'We return false to keep waiting while requests are pending'); + /* + TODO this just traces back to the `flushPendingFetches`, + we should do something similar to capture where the fetch was scheduled + from. + */ + assert.equal( + store._trackedAsyncRequests[0].trace.message, + "EmberData TrackedRequest: DS: Handle Adapter#findRecord of 'person' with id: '2'", + 'We captured a trace' + ); + + await request; + + assert.equal(waiter(), true, 'We return true to end waiting when no requests are pending'); + }); +}); diff --git a/tests/unit/store/create-record-test.js b/tests/unit/store/create-record-test.js new file mode 100644 index 00000000000..e2bd5e79459 --- /dev/null +++ b/tests/unit/store/create-record-test.js @@ -0,0 +1,149 @@ +import { A } from '@ember/array'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; +import setupStore from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; + +const { Model, attr, belongsTo, hasMany } = DS; + +let store, Record, Storage; + +module('unit/store/createRecord - Store creating records', { + beforeEach() { + Record = DS.Model.extend({ + title: DS.attr('string'), + }); + + Storage = DS.Model.extend({ + name: DS.attr('name'), + records: DS.hasMany('record', { async: false }), + }); + + store = createStore({ + adapter: DS.Adapter.extend(), + record: Record, + storage: Storage, + }); + }, +}); + +test(`doesn't modify passed in properties hash`, function(assert) { + const Post = Model.extend({ + title: attr(), + author: belongsTo('author', { async: false, inverse: 'post' }), + comments: hasMany('comment', { async: false, inverse: 'post' }), + }); + const Comment = Model.extend({ + text: attr(), + post: belongsTo('post', { async: false, inverse: 'comments' }), + }); + const Author = Model.extend({ + name: attr(), + post: belongsTo('post', { async: false, inverse: 'author' }), + }); + let env = setupStore({ + post: Post, + comment: Comment, + author: Author, + }); + let store = env.store; + let comment, author; + + run(() => { + comment = store.push({ + data: { + type: 'comment', + id: '1', + attributes: { + text: 'Hello darkness my old friend', + }, + }, + }); + author = store.push({ + data: { + type: 'author', + id: '1', + attributes: { + name: '@runspired', + }, + }, + }); + }); + + let properties = { + title: 'My Post', + randomProp: 'An unknown prop', + comments: [comment], + author, + }; + let propertiesClone = { + title: 'My Post', + randomProp: 'An unknown prop', + comments: [comment], + author, + }; + + store.createRecord('post', properties); + + assert.deepEqual(properties, propertiesClone, 'The properties hash is not modified'); +}); + +test('allow passing relationships as well as attributes', function(assert) { + let records, storage; + + run(() => { + store.push({ + data: [ + { + type: 'record', + id: '1', + attributes: { + title: "it's a beautiful day", + }, + }, + { + type: 'record', + id: '2', + attributes: { + title: "it's a beautiful day", + }, + }, + ], + }); + + records = store.peekAll('record'); + storage = store.createRecord('storage', { name: 'Great store', records: records }); + }); + + assert.equal(storage.get('name'), 'Great store', 'The attribute is well defined'); + assert.equal( + storage.get('records').findBy('id', '1'), + A(records).findBy('id', '1'), + 'Defined relationships are allowed in createRecord' + ); + assert.equal( + storage.get('records').findBy('id', '2'), + A(records).findBy('id', '2'), + 'Defined relationships are allowed in createRecord' + ); +}); + +module('unit/store/createRecord - Store with models by dash', { + beforeEach() { + let env = setupStore({ + someThing: DS.Model.extend({ + foo: DS.attr('string'), + }), + }); + store = env.store; + }, +}); + +test('creating a record by dasherize string finds the model', function(assert) { + let attributes = { foo: 'bar' }; + let record = store.createRecord('some-thing', attributes); + + assert.equal(record.get('foo'), attributes.foo, 'The record is created'); + assert.equal(store.modelFor('some-thing').modelName, 'some-thing'); +}); diff --git a/tests/unit/store/finders-test.js b/tests/unit/store/finders-test.js new file mode 100644 index 00000000000..5e53eb1484f --- /dev/null +++ b/tests/unit/store/finders-test.js @@ -0,0 +1,323 @@ +import { defer } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +module('unit/store/finders', { + beforeEach() { + this.Person = DS.Model.extend({ + updatedAt: DS.attr('string'), + name: DS.attr('string'), + firstName: DS.attr('string'), + lastName: DS.attr('string'), + }); + + this.Dog = DS.Model.extend({ + name: DS.attr('string'), + }); + + this.env = setupStore({ person: this.Person, dog: this.Dog }); + this.store = this.env.store; + this.adapter = this.env.adapter; + }, + + afterEach() { + run(this.env.container, 'destroy'); + }, +}); + +test('findRecord does not load a serializer until the adapter promise resolves', function(assert) { + assert.expect(2); + + let deferedFind = defer(); + + this.env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findRecord: () => deferedFind.promise, + }) + ); + + let serializerLoaded = false; + let serializerFor = this.store.serializerFor; + this.store.serializerFor = modelName => { + if (modelName === 'person') { + serializerLoaded = true; + } + return serializerFor.call(this.store, modelName); + }; + + let storePromise = run(() => this.store.findRecord('person', 1)); + assert.equal(false, serializerLoaded, 'serializer is not eagerly loaded'); + + return run(() => { + deferedFind.resolve({ + data: { id: 1, type: 'person', attributes: { name: 'John Churchill' } }, + }); + return storePromise.then(() => { + assert.equal(true, serializerLoaded, 'serializer is loaded'); + }); + }); +}); + +test('findMany does not load a serializer until the adapter promise resolves', function(assert) { + assert.expect(2); + + let deferedFind = defer(); + + this.env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findMany: () => deferedFind.promise, + }) + ); + + let serializerLoaded = false; + let serializerFor = this.store.serializerFor; + this.store.serializerFor = modelName => { + if (modelName === 'person') { + serializerLoaded = true; + } + return serializerFor.call(this.store, modelName); + }; + + let storePromise = run(() => { + this.store.findRecord('person', 1); + return this.store.findRecord('person', 2); + }); + assert.equal(false, serializerLoaded, 'serializer is not eagerly loaded'); + + return run(() => { + deferedFind.resolve({ + data: [ + { id: 1, type: 'person', attributes: { name: 'John Churchill' } }, + { id: 2, type: 'person', attributes: { name: 'Louis Joseph' } }, + ], + }); + return storePromise.then(() => { + assert.equal(true, serializerLoaded, 'serializer is loaded'); + }); + }); +}); + +test('findHasMany does not load a serializer until the adapter promise resolves', function(assert) { + assert.expect(2); + + let deferedFind = defer(); + + this.env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findHasMany: () => deferedFind.promise, + }) + ); + + this.Person.reopen({ + dogs: DS.hasMany('dog', { async: true }), + }); + + let serializerLoaded = false; + let serializerFor = this.store.serializerFor; + this.store.serializerFor = modelName => { + if (modelName === 'dog') { + serializerLoaded = true; + } + return serializerFor.call(this.store, modelName); + }; + + let storePromise = run(() => { + this.env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + dogs: { + links: { + related: 'http://exmaple.com/person/1/dogs', + }, + }, + }, + }, + }); + + return this.store.peekRecord('person', 1).get('dogs'); + }); + assert.equal(false, serializerLoaded, 'serializer is not eagerly loaded'); + + return run(() => { + deferedFind.resolve({ + data: [ + { id: 1, type: 'dog', attributes: { name: 'Scooby' } }, + { id: 2, type: 'dog', attributes: { name: 'Scrappy' } }, + ], + }); + return storePromise.then(() => { + assert.equal(true, serializerLoaded, 'serializer is loaded'); + }); + }); +}); + +test('findBelongsTo does not load a serializer until the adapter promise resolves', function(assert) { + assert.expect(2); + + let deferedFind = defer(); + + this.env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findBelongsTo: () => deferedFind.promise, + }) + ); + + this.Person.reopen({ + favoriteDog: DS.belongsTo('dog', { async: true }), + }); + + let serializerLoaded = false; + let serializerFor = this.store.serializerFor; + this.store.serializerFor = modelName => { + if (modelName === 'dog') { + serializerLoaded = true; + } + return serializerFor.call(this.store, modelName); + }; + + let storePromise = run(() => { + this.env.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'John Churchill', + }, + relationships: { + favoriteDog: { + links: { + related: 'http://exmaple.com/person/1/favorite-dog', + }, + }, + }, + }, + }); + + return this.store.peekRecord('person', 1).get('favoriteDog'); + }); + assert.equal(false, serializerLoaded, 'serializer is not eagerly loaded'); + + return run(() => { + deferedFind.resolve({ data: { id: 1, type: 'dog', attributes: { name: 'Scooby' } } }); + return storePromise.then(() => { + assert.equal(true, serializerLoaded, 'serializer is loaded'); + }); + }); +}); + +test('findAll does not load a serializer until the adapter promise resolves', function(assert) { + assert.expect(2); + + let deferedFind = defer(); + + this.env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + findAll: () => deferedFind.promise, + }) + ); + + let serializerLoaded = false; + let serializerFor = this.store.serializerFor; + this.store.serializerFor = modelName => { + if (modelName === 'person') { + serializerLoaded = true; + } + return serializerFor.call(this.store, modelName); + }; + + let storePromise = run(() => this.store.findAll('person')); + assert.equal(false, serializerLoaded, 'serializer is not eagerly loaded'); + + return run(() => { + deferedFind.resolve({ + data: [{ id: 1, type: 'person', attributes: { name: 'John Churchill' } }], + }); + return storePromise.then(() => { + assert.equal(true, serializerLoaded, 'serializer is loaded'); + }); + }); +}); + +test('query does not load a serializer until the adapter promise resolves', function(assert) { + assert.expect(2); + + let deferedFind = defer(); + + this.env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + query: () => deferedFind.promise, + }) + ); + + let serializerLoaded = false; + let serializerFor = this.store.serializerFor; + this.store.serializerFor = modelName => { + if (modelName === 'person') { + serializerLoaded = true; + } + return serializerFor.call(this.store, modelName); + }; + + let storePromise = run(() => this.store.query('person', { first_duke_of_marlborough: true })); + assert.equal(false, serializerLoaded, 'serializer is not eagerly loaded'); + + return run(() => { + deferedFind.resolve({ + data: [{ id: 1, type: 'person', attributes: { name: 'John Churchill' } }], + }); + return storePromise.then(() => { + assert.equal(true, serializerLoaded, 'serializer is loaded'); + }); + }); +}); + +test('queryRecord does not load a serializer until the adapter promise resolves', function(assert) { + assert.expect(2); + + let deferedFind = defer(); + + this.env.owner.register( + 'adapter:person', + DS.Adapter.extend({ + queryRecord: () => deferedFind.promise, + }) + ); + + let serializerLoaded = false; + let serializerFor = this.store.serializerFor; + this.store.serializerFor = modelName => { + if (modelName === 'person') { + serializerLoaded = true; + } + return serializerFor.call(this.store, modelName); + }; + + let storePromise = run(() => + this.store.queryRecord('person', { first_duke_of_marlborough: true }) + ); + assert.equal(false, serializerLoaded, 'serializer is not eagerly loaded'); + + return run(() => { + deferedFind.resolve({ + data: { id: 1, type: 'person', attributes: { name: 'John Churchill' } }, + }); + return storePromise.then(() => { + assert.equal(true, serializerLoaded, 'serializer is loaded'); + }); + }); +}); diff --git a/tests/unit/store/has-model-for-test.js b/tests/unit/store/has-model-for-test.js new file mode 100644 index 00000000000..47f648a2ba3 --- /dev/null +++ b/tests/unit/store/has-model-for-test.js @@ -0,0 +1,20 @@ +import { createStore } from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; +import DS from 'ember-data'; + +let store; + +module('unit/store/has-model-For', { + beforeEach() { + store = createStore({ + adapter: DS.Adapter.extend(), + 'one-foo': DS.Model.extend({}), + 'two-foo': DS.Model.extend({}), + }); + }, +}); + +test(`hasModelFor correctly normalizes`, function(assert) { + assert.equal(store._hasModelFor('oneFoo'), true); + assert.equal(store._hasModelFor('twoFoo').true); +}); diff --git a/tests/unit/store/has-record-for-id-test.js b/tests/unit/store/has-record-for-id-test.js new file mode 100644 index 00000000000..4fb93fc8e15 --- /dev/null +++ b/tests/unit/store/has-record-for-id-test.js @@ -0,0 +1,87 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let env, store, Person, PhoneNumber; +const { attr, hasMany, belongsTo } = DS; + +module('unit/store/hasRecordForId - Store hasRecordForId', { + beforeEach() { + Person = DS.Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + phoneNumbers: hasMany('phone-number', { async: false }), + }); + + PhoneNumber = DS.Model.extend({ + number: attr('string'), + person: belongsTo('person', { async: false }), + }); + + env = setupStore({ + person: Person, + 'phone-number': PhoneNumber, + }); + + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +test('hasRecordForId should return false for records in the empty state ', function(assert) { + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + phoneNumbers: { + data: [{ type: 'phone-number', id: '1' }], + }, + }, + }, + }); + + assert.equal( + false, + store.hasRecordForId('phone-number', 1), + 'hasRecordForId only returns true for loaded records' + ); + }); +}); + +test('hasRecordForId should return true for records in the loaded state ', function(assert) { + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + phoneNumbers: { + data: [{ type: 'phone-number', id: '1' }], + }, + }, + }, + }); + + assert.equal( + true, + store.hasRecordForId('person', 1), + 'hasRecordForId returns true for records loaded into the store' + ); + }); +}); diff --git a/tests/unit/store/model-for-test.js b/tests/unit/store/model-for-test.js new file mode 100644 index 00000000000..dbcde0aa566 --- /dev/null +++ b/tests/unit/store/model-for-test.js @@ -0,0 +1,56 @@ +import { run } from '@ember/runloop'; +import { dasherize, camelize } from '@ember/string'; +import setupStore from 'dummy/tests/helpers/store'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let container, store, registry, env; + +module('unit/store/model_for - DS.Store#modelFor', { + beforeEach() { + env = setupStore({ + blogPost: DS.Model.extend(), + 'blog.post': DS.Model.extend(), + }); + store = env.store; + container = env.container; + registry = env.registry; + }, + + afterEach() { + run(() => { + container.destroy(); + store.destroy(); + }); + }, +}); + +test('when fetching factory from string, sets a normalized key as modelName', function(assert) { + env.replaceContainerNormalize(key => dasherize(camelize(key))); + + assert.equal(registry.normalize('some.post'), 'some-post', 'precond - container camelizes'); + assert.equal( + store.modelFor('blog.post').modelName, + 'blog.post', + 'modelName is normalized to dasherized' + ); +}); + +test('when fetching factory from string and dashing normalizer, sets a normalized key as modelName', function(assert) { + env.replaceContainerNormalize(key => dasherize(camelize(key))); + + assert.equal(registry.normalize('some.post'), 'some-post', 'precond - container dasherizes'); + assert.equal( + store.modelFor('blog.post').modelName, + 'blog.post', + 'modelName is normalized to dasherized' + ); +}); + +test(`when fetching something that doesn't exist, throws error`, function(assert) { + assert.throws(() => { + store.modelFor('wild-stuff'); + }, /No model was found/); +}); diff --git a/tests/unit/store/peek-record-test.js b/tests/unit/store/peek-record-test.js new file mode 100644 index 00000000000..f3feee116ee --- /dev/null +++ b/tests/unit/store/peek-record-test.js @@ -0,0 +1,71 @@ +import EmberObject from '@ember/object'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; + +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let env, store, Person; + +module('unit/store/peekRecord - Store peekRecord', { + beforeEach() { + Person = DS.Model.extend(); + + env = setupStore({ + person: Person, + }); + + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +test('peekRecord should return the record if it is in the store ', function(assert) { + run(() => { + let person = store.push({ + data: { + type: 'person', + id: '1', + }, + }); + assert.equal( + person, + store.peekRecord('person', 1), + 'peekRecord only return the corresponding record in the store' + ); + }); +}); + +test('peekRecord should return null if the record is not in the store ', function(assert) { + run(() => { + assert.equal( + null, + store.peekRecord('person', 1), + 'peekRecord returns null if the corresponding record is not in the store' + ); + }); +}); + +testInDebug('peekRecord should assert if not passed both model name and id', function(assert) { + run(() => { + assert.expectAssertion(() => { + store.peekRecord('my-id'); + }, /You need to pass both a model name and id/); + }); +}); + +testInDebug('peekRecord should assert if passed a model class instead of model name', function( + assert +) { + run(() => { + assert.expectAssertion(() => { + let modelClass = EmberObject.extend(); + store.peekRecord(modelClass, 'id'); + }, /Passing classes to store methods has been removed/); + }); +}); diff --git a/tests/unit/store/push-test.js b/tests/unit/store/push-test.js new file mode 100644 index 00000000000..e4596766d31 --- /dev/null +++ b/tests/unit/store/push-test.js @@ -0,0 +1,1029 @@ +import EmberObject from '@ember/object'; +import { Promise as EmberPromise, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; +import Ember from 'ember'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let env, store, Person, PhoneNumber, Post; +const { attr, hasMany, belongsTo } = DS; + +module('unit/store/push - DS.Store#push', { + beforeEach() { + Person = DS.Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + phoneNumbers: hasMany('phone-number', { async: false }), + }); + + PhoneNumber = DS.Model.extend({ + number: attr('string'), + person: belongsTo('person', { async: false }), + }); + + Post = DS.Model.extend({ + postTitle: attr('string'), + }); + + env = setupStore({ + post: Post, + person: Person, + 'phone-number': PhoneNumber, + }); + + store = env.store; + + env.owner.register('serializer:post', DS.RESTSerializer); + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +test('Changed attributes are reset when matching data is pushed', function(assert) { + let person = run(() => { + return store.push({ + data: { + type: 'person', + id: 1, + attributes: { + firstName: 'original first name', + }, + }, + }); + }); + + assert.equal(person.get('firstName'), 'original first name'); + assert.equal(person.get('currentState.stateName'), 'root.loaded.saved'); + + run(() => person.set('firstName', 'updated first name')); + + assert.equal(person.get('firstName'), 'updated first name'); + assert.strictEqual(person.get('lastName'), undefined); + assert.equal(person.get('currentState.stateName'), 'root.loaded.updated.uncommitted'); + assert.deepEqual(person.changedAttributes().firstName, [ + 'original first name', + 'updated first name', + ]); + + run(() => { + store.push({ + data: { + type: 'person', + id: 1, + attributes: { + firstName: 'updated first name', + }, + }, + }); + }); + + assert.equal(person.get('firstName'), 'updated first name'); + assert.equal(person.get('currentState.stateName'), 'root.loaded.saved'); + assert.ok(!person.changedAttributes().firstName); +}); + +test('Calling push with a normalized hash returns a record', function(assert) { + assert.expect(2); + env.adapter.shouldBackgroundReloadRecord = () => false; + + return run(() => { + let person = store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + + return store.findRecord('person', 'wat').then(foundPerson => { + assert.equal( + foundPerson, + person, + 'record returned via load() is the same as the record returned from findRecord()' + ); + assert.deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { + id: 'wat', + firstName: 'Yehuda', + lastName: 'Katz', + }); + }); + }); +}); + +test('Supplying a model class for `push` is the same as supplying a string', function(assert) { + assert.expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; + + const Programmer = Person.extend(); + env.owner.register('model:programmer', Programmer); + + return run(() => { + store.push({ + data: { + type: 'programmer', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + + return store.findRecord('programmer', 'wat').then(foundProgrammer => { + assert.deepEqual(foundProgrammer.getProperties('id', 'firstName', 'lastName'), { + id: 'wat', + firstName: 'Yehuda', + lastName: 'Katz', + }); + }); + }); +}); + +test(`Calling push triggers 'didLoad' even if the record hasn't been requested from the adapter`, function(assert) { + assert.expect(1); + + let didLoad = new EmberPromise((resolve, reject) => { + Person.reopen({ + didLoad() { + try { + assert.ok(true, 'The didLoad callback was called'); + resolve(); + } catch (e) { + reject(e); + } + }, + }); + }); + + run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + }); + + return didLoad; +}); + +test('Calling push with partial records updates just those attributes', function(assert) { + assert.expect(2); + env.adapter.shouldBackgroundReloadRecord = () => false; + + return run(() => { + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + }, + }); + + let person = store.peekRecord('person', 'wat'); + + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + lastName: 'Katz!', + }, + }, + }); + + return store.findRecord('person', 'wat').then(foundPerson => { + assert.equal( + foundPerson, + person, + 'record returned via load() is the same as the record returned from findRecord()' + ); + assert.deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { + id: 'wat', + firstName: 'Yehuda', + lastName: 'Katz!', + }); + }); + }); +}); + +test('Calling push on normalize allows partial updates with raw JSON', function(assert) { + env.owner.register('serializer:person', DS.RESTSerializer); + let person; + + run(() => { + person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Robert', + lastName: 'Jackson', + }, + }, + }); + + store.push( + store.normalize('person', { + id: '1', + firstName: 'Jacquie', + }) + ); + }); + + assert.equal(person.get('firstName'), 'Jacquie', 'you can push raw JSON into the store'); + assert.equal(person.get('lastName'), 'Jackson', 'existing fields are untouched'); +}); + +test('Calling push with a normalized hash containing IDs of related records returns a record', function(assert) { + assert.expect(1); + + Person.reopen({ + phoneNumbers: hasMany('phone-number', { + async: true, + }), + }); + + env.adapter.findRecord = function(store, type, id) { + if (id === '1') { + return resolve({ + data: { + id: 1, + type: 'phone-number', + attributes: { number: '5551212' }, + relationships: { + person: { + data: { id: 'wat', type: 'person' }, + }, + }, + }, + }); + } + + if (id === '2') { + return resolve({ + data: { + id: 2, + type: 'phone-number', + attributes: { number: '5552121' }, + relationships: { + person: { + data: { id: 'wat', type: 'person' }, + }, + }, + }, + }); + } + }; + + return run(() => { + let normalized = store.normalize('person', { + id: 'wat', + type: 'person', + attributes: { + 'first-name': 'John', + 'last-name': 'Smith', + }, + relationships: { + 'phone-numbers': { + data: [{ id: 1, type: 'phone-number' }, { id: 2, type: 'phone-number' }], + }, + }, + }); + let person = store.push(normalized); + + return person.get('phoneNumbers').then(phoneNumbers => { + let items = phoneNumbers.map(item => { + return item ? item.getProperties('id', 'number', 'person') : null; + }); + assert.deepEqual(items, [ + { + id: '1', + number: '5551212', + person: person, + }, + { + id: '2', + number: '5552121', + person: person, + }, + ]); + }); + }); +}); + +test('Calling pushPayload allows pushing raw JSON', function(assert) { + run(() => { + store.pushPayload('post', { + posts: [ + { + id: '1', + postTitle: 'Ember rocks', + }, + ], + }); + }); + + let post = store.peekRecord('post', 1); + + assert.equal(post.get('postTitle'), 'Ember rocks', 'you can push raw JSON into the store'); + + run(() => { + store.pushPayload('post', { + posts: [ + { + id: '1', + postTitle: 'Ember rocks (updated)', + }, + ], + }); + }); + + assert.equal(post.get('postTitle'), 'Ember rocks (updated)', 'You can update data in the store'); +}); + +test('Calling pushPayload allows pushing singular payload properties', function(assert) { + run(() => { + store.pushPayload('post', { + post: { + id: '1', + postTitle: 'Ember rocks', + }, + }); + }); + + let post = store.peekRecord('post', 1); + + assert.equal(post.get('postTitle'), 'Ember rocks', 'you can push raw JSON into the store'); + + run(() => { + store.pushPayload('post', { + post: { + id: '1', + postTitle: 'Ember rocks (updated)', + }, + }); + }); + + assert.equal(post.get('postTitle'), 'Ember rocks (updated)', 'You can update data in the store'); +}); + +test(`Calling pushPayload should use the type's serializer for normalizing`, function(assert) { + assert.expect(4); + + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + normalize() { + assert.ok(true, 'normalized is called on Post serializer'); + return this._super(...arguments); + }, + }) + ); + + env.owner.register( + 'serializer:person', + DS.RESTSerializer.extend({ + normalize() { + assert.ok(true, 'normalized is called on Person serializer'); + return this._super(...arguments); + }, + }) + ); + + run(() => { + store.pushPayload('post', { + posts: [ + { + id: 1, + postTitle: 'Ember rocks', + }, + ], + people: [ + { + id: 2, + firstName: 'Yehuda', + }, + ], + }); + }); + + let post = store.peekRecord('post', 1); + + assert.equal(post.get('postTitle'), 'Ember rocks', 'you can push raw JSON into the store'); + + let person = store.peekRecord('person', 2); + + assert.equal(person.get('firstName'), 'Yehuda', 'you can push raw JSON into the store'); +}); + +test(`Calling pushPayload without a type uses application serializer's pushPayload method`, function(assert) { + assert.expect(1); + + env.owner.register( + 'serializer:application', + DS.RESTSerializer.extend({ + pushPayload() { + assert.ok(true, `pushPayload is called on Application serializer`); + return this._super(...arguments); + }, + }) + ); + + run(() => { + store.pushPayload({ + posts: [{ id: '1', postTitle: 'Ember rocks' }], + }); + }); +}); + +test(`Calling pushPayload without a type should use a model's serializer when normalizing`, function(assert) { + assert.expect(4); + + env.owner.register( + 'serializer:post', + DS.RESTSerializer.extend({ + normalize() { + assert.ok(true, 'normalized is called on Post serializer'); + return this._super(...arguments); + }, + }) + ); + + env.owner.register( + 'serializer:application', + DS.RESTSerializer.extend({ + normalize() { + assert.ok(true, 'normalized is called on Application serializer'); + return this._super(...arguments); + }, + }) + ); + + run(() => { + store.pushPayload({ + posts: [ + { + id: '1', + postTitle: 'Ember rocks', + }, + ], + people: [ + { + id: '2', + firstName: 'Yehuda', + }, + ], + }); + }); + + var post = store.peekRecord('post', 1); + + assert.equal(post.get('postTitle'), 'Ember rocks', 'you can push raw JSON into the store'); + + var person = store.peekRecord('person', 2); + + assert.equal(person.get('firstName'), 'Yehuda', 'you can push raw JSON into the store'); +}); + +test('Calling pushPayload allows partial updates with raw JSON', function(assert) { + env.owner.register('serializer:person', DS.RESTSerializer); + + run(() => { + store.pushPayload('person', { + people: [ + { + id: '1', + firstName: 'Robert', + lastName: 'Jackson', + }, + ], + }); + }); + + let person = store.peekRecord('person', 1); + + assert.equal(person.get('firstName'), 'Robert', 'you can push raw JSON into the store'); + assert.equal(person.get('lastName'), 'Jackson', 'you can push raw JSON into the store'); + + run(() => { + store.pushPayload('person', { + people: [ + { + id: '1', + firstName: 'Jacquie', + }, + ], + }); + }); + + assert.equal(person.get('firstName'), 'Jacquie', 'you can push raw JSON into the store'); + assert.equal(person.get('lastName'), 'Jackson', 'existing fields are untouched'); +}); + +testInDebug('calling push without data argument as an object raises an error', function(assert) { + let invalidValues = [null, 1, 'string', EmberObject.create(), EmberObject.extend(), true]; + + assert.expect(invalidValues.length); + + invalidValues.forEach(invalidValue => { + assert.expectAssertion(() => { + run(() => { + store.push('person', invalidValue); + }); + }, /object/); + }); +}); + +testInDebug( + 'Calling push with a link for a non async relationship should warn if no data', + function(assert) { + Person.reopen({ + phoneNumbers: hasMany('phone-number', { async: false }), + }); + + assert.expectWarning(() => { + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + phoneNumbers: { + links: { + related: '/api/people/1/phone-numbers', + }, + }, + }, + }, + }); + }); + }, /You pushed a record of type 'person' with a relationship 'phoneNumbers' configured as 'async: false'. You've included a link but no primary data, this may be an error in your payload. EmberData will treat this relationship as known-to-be-empty./); + } +); + +testInDebug( + 'Calling push with a link for a non async relationship should not warn when data is present', + function(assert) { + Person.reopen({ + phoneNumbers: hasMany('phone-number', { async: false }), + }); + + assert.expectNoWarning(() => { + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + phoneNumbers: { + data: [{ type: 'phone-number', id: '2' }, { type: 'phone-number', id: '3' }], + links: { + related: '/api/people/1/phone-numbers', + }, + }, + }, + }, + }); + }); + }); + } +); + +testInDebug( + 'Calling push with a link for a non async relationship should not reset an existing relationship', + function(assert) { + // GET /persons/1?include=phone-numbers + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + phoneNumbers: { + data: [{ type: 'phone-number', id: '2' }], + links: { + related: '/api/people/1/phone-numbers', + }, + }, + }, + }, + included: [ + { + type: 'phone-number', + id: '2', + attributes: { + number: '1-800-DATA', + }, + }, + ], + }); + + let person = store.peekRecord('person', 1); + + assert.equal(person.get('phoneNumbers.length'), 1); + assert.equal(person.get('phoneNumbers.firstObject.number'), '1-800-DATA'); + + // GET /persons/1 + assert.expectNoWarning(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + phoneNumbers: { + links: { + related: '/api/people/1/phone-numbers', + }, + }, + }, + }, + }); + }); + + assert.equal(person.get('phoneNumbers.length'), 1); + assert.equal(person.get('phoneNumbers.firstObject.number'), '1-800-DATA'); + } +); + +testInDebug('Calling push with an unknown model name throws an assertion error', function(assert) { + assert.expectAssertion(() => { + run(() => { + store.push({ + data: { + id: '1', + type: 'unknown', + }, + }); + }); + }, /You tried to push data with a type 'unknown' but no model could be found with that name/); +}); + +test('Calling push with a link containing an object', function(assert) { + Person.reopen({ + phoneNumbers: hasMany('phone-number', { async: true }), + }); + + run(() => { + store.push( + store.normalize('person', { + id: '1', + type: 'person', + attributes: { + 'first-name': 'Tan', + }, + relationships: { + 'phone-numbers': { + links: { related: '/api/people/1/phone-numbers' }, + }, + }, + }) + ); + }); + + let person = store.peekRecord('person', 1); + + assert.equal(person.get('firstName'), 'Tan', 'you can use links containing an object'); +}); + +test('Calling push with a link containing the value null', function(assert) { + run(() => { + store.push( + store.normalize('person', { + id: '1', + type: 'person', + attributes: { + 'first-name': 'Tan', + }, + relationships: { + 'phone-numbers': { + links: { + related: null, + }, + }, + }, + }) + ); + }); + + let person = store.peekRecord('person', 1); + + assert.equal(person.get('firstName'), 'Tan', 'you can use links that contain null as a value'); +}); + +testInDebug('calling push with hasMany relationship the value must be an array', function(assert) { + assert.expectAssertion(() => { + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + phoneNumbers: { + data: 1, + }, + }, + }, + }); + }); + }); +}); + +testInDebug('calling push with missing or invalid `id` throws assertion error', function(assert) { + let invalidValues = [{}, { id: null }, { id: '' }]; + + assert.expect(invalidValues.length); + + invalidValues.forEach(invalidValue => { + assert.expectAssertion(() => { + run(() => { + store.push({ + data: invalidValue, + }); + }); + }, /You must include an 'id'/); + }); +}); + +testInDebug('calling push with belongsTo relationship the value must not be an array', function( + assert +) { + assert.expectAssertion(() => { + run(() => { + store.push({ + data: { + type: 'phone-number', + id: '1', + relationships: { + person: { + data: [1], + }, + }, + }, + }); + }); + }, /must not be an array/); +}); + +testInDebug( + 'Enabling Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS should warn on unknown attributes', + function(assert) { + run(() => { + let originalFlagValue = Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS; + try { + Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS = true; + assert.expectWarning(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Tomster', + emailAddress: 'tomster@emberjs.com', + isMascot: true, + }, + }, + }); + }, `The payload for 'person' contains these unknown attributes: emailAddress,isMascot. Make sure they've been defined in your model.`); + } finally { + Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS = originalFlagValue; + } + }); + } +); + +testInDebug( + 'Enabling Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS should warn on unknown relationships', + function(assert) { + run(() => { + var originalFlagValue = Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS; + try { + Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS = true; + assert.expectWarning(() => { + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + phoneNumbers: {}, + emailAddresses: {}, + mascots: {}, + }, + }, + }); + }, `The payload for 'person' contains these unknown relationships: emailAddresses,mascots. Make sure they've been defined in your model.`); + } finally { + Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS = originalFlagValue; + } + }); + } +); + +testInDebug('Calling push with unknown keys should not warn by default', function(assert) { + assert.expectNoWarning(() => { + run(() => { + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Tomster', + emailAddress: 'tomster@emberjs.com', + isMascot: true, + }, + }, + }); + }); + }, /The payload for 'person' contains these unknown .*: .* Make sure they've been defined in your model./); +}); + +test('_push returns an instance of InternalModel if an object is pushed', function(assert) { + let pushResult; + + run(() => { + pushResult = store._push({ + data: { + id: 1, + type: 'person', + }, + }); + }); + + assert.ok(pushResult instanceof DS.InternalModel); + assert.notOk(pushResult.record, 'InternalModel is not materialized'); +}); + +test('_push does not require a modelName to resolve to a modelClass', function(assert) { + let originalCall = store.modelFor; + store.modelFor = function() { + assert.notOk('modelFor was triggered as a result of a call to store._push'); + }; + + run(() => { + store._push({ + data: { + id: 1, + type: 'person', + }, + }); + }); + + store.modelFor = originalCall; + assert.ok('We made it'); +}); + +test('_push returns an array of InternalModels if an array is pushed', function(assert) { + let pushResult; + + run(() => { + pushResult = store._push({ + data: [ + { + id: 1, + type: 'person', + }, + ], + }); + }); + + assert.ok(pushResult instanceof Array); + assert.ok(pushResult[0] instanceof DS.InternalModel); + assert.notOk(pushResult[0].record, 'InternalModel is not materialized'); +}); + +test('_push returns null if no data is pushed', function(assert) { + let pushResult; + + run(() => { + pushResult = store._push({ + data: null, + }); + }); + + assert.strictEqual(pushResult, null); +}); + +module('unit/store/push - DS.Store#push with JSON-API', { + beforeEach() { + const Person = DS.Model.extend({ + name: DS.attr('string'), + cars: DS.hasMany('car', { async: false }), + }); + + const Car = DS.Model.extend({ + make: DS.attr('string'), + model: DS.attr('string'), + person: DS.belongsTo('person', { async: false }), + }); + + env = setupStore({ + adapter: DS.Adapter, + car: Car, + person: Person, + }); + + store = env.store; + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +test('Should support pushing multiple models into the store', function(assert) { + assert.expect(2); + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: 1, + attributes: { + name: 'Tom Dale', + }, + }, + { + type: 'person', + id: 2, + attributes: { + name: 'Tomster', + }, + }, + ], + }); + }); + + let tom = store.peekRecord('person', 1); + assert.equal(tom.get('name'), 'Tom Dale', 'Tom should be in the store'); + + let tomster = store.peekRecord('person', 2); + assert.equal(tomster.get('name'), 'Tomster', 'Tomster should be in the store'); +}); + +test('Should support pushing included models into the store', function(assert) { + assert.expect(2); + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: 1, + attributes: { + name: 'Tomster', + }, + relationships: { + cars: [ + { + data: { + type: 'person', + id: 1, + }, + }, + ], + }, + }, + ], + included: [ + { + type: 'car', + id: 1, + attributes: { + make: 'Dodge', + model: 'Neon', + }, + relationships: { + person: { + data: { + id: 1, + type: 'person', + }, + }, + }, + }, + ], + }); + }); + + let tomster = store.peekRecord('person', 1); + assert.equal(tomster.get('name'), 'Tomster', 'Tomster should be in the store'); + + let car = store.peekRecord('car', 1); + assert.equal(car.get('model'), 'Neon', "Tomster's car should be in the store"); +}); diff --git a/tests/unit/store/serializer-for-test.js b/tests/unit/store/serializer-for-test.js new file mode 100644 index 00000000000..10d1e368150 --- /dev/null +++ b/tests/unit/store/serializer-for-test.js @@ -0,0 +1,61 @@ +import { run } from '@ember/runloop'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let container, store, registry, Person; + +module('unit/store/serializer_for - DS.Store#serializerFor', { + beforeEach() { + Person = DS.Model.extend({}); + var env = setupStore({ person: Person }); + store = env.store; + container = env.container; + registry = env.registry; + }, + + afterEach() { + run(() => { + container.destroy(); + store.destroy(); + }); + }, +}); + +test('Calling serializerFor looks up `serializer:` from the container', function(assert) { + const PersonSerializer = DS.JSONSerializer.extend(); + + registry.register('serializer:person', PersonSerializer); + + assert.ok( + store.serializerFor('person') instanceof PersonSerializer, + 'serializer returned from serializerFor is an instance of the registered Serializer class' + ); +}); + +test('Calling serializerFor with a type that has not been registered looks up the default ApplicationSerializer', function(assert) { + const ApplicationSerializer = DS.JSONSerializer.extend(); + + registry.register('serializer:application', ApplicationSerializer); + + assert.ok( + store.serializerFor('person') instanceof ApplicationSerializer, + 'serializer returned from serializerFor is an instance of ApplicationSerializer' + ); +}); + +test('Calling serializerFor with a type that has not been registered and in an application that does not have an ApplicationSerializer looks up the default Ember Data serializer', function(assert) { + assert.ok( + store.serializerFor('person') instanceof DS.JSONSerializer, + 'serializer returned from serializerFor is an instance of DS.JSONSerializer' + ); +}); + +testInDebug('Calling serializerFor with a model class should assert', function(assert) { + assert.expectAssertion(() => { + store.serializerFor(Person); + }, /Passing classes to store.serializerFor has been removed/); +}); diff --git a/tests/unit/store/unload-test.js b/tests/unit/store/unload-test.js new file mode 100644 index 00000000000..2ba613a8ece --- /dev/null +++ b/tests/unit/store/unload-test.js @@ -0,0 +1,231 @@ +import { resolve } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +let store, tryToFind, Record; + +module('unit/store/unload - Store unloading records', { + beforeEach() { + Record = DS.Model.extend({ + title: DS.attr('string'), + wasFetched: DS.attr('boolean'), + }); + + Record.reopenClass({ + toString() { + return 'Record'; + }, + }); + + store = createStore({ + adapter: DS.Adapter.extend({ + findRecord(store, type, id, snapshot) { + tryToFind = true; + return resolve({ + data: { id, type: snapshot.modelName, attributes: { 'was-fetched': true } }, + }); + }, + }), + + record: Record, + }); + }, + + afterEach() { + run(store, 'destroy'); + }, +}); + +testInDebug('unload a dirty record asserts', function(assert) { + assert.expect(2); + + run(() => { + store.push({ + data: { + type: 'record', + id: '1', + attributes: { + title: 'toto', + }, + }, + }); + + let record = store.peekRecord('record', 1); + + record.set('title', 'toto2'); + record._internalModel.send('willCommit'); + + assert.equal(get(record, 'hasDirtyAttributes'), true, 'record is dirty'); + + assert.expectAssertion( + function() { + record.unloadRecord(); + }, + 'You can only unload a record which is not inFlight. `' + + record._internalModel.toString() + + '`', + 'can not unload dirty record' + ); + + // force back into safe to unload mode. + run(() => { + record._internalModel.transitionTo('deleted.saved'); + }); + }); +}); + +test('unload a record', function(assert) { + assert.expect(2); + + return run(() => { + store.push({ + data: { + type: 'record', + id: '1', + attributes: { + title: 'toto', + }, + }, + }); + + return store.findRecord('record', 1).then(record => { + assert.equal(get(record, 'id'), 1, 'found record with id 1'); + + run(() => store.unloadRecord(record)); + + tryToFind = false; + + return store.findRecord('record', 1).then(() => { + assert.equal(tryToFind, true, 'not found record with id 1'); + }); + }); + }); +}); + +test('unload followed by create of the same type + id', function(assert) { + let record = store.createRecord('record', { id: 1 }); + + assert.ok(store.recordForId('record', 1) === record, 'record should exactly equal'); + + return run(() => { + record.unloadRecord(); + let createdRecord = store.createRecord('record', { id: 1 }); + assert.ok(record !== createdRecord, 'newly created record is fresh (and was created)'); + }); +}); + +module('DS.Store - unload record with relationships'); + +test('can commit store after unload record with relationships', function(assert) { + assert.expect(1); + + const Brand = DS.Model.extend({ + name: DS.attr('string'), + }); + + Brand.reopenClass({ + toString() { + return 'Brand'; + }, + }); + + const Product = DS.Model.extend({ + description: DS.attr('string'), + brand: DS.belongsTo('brand', { + async: false, + }), + }); + + Product.reopenClass({ + toString() { + return 'Product'; + }, + }); + + const Like = DS.Model.extend({ + product: DS.belongsTo('product', { + async: false, + }), + }); + + Like.reopenClass({ + toString() { + return 'Like'; + }, + }); + + let store = createStore({ + adapter: DS.Adapter.extend({ + findRecord(store, type, id, snapshot) { + return resolve({ + data: { + id: 1, + type: snapshot.modelName, + attributes: { + description: 'cuisinart', + brand: 1, + }, + }, + }); + }, + + createRecord(store, type, snapshot) { + return resolve(); + }, + }), + brand: Brand, + product: Product, + like: Like, + }); + + return run(() => { + store.push({ + data: [ + { + type: 'brand', + id: '1', + attributes: { + name: 'EmberJS', + }, + }, + { + type: 'product', + id: '1', + attributes: { + description: 'toto', + }, + relationships: { + brand: { + data: { type: 'brand', id: '1' }, + }, + }, + }, + ], + }); + + let product = store.peekRecord('product', 1); + let like = store.createRecord('like', { id: 1, product: product }); + + return like.save(); + }) + .then(() => { + // TODO: this is strange, future travelers please address + run(() => store.unloadRecord(store.peekRecord('product', 1))); + }) + .then(() => { + return store.findRecord('product', 1); + }) + .then(product => { + assert.equal( + product.get('description'), + 'cuisinart', + "The record was unloaded and the adapter's `findRecord` was called" + ); + }); +}); diff --git a/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js b/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js new file mode 100644 index 00000000000..43c2db2e5d4 --- /dev/null +++ b/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js @@ -0,0 +1,805 @@ +import { run } from '@ember/runloop'; +import DS from 'ember-data'; +import { createStore } from 'dummy/tests/helpers/store'; +import deepCopy from 'dummy/tests/helpers/deep-copy'; +import { module, test } from 'qunit'; +import testInDebug from '../../../helpers/test-in-debug'; + +const { Model, hasMany, belongsTo, attr } = DS; + +module('unit/system/relationships/relationship-payloads-manager (polymorphic)', { + beforeEach() { + const User = DS.Model.extend({ + hats: hasMany('hat', { async: false, polymorphic: true, inverse: 'user' }), + sharedHats: hasMany('hat', { async: false, polymorphic: true, inverse: 'sharingUsers' }), + }); + User.toString = () => 'User'; + + const Alien = User.extend({}); + Alien.toString = () => 'Alien'; + + const Hat = Model.extend({ + type: attr('string'), + user: belongsTo('user', { async: false, inverse: 'hats', polymorphic: true }), + sharingUsers: belongsTo('users', { async: false, inverse: 'sharedHats', polymorphic: true }), + hat: belongsTo('hat', { async: false, inverse: 'hats', polymorphic: true }), + hats: hasMany('hat', { async: false, inverse: 'hat', polymorphic: true }), + }); + const BigHat = Hat.extend({}); + const SmallHat = Hat.extend({}); + + this.store = createStore({ + user: User, + alien: Alien, + hat: Hat, + 'big-hat': BigHat, + 'small-hat': SmallHat, + }); + }, +}); + +test('push one side is polymorphic, baseType then subTypes', function(assert) { + let id = 1; + + function makeHat(type, props) { + const resource = deepCopy(props); + resource.id = `${id++}`; + resource.type = type; + resource.attributes.type = type; + return resource; + } + + const hatData = { + attributes: {}, + relationships: { + user: { + data: { id: '1', type: 'user' }, + }, + }, + }; + + const hatData1 = makeHat('hat', hatData), + bigHatData1 = makeHat('big-hat', hatData), + smallHatData1 = makeHat('small-hat', hatData); + + const userData = { + data: { + id: '1', + type: 'user', + attributes: {}, + }, + included: [hatData1, bigHatData1, smallHatData1], + }; + + const user = run(() => this.store.push(userData)); + + const finalResult = user.get('hats').mapBy('type'); + + assert.deepEqual(finalResult, ['hat', 'big-hat', 'small-hat'], 'We got all our hats!'); +}); + +test('push one side is polymorphic, subType then baseType', function(assert) { + let id = 1; + + function makeHat(type, props) { + const resource = deepCopy(props); + resource.id = `${id++}`; + resource.type = type; + resource.attributes.type = type; + return resource; + } + + const hatData = { + attributes: {}, + relationships: { + user: { + data: { id: '1', type: 'user' }, + }, + }, + }; + + const bigHatData1 = makeHat('hat', hatData), + smallHatData1 = makeHat('small-hat', hatData), + hatData1 = makeHat('big-hat', hatData), + included = [bigHatData1, smallHatData1, hatData1]; + + const userData = { + data: { + id: '1', + type: 'user', + attributes: {}, + }, + included, + }; + + const user = run(() => this.store.push(userData)), + finalResult = user.get('hats').mapBy('type'), + expectedResults = included.map(m => m.type); + + assert.deepEqual(finalResult, expectedResults, 'We got all our hats!'); +}); + +test('push one side is polymorphic, different subtypes', function(assert) { + let id = 1; + + function makeHat(type, props) { + const resource = deepCopy(props); + resource.id = `${id++}`; + resource.type = type; + resource.attributes.type = type; + return resource; + } + + const hatData = { + attributes: {}, + relationships: { + user: { + data: { id: '1', type: 'user' }, + }, + }, + }; + + const bigHatData1 = makeHat('big-hat', hatData), + smallHatData1 = makeHat('small-hat', hatData), + bigHatData2 = makeHat('big-hat', hatData), + smallHatData2 = makeHat('small-hat', hatData), + included = [bigHatData1, smallHatData1, bigHatData2, smallHatData2]; + + const userData = { + data: { + id: '1', + type: 'user', + attributes: {}, + }, + included, + }; + + const user = run(() => this.store.push(userData)), + finalResult = user.get('hats').mapBy('type'), + expectedResults = included.map(m => m.type); + + assert.deepEqual(finalResult, expectedResults, 'We got all our hats!'); +}); + +test('push both sides are polymorphic', function(assert) { + let id = 1; + + function makeHat(type, props) { + const resource = deepCopy(props); + resource.id = `${id++}`; + resource.type = type; + resource.attributes.type = type; + return resource; + } + + const alienHatData = { + attributes: {}, + relationships: { + user: { + data: { id: '1', type: 'alien' }, + }, + }, + }; + + const bigHatData1 = makeHat('hat', alienHatData), + hatData1 = makeHat('big-hat', alienHatData), + alienIncluded = [bigHatData1, hatData1]; + + const alienData = { + data: { + id: '1', + type: 'alien', + attributes: {}, + }, + included: alienIncluded, + }; + + const expectedAlienResults = alienIncluded.map(m => m.type), + alien = run(() => this.store.push(alienData)), + alienFinalHats = alien.get('hats').mapBy('type'); + + assert.deepEqual(alienFinalHats, expectedAlienResults, 'We got all alien hats!'); +}); + +test('handles relationships where both sides are polymorphic', function(assert) { + let id = 1; + function makePolymorphicHatForPolymorphicPerson(type, isForBigPerson = true) { + return { + id: `${id++}`, + type, + relationships: { + person: { + data: { + id: isForBigPerson ? '1' : '2', + type: isForBigPerson ? 'big-person' : 'small-person', + }, + }, + }, + }; + } + + const bigHatData1 = makePolymorphicHatForPolymorphicPerson('big-hat'); + const bigHatData2 = makePolymorphicHatForPolymorphicPerson('big-hat'); + const bigHatData3 = makePolymorphicHatForPolymorphicPerson('big-hat', false); + const smallHatData1 = makePolymorphicHatForPolymorphicPerson('small-hat'); + const smallHatData2 = makePolymorphicHatForPolymorphicPerson('small-hat'); + const smallHatData3 = makePolymorphicHatForPolymorphicPerson('small-hat', false); + + const bigPersonData = { + data: { + id: '1', + type: 'big-person', + attributes: {}, + }, + included: [bigHatData1, smallHatData1, bigHatData2, smallHatData2], + }; + + const smallPersonData = { + data: { + id: '2', + type: 'small-person', + attributes: {}, + }, + included: [bigHatData3, smallHatData3], + }; + + const PersonModel = Model.extend({ + hats: hasMany('hat', { + async: false, + polymorphic: true, + inverse: 'person', + }), + }); + const HatModel = Model.extend({ + type: attr('string'), + person: belongsTo('person', { + async: false, + inverse: 'hats', + polymorphic: true, + }), + }); + const BigHatModel = HatModel.extend({}); + const SmallHatModel = HatModel.extend({}); + + const BigPersonModel = PersonModel.extend({}); + const SmallPersonModel = PersonModel.extend({}); + + const store = (this.store = createStore({ + person: PersonModel, + bigPerson: BigPersonModel, + smallPerson: SmallPersonModel, + hat: HatModel, + bigHat: BigHatModel, + smallHat: SmallHatModel, + })); + + const bigPerson = run(() => { + return store.push(bigPersonData); + }); + + const smallPerson = run(() => { + return store.push(smallPersonData); + }); + + const finalBigResult = bigPerson.get('hats').toArray(); + const finalSmallResult = smallPerson.get('hats').toArray(); + + assert.equal(finalBigResult.length, 4, 'We got all our hats!'); + assert.equal(finalSmallResult.length, 2, 'We got all our hats!'); +}); + +test('handles relationships where both sides are polymorphic reflexive', function(assert) { + function link(a, b, relationshipName, recurse = true) { + a.relationships = a.relationships || {}; + const rel = (a.relationships[relationshipName] = a.relationships[relationshipName] || {}); + + if (Array.isArray(b)) { + rel.data = b.map(i => { + let { type, id } = i; + + if (recurse === true) { + link(i, [a], relationshipName, false); + } + + return { type, id }; + }); + } else { + rel.data = { + type: b.type, + id: b.id, + }; + + if (recurse === true) { + link(b, a, relationshipName, false); + } + } + } + + let id = 1; + const Person = Model.extend({ + name: attr(), + family: hasMany('person', { async: false, polymorphic: true, inverse: 'family' }), + twin: belongsTo('person', { async: false, polymorphic: true, inverse: 'twin' }), + }); + const Girl = Person.extend({}); + const Boy = Person.extend({}); + const Grownup = Person.extend({}); + + const brotherPayload = { + type: 'boy', + id: `${id++}`, + attributes: { + name: 'Gavin', + }, + }; + const sisterPayload = { + type: 'girl', + id: `${id++}`, + attributes: { + name: 'Rose', + }, + }; + const fatherPayload = { + type: 'grownup', + id: `${id++}`, + attributes: { + name: 'Garak', + }, + }; + const motherPayload = { + type: 'grownup', + id: `${id++}`, + attributes: { + name: 'Kira', + }, + }; + + link(brotherPayload, sisterPayload, 'twin'); + link(brotherPayload, [sisterPayload, fatherPayload, motherPayload], 'family'); + + const payload = { + data: brotherPayload, + included: [sisterPayload, fatherPayload, motherPayload], + }; + const expectedFamilyReferences = [ + { type: 'girl', id: sisterPayload.id }, + { type: 'grownup', id: fatherPayload.id }, + { type: 'grownup', id: motherPayload.id }, + ]; + const expectedTwinReference = { type: 'girl', id: sisterPayload.id }; + + const store = (this.store = createStore({ + person: Person, + grownup: Grownup, + boy: Boy, + girl: Girl, + })); + + const boyInstance = run(() => { + return store.push(payload); + }); + + const familyResultReferences = boyInstance + .get('family') + .toArray() + .map(i => { + return { type: i.constructor.modelName, id: i.id }; + }); + const twinResult = boyInstance.get('twin'); + const twinResultReference = { type: twinResult.constructor.modelName, id: twinResult.id }; + + assert.deepEqual(familyResultReferences, expectedFamilyReferences, 'We linked family correctly'); + assert.deepEqual(twinResultReference, expectedTwinReference, 'We linked twin correctly'); +}); + +test('handles relationships where both sides are polymorphic reflexive but the primary payload does not include linkage', function(assert) { + function link(a, b, relationshipName, recurse = true) { + a.relationships = a.relationships || {}; + const rel = (a.relationships[relationshipName] = a.relationships[relationshipName] || {}); + + if (Array.isArray(b)) { + rel.data = b.map(i => { + let { type, id } = i; + + if (recurse === true) { + link(i, [a], relationshipName, false); + } + + return { type, id }; + }); + } else { + rel.data = { + type: b.type, + id: b.id, + }; + + if (recurse === true) { + link(b, a, relationshipName, false); + } + } + } + + let id = 1; + const Person = Model.extend({ + name: attr(), + family: hasMany('person', { async: false, polymorphic: true, inverse: 'family' }), + twin: belongsTo('person', { async: false, polymorphic: true, inverse: 'twin' }), + }); + const Girl = Person.extend({}); + const Boy = Person.extend({}); + const Grownup = Person.extend({}); + + const brotherPayload = { + type: 'boy', + id: `${id++}`, + attributes: { + name: 'Gavin', + }, + }; + const sisterPayload = { + type: 'girl', + id: `${id++}`, + attributes: { + name: 'Rose', + }, + }; + const fatherPayload = { + type: 'grownup', + id: `${id++}`, + attributes: { + name: 'Garak', + }, + }; + const motherPayload = { + type: 'grownup', + id: `${id++}`, + attributes: { + name: 'Kira', + }, + }; + + link(brotherPayload, sisterPayload, 'twin'); + link(brotherPayload, [sisterPayload, fatherPayload, motherPayload], 'family'); + + // unlink all relationships from the primary payload + delete brotherPayload.relationships; + + const payload = { + data: brotherPayload, + included: [sisterPayload, fatherPayload, motherPayload], + }; + const expectedFamilyReferences = [ + { type: 'girl', id: sisterPayload.id }, + { type: 'grownup', id: fatherPayload.id }, + { type: 'grownup', id: motherPayload.id }, + ]; + const expectedTwinReference = { type: 'girl', id: sisterPayload.id }; + + const store = (this.store = createStore({ + person: Person, + grownup: Grownup, + boy: Boy, + girl: Girl, + })); + + const boyInstance = run(() => { + return store.push(payload); + }); + + const familyResultReferences = boyInstance + .get('family') + .toArray() + .map(i => { + return { type: i.constructor.modelName, id: i.id }; + }); + const twinResult = boyInstance.get('twin'); + const twinResultReference = twinResult && { + type: twinResult.constructor.modelName, + id: twinResult.id, + }; + + assert.deepEqual(familyResultReferences, expectedFamilyReferences, 'We linked family correctly'); + assert.deepEqual(twinResultReference, expectedTwinReference, 'We linked twin correctly'); +}); + +test('push polymorphic self-referential non-reflexive relationship', function(assert) { + const store = this.store; + const hat1Data = { + data: { + id: '1', + type: 'big-hat', + attributes: {}, + }, + }; + const hat2Data = { + data: { + id: '2', + type: 'big-hat', + attributes: {}, + relationships: { + hats: { + data: [{ id: '1', type: 'big-hat' }], + }, + }, + }, + }; + + const hat1 = run(() => store.push(hat1Data)); + const hat2 = run(() => store.push(hat2Data)); + + const expectedHatReference = { id: '2', type: 'big-hat' }; + const expectedHatsReferences = [{ id: '1', type: 'big-hat' }]; + + const finalHatsReferences = hat2 + .get('hats') + .toArray() + .map(i => { + return { type: i.constructor.modelName, id: i.id }; + }); + const hatResult = hat1.get('hat'); + const finalHatReference = hatResult && { + type: hatResult.constructor.modelName, + id: hatResult.id, + }; + + assert.deepEqual(finalHatReference, expectedHatReference, 'we set hat on hat:1'); + assert.deepEqual(finalHatsReferences, expectedHatsReferences, 'We have hats on hat:2'); +}); + +test('push polymorphic self-referential circular non-reflexive relationship', function(assert) { + const store = this.store; + const hatData = { + data: { + id: '1', + type: 'big-hat', + attributes: {}, + relationships: { + hat: { + data: { id: '1', type: 'big-hat' }, + }, + hats: { + data: [{ id: '1', type: 'big-hat' }], + }, + }, + }, + }; + + const hat = run(() => store.push(hatData)); + + const expectedHatReference = { id: '1', type: 'big-hat' }; + const expectedHatsReferences = [{ id: '1', type: 'big-hat' }]; + + const finalHatsReferences = hat + .get('hats') + .toArray() + .map(i => { + return { type: i.constructor.modelName, id: i.id }; + }); + const hatResult = hat.get('hat'); + const finalHatReference = hatResult && { + type: hatResult.constructor.modelName, + id: hatResult.id, + }; + + assert.deepEqual(finalHatReference, expectedHatReference, 'we set hat on hat:1'); + assert.deepEqual(finalHatsReferences, expectedHatsReferences, 'We have hats on hat:2'); +}); + +test('polymorphic hasMany to types with separate id-spaces', function(assert) { + const user = run(() => + this.store.push({ + data: { + id: '1', + type: 'user', + relationships: { + hats: { + data: [{ id: '1', type: 'big-hat' }, { id: '1', type: 'small-hat' }], + }, + }, + }, + included: [ + { + id: '1', + type: 'big-hat', + }, + { + id: '1', + type: 'small-hat', + }, + ], + }) + ); + + const hats = user.get('hats'); + + assert.deepEqual(hats.map(h => h.constructor.modelName), ['big-hat', 'small-hat']); + assert.deepEqual(hats.map(h => h.id), ['1', '1']); +}); + +test('polymorphic hasMany to types with separate id-spaces, from inverse payload', function(assert) { + const user = run(() => + this.store.push({ + data: { + id: '1', + type: 'user', + }, + included: [ + { + id: '1', + type: 'big-hat', + relationships: { + user: { + data: { id: '1', type: 'user' }, + }, + }, + }, + { + id: '1', + type: 'small-hat', + relationships: { + user: { + data: { id: '1', type: 'user' }, + }, + }, + }, + ], + }) + ); + + const hats = user.get('hats'); + + assert.deepEqual(hats.map(h => h.constructor.modelName), ['big-hat', 'small-hat']); + assert.deepEqual(hats.map(h => h.id), ['1', '1']); +}); + +test('polymorphic hasMany to polymorphic hasMany types with separate id-spaces', function(assert) { + let bigHatId = 1; + let smallHatId = 1; + function makePolymorphicHatForPolymorphicPerson(type, isForBigPerson = true) { + const isSmallHat = type === 'small-hat'; + return { + id: `${isSmallHat ? smallHatId++ : bigHatId++}`, + type, + relationships: { + person: { + data: { + id: '1', + type: isForBigPerson ? 'big-person' : 'small-person', + }, + }, + }, + }; + } + + const bigHatData1 = makePolymorphicHatForPolymorphicPerson('big-hat'); + const bigHatData2 = makePolymorphicHatForPolymorphicPerson('big-hat'); + const bigHatData3 = makePolymorphicHatForPolymorphicPerson('big-hat', false); + const smallHatData1 = makePolymorphicHatForPolymorphicPerson('small-hat'); + const smallHatData2 = makePolymorphicHatForPolymorphicPerson('small-hat'); + const smallHatData3 = makePolymorphicHatForPolymorphicPerson('small-hat', false); + + const bigPersonData = { + data: { + id: '1', + type: 'big-person', + attributes: {}, + }, + included: [bigHatData1, smallHatData1, bigHatData2, smallHatData2], + }; + + const smallPersonData = { + data: { + id: '1', + type: 'small-person', + attributes: {}, + }, + included: [bigHatData3, smallHatData3], + }; + + const PersonModel = Model.extend({ + hats: hasMany('hat', { + async: false, + polymorphic: true, + inverse: 'person', + }), + }); + const HatModel = Model.extend({ + type: attr('string'), + person: belongsTo('person', { + async: false, + inverse: 'hats', + polymorphic: true, + }), + }); + const BigHatModel = HatModel.extend({}); + const SmallHatModel = HatModel.extend({}); + + const BigPersonModel = PersonModel.extend({}); + const SmallPersonModel = PersonModel.extend({}); + + const store = (this.store = createStore({ + person: PersonModel, + bigPerson: BigPersonModel, + smallPerson: SmallPersonModel, + hat: HatModel, + bigHat: BigHatModel, + smallHat: SmallHatModel, + })); + + const bigPerson = run(() => { + return store.push(bigPersonData); + }); + + const smallPerson = run(() => { + return store.push(smallPersonData); + }); + + const finalBigResult = bigPerson.get('hats').toArray(); + const finalSmallResult = smallPerson.get('hats').toArray(); + + assert.deepEqual( + finalBigResult.map(h => ({ type: h.constructor.modelName, id: h.get('id') })), + [ + { type: 'big-hat', id: '1' }, + { type: 'small-hat', id: '1' }, + { type: 'big-hat', id: '2' }, + { type: 'small-hat', id: '2' }, + ], + 'big-person hats is all good' + ); + + assert.deepEqual( + finalSmallResult.map(h => ({ type: h.constructor.modelName, id: h.get('id') })), + [{ type: 'big-hat', id: '3' }, { type: 'small-hat', id: '3' }], + 'small-person hats is all good' + ); +}); + +testInDebug('Invalid inverses throw errors', function(assert) { + let PostModel = Model.extend({ + comments: hasMany('comment', { async: false, inverse: 'post' }), + }); + let CommentModel = Model.extend({ + post: belongsTo('post', { async: false, inverse: null }), + }); + let store = createStore({ + post: PostModel, + comment: CommentModel, + }); + + function runInvalidPush() { + return run(() => { + return store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], + }, + }, + }, + included: [ + { + type: 'comment', + id: '1', + relationships: { + post: { + data: { + type: 'post', + id: '1', + }, + }, + }, + }, + ], + }); + }); + } + + assert.expectAssertion( + runInvalidPush, + /The comment:post relationship declares 'inverse: null', but it was resolved as the inverse for post:comments/, + 'We detected the invalid inverse' + ); +}); diff --git a/tests/unit/system/snapshot-record-array-test.js b/tests/unit/system/snapshot-record-array-test.js new file mode 100644 index 00000000000..38c25f8d73d --- /dev/null +++ b/tests/unit/system/snapshot-record-array-test.js @@ -0,0 +1,73 @@ +import { A } from '@ember/array'; +import { SnapshotRecordArray } from 'ember-data/-private'; +import { module, test } from 'qunit'; + +module('Unit - snapshot-record-array'); + +test('constructor', function(assert) { + let array = A([1, 2]); + array.type = 'some type'; + let meta = {}; + let options = { + adapterOptions: 'some options', + include: 'include me', + }; + + let snapshot = new SnapshotRecordArray(array, meta, options); + + assert.equal(snapshot.length, 2); + assert.equal(snapshot.meta, meta); + assert.equal(snapshot.type, 'some type'); + assert.equal(snapshot.adapterOptions, 'some options'); + assert.equal(snapshot.include, 'include me'); +}); + +test('#snapshot', function(assert) { + let array = A([1, 2]); + let didTakeSnapshot = 0; + let snapshotTaken = {}; + + array.type = 'some type'; + array._takeSnapshot = function() { + didTakeSnapshot++; + return snapshotTaken; + }; + + let meta = {}; + let options = { + adapterOptions: 'some options', + include: 'include me', + }; + + let snapshot = new SnapshotRecordArray(array, meta, options); + + assert.equal(didTakeSnapshot, 0, 'no shapshot shouldn yet be taken'); + assert.equal(snapshot.snapshots(), snapshotTaken, 'should be correct snapshot'); + assert.equal(didTakeSnapshot, 1, 'one snapshot should have been taken'); + assert.equal(snapshot.snapshots(), snapshotTaken, 'should return the exact same snapshot'); + assert.equal(didTakeSnapshot, 1, 'still only one snapshot should have been taken'); +}); + +test('SnapshotRecordArray.type loads the class lazily', function(assert) { + let array = A([1, 2]); + let typeLoaded = false; + + Object.defineProperty(array, 'type', { + get() { + typeLoaded = true; + return 'some type'; + }, + }); + + let meta = {}; + let options = { + adapterOptions: 'some options', + include: 'include me', + }; + + let snapshot = new SnapshotRecordArray(array, meta, options); + + assert.equal(false, typeLoaded, 'model class is not eager loaded'); + assert.equal(snapshot.type, 'some type'); + assert.equal(true, typeLoaded, 'model class is loaded'); +}); diff --git a/tests/unit/transform/boolean-test.js b/tests/unit/transform/boolean-test.js new file mode 100644 index 00000000000..6f9c206ccd2 --- /dev/null +++ b/tests/unit/transform/boolean-test.js @@ -0,0 +1,54 @@ +import DS from 'ember-data'; + +import { module, test } from 'qunit'; + +module('unit/transform - DS.BooleanTransform'); + +test('#serialize', function(assert) { + let transform = new DS.BooleanTransform(); + + assert.strictEqual(transform.serialize(null, { allowNull: true }), null); + assert.strictEqual(transform.serialize(undefined, { allowNull: true }), null); + + assert.equal(transform.serialize(null, { allowNull: false }), false); + assert.equal(transform.serialize(undefined, { allowNull: false }), false); + + assert.equal(transform.serialize(null, {}), false); + assert.equal(transform.serialize(undefined, {}), false); + + assert.equal(transform.serialize(true), true); + assert.equal(transform.serialize(false), false); +}); + +test('#deserialize', function(assert) { + let transform = new DS.BooleanTransform(); + + assert.strictEqual(transform.deserialize(null, { allowNull: true }), null); + assert.strictEqual(transform.deserialize(undefined, { allowNull: true }), null); + + assert.equal(transform.deserialize(null, { allowNull: false }), false); + assert.equal(transform.deserialize(undefined, { allowNull: false }), false); + + assert.equal(transform.deserialize(null, {}), false); + assert.equal(transform.deserialize(undefined, {}), false); + + assert.equal(transform.deserialize(true), true); + assert.equal(transform.deserialize(false), false); + + assert.equal(transform.deserialize('true'), true); + assert.equal(transform.deserialize('TRUE'), true); + assert.equal(transform.deserialize('false'), false); + assert.equal(transform.deserialize('FALSE'), false); + + assert.equal(transform.deserialize('t'), true); + assert.equal(transform.deserialize('T'), true); + assert.equal(transform.deserialize('f'), false); + assert.equal(transform.deserialize('F'), false); + + assert.equal(transform.deserialize('1'), true); + assert.equal(transform.deserialize('0'), false); + + assert.equal(transform.deserialize(1), true); + assert.equal(transform.deserialize(2), false); + assert.equal(transform.deserialize(0), false); +}); diff --git a/tests/unit/transform/date-test.js b/tests/unit/transform/date-test.js new file mode 100644 index 00000000000..d145d6046c2 --- /dev/null +++ b/tests/unit/transform/date-test.js @@ -0,0 +1,36 @@ +import { module, test } from 'qunit'; + +import DS from 'ember-data'; + +module('unit/transform - DS.DateTransform'); + +let dateString = '2015-01-01T00:00:00.000Z'; +let dateInMillis = Date.parse(dateString); +let date = new Date(dateString); + +test('#serialize', function(assert) { + let transform = new DS.DateTransform(); + + assert.strictEqual(transform.serialize(null), null); + assert.strictEqual(transform.serialize(undefined), null); + assert.strictEqual(transform.serialize(new Date('invalid')), null); + + assert.equal(transform.serialize(date), dateString); +}); + +test('#deserialize', function(assert) { + let transform = new DS.DateTransform(); + + // from String + assert.equal(transform.deserialize(dateString).toISOString(), dateString); + + // from Number + assert.equal(transform.deserialize(dateInMillis).valueOf(), dateInMillis); + + // from other + assert.strictEqual(transform.deserialize({}), null); + + // from none + assert.strictEqual(transform.deserialize(null), null); + assert.strictEqual(transform.deserialize(undefined), undefined); +}); diff --git a/tests/unit/transform/number-test.js b/tests/unit/transform/number-test.js new file mode 100644 index 00000000000..d1f61ecb85c --- /dev/null +++ b/tests/unit/transform/number-test.js @@ -0,0 +1,31 @@ +import DS from 'ember-data'; + +import { module, test } from 'qunit'; + +module('unit/transform - DS.NumberTransform'); + +test('#serialize', function(assert) { + let transform = new DS.NumberTransform(); + + assert.strictEqual(transform.serialize(null), null); + assert.strictEqual(transform.serialize(undefined), null); + assert.equal(transform.serialize('1.1'), 1.1); + assert.equal(transform.serialize(1.1), 1.1); + assert.equal(transform.serialize(new Number(1.1)), 1.1); + assert.strictEqual(transform.serialize(NaN), null); + assert.strictEqual(transform.serialize(Infinity), null); + assert.strictEqual(transform.serialize(-Infinity), null); +}); + +test('#deserialize', function(assert) { + let transform = new DS.NumberTransform(); + + assert.strictEqual(transform.deserialize(null), null); + assert.strictEqual(transform.deserialize(undefined), null); + assert.equal(transform.deserialize('1.1'), 1.1); + assert.equal(transform.deserialize(1.1), 1.1); + assert.equal(transform.deserialize(new Number(1.1)), 1.1); + assert.strictEqual(transform.deserialize(NaN), null); + assert.strictEqual(transform.deserialize(Infinity), null); + assert.strictEqual(transform.deserialize(-Infinity), null); +}); diff --git a/tests/unit/transform/string-test.js b/tests/unit/transform/string-test.js new file mode 100644 index 00000000000..c8958d0ecd2 --- /dev/null +++ b/tests/unit/transform/string-test.js @@ -0,0 +1,25 @@ +import DS from 'ember-data'; + +import { module, test } from 'qunit'; + +module('unit/transform - DS.StringTransform'); + +test('#serialize', function(assert) { + let transform = new DS.StringTransform(); + + assert.strictEqual(transform.serialize(null), null); + assert.strictEqual(transform.serialize(undefined), null); + + assert.equal(transform.serialize('foo'), 'foo'); + assert.equal(transform.serialize(1), '1'); +}); + +test('#deserialize', function(assert) { + let transform = new DS.StringTransform(); + + assert.strictEqual(transform.deserialize(null), null); + assert.strictEqual(transform.deserialize(undefined), null); + + assert.equal(transform.deserialize('foo'), 'foo'); + assert.equal(transform.deserialize(1), '1'); +}); diff --git a/tests/unit/utils-test.js b/tests/unit/utils-test.js new file mode 100644 index 00000000000..09ea78a9b58 --- /dev/null +++ b/tests/unit/utils-test.js @@ -0,0 +1,151 @@ +import { run } from '@ember/runloop'; +import Mixin from '@ember/object/mixin'; +import setupStore from 'dummy/tests/helpers/store'; + +import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { module, test } from 'qunit'; + +import DS from 'ember-data'; +import Model from 'ember-data/model'; + +import { assertPolymorphicType } from 'ember-data/-debug'; +import { modelHasAttributeOrRelationshipNamedType } from 'ember-data/-private'; + +let env, User, Message, Post, Person, Video, Medium; + +module('unit/utils', { + beforeEach() { + Person = Model.extend(); + User = Model.extend({ + messages: DS.hasMany('message', { async: false }), + }); + + Message = Model.extend(); + Post = Message.extend({ + medias: DS.hasMany('medium', { async: false }), + }); + + Medium = Mixin.create(); + Video = Model.extend(Medium); + + env = setupStore({ + user: User, + person: Person, + message: Message, + post: Post, + video: Video, + }); + + env.owner.register('mixin:medium', Medium); + }, + + afterEach() { + run(env.container, 'destroy'); + }, +}); + +testInDebug('assertPolymorphicType works for subclasses', function(assert) { + let user, post, person; + + run(() => { + env.store.push({ + data: [ + { + type: 'user', + id: '1', + relationships: { + messages: { + data: [], + }, + }, + }, + { + type: 'post', + id: '1', + }, + { + type: 'person', + id: '1', + }, + ], + }); + + user = env.store.peekRecord('user', 1); + post = env.store.peekRecord('post', 1); + person = env.store.peekRecord('person', 1); + }); + + let relationship = user.relationshipFor('messages'); + user = user._internalModel; + post = post._internalModel; + person = person._internalModel; + + try { + assertPolymorphicType(user, relationship, post, env.store); + } catch (e) { + assert.ok(false, 'should not throw an error'); + } + + assert.expectAssertion(() => { + assertPolymorphicType(user, relationship, person, env.store); + }, "The 'person' type does not implement 'message' and thus cannot be assigned to the 'messages' relationship in 'user'. Make it a descendant of 'message' or use a mixin of the same name."); +}); + +test('modelHasAttributeOrRelationshipNamedType', function(assert) { + let ModelWithTypeAttribute = Model.extend({ + type: DS.attr(), + }); + let ModelWithTypeBelongsTo = Model.extend({ + type: DS.belongsTo(), + }); + let ModelWithTypeHasMany = Model.extend({ + type: DS.hasMany(), + }); + + assert.equal(modelHasAttributeOrRelationshipNamedType(Model), false); + + assert.equal(modelHasAttributeOrRelationshipNamedType(ModelWithTypeAttribute), true); + assert.equal(modelHasAttributeOrRelationshipNamedType(ModelWithTypeBelongsTo), true); + assert.equal(modelHasAttributeOrRelationshipNamedType(ModelWithTypeHasMany), true); +}); + +testInDebug('assertPolymorphicType works for mixins', function(assert) { + let post, video, person; + + run(() => { + env.store.push({ + data: [ + { + type: 'post', + id: '1', + }, + { + type: 'video', + id: '1', + }, + { + type: 'person', + id: '1', + }, + ], + }); + post = env.store.peekRecord('post', 1); + video = env.store.peekRecord('video', 1); + person = env.store.peekRecord('person', 1); + }); + + let relationship = post.relationshipFor('medias'); + post = post._internalModel; + video = video._internalModel; + person = person._internalModel; + + try { + assertPolymorphicType(post, relationship, video, env.store); + } catch (e) { + assert.ok(false, 'should not throw an error'); + } + + assert.expectAssertion(() => { + assertPolymorphicType(post, relationship, person, env.store); + }, "The 'person' type does not implement 'medium' and thus cannot be assigned to the 'medias' relationship in 'post'. Make it a descendant of 'medium' or use a mixin of the same name."); +}); diff --git a/tests/unit/utils/parse-response-headers-test.js b/tests/unit/utils/parse-response-headers-test.js new file mode 100644 index 00000000000..20e8801953c --- /dev/null +++ b/tests/unit/utils/parse-response-headers-test.js @@ -0,0 +1,126 @@ +import { parseResponseHeaders } from 'ember-data/-private'; +import { module, test } from 'qunit'; + +const CRLF = '\u000d\u000a'; +const LF = '\u000a'; + +module('unit/adapters/parse-response-headers'); + +test('returns an NULL Object when headersString is undefined', function(assert) { + let headers = parseResponseHeaders(undefined); + + assert.deepEqual(headers, Object.create(null), 'NULL Object is returned'); +}); + +test('header parsing', function(assert) { + let headersString = [ + 'Content-Encoding: gzip', + 'content-type: application/json; charset=utf-8', + 'date: Fri, 05 Feb 2016 21:47:56 GMT', + ].join(CRLF); + + let headers = parseResponseHeaders(headersString); + + assert.equal(headers['content-encoding'], 'gzip', 'parses basic header pair'); + assert.equal( + headers['content-type'], + 'application/json; charset=utf-8', + 'parses header with complex value' + ); + assert.equal(headers['date'], 'Fri, 05 Feb 2016 21:47:56 GMT', 'parses header with date value'); +}); + +test('field-name parsing', function(assert) { + let headersString = [ + ' name-with-leading-whitespace: some value', + 'name-with-whitespace-before-colon : another value', + 'Uppercase-Name: yet another value', + ].join(CRLF); + + let headers = parseResponseHeaders(headersString); + + assert.equal( + headers['name-with-leading-whitespace'], + 'some value', + 'strips leading whitespace from field-name' + ); + assert.equal( + headers['name-with-whitespace-before-colon'], + 'another value', + 'strips whitespace before colon from field-name' + ); + assert.equal(headers['uppercase-name'], 'yet another value', 'lowercases the field-name'); +}); + +test('field-value parsing', function(assert) { + let headersString = [ + 'value-with-leading-space: value with leading whitespace', + 'value-without-leading-space:value without leading whitespace', + 'value-with-colon: value with: a colon', + 'value-with-trailing-whitespace: banana ', + ].join(CRLF); + + let headers = parseResponseHeaders(headersString); + + assert.equal( + headers['value-with-leading-space'], + 'value with leading whitespace', + 'strips leading whitespace in field-value' + ); + assert.equal( + headers['value-without-leading-space'], + 'value without leading whitespace', + 'works without leaading whitespace in field-value' + ); + assert.equal( + headers['value-with-colon'], + 'value with: a colon', + 'has correct value when value contains a colon' + ); + assert.equal( + headers['value-with-trailing-whitespace'], + 'banana', + 'strips trailing whitespace from field-value' + ); +}); +('\r\nfoo: bar'); + +test('ignores headers that do not contain a colon', function(assert) { + let headersString = [ + 'Content-Encoding: gzip', + 'I am ignored because I do not contain a colon', + 'apple: pie', + ].join(CRLF); + + let headers = parseResponseHeaders(headersString); + + assert.deepEqual(headers['content-encoding'], 'gzip', 'parses basic header pair'); + assert.deepEqual(headers['apple'], 'pie', 'parses basic header pair'); + assert.equal(Object.keys(headers).length, 3, 'only has the three valid headers'); +}); + +test('tollerate extra new-lines', function(assert) { + let headersString = CRLF + 'foo: bar'; + let headers = parseResponseHeaders(headersString); + + assert.deepEqual(headers['foo'], 'bar', 'parses basic header pair'); + assert.equal(Object.keys(headers).length, 1, 'only has the one valid header'); +}); + +test('works with only line feeds', function(assert) { + let headersString = [ + 'Content-Encoding: gzip', + 'content-type: application/json; charset=utf-8', + 'date: Fri, 05 Feb 2016 21:47:56 GMT', + ].join(LF); + + let headers = parseResponseHeaders(headersString); + + assert.equal(headers['Content-Encoding'], 'gzip', 'parses basic header pair'); + assert.equal( + headers['content-type'], + 'application/json; charset=utf-8', + 'parses header with complex value' + ); + assert.equal(headers['date'], 'Fri, 05 Feb 2016 21:47:56 GMT', 'parses header with date value'); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000000..aec3c076a4b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,36 @@ +{ + "compilerOptions": { + "target": "es2017", + "allowJs": true, + "moduleResolution": "node", + "allowSyntheticDefaultImports": true, + "noImplicitAny": false, + "noEmitOnError": false, + "strictNullChecks": true, + "experimentalDecorators": true, + "noEmit": true, + "skipLibCheck": true, + "inlineSourceMap": true, + "inlineSources": true, + "baseUrl": ".", + "module": "esnext", + "paths": { + "dummy/tests/*": ["tests/*"], + "dummy/*": ["tests/dummy/app/*", "app/*"], + "ember-data": ["addon"], + "ember-data/*": ["addon/*"], + "ember-data/test-support": ["addon-test-support"], + "ember-data/test-support/*": ["addon-test-support/*"], + "*": ["types/*"] + } + }, + "include": [ + "app/**/*", + "addon/**/*", + "tests/**/*", + "types/**/*", + "test-support/**/*", + "addon-test-support/**/*" + ], + "exclude": ["node_modules"] +} diff --git a/types/dummy/index.d.ts b/types/dummy/index.d.ts new file mode 100644 index 00000000000..5ff2c23a180 --- /dev/null +++ b/types/dummy/index.d.ts @@ -0,0 +1,24 @@ +/** + * Any types defined here are only for the purposes of building and testing + * ember-data. They will not be shipped to consumers. Ember-data still relies + * on some private Ember APIs -- those should be defined here as we encounter them. + */ + +// Heimdall is TS now, we should be able to make this +// not suck +type TCounterToken = number; +type TTimerToken = number; + +interface ICounterDict { + [counterName: string]: TCounterToken; +} + +interface IHeimdall { + registerMonitor(...counterNames: string[]): ICounterDict; + increment(counter: TCounterToken): void; + start(timerLabel: string): TTimerToken; + stop(token: TTimerToken): void; +} + +// hrm :/ +declare const heimdall: IHeimdall; diff --git a/vendor/.gitkeep b/vendor/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 00000000000..669b54139e4 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,8910 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@babel/code-frame@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8" + integrity sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA== + dependencies: + "@babel/highlight" "^7.0.0" + +"@babel/core@^7.0.0", "@babel/core@^7.3.3": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/core/-/core-7.3.4.tgz#921a5a13746c21e32445bf0798680e9d11a6530b" + integrity sha512-jRsuseXBo9pN197KnDwhhaaBzyZr2oIcLHHTt2oDdQrej5Qp57dCCJafWx5ivU8/alEYDpssYqv1MUqcxwQlrA== + dependencies: + "@babel/code-frame" "^7.0.0" + "@babel/generator" "^7.3.4" + "@babel/helpers" "^7.2.0" + "@babel/parser" "^7.3.4" + "@babel/template" "^7.2.2" + "@babel/traverse" "^7.3.4" + "@babel/types" "^7.3.4" + convert-source-map "^1.1.0" + debug "^4.1.0" + json5 "^2.1.0" + lodash "^4.17.11" + resolve "^1.3.2" + semver "^5.4.1" + source-map "^0.5.0" + +"@babel/generator@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/generator/-/generator-7.3.4.tgz#9aa48c1989257877a9d971296e5b73bfe72e446e" + integrity sha512-8EXhHRFqlVVWXPezBW5keTiQi/rJMQTg/Y9uVCEZ0CAF3PKtCCaVRnp64Ii1ujhkoDhhF1fVsImoN4yJ2uz4Wg== + dependencies: + "@babel/types" "^7.3.4" + jsesc "^2.5.1" + lodash "^4.17.11" + source-map "^0.5.0" + trim-right "^1.0.1" + +"@babel/helper-annotate-as-pure@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32" + integrity sha512-3UYcJUj9kvSLbLbUIfQTqzcy5VX7GRZ/CCDrnOaZorFFM01aXp1+GJwuFGV4NDDoAS+mOUyHcO6UD/RfqOks3Q== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-builder-binary-assignment-operator-visitor@^7.1.0": + version "7.1.0" + resolved "https://registry.npmjs.org/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.1.0.tgz#6b69628dfe4087798e0c4ed98e3d4a6b2fbd2f5f" + integrity sha512-qNSR4jrmJ8M1VMM9tibvyRAHXQs2PmaksQF7c1CGJNipfe3D8p+wgNwgso/P2A2r2mdgBWAXljNWR0QRZAMW8w== + dependencies: + "@babel/helper-explode-assignable-expression" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-call-delegate@^7.1.0": + version "7.1.0" + resolved "https://registry.npmjs.org/@babel/helper-call-delegate/-/helper-call-delegate-7.1.0.tgz#6a957f105f37755e8645343d3038a22e1449cc4a" + integrity sha512-YEtYZrw3GUK6emQHKthltKNZwszBcHK58Ygcis+gVUrF4/FmTVr5CCqQNSfmvg2y+YDEANyYoaLz/SHsnusCwQ== + dependencies: + "@babel/helper-hoist-variables" "^7.0.0" + "@babel/traverse" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-create-class-features-plugin@^7.3.0", "@babel/helper-create-class-features-plugin@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.3.4.tgz#092711a7a3ad8ea34de3e541644c2ce6af1f6f0c" + integrity sha512-uFpzw6L2omjibjxa8VGZsJUPL5wJH0zzGKpoz0ccBkzIa6C8kWNUbiBmQ0rgOKWlHJ6qzmfa6lTiGchiV8SC+g== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-member-expression-to-functions" "^7.0.0" + "@babel/helper-optimise-call-expression" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-replace-supers" "^7.3.4" + "@babel/helper-split-export-declaration" "^7.0.0" + +"@babel/helper-define-map@^7.1.0": + version "7.1.0" + resolved "https://registry.npmjs.org/@babel/helper-define-map/-/helper-define-map-7.1.0.tgz#3b74caec329b3c80c116290887c0dd9ae468c20c" + integrity sha512-yPPcW8dc3gZLN+U1mhYV91QU3n5uTbx7DUdf8NnPbjS0RMwBuHi9Xt2MUgppmNz7CJxTBWsGczTiEp1CSOTPRg== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/types" "^7.0.0" + lodash "^4.17.10" + +"@babel/helper-explode-assignable-expression@^7.1.0": + version "7.1.0" + resolved "https://registry.npmjs.org/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.1.0.tgz#537fa13f6f1674df745b0c00ec8fe4e99681c8f6" + integrity sha512-NRQpfHrJ1msCHtKjbzs9YcMmJZOg6mQMmGRB+hbamEdG5PNpaSm95275VD92DvJKuyl0s2sFiDmMZ+EnnvufqA== + dependencies: + "@babel/traverse" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-function-name@^7.1.0": + version "7.1.0" + resolved "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.1.0.tgz#a0ceb01685f73355d4360c1247f582bfafc8ff53" + integrity sha512-A95XEoCpb3TO+KZzJ4S/5uW5fNe26DjBGqf1o9ucyLyCmi1dXq/B3c8iaWTfBk3VvetUxl16e8tIrd5teOCfGw== + dependencies: + "@babel/helper-get-function-arity" "^7.0.0" + "@babel/template" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-get-function-arity@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz#83572d4320e2a4657263734113c42868b64e49c3" + integrity sha512-r2DbJeg4svYvt3HOS74U4eWKsUAMRH01Z1ds1zx8KNTPtpTL5JAsdFv8BNyOpVqdFhHkkRDIg5B4AsxmkjAlmQ== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-hoist-variables@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.0.0.tgz#46adc4c5e758645ae7a45deb92bab0918c23bb88" + integrity sha512-Ggv5sldXUeSKsuzLkddtyhyHe2YantsxWKNi7A+7LeD12ExRDWTRk29JCXpaHPAbMaIPZSil7n+lq78WY2VY7w== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-member-expression-to-functions@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.0.0.tgz#8cd14b0a0df7ff00f009e7d7a436945f47c7a16f" + integrity sha512-avo+lm/QmZlv27Zsi0xEor2fKcqWG56D5ae9dzklpIaY7cQMK5N8VSpaNVPPagiqmy7LrEjK1IWdGMOqPu5csg== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-module-imports@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d" + integrity sha512-aP/hlLq01DWNEiDg4Jn23i+CXxW/owM4WpDLFUbpjxe4NS3BhLVZQ5i7E0ZrxuQ/vwekIeciyamgB1UIYxxM6A== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-module-transforms@^7.1.0": + version "7.2.2" + resolved "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.2.2.tgz#ab2f8e8d231409f8370c883d20c335190284b963" + integrity sha512-YRD7I6Wsv+IHuTPkAmAS4HhY0dkPobgLftHp0cRGZSdrRvmZY8rFvae/GVu3bD00qscuvK3WPHB3YdNpBXUqrA== + dependencies: + "@babel/helper-module-imports" "^7.0.0" + "@babel/helper-simple-access" "^7.1.0" + "@babel/helper-split-export-declaration" "^7.0.0" + "@babel/template" "^7.2.2" + "@babel/types" "^7.2.2" + lodash "^4.17.10" + +"@babel/helper-optimise-call-expression@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.0.0.tgz#a2920c5702b073c15de51106200aa8cad20497d5" + integrity sha512-u8nd9NQePYNQV8iPWu/pLLYBqZBa4ZaY1YWRFMuxrid94wKI1QNt67NEZ7GAe5Kc/0LLScbim05xZFWkAdrj9g== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-plugin-utils@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250" + integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA== + +"@babel/helper-regex@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/helper-regex/-/helper-regex-7.0.0.tgz#2c1718923b57f9bbe64705ffe5640ac64d9bdb27" + integrity sha512-TR0/N0NDCcUIUEbqV6dCO+LptmmSQFQ7q70lfcEB4URsjD0E1HzicrwUH+ap6BAQ2jhCX9Q4UqZy4wilujWlkg== + dependencies: + lodash "^4.17.10" + +"@babel/helper-remap-async-to-generator@^7.1.0": + version "7.1.0" + resolved "https://registry.npmjs.org/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.1.0.tgz#361d80821b6f38da75bd3f0785ece20a88c5fe7f" + integrity sha512-3fOK0L+Fdlg8S5al8u/hWE6vhufGSn0bN09xm2LXMy//REAF8kDCrYoOBKYmA8m5Nom+sV9LyLCwrFynA8/slg== + dependencies: + "@babel/helper-annotate-as-pure" "^7.0.0" + "@babel/helper-wrap-function" "^7.1.0" + "@babel/template" "^7.1.0" + "@babel/traverse" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-replace-supers@^7.1.0", "@babel/helper-replace-supers@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.3.4.tgz#a795208e9b911a6eeb08e5891faacf06e7013e13" + integrity sha512-pvObL9WVf2ADs+ePg0jrqlhHoxRXlOa+SHRHzAXIz2xkYuOHfGl+fKxPMaS4Fq+uje8JQPobnertBBvyrWnQ1A== + dependencies: + "@babel/helper-member-expression-to-functions" "^7.0.0" + "@babel/helper-optimise-call-expression" "^7.0.0" + "@babel/traverse" "^7.3.4" + "@babel/types" "^7.3.4" + +"@babel/helper-simple-access@^7.1.0": + version "7.1.0" + resolved "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.1.0.tgz#65eeb954c8c245beaa4e859da6188f39d71e585c" + integrity sha512-Vk+78hNjRbsiu49zAPALxTb+JUQCz1aolpd8osOF16BGnLtseD21nbHgLPGUwrXEurZgiCOUmvs3ExTu4F5x6w== + dependencies: + "@babel/template" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-split-export-declaration@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz#3aae285c0311c2ab095d997b8c9a94cad547d813" + integrity sha512-MXkOJqva62dfC0w85mEf/LucPPS/1+04nmmRMPEBUB++hiiThQ2zPtX/mEWQ3mtzCEjIJvPY8nuwxXtQeQwUag== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-wrap-function@^7.1.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/helper-wrap-function/-/helper-wrap-function-7.2.0.tgz#c4e0012445769e2815b55296ead43a958549f6fa" + integrity sha512-o9fP1BZLLSrYlxYEYyl2aS+Flun5gtjTIG8iln+XuEzQTs0PLagAGSXUcqruJwD5fM48jzIEggCKpIfWTcR7pQ== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/template" "^7.1.0" + "@babel/traverse" "^7.1.0" + "@babel/types" "^7.2.0" + +"@babel/helpers@^7.2.0": + version "7.3.1" + resolved "https://registry.npmjs.org/@babel/helpers/-/helpers-7.3.1.tgz#949eec9ea4b45d3210feb7dc1c22db664c9e44b9" + integrity sha512-Q82R3jKsVpUV99mgX50gOPCWwco9Ec5Iln/8Vyu4osNIOQgSrd9RFrQeUvmvddFNoLwMyOUWU+5ckioEKpDoGA== + dependencies: + "@babel/template" "^7.1.2" + "@babel/traverse" "^7.1.5" + "@babel/types" "^7.3.0" + +"@babel/highlight@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz#f710c38c8d458e6dd9a201afb637fcb781ce99e4" + integrity sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw== + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^4.0.0" + +"@babel/parser@^7.0.0", "@babel/parser@^7.2.2", "@babel/parser@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.3.4.tgz#a43357e4bbf4b92a437fb9e465c192848287f27c" + integrity sha512-tXZCqWtlOOP4wgCp6RjRvLmfuhnqTLy9VHwRochJBCP2nDm27JnnuFEnXFASVyQNHk36jD1tAammsCEEqgscIQ== + +"@babel/plugin-proposal-async-generator-functions@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz#b289b306669dce4ad20b0252889a15768c9d417e" + integrity sha512-+Dfo/SCQqrwx48ptLVGLdE39YtWRuKc/Y9I5Fy0P1DDBB9lsAHpjcEJQt+4IifuSOSTLBKJObJqMvaO1pIE8LQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-remap-async-to-generator" "^7.1.0" + "@babel/plugin-syntax-async-generators" "^7.2.0" + +"@babel/plugin-proposal-class-properties@^7.1.0": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.3.4.tgz#410f5173b3dc45939f9ab30ca26684d72901405e" + integrity sha512-lUf8D3HLs4yYlAo8zjuneLvfxN7qfKv1Yzbj5vjqaqMJxgJA3Ipwp4VUJ+OrOdz53Wbww6ahwB8UhB2HQyLotA== + dependencies: + "@babel/helper-create-class-features-plugin" "^7.3.4" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-proposal-decorators@^7.1.2": + version "7.3.0" + resolved "https://registry.npmjs.org/@babel/plugin-proposal-decorators/-/plugin-proposal-decorators-7.3.0.tgz#637ba075fa780b1f75d08186e8fb4357d03a72a7" + integrity sha512-3W/oCUmsO43FmZIqermmq6TKaRSYhmh/vybPfVFwQWdSb8xwki38uAIvknCRzuyHRuYfCYmJzL9or1v0AffPjg== + dependencies: + "@babel/helper-create-class-features-plugin" "^7.3.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-decorators" "^7.2.0" + +"@babel/plugin-proposal-json-strings@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-proposal-json-strings/-/plugin-proposal-json-strings-7.2.0.tgz#568ecc446c6148ae6b267f02551130891e29f317" + integrity sha512-MAFV1CA/YVmYwZG0fBQyXhmj0BHCB5egZHCKWIFVv/XCxAeVGIHfos3SwDck4LvCllENIAg7xMKOG5kH0dzyUg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-json-strings" "^7.2.0" + +"@babel/plugin-proposal-object-rest-spread@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.3.4.tgz#47f73cf7f2a721aad5c0261205405c642e424654" + integrity sha512-j7VQmbbkA+qrzNqbKHrBsW3ddFnOeva6wzSe/zB7T+xaxGc+RCpwo44wCmRixAIGRoIpmVgvzFzNJqQcO3/9RA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-object-rest-spread" "^7.2.0" + +"@babel/plugin-proposal-optional-catch-binding@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.2.0.tgz#135d81edb68a081e55e56ec48541ece8065c38f5" + integrity sha512-mgYj3jCcxug6KUcX4OBoOJz3CMrwRfQELPQ5560F70YQUBZB7uac9fqaWamKR1iWUzGiK2t0ygzjTScZnVz75g== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-optional-catch-binding" "^7.2.0" + +"@babel/plugin-proposal-unicode-property-regex@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.2.0.tgz#abe7281fe46c95ddc143a65e5358647792039520" + integrity sha512-LvRVYb7kikuOtIoUeWTkOxQEV1kYvL5B6U3iWEGCzPNRus1MzJweFqORTj+0jkxozkTSYNJozPOddxmqdqsRpw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.0.0" + regexpu-core "^4.2.0" + +"@babel/plugin-syntax-async-generators@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.2.0.tgz#69e1f0db34c6f5a0cf7e2b3323bf159a76c8cb7f" + integrity sha512-1ZrIRBv2t0GSlcwVoQ6VgSLpLgiN/FVQUzt9znxo7v2Ov4jJrs8RY8tv0wvDmFN3qIdMKWrmMMW6yZ0G19MfGg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-decorators@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-syntax-decorators/-/plugin-syntax-decorators-7.2.0.tgz#c50b1b957dcc69e4b1127b65e1c33eef61570c1b" + integrity sha512-38QdqVoXdHUQfTpZo3rQwqQdWtCn5tMv4uV6r2RMfTqNBuv4ZBhz79SfaQWKTVmxHjeFv/DnXVC/+agHCklYWA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-json-strings@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.2.0.tgz#72bd13f6ffe1d25938129d2a186b11fd62951470" + integrity sha512-5UGYnMSLRE1dqqZwug+1LISpA403HzlSfsg6P9VXU6TBjcSHeNlw4DxDx7LgpF+iKZoOG/+uzqoRHTdcUpiZNg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-object-rest-spread@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz#3b7a3e733510c57e820b9142a6579ac8b0dfad2e" + integrity sha512-t0JKGgqk2We+9may3t0xDdmneaXmyxq0xieYcKHxIsrJO64n1OiMWNUtc5gQK1PA0NpdCRrtZp4z+IUaKugrSA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-optional-catch-binding@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-syntax-optional-catch-binding/-/plugin-syntax-optional-catch-binding-7.2.0.tgz#a94013d6eda8908dfe6a477e7f9eda85656ecf5c" + integrity sha512-bDe4xKNhb0LI7IvZHiA13kff0KEfaGX/Hv4lMA9+7TEc63hMNvfKo6ZFpXhKuEp+II/q35Gc4NoMeDZyaUbj9w== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-typescript@^7.2.0": + version "7.3.3" + resolved "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.3.3.tgz#a7cc3f66119a9f7ebe2de5383cce193473d65991" + integrity sha512-dGwbSMA1YhVS8+31CnPR7LB4pcbrzcV99wQzby4uAfrkZPYZlQ7ImwdpzLqi6Z6IL02b8IAL379CaMwo0x5Lag== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-arrow-functions@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.2.0.tgz#9aeafbe4d6ffc6563bf8f8372091628f00779550" + integrity sha512-ER77Cax1+8/8jCB9fo4Ud161OZzWN5qawi4GusDuRLcDbDG+bIGYY20zb2dfAFdTRGzrfq2xZPvF0R64EHnimg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-async-to-generator@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.3.4.tgz#4e45408d3c3da231c0e7b823f407a53a7eb3048c" + integrity sha512-Y7nCzv2fw/jEZ9f678MuKdMo99MFDJMT/PvD9LisrR5JDFcJH6vYeH6RnjVt3p5tceyGRvTtEN0VOlU+rgHZjA== + dependencies: + "@babel/helper-module-imports" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-remap-async-to-generator" "^7.1.0" + +"@babel/plugin-transform-block-scoped-functions@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.2.0.tgz#5d3cc11e8d5ddd752aa64c9148d0db6cb79fd190" + integrity sha512-ntQPR6q1/NKuphly49+QiQiTN0O63uOwjdD6dhIjSWBI5xlrbUFh720TIpzBhpnrLfv2tNH/BXvLIab1+BAI0w== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-block-scoping@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.3.4.tgz#5c22c339de234076eee96c8783b2fed61202c5c4" + integrity sha512-blRr2O8IOZLAOJklXLV4WhcEzpYafYQKSGT3+R26lWG41u/FODJuBggehtOwilVAcFu393v3OFj+HmaE6tVjhA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + lodash "^4.17.11" + +"@babel/plugin-transform-classes@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/plugin-transform-classes/-/plugin-transform-classes-7.3.4.tgz#dc173cb999c6c5297e0b5f2277fdaaec3739d0cc" + integrity sha512-J9fAvCFBkXEvBimgYxCjvaVDzL6thk0j0dBvCeZmIUDBwyt+nv6HfbImsSrWsYXfDNDivyANgJlFXDUWRTZBuA== + dependencies: + "@babel/helper-annotate-as-pure" "^7.0.0" + "@babel/helper-define-map" "^7.1.0" + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-optimise-call-expression" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-replace-supers" "^7.3.4" + "@babel/helper-split-export-declaration" "^7.0.0" + globals "^11.1.0" + +"@babel/plugin-transform-computed-properties@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.2.0.tgz#83a7df6a658865b1c8f641d510c6f3af220216da" + integrity sha512-kP/drqTxY6Xt3NNpKiMomfgkNn4o7+vKxK2DDKcBG9sHj51vHqMBGy8wbDS/J4lMxnqs153/T3+DmCEAkC5cpA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-destructuring@^7.2.0": + version "7.3.2" + resolved "https://registry.npmjs.org/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.3.2.tgz#f2f5520be055ba1c38c41c0e094d8a461dd78f2d" + integrity sha512-Lrj/u53Ufqxl/sGxyjsJ2XNtNuEjDyjpqdhMNh5aZ+XFOdThL46KBj27Uem4ggoezSYBxKWAil6Hu8HtwqesYw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-dotall-regex@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.2.0.tgz#f0aabb93d120a8ac61e925ea0ba440812dbe0e49" + integrity sha512-sKxnyHfizweTgKZf7XsXu/CNupKhzijptfTM+bozonIuyVrLWVUvYjE2bhuSBML8VQeMxq4Mm63Q9qvcvUcciQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.0.0" + regexpu-core "^4.1.3" + +"@babel/plugin-transform-duplicate-keys@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.2.0.tgz#d952c4930f312a4dbfff18f0b2914e60c35530b3" + integrity sha512-q+yuxW4DsTjNceUiTzK0L+AfQ0zD9rWaTLiUqHA8p0gxx7lu1EylenfzjeIWNkPy6e/0VG/Wjw9uf9LueQwLOw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-exponentiation-operator@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.2.0.tgz#a63868289e5b4007f7054d46491af51435766008" + integrity sha512-umh4hR6N7mu4Elq9GG8TOu9M0bakvlsREEC+ialrQN6ABS4oDQ69qJv1VtR3uxlKMCQMCvzk7vr17RHKcjx68A== + dependencies: + "@babel/helper-builder-binary-assignment-operator-visitor" "^7.1.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-for-of@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.2.0.tgz#ab7468befa80f764bb03d3cb5eef8cc998e1cad9" + integrity sha512-Kz7Mt0SsV2tQk6jG5bBv5phVbkd0gd27SgYD4hH1aLMJRchM0dzHaXvrWhVZ+WxAlDoAKZ7Uy3jVTW2mKXQ1WQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-function-name@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-function-name/-/plugin-transform-function-name-7.2.0.tgz#f7930362829ff99a3174c39f0afcc024ef59731a" + integrity sha512-kWgksow9lHdvBC2Z4mxTsvc7YdY7w/V6B2vy9cTIPtLEE9NhwoWivaxdNM/S37elu5bqlLP/qOY906LukO9lkQ== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-literals@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-literals/-/plugin-transform-literals-7.2.0.tgz#690353e81f9267dad4fd8cfd77eafa86aba53ea1" + integrity sha512-2ThDhm4lI4oV7fVQ6pNNK+sx+c/GM5/SaML0w/r4ZB7sAneD/piDJtwdKlNckXeyGK7wlwg2E2w33C/Hh+VFCg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-modules-amd@^7.0.0", "@babel/plugin-transform-modules-amd@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.2.0.tgz#82a9bce45b95441f617a24011dc89d12da7f4ee6" + integrity sha512-mK2A8ucqz1qhrdqjS9VMIDfIvvT2thrEsIQzbaTdc5QFzhDjQv2CkJJ5f6BXIkgbmaoax3zBr2RyvV/8zeoUZw== + dependencies: + "@babel/helper-module-transforms" "^7.1.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-modules-commonjs@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.2.0.tgz#c4f1933f5991d5145e9cfad1dfd848ea1727f404" + integrity sha512-V6y0uaUQrQPXUrmj+hgnks8va2L0zcZymeU7TtWEgdRLNkceafKXEduv7QzgQAE4lT+suwooG9dC7LFhdRAbVQ== + dependencies: + "@babel/helper-module-transforms" "^7.1.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-simple-access" "^7.1.0" + +"@babel/plugin-transform-modules-systemjs@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.3.4.tgz#813b34cd9acb6ba70a84939f3680be0eb2e58861" + integrity sha512-VZ4+jlGOF36S7TjKs8g4ojp4MEI+ebCQZdswWb/T9I4X84j8OtFAyjXjt/M16iIm5RIZn0UMQgg/VgIwo/87vw== + dependencies: + "@babel/helper-hoist-variables" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-modules-umd@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-modules-umd/-/plugin-transform-modules-umd-7.2.0.tgz#7678ce75169f0877b8eb2235538c074268dd01ae" + integrity sha512-BV3bw6MyUH1iIsGhXlOK6sXhmSarZjtJ/vMiD9dNmpY8QXFFQTj+6v92pcfy1iqa8DeAfJFwoxcrS/TUZda6sw== + dependencies: + "@babel/helper-module-transforms" "^7.1.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-named-capturing-groups-regex@^7.3.0": + version "7.3.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.3.0.tgz#140b52985b2d6ef0cb092ef3b29502b990f9cd50" + integrity sha512-NxIoNVhk9ZxS+9lSoAQ/LM0V2UEvARLttEHUrRDGKFaAxOYQcrkN/nLRE+BbbicCAvZPl7wMP0X60HsHE5DtQw== + dependencies: + regexp-tree "^0.1.0" + +"@babel/plugin-transform-new-target@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-new-target/-/plugin-transform-new-target-7.0.0.tgz#ae8fbd89517fa7892d20e6564e641e8770c3aa4a" + integrity sha512-yin069FYjah+LbqfGeTfzIBODex/e++Yfa0rH0fpfam9uTbuEeEOx5GLGr210ggOV77mVRNoeqSYqeuaqSzVSw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-object-super@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.2.0.tgz#b35d4c10f56bab5d650047dad0f1d8e8814b6598" + integrity sha512-VMyhPYZISFZAqAPVkiYb7dUe2AsVi2/wCT5+wZdsNO31FojQJa9ns40hzZ6U9f50Jlq4w6qwzdBB2uwqZ00ebg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-replace-supers" "^7.1.0" + +"@babel/plugin-transform-parameters@^7.2.0": + version "7.3.3" + resolved "https://registry.npmjs.org/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.3.3.tgz#3a873e07114e1a5bee17d04815662c8317f10e30" + integrity sha512-IrIP25VvXWu/VlBWTpsjGptpomtIkYrN/3aDp4UKm7xK6UxZY88kcJ1UwETbzHAlwN21MnNfwlar0u8y3KpiXw== + dependencies: + "@babel/helper-call-delegate" "^7.1.0" + "@babel/helper-get-function-arity" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-regenerator@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.3.4.tgz#1601655c362f5b38eead6a52631f5106b29fa46a" + integrity sha512-hvJg8EReQvXT6G9H2MvNPXkv9zK36Vxa1+csAVTpE1J3j0zlHplw76uudEbJxgvqZzAq9Yh45FLD4pk5mKRFQA== + dependencies: + regenerator-transform "^0.13.4" + +"@babel/plugin-transform-runtime@^7.2.0": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.3.4.tgz#57805ac8c1798d102ecd75c03b024a5b3ea9b431" + integrity sha512-PaoARuztAdd5MgeVjAxnIDAIUet5KpogqaefQvPOmPYCxYoaPhautxDh3aO8a4xHsKgT/b9gSxR0BKK1MIewPA== + dependencies: + "@babel/helper-module-imports" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + resolve "^1.8.1" + semver "^5.5.1" + +"@babel/plugin-transform-shorthand-properties@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.2.0.tgz#6333aee2f8d6ee7e28615457298934a3b46198f0" + integrity sha512-QP4eUM83ha9zmYtpbnyjTLAGKQritA5XW/iG9cjtuOI8s1RuL/3V6a3DeSHfKutJQ+ayUfeZJPcnCYEQzaPQqg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-spread@^7.2.0": + version "7.2.2" + resolved "https://registry.npmjs.org/@babel/plugin-transform-spread/-/plugin-transform-spread-7.2.2.tgz#3103a9abe22f742b6d406ecd3cd49b774919b406" + integrity sha512-KWfky/58vubwtS0hLqEnrWJjsMGaOeSBn90Ezn5Jeg9Z8KKHmELbP1yGylMlm5N6TPKeY9A2+UaSYLdxahg01w== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-sticky-regex@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.2.0.tgz#a1e454b5995560a9c1e0d537dfc15061fd2687e1" + integrity sha512-KKYCoGaRAf+ckH8gEL3JHUaFVyNHKe3ASNsZ+AlktgHevvxGigoIttrEJb8iKN03Q7Eazlv1s6cx2B2cQ3Jabw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.0.0" + +"@babel/plugin-transform-template-literals@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.2.0.tgz#d87ed01b8eaac7a92473f608c97c089de2ba1e5b" + integrity sha512-FkPix00J9A/XWXv4VoKJBMeSkyY9x/TqIh76wzcdfl57RJJcf8CehQ08uwfhCDNtRQYtHQKBTwKZDEyjE13Lwg== + dependencies: + "@babel/helper-annotate-as-pure" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-typeof-symbol@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.2.0.tgz#117d2bcec2fbf64b4b59d1f9819894682d29f2b2" + integrity sha512-2LNhETWYxiYysBtrBTqL8+La0jIoQQnIScUJc74OYvUGRmkskNY4EzLCnjHBzdmb38wqtTaixpo1NctEcvMDZw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-typescript@^7.1.0", "@babel/plugin-transform-typescript@^7.2.0": + version "7.3.2" + resolved "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.3.2.tgz#59a7227163e55738842f043d9e5bd7c040447d96" + integrity sha512-Pvco0x0ZSCnexJnshMfaibQ5hnK8aUHSvjCQhC1JR8eeg+iBwt0AtCO7gWxJ358zZevuf9wPSO5rv+WJcbHPXQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-typescript" "^7.2.0" + +"@babel/plugin-transform-unicode-regex@^7.2.0": + version "7.2.0" + resolved "https://registry.npmjs.org/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.2.0.tgz#4eb8db16f972f8abb5062c161b8b115546ade08b" + integrity sha512-m48Y0lMhrbXEJnVUaYly29jRXbQ3ksxPrS1Tg8t+MHqzXhtBYAvI51euOBaoAlZLPHsieY9XPVMf80a5x0cPcA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.0.0" + regexpu-core "^4.1.3" + +"@babel/polyfill@^7.0.0": + version "7.2.5" + resolved "https://registry.npmjs.org/@babel/polyfill/-/polyfill-7.2.5.tgz#6c54b964f71ad27edddc567d065e57e87ed7fa7d" + integrity sha512-8Y/t3MWThtMLYr0YNC/Q76tqN1w30+b0uQMeFUYauG2UGTR19zyUtFrAzT23zNtBxPp+LbE5E/nwV/q/r3y6ug== + dependencies: + core-js "^2.5.7" + regenerator-runtime "^0.12.0" + +"@babel/preset-env@^7.0.0": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.3.4.tgz#887cf38b6d23c82f19b5135298bdb160062e33e1" + integrity sha512-2mwqfYMK8weA0g0uBKOt4FE3iEodiHy9/CW0b+nWXcbL+pGzLx8ESYc+j9IIxr6LTDHWKgPm71i9smo02bw+gA== + dependencies: + "@babel/helper-module-imports" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-proposal-async-generator-functions" "^7.2.0" + "@babel/plugin-proposal-json-strings" "^7.2.0" + "@babel/plugin-proposal-object-rest-spread" "^7.3.4" + "@babel/plugin-proposal-optional-catch-binding" "^7.2.0" + "@babel/plugin-proposal-unicode-property-regex" "^7.2.0" + "@babel/plugin-syntax-async-generators" "^7.2.0" + "@babel/plugin-syntax-json-strings" "^7.2.0" + "@babel/plugin-syntax-object-rest-spread" "^7.2.0" + "@babel/plugin-syntax-optional-catch-binding" "^7.2.0" + "@babel/plugin-transform-arrow-functions" "^7.2.0" + "@babel/plugin-transform-async-to-generator" "^7.3.4" + "@babel/plugin-transform-block-scoped-functions" "^7.2.0" + "@babel/plugin-transform-block-scoping" "^7.3.4" + "@babel/plugin-transform-classes" "^7.3.4" + "@babel/plugin-transform-computed-properties" "^7.2.0" + "@babel/plugin-transform-destructuring" "^7.2.0" + "@babel/plugin-transform-dotall-regex" "^7.2.0" + "@babel/plugin-transform-duplicate-keys" "^7.2.0" + "@babel/plugin-transform-exponentiation-operator" "^7.2.0" + "@babel/plugin-transform-for-of" "^7.2.0" + "@babel/plugin-transform-function-name" "^7.2.0" + "@babel/plugin-transform-literals" "^7.2.0" + "@babel/plugin-transform-modules-amd" "^7.2.0" + "@babel/plugin-transform-modules-commonjs" "^7.2.0" + "@babel/plugin-transform-modules-systemjs" "^7.3.4" + "@babel/plugin-transform-modules-umd" "^7.2.0" + "@babel/plugin-transform-named-capturing-groups-regex" "^7.3.0" + "@babel/plugin-transform-new-target" "^7.0.0" + "@babel/plugin-transform-object-super" "^7.2.0" + "@babel/plugin-transform-parameters" "^7.2.0" + "@babel/plugin-transform-regenerator" "^7.3.4" + "@babel/plugin-transform-shorthand-properties" "^7.2.0" + "@babel/plugin-transform-spread" "^7.2.0" + "@babel/plugin-transform-sticky-regex" "^7.2.0" + "@babel/plugin-transform-template-literals" "^7.2.0" + "@babel/plugin-transform-typeof-symbol" "^7.2.0" + "@babel/plugin-transform-unicode-regex" "^7.2.0" + browserslist "^4.3.4" + invariant "^2.2.2" + js-levenshtein "^1.1.3" + semver "^5.3.0" + +"@babel/runtime@^7.2.0": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.3.4.tgz#73d12ba819e365fcf7fd152aed56d6df97d21c83" + integrity sha512-IvfvnMdSaLBateu0jfsYIpZTxAc2cKEXEMiezGGN75QcBcecDUKd3PgLAncT0oOgxKy8dd8hrJKj9MfzgfZd6g== + dependencies: + regenerator-runtime "^0.12.0" + +"@babel/template@^7.1.0", "@babel/template@^7.1.2", "@babel/template@^7.2.2": + version "7.2.2" + resolved "https://registry.npmjs.org/@babel/template/-/template-7.2.2.tgz#005b3fdf0ed96e88041330379e0da9a708eb2907" + integrity sha512-zRL0IMM02AUDwghf5LMSSDEz7sBCO2YnNmpg3uWTZj/v1rcG2BmQUvaGU8GhU8BvfMh1k2KIAYZ7Ji9KXPUg7g== + dependencies: + "@babel/code-frame" "^7.0.0" + "@babel/parser" "^7.2.2" + "@babel/types" "^7.2.2" + +"@babel/traverse@^7.0.0", "@babel/traverse@^7.1.0", "@babel/traverse@^7.1.5", "@babel/traverse@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/traverse/-/traverse-7.3.4.tgz#1330aab72234f8dea091b08c4f8b9d05c7119e06" + integrity sha512-TvTHKp6471OYEcE/91uWmhR6PrrYywQntCHSaZ8CM8Vmp+pjAusal4nGB2WCCQd0rvI7nOMKn9GnbcvTUz3/ZQ== + dependencies: + "@babel/code-frame" "^7.0.0" + "@babel/generator" "^7.3.4" + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-split-export-declaration" "^7.0.0" + "@babel/parser" "^7.3.4" + "@babel/types" "^7.3.4" + debug "^4.1.0" + globals "^11.1.0" + lodash "^4.17.11" + +"@babel/types@^7.0.0", "@babel/types@^7.1.5", "@babel/types@^7.2.0", "@babel/types@^7.2.2", "@babel/types@^7.3.0", "@babel/types@^7.3.4": + version "7.3.4" + resolved "https://registry.npmjs.org/@babel/types/-/types-7.3.4.tgz#bf482eaeaffb367a28abbf9357a94963235d90ed" + integrity sha512-WEkp8MsLftM7O/ty580wAmZzN1nDmCACc5+jFzUt+GUFNNIi3LdRlueYz0YIlmJhlZx1QYDMZL5vdWCL0fNjFQ== + dependencies: + esutils "^2.0.2" + lodash "^4.17.11" + to-fast-properties "^2.0.0" + +"@cnakazawa/watch@^1.0.3": + version "1.0.3" + resolved "https://registry.npmjs.org/@cnakazawa/watch/-/watch-1.0.3.tgz#099139eaec7ebf07a27c1786a3ff64f39464d2ef" + integrity sha512-r5160ogAvGyHsal38Kux7YYtodEKOj89RGb28ht1jh3SJb08VwRwAKKJL0bGb04Zd/3r9FL3BFIc3bBidYffCA== + dependencies: + exec-sh "^0.3.2" + minimist "^1.2.0" + +"@ember-decorators/babel-transforms@^5.1.4": + version "5.1.4" + resolved "https://registry.npmjs.org/@ember-decorators/babel-transforms/-/babel-transforms-5.1.4.tgz#e26e0480425e4b6e43be75e24ba85103a02d5459" + integrity sha512-uawhQ7fVAaeUgL13aOyvchW77i3Gu1T1lSNf7ZGTRj4SZKIVHPC0HyNTNShd/YIdnTLdBlch0ybCj/2/KJ0mMA== + dependencies: + "@babel/plugin-proposal-class-properties" "^7.1.0" + "@babel/plugin-proposal-decorators" "^7.1.2" + ember-cli-babel-plugin-helpers "^1.0.0" + ember-cli-version-checker "^3.0.0" + +"@ember-decorators/component@^5.1.4": + version "5.1.4" + resolved "https://registry.npmjs.org/@ember-decorators/component/-/component-5.1.4.tgz#bb1fba00fc025366cf1f60252b76c07ac8b6fbbe" + integrity sha512-Pe4D/nN0vpRPq9tkeNuKVtWBjTorcqjwlgRHMiiLvzFTVA4LYATyLtRNRGJXNgW1RFn98kHUy7jLyN/EhYw6qg== + dependencies: + "@ember-decorators/utils" "^5.1.4" + ember-cli-babel "^7.1.3" + +"@ember-decorators/controller@^5.1.4": + version "5.1.4" + resolved "https://registry.npmjs.org/@ember-decorators/controller/-/controller-5.1.4.tgz#8dd322bccd81a97892979bd44c92c9aa9d4fe272" + integrity sha512-+NSxQCWM3I7VBCNRSR1W8JcGUNxS01XZaAP1DgQJO9NONNzHgskS3F/7NtZJxGc0Dao9mMiQ5XRPuVIsTVekQA== + dependencies: + "@ember-decorators/utils" "^5.1.4" + ember-cli-babel "^7.1.3" + ember-compatibility-helpers "^1.1.2" + +"@ember-decorators/data@^5.1.4": + version "5.1.4" + resolved "https://registry.npmjs.org/@ember-decorators/data/-/data-5.1.4.tgz#08e0fefe83ce855bcc5837bd8ea7feb5ecefb2ac" + integrity sha512-VKADr3MF6TobFgivKM8BaLIoFHuxgqR9Jtr5vY84TVEgUsTpbkx7xTYJRNWECzmY9hOJ7myqL/KH3mA+vrq3fw== + dependencies: + "@ember-decorators/utils" "^5.1.4" + ember-cli-babel "^7.1.3" + ember-compatibility-helpers "^1.1.2" + +"@ember-decorators/object@^5.1.4": + version "5.1.4" + resolved "https://registry.npmjs.org/@ember-decorators/object/-/object-5.1.4.tgz#41ea33864cf742b42e47b6d13b6edf8baa5e7b28" + integrity sha512-r3zFXUp8yuHHq+7XKLFvq+xAAap4JK9i8gDjuyu1eW8sxeAszn/3sK5b+l1LT9wSC9aALhYhAIBeNRjcan8APA== + dependencies: + "@ember-decorators/utils" "^5.1.4" + ember-cli-babel "^7.1.3" + ember-compatibility-helpers "^1.1.2" + +"@ember-decorators/service@^5.1.4": + version "5.1.4" + resolved "https://registry.npmjs.org/@ember-decorators/service/-/service-5.1.4.tgz#a42525245eff3fc327845bdbca4bb38f9e3a6663" + integrity sha512-7Lmh8DDe21BhDi5ZKGHHmijl+QwTFBeVLeD6UqDlO8XBwPstPIyVUPXdpSSvqjSxaXx8gj1vke356JAEGxiN9g== + dependencies: + "@ember-decorators/utils" "^5.1.4" + ember-cli-babel "^7.1.3" + ember-compatibility-helpers "^1.1.2" + +"@ember-decorators/utils@^5.1.4": + version "5.1.4" + resolved "https://registry.npmjs.org/@ember-decorators/utils/-/utils-5.1.4.tgz#e8a18e614b3bd282c548803fd5e94d49d8fbaeee" + integrity sha512-wWJwhVIG1xwY0PbyWx7GHIkEvqDejzJ6trHtHSsTjBhhLbBtQqJN3DCHe4IltCyvizhzusRiFrZJB1g+eWiXCA== + dependencies: + babel-plugin-debug-macros "^0.2.0" + ember-cli-babel "^7.1.3" + ember-cli-version-checker "^3.0.0" + ember-compatibility-helpers "^1.1.2" + semver "^5.6.0" + +"@ember/ordered-set@^2.0.3": + version "2.0.3" + resolved "https://registry.npmjs.org/@ember/ordered-set/-/ordered-set-2.0.3.tgz#2ac1ca73b3bd116063cae814898832ef434a57f9" + integrity sha512-F4yfVk6WMc4AUHxeZsC3CaKyTvO0qSZJy7WWHCFTlVDQw6vubn+FvnGdhzpN1F00EiXMI4Tv1tJdSquHcCnYrA== + dependencies: + ember-cli-babel "^6.16.0" + ember-compatibility-helpers "^1.1.1" + +"@ember/test-helpers@^1.5.0": + version "1.5.0" + resolved "https://registry.npmjs.org/@ember/test-helpers/-/test-helpers-1.5.0.tgz#a480181c412778294e317c256d04ca52e63c813a" + integrity sha512-RrS0O3VlDASMsI6v9nxUgO0k8EJGy1nzz/1HgiScbu8LbCpPj4Mp8S82yT/olXA3TShu7c/RfLZHjlN/iRW2OA== + dependencies: + broccoli-debug "^0.6.5" + broccoli-funnel "^2.0.2" + ember-assign-polyfill "^2.6.0" + ember-cli-babel "^7.4.3" + ember-cli-htmlbars-inline-precompile "^2.1.0" + +"@glimmer/di@^0.2.0": + version "0.2.1" + resolved "https://registry.npmjs.org/@glimmer/di/-/di-0.2.1.tgz#5286b6b32040232b751138f6d006130c728d4b3d" + integrity sha512-0D53YVuEgGdHfTl9LGWDZqVzGhn4cT0CXqyAuOYkKFLvqboJXz6SnkRhQNPhhA2hLVrPnvUz3+choQmPhHLGGQ== + +"@glimmer/env@^0.1.7": + version "0.1.7" + resolved "https://registry.npmjs.org/@glimmer/env/-/env-0.1.7.tgz#fd2d2b55a9029c6b37a6c935e8c8871ae70dfa07" + integrity sha1-/S0rVakCnGs3psk16MiHGucN+gc= + +"@glimmer/resolver@^0.4.1": + version "0.4.3" + resolved "https://registry.npmjs.org/@glimmer/resolver/-/resolver-0.4.3.tgz#b1baae5c3291b4621002ccf8d7870466097e841d" + integrity sha512-UhX6vlZbWRMq6pCquSC3wfWLM9kO0PhQPD1dZ3XnyZkmsvEE94Cq+EncA9JalUuevKoJrfUFRvrZ0xaz+yar3g== + dependencies: + "@glimmer/di" "^0.2.0" + +"@sindresorhus/is@^0.7.0": + version "0.7.0" + resolved "https://registry.npmjs.org/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd" + integrity sha512-ONhaKPIufzzrlNbqtWFFd+jlnemX6lJAgq9ZeiZtS7I1PIf/la7CW4m83rTXRnVnsMbW2k56pGYu7AUFJD9Pow== + +"@types/acorn@^4.0.3": + version "4.0.5" + resolved "https://registry.npmjs.org/@types/acorn/-/acorn-4.0.5.tgz#e29fdf884695e77be4e99e67d748f5147255752d" + integrity sha512-603sPiZ4GVRHPvn6vNgEAvJewKsy+zwRWYS2MeIMemgoAtcjlw2G3lALxrb9OPA17J28bkB71R33yXlQbUatCA== + dependencies: + "@types/estree" "*" + +"@types/ember-qunit@~3.4.5": + version "3.4.6" + resolved "https://registry.npmjs.org/@types/ember-qunit/-/ember-qunit-3.4.6.tgz#b09ae84192c16fbd1da0d1be26fa02b67691250d" + integrity sha512-ARB2JDNV3qzrZ94fC+YdV9jT9hYAXP8pXcqAVzVEYVL5/upSxKcYZjiCSScpKzXikN8yieIGNqSGArhQrcdzFA== + dependencies: + "@types/ember" "*" + "@types/ember-test-helpers" "*" + +"@types/ember-test-helpers@*", "@types/ember-test-helpers@~1.0.5": + version "1.0.5" + resolved "https://registry.npmjs.org/@types/ember-test-helpers/-/ember-test-helpers-1.0.5.tgz#b0a8a3b9386ddf372eef11ba95487be806674ca2" + integrity sha512-LewaqxBqUDxT40Lb8M7r0pDlF78b5O87mQRK+8GqrreK/s3MSX/BXgxi5hbWF3TPJ57iX3G4S2TNO8z8soXYdA== + dependencies: + "@types/ember" "*" + "@types/htmlbars-inline-precompile" "*" + "@types/jquery" "*" + "@types/rsvp" "*" + +"@types/ember-testing-helpers@~0.0.3": + version "0.0.3" + resolved "https://registry.npmjs.org/@types/ember-testing-helpers/-/ember-testing-helpers-0.0.3.tgz#1a6cfc484b63d19ddd822c87e4dd710597db17d9" + integrity sha512-QG3QBBR7PFzz3zhLTbsZWBgk3cNQIZYVG6rbXKMM36+YP3dcSkkWQ6CRTyQImUIfgAkYPMaWqGlGEtkuanq3Bg== + dependencies: + "@types/jquery" "*" + "@types/rsvp" "*" + +"@types/ember@*", "@types/ember@~3.0.29": + version "3.0.29" + resolved "https://registry.npmjs.org/@types/ember/-/ember-3.0.29.tgz#a437a60a41f8df9cba52de267bfd0007566eae41" + integrity sha512-qW8quUN996GHQlNC4jnQlRcIeZUMW4lL8M16FMAbHEv3cEvY1aPX6GQc4TPt167eR1fAjykfB4cTG6OQFxGHXQ== + dependencies: + "@types/ember__application" "*" + "@types/ember__array" "*" + "@types/ember__component" "*" + "@types/ember__controller" "*" + "@types/ember__debug" "*" + "@types/ember__engine" "*" + "@types/ember__error" "*" + "@types/ember__object" "*" + "@types/ember__polyfills" "*" + "@types/ember__routing" "*" + "@types/ember__runloop" "*" + "@types/ember__service" "*" + "@types/ember__string" "*" + "@types/ember__test" "*" + "@types/ember__utils" "*" + "@types/htmlbars-inline-precompile" "*" + "@types/jquery" "*" + "@types/rsvp" "*" + +"@types/ember__application@*": + version "3.0.7" + resolved "https://registry.npmjs.org/@types/ember__application/-/ember__application-3.0.7.tgz#8a34f6d75661256d6d6859dcdde848bdd3bea47e" + integrity sha512-7M5Oba1u9fQ1rLs/LeyHqDhnMAqJJF+K2HBBYkbPkD8hf+DR8Ae5PvWXgHwjAmiiWe559zJcapCqawPgzMw8lg== + dependencies: + "@types/ember__application" "*" + "@types/ember__engine" "*" + "@types/ember__object" "*" + "@types/ember__routing" "*" + +"@types/ember__array@*": + version "3.0.4" + resolved "https://registry.npmjs.org/@types/ember__array/-/ember__array-3.0.4.tgz#6b04b9188da1c315d808304c989a6e7ed24d7ad3" + integrity sha512-WPqytL1qOKoNpcY3eHKp8f7lejTGFyiySAH+yPhXMX1X2F6Y8nkCQGmmTQ9W9+nYQbyVlA3SCXqd1uTzCEOLjg== + dependencies: + "@types/ember__array" "*" + "@types/ember__object" "*" + +"@types/ember__component@*": + version "3.0.5" + resolved "https://registry.npmjs.org/@types/ember__component/-/ember__component-3.0.5.tgz#ae0a64d53ec3bff7a100347fac52320cba068c22" + integrity sha512-pGDNR2OkPjNIcpdV/XEtzU/yE5n+vzRcYHtUCaA7dn0qoMAAiMPkJjeNMGkWQIv1q+aLyXvjiV9elcP2i1HA9g== + dependencies: + "@types/ember__component" "*" + "@types/ember__object" "*" + "@types/jquery" "*" + +"@types/ember__controller@*": + version "3.0.4" + resolved "https://registry.npmjs.org/@types/ember__controller/-/ember__controller-3.0.4.tgz#27b7da14770c3b5eb48c70eea6ebab13fa8987da" + integrity sha512-sJES+IfUCghjcTDpSmozViAdt32vk9YGUBvddDBfTtLTHc0tjM3FV93fZxIXCRyl6U8zSExve+KLfYtnLHd52A== + dependencies: + "@types/ember__object" "*" + +"@types/ember__debug@*", "@types/ember__debug@^3.0.3": + version "3.0.4" + resolved "https://registry.npmjs.org/@types/ember__debug/-/ember__debug-3.0.4.tgz#cdf87a580688a0e3053820eff6f390fbb7ba0e80" + integrity sha512-jTdLdNGvDn3MhktfskhdxOaDHO09QtQqeh+krI7EDePl2+Xom+KnNeveFeCkzxDkYOa+/R7UNSxW4yN/3YTw3w== + dependencies: + "@types/ember__debug" "*" + "@types/ember__engine" "*" + "@types/ember__object" "*" + +"@types/ember__engine@*": + version "3.0.4" + resolved "https://registry.npmjs.org/@types/ember__engine/-/ember__engine-3.0.4.tgz#7e79d72653f5c7fd9f6d828d32540be372128aca" + integrity sha512-DfbM0iKgF8mvthZwshDgYn8H1BZQJOk42X5b183K7vbkaye49seeTnPDelrVRRnlMXH6BA6OHAghY92axwVLzw== + dependencies: + "@types/ember__engine" "*" + "@types/ember__object" "*" + +"@types/ember__error@*": + version "3.0.3" + resolved "https://registry.npmjs.org/@types/ember__error/-/ember__error-3.0.3.tgz#73e5d9f05212d7965e7c2f4df39abdbf5ea41ab1" + integrity sha512-P1+YLJJ9xzc8w5mKYtXsrS070MOTjsNeoGoEHnj7nO5IfeyC34yTHdceW9hoBMRLZs2tZ+cjElUNdR1kxpl+oA== + +"@types/ember__object@*": + version "3.0.8" + resolved "https://registry.npmjs.org/@types/ember__object/-/ember__object-3.0.8.tgz#b62daeb8c86e377831c8320ba6dfaae9613bee8e" + integrity sha512-Rc6tQfFzXYJi7UtWrMd2ZZjlC3x2NI32UeqCwR/CxoH0pivmXStnjVDf/W3k601zRG0XYVUeDXpo8vb/Nhwfeg== + dependencies: + "@types/ember__object" "*" + "@types/rsvp" "*" + +"@types/ember__polyfills@*": + version "3.0.5" + resolved "https://registry.npmjs.org/@types/ember__polyfills/-/ember__polyfills-3.0.5.tgz#8f2c97b42f089afed53b4c137a6d7bbf4f7aa12e" + integrity sha512-yffc3Alk/Z12LwpRXvchcqrmou5fo37wZMoFiAOiqBYzJO3JL9gcYcrYuwg0eBdR/EwOr3aUeE8S+XAqXx3pIQ== + +"@types/ember__routing@*": + version "3.0.7" + resolved "https://registry.npmjs.org/@types/ember__routing/-/ember__routing-3.0.7.tgz#73f54958ae0a7d28a8da0f91e928a8a48eab02b9" + integrity sha512-JZV5uIsh12FVBKrcKcaxnV8oiqo/13wvlr4UGfw4Xts7lM3/wbAy3uchfpZtkAImBHeXuxGF51YoIBc2ROCK0w== + dependencies: + "@types/ember__component" "*" + "@types/ember__controller" "*" + "@types/ember__object" "*" + "@types/ember__routing" "*" + "@types/ember__service" "*" + +"@types/ember__runloop@*": + version "3.0.5" + resolved "https://registry.npmjs.org/@types/ember__runloop/-/ember__runloop-3.0.5.tgz#7101cc0d5b06d2b578a34ce4b9e8355d9061ac71" + integrity sha512-9K5P0HgP5XxOzZqovsSU5iZfn2czpNMCbA9b1NLhDMdfPqySu7Ow3x0pJIj46hmRuaA2P3f/6PrXIlgsOB0fFQ== + dependencies: + "@types/ember__runloop" "*" + +"@types/ember__service@*": + version "3.0.3" + resolved "https://registry.npmjs.org/@types/ember__service/-/ember__service-3.0.3.tgz#1c43997be716d557f3553c0d27707f62fbabb26d" + integrity sha512-hCH6+yIjS4dapUFjycqGN5mJiVB6q8OZ2vEX3+sEwzlZ696Ya01XV9eC2zGLjU+sDb398oJ1fNI4ycg2uq3cyw== + dependencies: + "@types/ember__object" "*" + +"@types/ember__string@*": + version "3.0.6" + resolved "https://registry.npmjs.org/@types/ember__string/-/ember__string-3.0.6.tgz#79b10b0fc0136a9c86536bc55cbd18cae9a9bd3b" + integrity sha512-VBKH8nR/uK2tlr9eob8Nl+0cKP62GNtFWqq4PVGusnBMPFktGley1gsUhqNYJ9G3y2mvVfikicxM2/bE5AMYLA== + +"@types/ember__test-helpers@~0.7.8": + version "0.7.8" + resolved "https://registry.npmjs.org/@types/ember__test-helpers/-/ember__test-helpers-0.7.8.tgz#16d6e060ec88e5510756d00e8f191fa48d9e0362" + integrity sha512-23YMSoKqiqJHeg6uWusAqLdYb4He2U9gZZYy9JUslzHrQV9eSWmQDFHVRXfy9zWj0Rbh+ssKEWlMGwckZyKgRA== + dependencies: + "@types/ember" "*" + "@types/ember__application" "*" + "@types/ember__error" "*" + "@types/htmlbars-inline-precompile" "*" + +"@types/ember__test@*": + version "3.0.5" + resolved "https://registry.npmjs.org/@types/ember__test/-/ember__test-3.0.5.tgz#8435b9b3caa5b97a9057d8f4e922c20f2279f93f" + integrity sha512-7F45zVSaM1hqXtv0bTMOLwgvATPfAGsnvU5CmMdUpuLBHRnOIe5HDAx0s1Yr4I318IAT5LgAX180dIJmXs1/+g== + dependencies: + "@types/ember__application" "*" + +"@types/ember__utils@*": + version "3.0.2" + resolved "https://registry.npmjs.org/@types/ember__utils/-/ember__utils-3.0.2.tgz#d4c32007d0c84c95faa9221a1582b87ac3b1b4f3" + integrity sha512-d6fswmNDozslgUk+0DfC1oG0vD8R5ivvrEe0t3BuWSnF+TVyYhj24KZINecpBySg/4RODCg2IVV1GeRsimqzkg== + +"@types/estree@*", "@types/estree@0.0.39": + version "0.0.39" + resolved "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + +"@types/htmlbars-inline-precompile@*": + version "1.0.1" + resolved "https://registry.npmjs.org/@types/htmlbars-inline-precompile/-/htmlbars-inline-precompile-1.0.1.tgz#de564513fabb165746aecd76369c87bd85e5bbb4" + integrity sha512-sVD2e6QAAHW0Y6Btse+tTA9k9g0iKm87wjxRsgZRU5EwSooz80tenbV+fA+f2BI2g0G2CqxsS1rIlwQCtPRQow== + +"@types/jquery@*": + version "3.3.29" + resolved "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.29.tgz#680a2219ce3c9250483722fccf5570d1e2d08abd" + integrity sha512-FhJvBninYD36v3k6c+bVk1DSZwh7B5Dpb/Pyk3HKVsiohn0nhbefZZ+3JXbWQhFyt0MxSl2jRDdGQPHeOHFXrQ== + dependencies: + "@types/sizzle" "*" + +"@types/minimatch@^3.0.3": + version "3.0.3" + resolved "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" + integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== + +"@types/node@^9.6.0": + version "9.6.45" + resolved "https://registry.npmjs.org/@types/node/-/node-9.6.45.tgz#a9e5cfd026a3abaaf17e3c0318a470da9f2f178e" + integrity sha512-9scD7xI1kpIoMs3gVFMOWsWDyRIQ1AOZwe56i1CQPE6N/P4POYkn9UtW5F66t8C2AIoPtVfOFycQ2r11t3pcyg== + +"@types/qunit@^2.5.3": + version "2.5.4" + resolved "https://registry.npmjs.org/@types/qunit/-/qunit-2.5.4.tgz#0518940acc6013259a8619a1ec34ce0e4ff8d1c4" + integrity sha512-VHi2lEd4/zp8OOouf43JXGJJ5ZxHvdLL1dU0Yakp6Iy73SjpuXl7yjwAwmh1qhTv8krDgHteSwaySr++uXX9YQ== + +"@types/rsvp@*", "@types/rsvp@^4.0.2": + version "4.0.2" + resolved "https://registry.npmjs.org/@types/rsvp/-/rsvp-4.0.2.tgz#bf9f72eaa6771292638a85bb8ce1db97e754b371" + integrity sha512-48ZwxFD1hdBj8QMOSNGA2kYuo3+SKh8OEYh5cMi7cPRZXBF9jwVPV4yqA7EcJTNlAJL0v99pEUYetl0TsufMQA== + +"@types/sizzle@*": + version "2.3.2" + resolved "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47" + integrity sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg== + +"@types/tmp@^0.0.33": + version "0.0.33" + resolved "https://registry.npmjs.org/@types/tmp/-/tmp-0.0.33.tgz#1073c4bc824754ae3d10cfab88ab0237ba964e4d" + integrity sha1-EHPEvIJHVK49EM+riKsCN7qWTk0= + +"@xg-wang/whatwg-fetch@^3.0.0": + version "3.0.0" + resolved "https://registry.npmjs.org/@xg-wang/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#f7b222c012a238e7d6e89ed3d72a1e0edb58453d" + integrity sha512-ULtqA6L75RLzTNW68IiOja0XYv4Ebc3OGMzfia1xxSEMpD0mk/pMvkQX0vbCFyQmKc5xGp80Ms2WiSlXLh8hbA== + +abbrev@1: + version "1.1.1" + resolved "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" + integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== + +abortcontroller-polyfill@^1.1.9, abortcontroller-polyfill@^1.2.5: + version "1.2.9" + resolved "https://registry.yarnpkg.com/abortcontroller-polyfill/-/abortcontroller-polyfill-1.2.9.tgz#402311d2aac7e8e093ecb045726b45fdafd834fe" + integrity sha512-0goWhDrwoWtK6XCdFdzPtvHBmmQU91j3tULNL85MAnDuM7bNlzUDfmL5AZGL819L7pn9kra35HJGWG25UgRCBw== + +accepts@~1.3.4, accepts@~1.3.5: + version "1.3.5" + resolved "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz#eb777df6011723a3b14e8a72c0805c8e86746bd2" + integrity sha1-63d99gEXI6OxTopywIBcjoZ0a9I= + dependencies: + mime-types "~2.1.18" + negotiator "0.6.1" + +acorn-dynamic-import@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz#901ceee4c7faaef7e07ad2a47e890675da50a278" + integrity sha512-zVWV8Z8lislJoOKKqdNMOB+s6+XV5WERty8MnKBeFgwA+19XJjJHs2RP5dzM57FftIs+jQnRToLiWazKr6sSWg== + dependencies: + acorn "^5.0.0" + +acorn-jsx@^5.0.0: + version "5.0.1" + resolved "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.1.tgz#32a064fd925429216a09b141102bfdd185fae40e" + integrity sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg== + +acorn@^5.0.0, acorn@^5.5.3: + version "5.7.3" + resolved "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279" + integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw== + +acorn@^6.0.7: + version "6.1.1" + resolved "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz#7d25ae05bb8ad1f9b699108e1094ecd7884adc1f" + integrity sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA== + +after@0.8.2: + version "0.8.2" + resolved "https://registry.npmjs.org/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f" + integrity sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8= + +agent-base@2: + version "2.1.1" + resolved "https://registry.npmjs.org/agent-base/-/agent-base-2.1.1.tgz#d6de10d5af6132d5bd692427d46fc538539094c7" + integrity sha1-1t4Q1a9hMtW9aSQn1G/FOFOQlMc= + dependencies: + extend "~3.0.0" + semver "~5.0.1" + +ajv@^6.9.1: + version "6.10.0" + resolved "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz#90d0d54439da587cd7e843bfb7045f50bd22bdf1" + integrity sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg== + dependencies: + fast-deep-equal "^2.0.1" + fast-json-stable-stringify "^2.0.0" + json-schema-traverse "^0.4.1" + uri-js "^4.2.2" + +amd-name-resolver@1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/amd-name-resolver/-/amd-name-resolver-1.2.0.tgz#fc41b3848824b557313897d71f8d5a0184fbe679" + integrity sha512-hlSTWGS1t6/xq5YCed7YALg7tKZL3rkl7UwEZ/eCIkn8JxmM6fU6Qs/1hwtjQqfuYxlffuUcgYEm0f5xP4YKaA== + dependencies: + ensure-posix-path "^1.0.1" + +amd-name-resolver@^1.2.0, amd-name-resolver@^1.2.1, amd-name-resolver@^1.3.1: + version "1.3.1" + resolved "https://registry.npmjs.org/amd-name-resolver/-/amd-name-resolver-1.3.1.tgz#ffe71c683c6e7191fc4ae1bb3aaed15abea135d9" + integrity sha512-26qTEWqZQ+cxSYygZ4Cf8tsjDBLceJahhtewxtKZA3SRa4PluuqYCuheemDQD+7Mf5B7sr+zhTDWAHDh02a1Dw== + dependencies: + ensure-posix-path "^1.0.1" + object-hash "^1.3.1" + +amdefine@>=0.0.4: + version "1.0.1" + resolved "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" + integrity sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU= + +ansi-colors@3.2.3: + version "3.2.3" + resolved "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz#57d35b8686e851e2cc04c403f1c00203976a1813" + integrity sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw== + +ansi-escapes@^3.2.0: + version "3.2.0" + resolved "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b" + integrity sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ== + +ansi-regex@^2.0.0: + version "2.1.1" + resolved "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" + integrity sha1-w7M6te42DYbg5ijwRorn7yfWVN8= + +ansi-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" + integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg= + +ansi-regex@^4.1.0: + version "4.1.0" + resolved "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" + integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg== + +ansi-styles@^2.2.1: + version "2.2.1" + resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" + integrity sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4= + +ansi-styles@^3.0.0, ansi-styles@^3.2.0, ansi-styles@^3.2.1: + version "3.2.1" + resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" + integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA== + dependencies: + color-convert "^1.9.0" + +ansi-to-html@^0.6.6: + version "0.6.10" + resolved "https://registry.npmjs.org/ansi-to-html/-/ansi-to-html-0.6.10.tgz#412114353bac2589a034db7ec5b371b8ba771131" + integrity sha512-znsY3gvsk4CiApWu1yVYF8Nx5Vy0FEe8B0YwyxdbCdErJu5lfKlRHB2twtUjR+dxR4WewTk2OP8XqTmWYnImOg== + dependencies: + entities "^1.1.1" + +ansicolors@~0.2.1: + version "0.2.1" + resolved "https://registry.npmjs.org/ansicolors/-/ansicolors-0.2.1.tgz#be089599097b74a5c9c4a84a0cdbcdb62bd87aef" + integrity sha1-vgiVmQl7dKXJxKhKDNvNtivYeu8= + +anymatch@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb" + integrity sha512-5teOsQWABXHHBFP9y3skS5P3d/WfWXpv3FUpy+LorMrNYaT9pI4oLMQX7jzQ2KklNpGpWHzdCXTDT2Y3XGlZBw== + dependencies: + micromatch "^3.1.4" + normalize-path "^2.1.1" + +aproba@^1.0.3: + version "1.2.0" + resolved "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a" + integrity sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw== + +are-we-there-yet@~1.1.2: + version "1.1.5" + resolved "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz#4b35c2944f062a8bfcda66410760350fe9ddfc21" + integrity sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w== + dependencies: + delegates "^1.0.0" + readable-stream "^2.0.6" + +argparse@^1.0.7, argparse@~1.0.2: + version "1.0.10" + resolved "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" + integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg== + dependencies: + sprintf-js "~1.0.2" + +arr-diff@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520" + integrity sha1-1kYQdP6/7HHn4VI1dhoyml3HxSA= + +arr-flatten@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.1.0.tgz#36048bbff4e7b47e136644316c99669ea5ae91f1" + integrity sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg== + +arr-union@^3.1.0: + version "3.1.0" + resolved "https://registry.npmjs.org/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4" + integrity sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ= + +array-equal@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93" + integrity sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM= + +array-flatten@1.1.1: + version "1.1.1" + resolved "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" + integrity sha1-ml9pkFGx5wczKPKgCJaLZOopVdI= + +array-to-error@^1.0.0: + version "1.1.1" + resolved "https://registry.npmjs.org/array-to-error/-/array-to-error-1.1.1.tgz#d68812926d14097a205579a667eeaf1856a44c07" + integrity sha1-1ogSkm0UCXogVXmmZ+6vGFakTAc= + dependencies: + array-to-sentence "^1.1.0" + +array-to-sentence@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/array-to-sentence/-/array-to-sentence-1.1.0.tgz#c804956dafa53232495b205a9452753a258d39fc" + integrity sha1-yASVba+lMjJJWyBalFJ1OiWNOfw= + +array-unique@^0.3.2: + version "0.3.2" + resolved "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" + integrity sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg= + +arraybuffer.slice@~0.0.7: + version "0.0.7" + resolved "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz#3bbc4275dd584cc1b10809b89d4e8b63a69e7675" + integrity sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog== + +asn1@0.1.11: + version "0.1.11" + resolved "https://registry.npmjs.org/asn1/-/asn1-0.1.11.tgz#559be18376d08a4ec4dbe80877d27818639b2df7" + integrity sha1-VZvhg3bQik7E2+gId9J4GGObLfc= + +assert-plus@^0.1.5: + version "0.1.5" + resolved "https://registry.npmjs.org/assert-plus/-/assert-plus-0.1.5.tgz#ee74009413002d84cec7219c6ac811812e723160" + integrity sha1-7nQAlBMALYTOxyGcasgRgS5yMWA= + +assertion-error@^1.0.1, assertion-error@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" + integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== + +assign-symbols@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367" + integrity sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c= + +ast-types@0.9.6: + version "0.9.6" + resolved "https://registry.npmjs.org/ast-types/-/ast-types-0.9.6.tgz#102c9e9e9005d3e7e3829bf0c4fa24ee862ee9b9" + integrity sha1-ECyenpAF0+fjgpvwxPok7oYu6bk= + +astral-regex@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" + integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg== + +async-disk-cache@^1.2.1: + version "1.3.4" + resolved "https://registry.npmjs.org/async-disk-cache/-/async-disk-cache-1.3.4.tgz#a5c9f72f199a9933583659f57a0e11377884f816" + integrity sha512-qsIvGJ/XYZ5bSGf5vHt2aEQHZnyuehmk/+51rCJhpkZl4LtvOZ+STbhLbdFAJGYO+dLzUT5Bb4nLKqHBX83vhw== + dependencies: + debug "^2.1.3" + heimdalljs "^0.2.3" + istextorbinary "2.1.0" + mkdirp "^0.5.0" + rimraf "^2.5.3" + rsvp "^3.0.18" + username-sync "^1.0.2" + +async-limiter@~1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8" + integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg== + +async-promise-queue@^1.0.3, async-promise-queue@^1.0.4: + version "1.0.4" + resolved "https://registry.npmjs.org/async-promise-queue/-/async-promise-queue-1.0.4.tgz#308baafbc74aff66a0bb6e7f4a18d4fe8434440c" + integrity sha512-GQ5X3DT+TefYuFPHdvIPXFTlKnh39U7dwtl+aUBGeKjMea9nBpv3c91DXgeyBQmY07vQ97f3Sr9XHqkamEameQ== + dependencies: + async "^2.4.1" + debug "^2.6.8" + +async@^1.5.2: + version "1.5.2" + resolved "https://registry.npmjs.org/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" + integrity sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo= + +async@^2.4.1, async@^2.5.0: + version "2.6.2" + resolved "https://registry.npmjs.org/async/-/async-2.6.2.tgz#18330ea7e6e313887f5d2f2a904bac6fe4dd5381" + integrity sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg== + dependencies: + lodash "^4.17.11" + +async@~0.2.9: + version "0.2.10" + resolved "https://registry.npmjs.org/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1" + integrity sha1-trvgsGdLnXGXCMo43owjfLUmw9E= + +async@~0.9.0: + version "0.9.2" + resolved "https://registry.npmjs.org/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d" + integrity sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0= + +atob@^2.1.1: + version "2.1.2" + resolved "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" + integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== + +aws-sign2@~0.5.0: + version "0.5.0" + resolved "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.5.0.tgz#c57103f7a17fc037f02d7c2e64b602ea223f7d63" + integrity sha1-xXED96F/wDfwLXwuZLYC6iI/fWM= + +babel-code-frame@^6.26.0: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" + integrity sha1-Y/1D99weO7fONZR9uP42mj9Yx0s= + dependencies: + chalk "^1.1.3" + esutils "^2.0.2" + js-tokens "^3.0.2" + +babel-core@^6.26.0: + version "6.26.3" + resolved "https://registry.npmjs.org/babel-core/-/babel-core-6.26.3.tgz#b2e2f09e342d0f0c88e2f02e067794125e75c207" + integrity sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA== + dependencies: + babel-code-frame "^6.26.0" + babel-generator "^6.26.0" + babel-helpers "^6.24.1" + babel-messages "^6.23.0" + babel-register "^6.26.0" + babel-runtime "^6.26.0" + babel-template "^6.26.0" + babel-traverse "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + convert-source-map "^1.5.1" + debug "^2.6.9" + json5 "^0.5.1" + lodash "^4.17.4" + minimatch "^3.0.4" + path-is-absolute "^1.0.1" + private "^0.1.8" + slash "^1.0.0" + source-map "^0.5.7" + +babel-eslint@^10.0.1: + version "10.0.1" + resolved "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.0.1.tgz#919681dc099614cd7d31d45c8908695092a1faed" + integrity sha512-z7OT1iNV+TjOwHNLLyJk+HN+YVWX+CLE6fPD2SymJZOZQBs+QIexFjhm4keGTm8MW9xr4EC9Q0PbaLB24V5GoQ== + dependencies: + "@babel/code-frame" "^7.0.0" + "@babel/parser" "^7.0.0" + "@babel/traverse" "^7.0.0" + "@babel/types" "^7.0.0" + eslint-scope "3.7.1" + eslint-visitor-keys "^1.0.0" + +babel-generator@^6.26.0: + version "6.26.1" + resolved "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.1.tgz#1844408d3b8f0d35a404ea7ac180f087a601bd90" + integrity sha512-HyfwY6ApZj7BYTcJURpM5tznulaBvyio7/0d4zFOeMPUmfxkCjHocCuoLa2SAGzBI8AREcH3eP3758F672DppA== + dependencies: + babel-messages "^6.23.0" + babel-runtime "^6.26.0" + babel-types "^6.26.0" + detect-indent "^4.0.0" + jsesc "^1.3.0" + lodash "^4.17.4" + source-map "^0.5.7" + trim-right "^1.0.1" + +babel-helper-builder-binary-assignment-operator-visitor@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helper-builder-binary-assignment-operator-visitor/-/babel-helper-builder-binary-assignment-operator-visitor-6.24.1.tgz#cce4517ada356f4220bcae8a02c2b346f9a56664" + integrity sha1-zORReto1b0IgvK6KAsKzRvmlZmQ= + dependencies: + babel-helper-explode-assignable-expression "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-call-delegate@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helper-call-delegate/-/babel-helper-call-delegate-6.24.1.tgz#ece6aacddc76e41c3461f88bfc575bd0daa2df8d" + integrity sha1-7Oaqzdx25Bw0YfiL/Fdb0Nqi340= + dependencies: + babel-helper-hoist-variables "^6.24.1" + babel-runtime "^6.22.0" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-define-map@^6.24.1: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-helper-define-map/-/babel-helper-define-map-6.26.0.tgz#a5f56dab41a25f97ecb498c7ebaca9819f95be5f" + integrity sha1-pfVtq0GiX5fstJjH66ypgZ+Vvl8= + dependencies: + babel-helper-function-name "^6.24.1" + babel-runtime "^6.26.0" + babel-types "^6.26.0" + lodash "^4.17.4" + +babel-helper-explode-assignable-expression@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helper-explode-assignable-expression/-/babel-helper-explode-assignable-expression-6.24.1.tgz#f25b82cf7dc10433c55f70592d5746400ac22caa" + integrity sha1-8luCz33BBDPFX3BZLVdGQArCLKo= + dependencies: + babel-runtime "^6.22.0" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-function-name@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helper-function-name/-/babel-helper-function-name-6.24.1.tgz#d3475b8c03ed98242a25b48351ab18399d3580a9" + integrity sha1-00dbjAPtmCQqJbSDUasYOZ01gKk= + dependencies: + babel-helper-get-function-arity "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-get-function-arity@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helper-get-function-arity/-/babel-helper-get-function-arity-6.24.1.tgz#8f7782aa93407c41d3aa50908f89b031b1b6853d" + integrity sha1-j3eCqpNAfEHTqlCQj4mwMbG2hT0= + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-hoist-variables@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helper-hoist-variables/-/babel-helper-hoist-variables-6.24.1.tgz#1ecb27689c9d25513eadbc9914a73f5408be7a76" + integrity sha1-HssnaJydJVE+rbyZFKc/VAi+enY= + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-optimise-call-expression@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helper-optimise-call-expression/-/babel-helper-optimise-call-expression-6.24.1.tgz#f7a13427ba9f73f8f4fa993c54a97882d1244257" + integrity sha1-96E0J7qfc/j0+pk8VKl4gtEkQlc= + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-regex@^6.24.1: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-helper-regex/-/babel-helper-regex-6.26.0.tgz#325c59f902f82f24b74faceed0363954f6495e72" + integrity sha1-MlxZ+QL4LyS3T6zu0DY5VPZJXnI= + dependencies: + babel-runtime "^6.26.0" + babel-types "^6.26.0" + lodash "^4.17.4" + +babel-helper-remap-async-to-generator@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helper-remap-async-to-generator/-/babel-helper-remap-async-to-generator-6.24.1.tgz#5ec581827ad723fecdd381f1c928390676e4551b" + integrity sha1-XsWBgnrXI/7N04HxySg5BnbkVRs= + dependencies: + babel-helper-function-name "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-replace-supers@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helper-replace-supers/-/babel-helper-replace-supers-6.24.1.tgz#bf6dbfe43938d17369a213ca8a8bf74b6a90ab1a" + integrity sha1-v22/5Dk40XNpohPKiov3S2qQqxo= + dependencies: + babel-helper-optimise-call-expression "^6.24.1" + babel-messages "^6.23.0" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helpers@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-helpers/-/babel-helpers-6.24.1.tgz#3471de9caec388e5c850e597e58a26ddf37602b2" + integrity sha1-NHHenK7DiOXIUOWX5Yom3fN2ArI= + dependencies: + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-messages@^6.23.0: + version "6.23.0" + resolved "https://registry.npmjs.org/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e" + integrity sha1-8830cDhYA1sqKVHG7F7fbGLyYw4= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-check-es2015-constants@^6.22.0: + version "6.22.0" + resolved "https://registry.npmjs.org/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.22.0.tgz#35157b101426fd2ffd3da3f75c7d1e91835bbf8a" + integrity sha1-NRV7EBQm/S/9PaP3XH0ekYNbv4o= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-debug-macros@^0.1.10: + version "0.1.11" + resolved "https://registry.npmjs.org/babel-plugin-debug-macros/-/babel-plugin-debug-macros-0.1.11.tgz#6c562bf561fccd406ce14ab04f42c218cf956605" + integrity sha512-hZw5qNNGAR02Y+yBUrtsnJHh8OXavkayPRqKGAXnIm4t5rWVpj3ArwsC7TWdpZsBguQvHAeyTxZ7s23yY60HHg== + dependencies: + semver "^5.3.0" + +babel-plugin-debug-macros@^0.2.0, babel-plugin-debug-macros@^0.2.0-beta.6: + version "0.2.0" + resolved "https://registry.npmjs.org/babel-plugin-debug-macros/-/babel-plugin-debug-macros-0.2.0.tgz#0120ac20ce06ccc57bf493b667cf24b85c28da7a" + integrity sha512-Wpmw4TbhR3Eq2t3W51eBAQSdKlr+uAyF0GI4GtPfMCD12Y4cIdpKC9l0RjNTH/P9isFypSqqewMPm7//fnZlNA== + dependencies: + semver "^5.3.0" + +babel-plugin-debug-macros@^0.3.0: + version "0.3.0" + resolved "https://registry.npmjs.org/babel-plugin-debug-macros/-/babel-plugin-debug-macros-0.3.0.tgz#7a025944faef0777804ef3518c54e8b040197397" + integrity sha512-D6qYBI/3+FvcKVnRnH6FBUwXPp/5o/jnJNVFKqVaZpYAWx88+R8jNNyaEX7iQFs7UfCib6rcY/9+ICR4jhjFCQ== + dependencies: + semver "^5.3.0" + +babel-plugin-ember-modules-api-polyfill@^2.6.0, babel-plugin-ember-modules-api-polyfill@^2.7.0: + version "2.7.0" + resolved "https://registry.npmjs.org/babel-plugin-ember-modules-api-polyfill/-/babel-plugin-ember-modules-api-polyfill-2.7.0.tgz#dcd6a9999da0d47d8c9185362bda6244ca525f4a" + integrity sha512-+QXPqmRngp13d7nKWrBcL6iIixpuyMNq107XV1dKvsvAO5BGFQ0mSk7Dl6/OgG+z2F1KquxkFfdXYBwbREQI6A== + dependencies: + ember-rfc176-data "^0.3.7" + +babel-plugin-feature-flags@^0.3.1: + version "0.3.1" + resolved "https://registry.npmjs.org/babel-plugin-feature-flags/-/babel-plugin-feature-flags-0.3.1.tgz#9c827cf9a4eb9a19f725ccb239e85cab02036fc1" + integrity sha1-nIJ8+aTrmhn3JcyyOehcqwIDb8E= + +babel-plugin-filter-imports@^2.0.4: + version "2.0.4" + resolved "https://registry.npmjs.org/babel-plugin-filter-imports/-/babel-plugin-filter-imports-2.0.4.tgz#9209b708ed3b228349c4e6f660358bf02685e803" + integrity sha512-Ra4VylqMFsmTJCUeLRJ/OP2ZqO0cCJQK2HKihNTnoKP4f8IhxHKL4EkbmfkwGjXCeDyXd0xQ6UTK8Nd+h9V/SQ== + dependencies: + "@babel/types" "^7.1.5" + lodash "^4.17.11" + +babel-plugin-htmlbars-inline-precompile@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/babel-plugin-htmlbars-inline-precompile/-/babel-plugin-htmlbars-inline-precompile-1.0.0.tgz#a9d2f6eaad8a3f3d361602de593a8cbef8179c22" + integrity sha512-4jvKEHR1bAX03hBDZ94IXsYCj3bwk9vYsn6ux6JZNL2U5pvzCWjqyrGahfsGNrhERyxw8IqcirOi9Q6WCo3dkQ== + +babel-plugin-module-resolver@^3.1.1: + version "3.2.0" + resolved "https://registry.npmjs.org/babel-plugin-module-resolver/-/babel-plugin-module-resolver-3.2.0.tgz#ddfa5e301e3b9aa12d852a9979f18b37881ff5a7" + integrity sha512-tjR0GvSndzPew/Iayf4uICWZqjBwnlMWjSx6brryfQ81F9rxBVqwDJtFCV8oOs0+vJeefK9TmdZtkIFdFe1UnA== + dependencies: + find-babel-config "^1.1.0" + glob "^7.1.2" + pkg-up "^2.0.0" + reselect "^3.0.1" + resolve "^1.4.0" + +babel-plugin-syntax-async-functions@^6.8.0: + version "6.13.0" + resolved "https://registry.npmjs.org/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" + integrity sha1-ytnK0RkbWtY0vzCuCHI5HgZHvpU= + +babel-plugin-syntax-exponentiation-operator@^6.8.0: + version "6.13.0" + resolved "https://registry.npmjs.org/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de" + integrity sha1-nufoM3KQ2pUoggGmpX9BcDF4MN4= + +babel-plugin-syntax-trailing-function-commas@^6.22.0: + version "6.22.0" + resolved "https://registry.npmjs.org/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3" + integrity sha1-ugNgk3+NBuQBgKQ/4NVhb/9TLPM= + +babel-plugin-transform-async-to-generator@^6.22.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-async-to-generator/-/babel-plugin-transform-async-to-generator-6.24.1.tgz#6536e378aff6cb1d5517ac0e40eb3e9fc8d08761" + integrity sha1-ZTbjeK/2yx1VF6wOQOs+n8jQh2E= + dependencies: + babel-helper-remap-async-to-generator "^6.24.1" + babel-plugin-syntax-async-functions "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-arrow-functions@^6.22.0: + version "6.22.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221" + integrity sha1-RSaSy3EdX3ncf4XkQM5BufJE0iE= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-block-scoped-functions@^6.22.0: + version "6.22.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-block-scoped-functions/-/babel-plugin-transform-es2015-block-scoped-functions-6.22.0.tgz#bbc51b49f964d70cb8d8e0b94e820246ce3a6141" + integrity sha1-u8UbSflk1wy42OC5ToICRs46YUE= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-block-scoping@^6.23.0: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz#d70f5299c1308d05c12f463813b0a09e73b1895f" + integrity sha1-1w9SmcEwjQXBL0Y4E7CgnnOxiV8= + dependencies: + babel-runtime "^6.26.0" + babel-template "^6.26.0" + babel-traverse "^6.26.0" + babel-types "^6.26.0" + lodash "^4.17.4" + +babel-plugin-transform-es2015-classes@^6.23.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-classes/-/babel-plugin-transform-es2015-classes-6.24.1.tgz#5a4c58a50c9c9461e564b4b2a3bfabc97a2584db" + integrity sha1-WkxYpQyclGHlZLSyo7+ryXolhNs= + dependencies: + babel-helper-define-map "^6.24.1" + babel-helper-function-name "^6.24.1" + babel-helper-optimise-call-expression "^6.24.1" + babel-helper-replace-supers "^6.24.1" + babel-messages "^6.23.0" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-computed-properties@^6.22.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-computed-properties/-/babel-plugin-transform-es2015-computed-properties-6.24.1.tgz#6fe2a8d16895d5634f4cd999b6d3480a308159b3" + integrity sha1-b+Ko0WiV1WNPTNmZttNICjCBWbM= + dependencies: + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-destructuring@^6.23.0: + version "6.23.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-destructuring/-/babel-plugin-transform-es2015-destructuring-6.23.0.tgz#997bb1f1ab967f682d2b0876fe358d60e765c56d" + integrity sha1-mXux8auWf2gtKwh2/jWNYOdlxW0= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-duplicate-keys@^6.22.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-duplicate-keys/-/babel-plugin-transform-es2015-duplicate-keys-6.24.1.tgz#73eb3d310ca969e3ef9ec91c53741a6f1576423e" + integrity sha1-c+s9MQypaePvnskcU3QabxV2Qj4= + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-for-of@^6.23.0: + version "6.23.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-for-of/-/babel-plugin-transform-es2015-for-of-6.23.0.tgz#f47c95b2b613df1d3ecc2fdb7573623c75248691" + integrity sha1-9HyVsrYT3x0+zC/bdXNiPHUkhpE= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-function-name@^6.22.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-function-name/-/babel-plugin-transform-es2015-function-name-6.24.1.tgz#834c89853bc36b1af0f3a4c5dbaa94fd8eacaa8b" + integrity sha1-g0yJhTvDaxrw86TF26qU/Y6sqos= + dependencies: + babel-helper-function-name "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-literals@^6.22.0: + version "6.22.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-literals/-/babel-plugin-transform-es2015-literals-6.22.0.tgz#4f54a02d6cd66cf915280019a31d31925377ca2e" + integrity sha1-T1SgLWzWbPkVKAAZox0xklN3yi4= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-modules-amd@^6.22.0, babel-plugin-transform-es2015-modules-amd@^6.24.0, babel-plugin-transform-es2015-modules-amd@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-modules-amd/-/babel-plugin-transform-es2015-modules-amd-6.24.1.tgz#3b3e54017239842d6d19c3011c4bd2f00a00d154" + integrity sha1-Oz5UAXI5hC1tGcMBHEvS8AoA0VQ= + dependencies: + babel-plugin-transform-es2015-modules-commonjs "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-modules-commonjs@^6.23.0, babel-plugin-transform-es2015-modules-commonjs@^6.24.1: + version "6.26.2" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.2.tgz#58a793863a9e7ca870bdc5a881117ffac27db6f3" + integrity sha512-CV9ROOHEdrjcwhIaJNBGMBCodN+1cfkwtM1SbUHmvyy35KGT7fohbpOxkE2uLz1o6odKK2Ck/tz47z+VqQfi9Q== + dependencies: + babel-plugin-transform-strict-mode "^6.24.1" + babel-runtime "^6.26.0" + babel-template "^6.26.0" + babel-types "^6.26.0" + +babel-plugin-transform-es2015-modules-systemjs@^6.23.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-modules-systemjs/-/babel-plugin-transform-es2015-modules-systemjs-6.24.1.tgz#ff89a142b9119a906195f5f106ecf305d9407d23" + integrity sha1-/4mhQrkRmpBhlfXxBuzzBdlAfSM= + dependencies: + babel-helper-hoist-variables "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-modules-umd@^6.23.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-modules-umd/-/babel-plugin-transform-es2015-modules-umd-6.24.1.tgz#ac997e6285cd18ed6176adb607d602344ad38468" + integrity sha1-rJl+YoXNGO1hdq22B9YCNErThGg= + dependencies: + babel-plugin-transform-es2015-modules-amd "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-object-super@^6.22.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-object-super/-/babel-plugin-transform-es2015-object-super-6.24.1.tgz#24cef69ae21cb83a7f8603dad021f572eb278f8d" + integrity sha1-JM72muIcuDp/hgPa0CH1cusnj40= + dependencies: + babel-helper-replace-supers "^6.24.1" + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-parameters@^6.23.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-parameters/-/babel-plugin-transform-es2015-parameters-6.24.1.tgz#57ac351ab49caf14a97cd13b09f66fdf0a625f2b" + integrity sha1-V6w1GrScrxSpfNE7CfZv3wpiXys= + dependencies: + babel-helper-call-delegate "^6.24.1" + babel-helper-get-function-arity "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-shorthand-properties@^6.22.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-shorthand-properties/-/babel-plugin-transform-es2015-shorthand-properties-6.24.1.tgz#24f875d6721c87661bbd99a4622e51f14de38aa0" + integrity sha1-JPh11nIch2YbvZmkYi5R8U3jiqA= + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-spread@^6.22.0: + version "6.22.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-spread/-/babel-plugin-transform-es2015-spread-6.22.0.tgz#d6d68a99f89aedc4536c81a542e8dd9f1746f8d1" + integrity sha1-1taKmfia7cRTbIGlQujdnxdG+NE= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-sticky-regex@^6.22.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-sticky-regex/-/babel-plugin-transform-es2015-sticky-regex-6.24.1.tgz#00c1cdb1aca71112cdf0cf6126c2ed6b457ccdbc" + integrity sha1-AMHNsaynERLN8M9hJsLta0V8zbw= + dependencies: + babel-helper-regex "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-template-literals@^6.22.0: + version "6.22.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-template-literals/-/babel-plugin-transform-es2015-template-literals-6.22.0.tgz#a84b3450f7e9f8f1f6839d6d687da84bb1236d8d" + integrity sha1-qEs0UPfp+PH2g51taH2oS7EjbY0= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-typeof-symbol@^6.23.0: + version "6.23.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-typeof-symbol/-/babel-plugin-transform-es2015-typeof-symbol-6.23.0.tgz#dec09f1cddff94b52ac73d505c84df59dcceb372" + integrity sha1-3sCfHN3/lLUqxz1QXITfWdzOs3I= + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-unicode-regex@^6.22.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-es2015-unicode-regex/-/babel-plugin-transform-es2015-unicode-regex-6.24.1.tgz#d38b12f42ea7323f729387f18a7c5ae1faeb35e9" + integrity sha1-04sS9C6nMj9yk4fxinxa4frrNek= + dependencies: + babel-helper-regex "^6.24.1" + babel-runtime "^6.22.0" + regexpu-core "^2.0.0" + +babel-plugin-transform-exponentiation-operator@^6.22.0: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-exponentiation-operator/-/babel-plugin-transform-exponentiation-operator-6.24.1.tgz#2ab0c9c7f3098fa48907772bb813fe41e8de3a0e" + integrity sha1-KrDJx/MJj6SJB3cruBP+QejeOg4= + dependencies: + babel-helper-builder-binary-assignment-operator-visitor "^6.24.1" + babel-plugin-syntax-exponentiation-operator "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-regenerator@^6.22.0: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.26.0.tgz#e0703696fbde27f0a3efcacf8b4dca2f7b3a8f2f" + integrity sha1-4HA2lvveJ/Cj78rPi03KL3s6jy8= + dependencies: + regenerator-transform "^0.10.0" + +babel-plugin-transform-strict-mode@^6.24.1: + version "6.24.1" + resolved "https://registry.npmjs.org/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" + integrity sha1-1fr3qleKZbvlkc9e2uBKDGcCB1g= + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-polyfill@^6.26.0: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153" + integrity sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM= + dependencies: + babel-runtime "^6.26.0" + core-js "^2.5.0" + regenerator-runtime "^0.10.5" + +babel-preset-env@^1.7.0: + version "1.7.0" + resolved "https://registry.npmjs.org/babel-preset-env/-/babel-preset-env-1.7.0.tgz#dea79fa4ebeb883cd35dab07e260c1c9c04df77a" + integrity sha512-9OR2afuKDneX2/q2EurSftUYM0xGu4O2D9adAhVfADDhrYDaxXV0rBbevVYoY9n6nyX1PmQW/0jtpJvUNr9CHg== + dependencies: + babel-plugin-check-es2015-constants "^6.22.0" + babel-plugin-syntax-trailing-function-commas "^6.22.0" + babel-plugin-transform-async-to-generator "^6.22.0" + babel-plugin-transform-es2015-arrow-functions "^6.22.0" + babel-plugin-transform-es2015-block-scoped-functions "^6.22.0" + babel-plugin-transform-es2015-block-scoping "^6.23.0" + babel-plugin-transform-es2015-classes "^6.23.0" + babel-plugin-transform-es2015-computed-properties "^6.22.0" + babel-plugin-transform-es2015-destructuring "^6.23.0" + babel-plugin-transform-es2015-duplicate-keys "^6.22.0" + babel-plugin-transform-es2015-for-of "^6.23.0" + babel-plugin-transform-es2015-function-name "^6.22.0" + babel-plugin-transform-es2015-literals "^6.22.0" + babel-plugin-transform-es2015-modules-amd "^6.22.0" + babel-plugin-transform-es2015-modules-commonjs "^6.23.0" + babel-plugin-transform-es2015-modules-systemjs "^6.23.0" + babel-plugin-transform-es2015-modules-umd "^6.23.0" + babel-plugin-transform-es2015-object-super "^6.22.0" + babel-plugin-transform-es2015-parameters "^6.23.0" + babel-plugin-transform-es2015-shorthand-properties "^6.22.0" + babel-plugin-transform-es2015-spread "^6.22.0" + babel-plugin-transform-es2015-sticky-regex "^6.22.0" + babel-plugin-transform-es2015-template-literals "^6.22.0" + babel-plugin-transform-es2015-typeof-symbol "^6.23.0" + babel-plugin-transform-es2015-unicode-regex "^6.22.0" + babel-plugin-transform-exponentiation-operator "^6.22.0" + babel-plugin-transform-regenerator "^6.22.0" + browserslist "^3.2.6" + invariant "^2.2.2" + semver "^5.3.0" + +babel-register@^6.26.0: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-register/-/babel-register-6.26.0.tgz#6ed021173e2fcb486d7acb45c6009a856f647071" + integrity sha1-btAhFz4vy0htestFxgCahW9kcHE= + dependencies: + babel-core "^6.26.0" + babel-runtime "^6.26.0" + core-js "^2.5.0" + home-or-tmp "^2.0.0" + lodash "^4.17.4" + mkdirp "^0.5.1" + source-map-support "^0.4.15" + +babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" + integrity sha1-llxwWGaOgrVde/4E/yM3vItWR/4= + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.11.0" + +babel-template@^6.24.1, babel-template@^6.26.0: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02" + integrity sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI= + dependencies: + babel-runtime "^6.26.0" + babel-traverse "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + lodash "^4.17.4" + +babel-traverse@^6.24.1, babel-traverse@^6.26.0: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" + integrity sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4= + dependencies: + babel-code-frame "^6.26.0" + babel-messages "^6.23.0" + babel-runtime "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + debug "^2.6.8" + globals "^9.18.0" + invariant "^2.2.2" + lodash "^4.17.4" + +babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0: + version "6.26.0" + resolved "https://registry.npmjs.org/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497" + integrity sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc= + dependencies: + babel-runtime "^6.26.0" + esutils "^2.0.2" + lodash "^4.17.4" + to-fast-properties "^1.0.3" + +babel6-plugin-strip-class-callcheck@^6.0.0: + version "6.0.0" + resolved "https://registry.npmjs.org/babel6-plugin-strip-class-callcheck/-/babel6-plugin-strip-class-callcheck-6.0.0.tgz#de841c1abebbd39f78de0affb2c9a52ee228fddf" + integrity sha1-3oQcGr6705943gr/ssmlLuIo/d8= + +babel6-plugin-strip-heimdall@^6.0.1: + version "6.0.1" + resolved "https://registry.npmjs.org/babel6-plugin-strip-heimdall/-/babel6-plugin-strip-heimdall-6.0.1.tgz#35f80eddec1f7fffdc009811dfbd46d9965072b6" + integrity sha1-NfgO3ewff//cAJgR371G2ZZQcrY= + +babylon@^6.18.0: + version "6.18.0" + resolved "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" + integrity sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ== + +backbone@^1.1.2: + version "1.4.0" + resolved "https://registry.npmjs.org/backbone/-/backbone-1.4.0.tgz#54db4de9df7c3811c3f032f34749a4cd27f3bd12" + integrity sha512-RLmDrRXkVdouTg38jcgHhyQ/2zjg7a8E6sz2zxfz21Hh17xDJYUHBZimVIt5fUyS8vbfpeSmTL3gUjTEvUV3qQ== + dependencies: + underscore ">=1.8.3" + +backo2@1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" + integrity sha1-MasayLEpNjRj41s+u2n038+6eUc= + +balanced-match@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" + integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= + +base64-arraybuffer@0.1.5: + version "0.1.5" + resolved "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz#73926771923b5a19747ad666aa5cd4bf9c6e9ce8" + integrity sha1-c5JncZI7Whl0etZmqlzUv5xunOg= + +base64-js@0.0.2: + version "0.0.2" + resolved "https://registry.npmjs.org/base64-js/-/base64-js-0.0.2.tgz#024f0f72afa25b75f9c0ee73cd4f55ec1bed9784" + integrity sha1-Ak8Pcq+iW3X5wO5zzU9V7Bvtl4Q= + +base64id@1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/base64id/-/base64id-1.0.0.tgz#47688cb99bb6804f0e06d3e763b1c32e57d8e6b6" + integrity sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY= + +base@^0.11.1: + version "0.11.2" + resolved "https://registry.npmjs.org/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f" + integrity sha512-5T6P4xPgpp0YDFvSWwEZ4NoE3aM4QBQXDzmVbraCkFj8zHM+mba8SyqB5DbZWyR7mYHo6Y7BdQo3MoA4m0TeQg== + dependencies: + cache-base "^1.0.1" + class-utils "^0.3.5" + component-emitter "^1.2.1" + define-property "^1.0.0" + isobject "^3.0.1" + mixin-deep "^1.2.0" + pascalcase "^0.1.1" + +basic-auth@~2.0.0: + version "2.0.1" + resolved "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a" + integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg== + dependencies: + safe-buffer "5.1.2" + +better-assert@~1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz#40866b9e1b9e0b55b481894311e68faffaebc522" + integrity sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI= + dependencies: + callsite "1.0.0" + +"binaryextensions@1 || 2": + version "2.1.2" + resolved "https://registry.npmjs.org/binaryextensions/-/binaryextensions-2.1.2.tgz#c83c3d74233ba7674e4f313cb2a2b70f54e94b7c" + integrity sha512-xVNN69YGDghOqCCtA6FI7avYrr02mTJjOgB0/f1VPD3pJC8QEvjTKWc4epDx8AqxxA75NI0QpVM2gPJXUbE4Tg== + +blank-object@^1.0.1: + version "1.0.2" + resolved "https://registry.npmjs.org/blank-object/-/blank-object-1.0.2.tgz#f990793fbe9a8c8dd013fb3219420bec81d5f4b9" + integrity sha1-+ZB5P76ajI3QE/syGUIL7IHV9Lk= + +blob@0.0.5: + version "0.0.5" + resolved "https://registry.npmjs.org/blob/-/blob-0.0.5.tgz#d680eeef25f8cd91ad533f5b01eed48e64caf683" + integrity sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig== + +bluebird@^3.1.1, bluebird@^3.4.6: + version "3.5.3" + resolved "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7" + integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw== + +body-parser@1.18.3: + version "1.18.3" + resolved "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz#5b292198ffdd553b3a0f20ded0592b956955c8b4" + integrity sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ= + dependencies: + bytes "3.0.0" + content-type "~1.0.4" + debug "2.6.9" + depd "~1.1.2" + http-errors "~1.6.3" + iconv-lite "0.4.23" + on-finished "~2.3.0" + qs "6.5.2" + raw-body "2.3.3" + type-is "~1.6.16" + +body@^5.1.0: + version "5.1.0" + resolved "https://registry.npmjs.org/body/-/body-5.1.0.tgz#e4ba0ce410a46936323367609ecb4e6553125069" + integrity sha1-5LoM5BCkaTYyM2dgnstOZVMSUGk= + dependencies: + continuable-cache "^0.3.1" + error "^7.0.0" + raw-body "~1.1.0" + safe-json-parse "~1.0.1" + +boom@0.4.x: + version "0.4.2" + resolved "https://registry.npmjs.org/boom/-/boom-0.4.2.tgz#7a636e9ded4efcefb19cef4947a3c67dfaee911b" + integrity sha1-emNune1O/O+xnO9JR6PGffrukRs= + dependencies: + hoek "0.9.x" + +bops@0.0.3: + version "0.0.3" + resolved "https://registry.npmjs.org/bops/-/bops-0.0.3.tgz#c5cbf6fea8be7401ca5ea6d1679e6c4e8b407c79" + integrity sha1-xcv2/qi+dAHKXqbRZ55sTotAfHk= + dependencies: + base64-js "0.0.2" + to-utf8 "0.0.1" + +bower-config@^1.3.0: + version "1.4.1" + resolved "https://registry.npmjs.org/bower-config/-/bower-config-1.4.1.tgz#85fd9df367c2b8dbbd0caa4c5f2bad40cd84c2cc" + integrity sha1-hf2d82fCuNu9DKpMXyutQM2Ewsw= + dependencies: + graceful-fs "^4.1.3" + mout "^1.0.0" + optimist "^0.6.1" + osenv "^0.1.3" + untildify "^2.1.0" + +bower-endpoint-parser@0.2.2: + version "0.2.2" + resolved "https://registry.npmjs.org/bower-endpoint-parser/-/bower-endpoint-parser-0.2.2.tgz#00b565adbfab6f2d35addde977e97962acbcb3f6" + integrity sha1-ALVlrb+rby01rd3pd+l5Yqy8s/Y= + +brace-expansion@^1.0.0, brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +braces@^2.3.1: + version "2.3.2" + resolved "https://registry.npmjs.org/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729" + integrity sha512-aNdbnj9P8PjdXU4ybaWLK2IF3jc/EoDYbC7AazW6to3TRsfXxscC9UXOB5iDiEQrkyIbWp2SLQda4+QAa7nc3w== + dependencies: + arr-flatten "^1.1.0" + array-unique "^0.3.2" + extend-shallow "^2.0.1" + fill-range "^4.0.0" + isobject "^3.0.1" + repeat-element "^1.1.2" + snapdragon "^0.8.1" + snapdragon-node "^2.0.1" + split-string "^3.0.2" + to-regex "^3.0.1" + +broccoli-amd-funnel@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/broccoli-amd-funnel/-/broccoli-amd-funnel-2.0.1.tgz#dbdbfd28841731342d538126567c25bea3f15310" + integrity sha512-VRE+0PYAN4jQfkIq3GKRj4U/4UV9rVpLan5ll6fVYV4ziVg4OEfR5GUnILEg++QtR4xSaugRxCPU5XJLDy3bNQ== + dependencies: + broccoli-plugin "^1.3.0" + symlink-or-copy "^1.2.0" + +broccoli-babel-transpiler@^6.5.0: + version "6.5.1" + resolved "https://registry.npmjs.org/broccoli-babel-transpiler/-/broccoli-babel-transpiler-6.5.1.tgz#a4afc8d3b59b441518eb9a07bd44149476e30738" + integrity sha512-w6GcnkxvHcNCte5FcLGEG1hUdQvlfvSN/6PtGWU/otg69Ugk8rUk51h41R0Ugoc+TNxyeFG1opRt2RlA87XzNw== + dependencies: + babel-core "^6.26.0" + broccoli-funnel "^2.0.1" + broccoli-merge-trees "^2.0.0" + broccoli-persistent-filter "^1.4.3" + clone "^2.0.0" + hash-for-dep "^1.2.3" + heimdalljs-logger "^0.1.7" + json-stable-stringify "^1.0.0" + rsvp "^4.8.2" + workerpool "^2.3.0" + +broccoli-babel-transpiler@^7.1.1, broccoli-babel-transpiler@^7.1.2, broccoli-babel-transpiler@^7.2.0: + version "7.2.0" + resolved "https://registry.npmjs.org/broccoli-babel-transpiler/-/broccoli-babel-transpiler-7.2.0.tgz#5c0d694c4055106abb385e2d3d88936d35b7cb18" + integrity sha512-lkP9dNFfK810CRHHWsNl9rjyYqcXH3qg0kArnA6tV9Owx3nlZm3Eyr0cGo6sMUQCNLH+2oKrRjOdUGSc6Um6Cw== + dependencies: + "@babel/core" "^7.3.3" + "@babel/polyfill" "^7.0.0" + broccoli-funnel "^2.0.2" + broccoli-merge-trees "^3.0.2" + broccoli-persistent-filter "^2.2.1" + clone "^2.1.2" + hash-for-dep "^1.4.7" + heimdalljs-logger "^0.1.9" + json-stable-stringify "^1.0.1" + rsvp "^4.8.4" + workerpool "^3.1.1" + +broccoli-builder@^0.18.14: + version "0.18.14" + resolved "https://registry.npmjs.org/broccoli-builder/-/broccoli-builder-0.18.14.tgz#4b79e2f844de11a4e1b816c3f49c6df4776c312d" + integrity sha1-S3ni+ETeEaThuBbD9Jxt9HdsMS0= + dependencies: + broccoli-node-info "^1.1.0" + heimdalljs "^0.2.0" + promise-map-series "^0.2.1" + quick-temp "^0.1.2" + rimraf "^2.2.8" + rsvp "^3.0.17" + silent-error "^1.0.1" + +broccoli-caching-writer@^2.2.0: + version "2.3.1" + resolved "https://registry.npmjs.org/broccoli-caching-writer/-/broccoli-caching-writer-2.3.1.tgz#b93cf58f9264f003075868db05774f4e7f25bd07" + integrity sha1-uTz1j5Jk8AMHWGjbBXdPTn8lvQc= + dependencies: + broccoli-kitchen-sink-helpers "^0.2.5" + broccoli-plugin "1.1.0" + debug "^2.1.1" + rimraf "^2.2.8" + rsvp "^3.0.17" + walk-sync "^0.2.5" + +broccoli-caching-writer@^3.0.3: + version "3.0.3" + resolved "https://registry.npmjs.org/broccoli-caching-writer/-/broccoli-caching-writer-3.0.3.tgz#0bd2c96a9738d6a6ab590f07ba35c5157d7db476" + integrity sha1-C9LJapc41qarWQ8HujXFFX19tHY= + dependencies: + broccoli-kitchen-sink-helpers "^0.3.1" + broccoli-plugin "^1.2.1" + debug "^2.1.1" + rimraf "^2.2.8" + rsvp "^3.0.17" + walk-sync "^0.3.0" + +broccoli-caching-writer@~2.0.4: + version "2.0.4" + resolved "https://registry.npmjs.org/broccoli-caching-writer/-/broccoli-caching-writer-2.0.4.tgz#d995d7d1977292e498f78df05887230fcb4a5e2c" + integrity sha1-2ZXX0ZdykuSY943wWIcjD8tKXiw= + dependencies: + broccoli-kitchen-sink-helpers "^0.2.5" + broccoli-plugin "1.1.0" + debug "^2.1.1" + lodash-node "^3.2.0" + rimraf "^2.2.8" + rsvp "^3.0.17" + symlink-or-copy "^1.0.0" + walk-sync "^0.2.0" + +broccoli-clean-css@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/broccoli-clean-css/-/broccoli-clean-css-1.1.0.tgz#9db143d9af7e0ae79c26e3ac5a9bb2d720ea19fa" + integrity sha1-nbFD2a9+CuecJuOsWpuy1yDqGfo= + dependencies: + broccoli-persistent-filter "^1.1.6" + clean-css-promise "^0.1.0" + inline-source-map-comment "^1.0.5" + json-stable-stringify "^1.0.0" + +broccoli-concat@^3.2.2, broccoli-concat@^3.7.3: + version "3.7.3" + resolved "https://registry.npmjs.org/broccoli-concat/-/broccoli-concat-3.7.3.tgz#0dca01311567ffb13180e6b4eb111824628e4885" + integrity sha512-2Ma9h81EJ0PRb9n4sW0i8KZlcnpTQfKxcj87zvi5DFe1fd8CTDEdseHDotK2beuA2l+LbgVPfd8EHaBJKm/Y8g== + dependencies: + broccoli-debug "^0.6.5" + broccoli-kitchen-sink-helpers "^0.3.1" + broccoli-plugin "^1.3.0" + ensure-posix-path "^1.0.2" + fast-sourcemap-concat "^1.4.0" + find-index "^1.1.0" + fs-extra "^4.0.3" + fs-tree-diff "^0.5.7" + lodash.merge "^4.3.1" + lodash.omit "^4.1.0" + lodash.uniq "^4.2.0" + walk-sync "^0.3.2" + +broccoli-config-loader@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/broccoli-config-loader/-/broccoli-config-loader-1.0.1.tgz#d10aaf8ebc0cb45c1da5baa82720e1d88d28c80a" + integrity sha512-MDKYQ50rxhn+g17DYdfzfEM9DjTuSGu42Db37A8TQHQe8geYEcUZ4SQqZRgzdAI3aRQNlA1yBHJfOeGmOjhLIg== + dependencies: + broccoli-caching-writer "^3.0.3" + +broccoli-config-replace@^1.1.2: + version "1.1.2" + resolved "https://registry.npmjs.org/broccoli-config-replace/-/broccoli-config-replace-1.1.2.tgz#6ea879d92a5bad634d11329b51fc5f4aafda9c00" + integrity sha1-bqh52SpbrWNNETKbUfxfSq/anAA= + dependencies: + broccoli-kitchen-sink-helpers "^0.3.1" + broccoli-plugin "^1.2.0" + debug "^2.2.0" + fs-extra "^0.24.0" + +broccoli-debug@^0.6.4, broccoli-debug@^0.6.5: + version "0.6.5" + resolved "https://registry.npmjs.org/broccoli-debug/-/broccoli-debug-0.6.5.tgz#164a5cdafd8936e525e702bf8f91f39d758e2e78" + integrity sha512-RIVjHvNar9EMCLDW/FggxFRXqpjhncM/3qq87bn/y+/zR9tqEkHvTqbyOc4QnB97NO2m6342w4wGkemkaeOuWg== + dependencies: + broccoli-plugin "^1.2.1" + fs-tree-diff "^0.5.2" + heimdalljs "^0.2.1" + heimdalljs-logger "^0.1.7" + symlink-or-copy "^1.1.8" + tree-sync "^1.2.2" + +broccoli-file-creator@^1.1.1: + version "1.2.0" + resolved "https://registry.npmjs.org/broccoli-file-creator/-/broccoli-file-creator-1.2.0.tgz#27f1b25b1b00e7bb7bf3d5d7abed5f4d5388df4d" + integrity sha512-l9zthHg6bAtnOfRr/ieZ1srRQEsufMZID7xGYRW3aBDv3u/3Eux+Iawl10tAGYE5pL9YB4n5X4vxkp6iNOoZ9g== + dependencies: + broccoli-plugin "^1.1.0" + mkdirp "^0.5.1" + +broccoli-file-creator@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/broccoli-file-creator/-/broccoli-file-creator-2.1.1.tgz#7351dd2496c762cfce7736ce9b49e3fce0c7b7db" + integrity sha512-YpjOExWr92C5vhnK0kmD81kM7U09kdIRZk9w4ZDCDHuHXW+VE/x6AGEOQQW3loBQQ6Jk+k+TSm8dESy4uZsnjw== + dependencies: + broccoli-plugin "^1.1.0" + mkdirp "^0.5.1" + +broccoli-filter@^1.0.1: + version "1.3.0" + resolved "https://registry.npmjs.org/broccoli-filter/-/broccoli-filter-1.3.0.tgz#71e3a8e32a17f309e12261919c5b1006d6766de6" + integrity sha512-VXJXw7eBfG82CFxaBDjYmyN7V72D4In2zwLVQJd/h3mBfF3CMdRTsv2L20lmRTtCv1sAHcB+LgMso90e/KYiLw== + dependencies: + broccoli-kitchen-sink-helpers "^0.3.1" + broccoli-plugin "^1.0.0" + copy-dereference "^1.0.0" + debug "^2.2.0" + mkdirp "^0.5.1" + promise-map-series "^0.2.1" + rsvp "^3.0.18" + symlink-or-copy "^1.0.1" + walk-sync "^0.3.1" + +broccoli-funnel-reducer@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/broccoli-funnel-reducer/-/broccoli-funnel-reducer-1.0.0.tgz#11365b2a785aec9b17972a36df87eef24c5cc0ea" + integrity sha1-ETZbKnha7JsXlyo234fu8kxcwOo= + +broccoli-funnel@^1.0.1: + version "1.2.0" + resolved "https://registry.npmjs.org/broccoli-funnel/-/broccoli-funnel-1.2.0.tgz#cddc3afc5ff1685a8023488fff74ce6fb5a51296" + integrity sha1-zdw6/F/xaFqAI0iP/3TOb7WlEpY= + dependencies: + array-equal "^1.0.0" + blank-object "^1.0.1" + broccoli-plugin "^1.3.0" + debug "^2.2.0" + exists-sync "0.0.4" + fast-ordered-set "^1.0.0" + fs-tree-diff "^0.5.3" + heimdalljs "^0.2.0" + minimatch "^3.0.0" + mkdirp "^0.5.0" + path-posix "^1.0.0" + rimraf "^2.4.3" + symlink-or-copy "^1.0.0" + walk-sync "^0.3.1" + +broccoli-funnel@^2.0.0, broccoli-funnel@^2.0.1, broccoli-funnel@^2.0.2: + version "2.0.2" + resolved "https://registry.npmjs.org/broccoli-funnel/-/broccoli-funnel-2.0.2.tgz#0edf629569bc10bd02cc525f74b9a38e71366a75" + integrity sha512-/vDTqtv7ipjEZQOVqO4vGDVAOZyuYzQ/EgGoyewfOgh1M7IQAToBKZI0oAQPgMBeFPPlIbfMuAngk+ohPBuaHQ== + dependencies: + array-equal "^1.0.0" + blank-object "^1.0.1" + broccoli-plugin "^1.3.0" + debug "^2.2.0" + fast-ordered-set "^1.0.0" + fs-tree-diff "^0.5.3" + heimdalljs "^0.2.0" + minimatch "^3.0.0" + mkdirp "^0.5.0" + path-posix "^1.0.0" + rimraf "^2.4.3" + symlink-or-copy "^1.0.0" + walk-sync "^0.3.1" + +broccoli-kitchen-sink-helpers@^0.2.5: + version "0.2.9" + resolved "https://registry.npmjs.org/broccoli-kitchen-sink-helpers/-/broccoli-kitchen-sink-helpers-0.2.9.tgz#a5e0986ed8d76fb5984b68c3f0450d3a96e36ecc" + integrity sha1-peCYbtjXb7WYS2jD8EUNOpbjbsw= + dependencies: + glob "^5.0.10" + mkdirp "^0.5.1" + +broccoli-kitchen-sink-helpers@^0.3.1: + version "0.3.1" + resolved "https://registry.npmjs.org/broccoli-kitchen-sink-helpers/-/broccoli-kitchen-sink-helpers-0.3.1.tgz#77c7c18194b9664163ec4fcee2793444926e0c06" + integrity sha1-d8fBgZS5ZkFj7E/O4nk0RJJuDAY= + dependencies: + glob "^5.0.10" + mkdirp "^0.5.1" + +broccoli-merge-trees@^1.0.0, broccoli-merge-trees@^1.1.1: + version "1.2.4" + resolved "https://registry.npmjs.org/broccoli-merge-trees/-/broccoli-merge-trees-1.2.4.tgz#a001519bb5067f06589d91afa2942445a2d0fdb5" + integrity sha1-oAFRm7UGfwZYnZGvopQkRaLQ/bU= + dependencies: + broccoli-plugin "^1.3.0" + can-symlink "^1.0.0" + fast-ordered-set "^1.0.2" + fs-tree-diff "^0.5.4" + heimdalljs "^0.2.1" + heimdalljs-logger "^0.1.7" + rimraf "^2.4.3" + symlink-or-copy "^1.0.0" + +broccoli-merge-trees@^2.0.0: + version "2.0.1" + resolved "https://registry.npmjs.org/broccoli-merge-trees/-/broccoli-merge-trees-2.0.1.tgz#14d4b7fc1a90318c12b16f843e6ba2693808100c" + integrity sha512-WjaexJ+I8BxP5V5RNn6um/qDRSmKoiBC/QkRi79FT9ClHfldxRyCDs9mcV7mmoaPlsshmmPaUz5jdtcKA6DClQ== + dependencies: + broccoli-plugin "^1.3.0" + merge-trees "^1.0.1" + +broccoli-merge-trees@^3.0.0, broccoli-merge-trees@^3.0.1, broccoli-merge-trees@^3.0.2: + version "3.0.2" + resolved "https://registry.npmjs.org/broccoli-merge-trees/-/broccoli-merge-trees-3.0.2.tgz#f33b451994225522b5c9bcf27d59decfd8ba537d" + integrity sha512-ZyPAwrOdlCddduFbsMyyFzJUrvW6b04pMvDiAQZrCwghlvgowJDY+EfoXn+eR1RRA5nmGHJ+B68T63VnpRiT1A== + dependencies: + broccoli-plugin "^1.3.0" + merge-trees "^2.0.0" + +broccoli-middleware@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/broccoli-middleware/-/broccoli-middleware-2.0.1.tgz#093314f13e52fad7fa8c4254a4e4a4560c857a65" + integrity sha512-V/K5uozcEH/XJ09ZAL8aJt/W2UwJU8I8fA2FAg3u9gzs5dQrehHDtgSoKS2QjPjurRC1GSiYLcsMp36sezaQQg== + dependencies: + handlebars "^4.0.4" + mime-types "^2.1.18" + +broccoli-module-normalizer@^1.3.0: + version "1.3.0" + resolved "https://registry.npmjs.org/broccoli-module-normalizer/-/broccoli-module-normalizer-1.3.0.tgz#f9982d9cbb776b4ed754161cc6547784d3eb19de" + integrity sha512-0idZCOtdVG6xXoQ36Psc1ApMCr3lW5DB+WEAOEwHcUoESIBHzwcRPQTxheGIjZ5o0hxpsRYAUH5x0ErtNezbrQ== + dependencies: + broccoli-plugin "^1.3.0" + merge-trees "^1.0.1" + rimraf "^2.6.2" + symlink-or-copy "^1.1.8" + +broccoli-module-unification-reexporter@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/broccoli-module-unification-reexporter/-/broccoli-module-unification-reexporter-1.0.0.tgz#031909c5d3f159ec11d5f9e2346f2861db8acb3e" + integrity sha512-HTi9ua520M20aBZomaiBopsSt3yjL7J/paR3XPjieygK7+ShATBiZdn0B+ZPiniBi4I8JuMn1q0fNFUevtP//A== + dependencies: + broccoli-plugin "^1.3.0" + mkdirp "^0.5.1" + walk-sync "^0.3.2" + +broccoli-node-info@1.1.0, broccoli-node-info@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/broccoli-node-info/-/broccoli-node-info-1.1.0.tgz#3aa2e31e07e5bdb516dd25214f7c45ba1c459412" + integrity sha1-OqLjHgflvbUW3SUhT3xFuhxFlBI= + +broccoli-persistent-filter@^1.1.5, broccoli-persistent-filter@^1.1.6, broccoli-persistent-filter@^1.4.3: + version "1.4.6" + resolved "https://registry.npmjs.org/broccoli-persistent-filter/-/broccoli-persistent-filter-1.4.6.tgz#80762d19000880a77da33c34373299c0f6a3e615" + integrity sha512-0RejLwoC95kv4kta8KAa+FmECJCK78Qgm8SRDEK7YyU0N9Cx6KpY3UCDy9WELl3mCXLN8TokNxc7/hp3lL4lfw== + dependencies: + async-disk-cache "^1.2.1" + async-promise-queue "^1.0.3" + broccoli-plugin "^1.0.0" + fs-tree-diff "^0.5.2" + hash-for-dep "^1.0.2" + heimdalljs "^0.2.1" + heimdalljs-logger "^0.1.7" + mkdirp "^0.5.1" + promise-map-series "^0.2.1" + rimraf "^2.6.1" + rsvp "^3.0.18" + symlink-or-copy "^1.0.1" + walk-sync "^0.3.1" + +broccoli-persistent-filter@^2.1.1, broccoli-persistent-filter@^2.2.1: + version "2.2.2" + resolved "https://registry.npmjs.org/broccoli-persistent-filter/-/broccoli-persistent-filter-2.2.2.tgz#e0180e75ede5dd05d4c702f24f6c049e93fba915" + integrity sha512-PW12RD1yY+x5SASUADuUMJce+dVSmjBO3pV1rLNHmT1C31rp1P++TvX7AgUObFmGhL7qlwviSdhMbBkY1v3G2w== + dependencies: + async-disk-cache "^1.2.1" + async-promise-queue "^1.0.3" + broccoli-plugin "^1.0.0" + fs-tree-diff "^1.0.2" + hash-for-dep "^1.5.0" + heimdalljs "^0.2.1" + heimdalljs-logger "^0.1.7" + mkdirp "^0.5.1" + promise-map-series "^0.2.1" + rimraf "^2.6.1" + rsvp "^4.7.0" + symlink-or-copy "^1.0.1" + walk-sync "^1.0.0" + +broccoli-plugin@1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/broccoli-plugin/-/broccoli-plugin-1.1.0.tgz#73e2cfa05f8ea1e3fc1420c40c3d9e7dc724bf02" + integrity sha1-c+LPoF+OoeP8FCDEDD2efcckvwI= + dependencies: + promise-map-series "^0.2.1" + quick-temp "^0.1.3" + rimraf "^2.3.4" + symlink-or-copy "^1.0.1" + +broccoli-plugin@^1.0.0, broccoli-plugin@^1.1.0, broccoli-plugin@^1.2.0, broccoli-plugin@^1.2.1, broccoli-plugin@^1.3.0, broccoli-plugin@^1.3.1: + version "1.3.1" + resolved "https://registry.npmjs.org/broccoli-plugin/-/broccoli-plugin-1.3.1.tgz#a26315732fb99ed2d9fb58f12a1e14e986b4fabd" + integrity sha512-DW8XASZkmorp+q7J4EeDEZz+LoyKLAd2XZULXyD9l4m9/hAKV3vjHmB1kiUshcWAYMgTP1m2i4NnqCE/23h6AQ== + dependencies: + promise-map-series "^0.2.1" + quick-temp "^0.1.3" + rimraf "^2.3.4" + symlink-or-copy "^1.1.8" + +broccoli-rollup@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/broccoli-rollup/-/broccoli-rollup-2.1.1.tgz#0b77dc4b7560a53e998ea85f3b56772612d4988d" + integrity sha512-aky/Ovg5DbsrsJEx2QCXxHLA6ZR+9u1TNVTf85soP4gL8CjGGKQ/JU8R3BZ2ntkWzo6/83RCKzX6O+nlNKR5MQ== + dependencies: + "@types/node" "^9.6.0" + amd-name-resolver "^1.2.0" + broccoli-plugin "^1.2.1" + fs-tree-diff "^0.5.2" + heimdalljs "^0.2.1" + heimdalljs-logger "^0.1.7" + magic-string "^0.24.0" + node-modules-path "^1.0.1" + rollup "^0.57.1" + symlink-or-copy "^1.1.8" + walk-sync "^0.3.1" + +broccoli-slow-trees@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/broccoli-slow-trees/-/broccoli-slow-trees-3.0.1.tgz#9bf2a9e2f8eb3ed3a3f2abdde988da437ccdc9b4" + integrity sha1-m/Kp4vjrPtOj8qvd6YjaQ3zNybQ= + dependencies: + heimdalljs "^0.2.1" + +broccoli-source@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/broccoli-source/-/broccoli-source-1.1.0.tgz#54f0e82c8b73f46580cbbc4f578f0b32fca8f809" + integrity sha1-VPDoLItz9GWAy7xPV48LMvyo+Ak= + +broccoli-sri-hash@^2.1.0: + version "2.1.2" + resolved "https://registry.npmjs.org/broccoli-sri-hash/-/broccoli-sri-hash-2.1.2.tgz#bc69905ed7a381ad325cc0d02ded071328ebf3f3" + integrity sha1-vGmQXtejga0yXMDQLe0HEyjr8/M= + dependencies: + broccoli-caching-writer "^2.2.0" + mkdirp "^0.5.1" + rsvp "^3.1.0" + sri-toolbox "^0.2.0" + symlink-or-copy "^1.0.1" + +broccoli-stew@^2.0.0, broccoli-stew@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/broccoli-stew/-/broccoli-stew-2.0.1.tgz#d0a507b79bf5fea9ff84032ae837dc48670ab1dc" + integrity sha512-EUzgkbYF4m8YVD2bkEa7OfYJ11V3dQ+yPuxdz/nFh8eMEn6dhOujtuSBnOWsvGDgsS9oqNZgx/MHJxI6Rr3AqQ== + dependencies: + broccoli-debug "^0.6.5" + broccoli-funnel "^2.0.0" + broccoli-merge-trees "^3.0.1" + broccoli-persistent-filter "^2.1.1" + broccoli-plugin "^1.3.1" + chalk "^2.4.1" + debug "^3.1.0" + ensure-posix-path "^1.0.1" + fs-extra "^6.0.1" + minimatch "^3.0.4" + resolve "^1.8.1" + rsvp "^4.8.4" + symlink-or-copy "^1.2.0" + walk-sync "^0.3.3" + +broccoli-string-replace@^0.1.2: + version "0.1.2" + resolved "https://registry.npmjs.org/broccoli-string-replace/-/broccoli-string-replace-0.1.2.tgz#1ed92f85680af8d503023925e754e4e33676b91f" + integrity sha1-HtkvhWgK+NUDAjkl51Tk4zZ2uR8= + dependencies: + broccoli-persistent-filter "^1.1.5" + minimatch "^3.0.3" + +broccoli-templater@^2.0.1: + version "2.0.2" + resolved "https://registry.npmjs.org/broccoli-templater/-/broccoli-templater-2.0.2.tgz#285a892071c0b3ad5ebc275d9e8b3465e2d120d6" + integrity sha512-71KpNkc7WmbEokTQpGcbGzZjUIY1NSVa3GB++KFKAfx5SZPUozCOsBlSTwxcv8TLoCAqbBnsX5AQPgg6vJ2l9g== + dependencies: + broccoli-plugin "^1.3.1" + fs-tree-diff "^0.5.9" + lodash.template "^4.4.0" + rimraf "^2.6.2" + walk-sync "^0.3.3" + +broccoli-test-helper@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/broccoli-test-helper/-/broccoli-test-helper-2.0.0.tgz#1cfbb76f7e856ad8df96d55ee2f5e0dddddf5d4f" + integrity sha512-TKwh8dBT+RcxKEG+vAoaRRhZsCMwZIHPZbCzBNCA0nUi1aoFB/LVosqwMC6H9Ipe06FxY5hpQxDLFbnBMdUPsA== + dependencies: + "@types/tmp" "^0.0.33" + broccoli "^2.0.0" + fixturify "^0.3.2" + fs-tree-diff "^0.5.9" + tmp "^0.0.33" + walk-sync "^0.3.3" + +broccoli-uglify-sourcemap@^2.1.1: + version "2.2.0" + resolved "https://registry.npmjs.org/broccoli-uglify-sourcemap/-/broccoli-uglify-sourcemap-2.2.0.tgz#2ff49389bdf342a550c3596750ba2dde95a8f7d4" + integrity sha1-L/STib3zQqVQw1lnULot3pWo99Q= + dependencies: + async-promise-queue "^1.0.4" + broccoli-plugin "^1.2.1" + debug "^3.1.0" + lodash.defaultsdeep "^4.6.0" + matcher-collection "^1.0.5" + mkdirp "^0.5.0" + source-map-url "^0.4.0" + symlink-or-copy "^1.0.1" + terser "^3.7.5" + walk-sync "^0.3.2" + workerpool "^2.3.0" + +broccoli-uglify-sourcemap@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/broccoli-uglify-sourcemap/-/broccoli-uglify-sourcemap-3.0.0.tgz#680a23e5e2df0abb0d921a71323c975f1e237524" + integrity sha512-V3TK8uJjbnuU5QSbevMVicxOQe/AFyJl0BxKZv0Auuti85LeV4f09qzrlCYdamyIPPBeaI1sFxR/9TVqC08WoA== + dependencies: + async-promise-queue "^1.0.4" + broccoli-plugin "^1.2.1" + debug "^4.1.0" + lodash.defaultsdeep "^4.6.0" + matcher-collection "^1.0.5" + mkdirp "^0.5.0" + source-map-url "^0.4.0" + symlink-or-copy "^1.0.1" + terser "^3.16.1" + walk-sync "^1.1.3" + workerpool "^3.1.1" + +broccoli@^2.0.0: + version "2.1.0" + resolved "https://registry.npmjs.org/broccoli/-/broccoli-2.1.0.tgz#5c896691bd440bdb60afbb56c79d08abfe8aa620" + integrity sha512-huFxLd4oD96nnqFbakmxwV05okdw8d9Xto0dQ20nfgL5O3No4TlKltNvRIcnDAQVJe+VCMQleFRMdgzrRbGT3Q== + dependencies: + broccoli-node-info "1.1.0" + broccoli-slow-trees "^3.0.1" + broccoli-source "^1.1.0" + commander "^2.15.1" + connect "^3.6.6" + esm "^3.2.4" + findup-sync "^2.0.0" + handlebars "^4.0.11" + heimdalljs "^0.2.5" + heimdalljs-logger "^0.1.9" + mime-types "^2.1.19" + promise.prototype.finally "^3.1.0" + resolve-path "^1.4.0" + rimraf "^2.6.2" + sane "^4.0.0" + tmp "0.0.33" + tree-sync "^1.2.2" + underscore.string "^3.2.2" + watch-detector "^0.1.0" + +browser-stdout@1.3.1: + version "1.3.1" + resolved "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60" + integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw== + +browserslist@^3.2.6: + version "3.2.8" + resolved "https://registry.npmjs.org/browserslist/-/browserslist-3.2.8.tgz#b0005361d6471f0f5952797a76fc985f1f978fc6" + integrity sha512-WHVocJYavUwVgVViC0ORikPHQquXwVh939TaelZ4WDqpWgTX/FsGhl/+P4qBUAGcRvtOgDgC+xftNWWp2RUTAQ== + dependencies: + caniuse-lite "^1.0.30000844" + electron-to-chromium "^1.3.47" + +browserslist@^4.0.0, browserslist@^4.3.4: + version "4.4.2" + resolved "https://registry.npmjs.org/browserslist/-/browserslist-4.4.2.tgz#6ea8a74d6464bb0bd549105f659b41197d8f0ba2" + integrity sha512-ISS/AIAiHERJ3d45Fz0AVYKkgcy+F/eJHzKEvv1j0wwKGKD9T3BrwKr/5g45L+Y4XIK5PlTqefHciRFcfE1Jxg== + dependencies: + caniuse-lite "^1.0.30000939" + electron-to-chromium "^1.3.113" + node-releases "^1.1.8" + +bser@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/bser/-/bser-2.0.0.tgz#9ac78d3ed5d915804fd87acb158bc797147a1719" + integrity sha1-mseNPtXZFYBP2HrLFYvHlxR6Fxk= + dependencies: + node-int64 "^0.4.0" + +buffer-alloc-unsafe@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz#bd7dc26ae2972d0eda253be061dba992349c19f0" + integrity sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg== + +buffer-alloc@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz#890dd90d923a873e08e10e5fd51a57e5b7cce0ec" + integrity sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow== + dependencies: + buffer-alloc-unsafe "^1.1.0" + buffer-fill "^1.0.0" + +buffer-fill@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz#f8f78b76789888ef39f205cd637f68e702122b2c" + integrity sha1-+PeLdniYiO858gXNY39o5wISKyw= + +buffer-from@^1.0.0: + version "1.1.1" + resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef" + integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A== + +builtins@^1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/builtins/-/builtins-1.0.3.tgz#cb94faeb61c8696451db36534e1422f94f0aee88" + integrity sha1-y5T662HIaWRR2zZTThQi+U8K7og= + +bytes@1: + version "1.0.0" + resolved "https://registry.npmjs.org/bytes/-/bytes-1.0.0.tgz#3569ede8ba34315fab99c3e92cb04c7220de1fa8" + integrity sha1-NWnt6Lo0MV+rmcPpLLBMciDeH6g= + +bytes@3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" + integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg= + +cache-base@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" + integrity sha512-AKcdTnFSWATd5/GCPRxr2ChwIJ85CeyrEyjRHlKxQ56d4XJMGym0uAiKn0xbLOGOl3+yRpOTi484dVCEc5AUzQ== + dependencies: + collection-visit "^1.0.0" + component-emitter "^1.2.1" + get-value "^2.0.6" + has-value "^1.0.0" + isobject "^3.0.1" + set-value "^2.0.0" + to-object-path "^0.3.0" + union-value "^1.0.0" + unset-value "^1.0.0" + +cacheable-request@^2.1.1: + version "2.1.4" + resolved "https://registry.npmjs.org/cacheable-request/-/cacheable-request-2.1.4.tgz#0d808801b6342ad33c91df9d0b44dc09b91e5c3d" + integrity sha1-DYCIAbY0KtM8kd+dC0TcCbkeXD0= + dependencies: + clone-response "1.0.2" + get-stream "3.0.0" + http-cache-semantics "3.8.1" + keyv "3.0.0" + lowercase-keys "1.0.0" + normalize-url "2.0.1" + responselike "1.0.2" + +calculate-cache-key-for-tree@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/calculate-cache-key-for-tree/-/calculate-cache-key-for-tree-1.1.0.tgz#0c3e42c9c134f3c9de5358c0f16793627ea976d6" + integrity sha1-DD5CycE088neU1jA8WeTYn6pdtY= + dependencies: + json-stable-stringify "^1.0.1" + +callsite@1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20" + integrity sha1-KAOY5dZkvXQDi28JBRU+borxvCA= + +callsites@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/callsites/-/callsites-3.0.0.tgz#fb7eb569b72ad7a45812f93fd9430a3e410b3dd3" + integrity sha512-tWnkwu9YEq2uzlBDI4RcLn8jrFvF9AOi8PxDNU3hZZjJcjkcRAq3vCI+vZcg1SuxISDYe86k9VZFwAxDiJGoAw== + +camelcase@^5.0.0: + version "5.2.0" + resolved "https://registry.npmjs.org/camelcase/-/camelcase-5.2.0.tgz#e7522abda5ed94cc0489e1b8466610e88404cf45" + integrity sha512-IXFsBS2pC+X0j0N/GE7Dm7j3bsEBp+oTpb7F50dwEVX7rf3IgwO9XatnegTsDtniKCUtEJH4fSU6Asw7uoVLfQ== + +can-symlink@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/can-symlink/-/can-symlink-1.0.0.tgz#97b607d8a84bb6c6e228b902d864ecb594b9d219" + integrity sha1-l7YH2KhLtsbiKLkC2GTstZS50hk= + dependencies: + tmp "0.0.28" + +caniuse-api@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/caniuse-api/-/caniuse-api-3.0.0.tgz#5e4d90e2274961d46291997df599e3ed008ee4c0" + integrity sha512-bsTwuIg/BZZK/vreVTYYbSWoe2F+71P7K5QGEX+pT250DZbfU1MQ5prOKpPR+LL6uWKK3KMwMCAS74QB3Um1uw== + dependencies: + browserslist "^4.0.0" + caniuse-lite "^1.0.0" + lodash.memoize "^4.1.2" + lodash.uniq "^4.5.0" + +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000844, caniuse-lite@^1.0.30000939: + version "1.0.30000942" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000942.tgz#454139b28274bce70bfe1d50c30970df7430c6e4" + integrity sha512-wLf+IhZUy2rfz48tc40OH7jHjXjnvDFEYqBHluINs/6MgzoNLPf25zhE4NOVzqxLKndf+hau81sAW0RcGHIaBQ== + +capture-exit@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/capture-exit/-/capture-exit-1.2.0.tgz#1c5fcc489fd0ab00d4f1ac7ae1072e3173fbab6f" + integrity sha1-HF/MSJ/QqwDU8ax64QcuMXP7q28= + dependencies: + rsvp "^3.3.3" + +capture-exit@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4" + integrity sha512-PiT/hQmTonHhl/HFGN+Lx3JJUznrVYJ3+AQsnthneZbvW7x+f08Tk7yLJTLEOUvBTbduLeeBkxEaYXUOUrRq6g== + dependencies: + rsvp "^4.8.4" + +capture-stack-trace@^1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/capture-stack-trace/-/capture-stack-trace-1.0.1.tgz#a6c0bbe1f38f3aa0b92238ecb6ff42c344d4135d" + integrity sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw== + +cardinal@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/cardinal/-/cardinal-1.0.0.tgz#50e21c1b0aa37729f9377def196b5a9cec932ee9" + integrity sha1-UOIcGwqjdyn5N33vGWtanOyTLuk= + dependencies: + ansicolors "~0.2.1" + redeyed "~1.0.0" + +chai-as-promised@^6.0.0: + version "6.0.0" + resolved "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-6.0.0.tgz#1a02a433a6f24dafac63b9c96fa1684db1aa8da6" + integrity sha1-GgKkM6byTa+sY7nJb6FoTbGqjaY= + dependencies: + check-error "^1.0.2" + +chai-as-promised@^7.0.0: + version "7.1.1" + resolved "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz#08645d825deb8696ee61725dbf590c012eb00ca0" + integrity sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA== + dependencies: + check-error "^1.0.2" + +chai-files@^1.0.0, chai-files@^1.1.0: + version "1.4.0" + resolved "https://registry.npmjs.org/chai-files/-/chai-files-1.4.0.tgz#0e25610fadc551b1eae79c2f4ee79faf2f842296" + integrity sha1-DiVhD63FUbHq55wvTuefry+EIpY= + dependencies: + assertion-error "^1.0.1" + +chai@^3.3.0: + version "3.5.0" + resolved "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247" + integrity sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc= + dependencies: + assertion-error "^1.0.1" + deep-eql "^0.1.3" + type-detect "^1.0.0" + +chai@^4.1.0: + version "4.2.0" + resolved "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5" + integrity sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw== + dependencies: + assertion-error "^1.1.0" + check-error "^1.0.2" + deep-eql "^3.0.1" + get-func-name "^2.0.0" + pathval "^1.1.0" + type-detect "^4.0.5" + +chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3: + version "1.1.3" + resolved "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" + integrity sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg= + dependencies: + ansi-styles "^2.2.1" + escape-string-regexp "^1.0.2" + has-ansi "^2.0.0" + strip-ansi "^3.0.0" + supports-color "^2.0.0" + +chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2: + version "2.4.2" + resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" + integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== + dependencies: + ansi-styles "^3.2.1" + escape-string-regexp "^1.0.5" + supports-color "^5.3.0" + +chardet@^0.7.0: + version "0.7.0" + resolved "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" + integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== + +charm@^1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/charm/-/charm-1.0.2.tgz#8add367153a6d9a581331052c4090991da995e35" + integrity sha1-it02cVOm2aWBMxBSxAkJkdqZXjU= + dependencies: + inherits "^2.0.1" + +check-error@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82" + integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII= + +ci-info@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" + integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== + +class-utils@^0.3.5: + version "0.3.6" + resolved "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463" + integrity sha512-qOhPa/Fj7s6TY8H8esGu5QNpMMQxz79h+urzrNYN6mn+9BnxlDGf5QZ+XeCDsxSjPqsSR56XOZOJmpeurnLMeg== + dependencies: + arr-union "^3.1.0" + define-property "^0.2.5" + isobject "^3.0.0" + static-extend "^0.1.1" + +clean-base-url@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/clean-base-url/-/clean-base-url-1.0.0.tgz#c901cf0a20b972435b0eccd52d056824a4351b7b" + integrity sha1-yQHPCiC5ckNbDszVLQVoJKQ1G3s= + +clean-css-promise@^0.1.0: + version "0.1.1" + resolved "https://registry.npmjs.org/clean-css-promise/-/clean-css-promise-0.1.1.tgz#43f3d2c8dfcb2bf071481252cd9b76433c08eecb" + integrity sha1-Q/PSyN/LK/BxSBJSzZt2QzwI7ss= + dependencies: + array-to-error "^1.0.0" + clean-css "^3.4.5" + pinkie-promise "^2.0.0" + +clean-css@^3.4.5: + version "3.4.28" + resolved "https://registry.npmjs.org/clean-css/-/clean-css-3.4.28.tgz#bf1945e82fc808f55695e6ddeaec01400efd03ff" + integrity sha1-vxlF6C/ICPVWlebd6uwBQA79A/8= + dependencies: + commander "2.8.x" + source-map "0.4.x" + +clean-up-path@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/clean-up-path/-/clean-up-path-1.0.0.tgz#de9e8196519912e749c9eaf67c13d64fac72a3e5" + integrity sha512-PHGlEF0Z6976qQyN6gM7kKH6EH0RdfZcc8V+QhFe36eRxV0SMH5OUBZG7Bxa9YcreNzyNbK63cGiZxdSZgosRw== + +cli-cursor@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" + integrity sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU= + dependencies: + restore-cursor "^2.0.0" + +cli-spinners@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.0.0.tgz#4b078756fc17a8f72043fdc9f1f14bf4fa87e2df" + integrity sha512-yiEBmhaKPPeBj7wWm4GEdtPZK940p9pl3EANIrnJ3JnvWyrPjcFcsEq6qRUuQ7fzB0+Y82ld3p6B34xo95foWw== + +cli-table3@^0.5.1: + version "0.5.1" + resolved "https://registry.npmjs.org/cli-table3/-/cli-table3-0.5.1.tgz#0252372d94dfc40dbd8df06005f48f31f656f202" + integrity sha512-7Qg2Jrep1S/+Q3EceiZtQcDPWxhAvBw+ERf1162v4sikJrvojMHFqXt8QIVha8UlH9rgU0BeWPytZ9/TzYqlUw== + dependencies: + object-assign "^4.1.0" + string-width "^2.1.1" + optionalDependencies: + colors "^1.1.2" + +cli-table@^0.3.1: + version "0.3.1" + resolved "https://registry.npmjs.org/cli-table/-/cli-table-0.3.1.tgz#f53b05266a8b1a0b934b3d0821e6e2dc5914ae23" + integrity sha1-9TsFJmqLGguTSz0IIebi3FkUriM= + dependencies: + colors "1.0.3" + +cli-width@^2.0.0: + version "2.2.0" + resolved "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639" + integrity sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk= + +cliui@^4.0.0: + version "4.1.0" + resolved "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz#348422dbe82d800b3022eef4f6ac10bf2e4d1b49" + integrity sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ== + dependencies: + string-width "^2.1.1" + strip-ansi "^4.0.0" + wrap-ansi "^2.0.0" + +clone-response@1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz#d1dc973920314df67fbeb94223b4ee350239e96b" + integrity sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws= + dependencies: + mimic-response "^1.0.0" + +clone@^1.0.2: + version "1.0.4" + resolved "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" + integrity sha1-2jCcwmPfFZlMaIypAheco8fNfH4= + +clone@^2.0.0, clone@^2.1.2: + version "2.1.2" + resolved "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" + integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18= + +co@^4.6.0: + version "4.6.0" + resolved "https://registry.npmjs.org/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" + integrity sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ= + +code-point-at@^1.0.0: + version "1.1.0" + resolved "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" + integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c= + +collection-visit@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0" + integrity sha1-S8A3PBZLwykbTTaMgpzxqApZ3KA= + dependencies: + map-visit "^1.0.0" + object-visit "^1.0.0" + +color-convert@^1.9.0: + version "1.9.3" + resolved "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" + integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== + dependencies: + color-name "1.1.3" + +color-name@1.1.3: + version "1.1.3" + resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" + integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU= + +colors@1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" + integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs= + +colors@^1.1.2: + version "1.3.3" + resolved "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz#39e005d546afe01e01f9c4ca8fa50f686a01205d" + integrity sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg== + +combined-stream@~0.0.4: + version "0.0.7" + resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-0.0.7.tgz#0137e657baa5a7541c57ac37ac5fc07d73b4dc1f" + integrity sha1-ATfmV7qlp1QcV6w3rF/AfXO03B8= + dependencies: + delayed-stream "0.0.5" + +commander@2.12.2: + version "2.12.2" + resolved "https://registry.npmjs.org/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555" + integrity sha512-BFnaq5ZOGcDN7FlrtBT4xxkgIToalIIxwjxLWVJ8bGTpe1LroqMiqQXdA7ygc7CRvaYS+9zfPGFnJqFSayx+AA== + +commander@2.8.x: + version "2.8.1" + resolved "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz#06be367febfda0c330aa1e2a072d3dc9762425d4" + integrity sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ= + dependencies: + graceful-readlink ">= 1.0.0" + +commander@^2.15.1, commander@^2.6.0: + version "2.19.0" + resolved "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a" + integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg== + +commander@~2.17.1: + version "2.17.1" + resolved "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf" + integrity sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg== + +common-tags@^1.4.0, common-tags@^1.8.0: + version "1.8.0" + resolved "https://registry.npmjs.org/common-tags/-/common-tags-1.8.0.tgz#8e3153e542d4a39e9b10554434afaaf98956a937" + integrity sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw== + +component-bind@1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1" + integrity sha1-AMYIq33Nk4l8AAllGx06jh5zu9E= + +component-emitter@1.2.1, component-emitter@^1.2.1: + version "1.2.1" + resolved "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" + integrity sha1-E3kY1teCg/ffemt8WmPhQOaUJeY= + +component-inherit@0.0.3: + version "0.0.3" + resolved "https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143" + integrity sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM= + +compressible@~2.0.14: + version "2.0.16" + resolved "https://registry.npmjs.org/compressible/-/compressible-2.0.16.tgz#a49bf9858f3821b64ce1be0296afc7380466a77f" + integrity sha512-JQfEOdnI7dASwCuSPWIeVYwc/zMsu/+tRhoUvEfXz2gxOA2DNjmG5vhtFdBlhWPPGo+RdT9S3tgc/uH5qgDiiA== + dependencies: + mime-db ">= 1.38.0 < 2" + +compression@^1.7.3: + version "1.7.3" + resolved "https://registry.npmjs.org/compression/-/compression-1.7.3.tgz#27e0e176aaf260f7f2c2813c3e440adb9f1993db" + integrity sha512-HSjyBG5N1Nnz7tF2+O7A9XUhyjru71/fwgNb7oIsEVHR0WShfs2tIS/EySLgiTe98aOK18YDlMXpzjCXY/n9mg== + dependencies: + accepts "~1.3.5" + bytes "3.0.0" + compressible "~2.0.14" + debug "2.6.9" + on-headers "~1.0.1" + safe-buffer "5.1.2" + vary "~1.1.2" + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= + +configstore@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/configstore/-/configstore-4.0.0.tgz#5933311e95d3687efb592c528b922d9262d227e7" + integrity sha512-CmquAXFBocrzaSM8mtGPMM/HiWmyIpr4CcJl/rgY2uCObZ/S7cKU0silxslqJejl+t/T9HS8E0PUNQD81JGUEQ== + dependencies: + dot-prop "^4.1.0" + graceful-fs "^4.1.2" + make-dir "^1.0.0" + unique-string "^1.0.0" + write-file-atomic "^2.0.0" + xdg-basedir "^3.0.0" + +connect@^3.6.6: + version "3.6.6" + resolved "https://registry.npmjs.org/connect/-/connect-3.6.6.tgz#09eff6c55af7236e137135a72574858b6786f524" + integrity sha1-Ce/2xVr3I24TcTWnJXSFi2eG9SQ= + dependencies: + debug "2.6.9" + finalhandler "1.1.0" + parseurl "~1.3.2" + utils-merge "1.0.1" + +console-control-strings@^1.0.0, console-control-strings@~1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" + integrity sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4= + +console-ui@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/console-ui/-/console-ui-3.0.0.tgz#8abee8f701f4c3729953f74233624623f0f72100" + integrity sha512-uPlaGvTGLcu5i1EYuhr3b7yYDPkcrHEJYn25iXCtnFUwctjWNEkfAUvhXa4Rda9mv0reiucRrikfYd3EZjJiHw== + dependencies: + chalk "^2.1.0" + inquirer "^6" + json-stable-stringify "^1.0.1" + ora "^3.0.0" + through "^2.3.8" + +consolidate@^0.15.1: + version "0.15.1" + resolved "https://registry.npmjs.org/consolidate/-/consolidate-0.15.1.tgz#21ab043235c71a07d45d9aad98593b0dba56bab7" + integrity sha512-DW46nrsMJgy9kqAbPt5rKaCr7uFtpo4mSUvLHIUbJEjm0vo+aY5QLwBUq3FK4tRnJr/X0Psc0C4jf/h+HtXSMw== + dependencies: + bluebird "^3.1.1" + +content-disposition@0.5.2: + version "0.5.2" + resolved "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz#0cf68bb9ddf5f2be7961c3a85178cb85dba78cb4" + integrity sha1-DPaLud318r55YcOoUXjLhdunjLQ= + +content-type@~1.0.4: + version "1.0.4" + resolved "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" + integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA== + +continuable-cache@^0.3.1: + version "0.3.1" + resolved "https://registry.npmjs.org/continuable-cache/-/continuable-cache-0.3.1.tgz#bd727a7faed77e71ff3985ac93351a912733ad0f" + integrity sha1-vXJ6f67XfnH/OYWskzUakSczrQ8= + +convert-source-map@^1.1.0, convert-source-map@^1.5.1: + version "1.6.0" + resolved "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz#51b537a8c43e0f04dec1993bffcdd504e758ac20" + integrity sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A== + dependencies: + safe-buffer "~5.1.1" + +cookie-signature@1.0.6: + version "1.0.6" + resolved "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" + integrity sha1-4wOogrNCzD7oylE6eZmXNNqzriw= + +cookie@0.3.1: + version "0.3.1" + resolved "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" + integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s= + +copy-dereference@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/copy-dereference/-/copy-dereference-1.0.0.tgz#6b131865420fd81b413ba994b44d3655311152b6" + integrity sha1-axMYZUIP2BtBO6mUtE02VTERUrY= + +copy-descriptor@^0.1.0: + version "0.1.1" + resolved "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" + integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= + +core-js@^2.4.0, core-js@^2.5.0, core-js@^2.5.7: + version "2.6.5" + resolved "https://registry.npmjs.org/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895" + integrity sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A== + +core-object@^3.1.5: + version "3.1.5" + resolved "https://registry.npmjs.org/core-object/-/core-object-3.1.5.tgz#fa627b87502adc98045e44678e9a8ec3b9c0d2a9" + integrity sha512-sA2/4+/PZ/KV6CKgjrVrrUVBKCkdDO02CUlQ0YKTQoYUwPYNOtOAcWlbYhd5v/1JqYaA6oZ4sDlOU4ppVw6Wbg== + dependencies: + chalk "^2.0.0" + +core-util-is@~1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" + integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= + +create-error-class@^3.0.0: + version "3.0.2" + resolved "https://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz#06be7abef947a3f14a30fd610671d401bca8b7b6" + integrity sha1-Br56vvlHo/FKMP1hBnHUAbyot7Y= + dependencies: + capture-stack-trace "^1.0.0" + +cross-spawn@^6.0.0, cross-spawn@^6.0.5: + version "6.0.5" + resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" + integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== + dependencies: + nice-try "^1.0.4" + path-key "^2.0.1" + semver "^5.5.0" + shebang-command "^1.2.0" + which "^1.2.9" + +cryptiles@0.2.x: + version "0.2.2" + resolved "https://registry.npmjs.org/cryptiles/-/cryptiles-0.2.2.tgz#ed91ff1f17ad13d3748288594f8a48a0d26f325c" + integrity sha1-7ZH/HxetE9N0gohZT4pIoNJvMlw= + dependencies: + boom "0.4.x" + +crypto-random-string@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e" + integrity sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4= + +ctype@0.5.3: + version "0.5.3" + resolved "https://registry.npmjs.org/ctype/-/ctype-0.5.3.tgz#82c18c2461f74114ef16c135224ad0b9144ca12f" + integrity sha1-gsGMJGH3QRTvFsE1IkrQuRRMoS8= + +dag-map@^2.0.2: + version "2.0.2" + resolved "https://registry.npmjs.org/dag-map/-/dag-map-2.0.2.tgz#9714b472de82a1843de2fba9b6876938cab44c68" + integrity sha1-lxS0ct6CoYQ94vuptodpOMq0TGg= + +date-time@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/date-time/-/date-time-2.1.0.tgz#0286d1b4c769633b3ca13e1e62558d2dbdc2eba2" + integrity sha512-/9+C44X7lot0IeiyfgJmETtRMhBidBYM2QFFIkGa0U1k+hSyY87Nw7PY3eDqpvCBm7I3WCSfPeZskW/YYq6m4g== + dependencies: + time-zone "^1.0.0" + +debug@2, debug@2.6.9, debug@^2.1.0, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9: + version "2.6.9" + resolved "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== + dependencies: + ms "2.0.0" + +debug@3.2.6, debug@^3.0.1, debug@^3.1.0, debug@^3.2.6: + version "3.2.6" + resolved "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" + integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== + dependencies: + ms "^2.1.1" + +debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@~4.1.0: + version "4.1.1" + resolved "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" + integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== + dependencies: + ms "^2.1.1" + +debug@~3.1.0: + version "3.1.0" + resolved "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" + integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== + dependencies: + ms "2.0.0" + +decamelize@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" + integrity sha1-9lNNFRSCabIDUue+4m9QH5oZEpA= + +decode-uri-component@^0.2.0: + version "0.2.0" + resolved "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" + integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU= + +decompress-response@^3.3.0: + version "3.3.0" + resolved "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz#80a4dd323748384bfa248083622aedec982adff3" + integrity sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M= + dependencies: + mimic-response "^1.0.0" + +deep-eql@^0.1.3: + version "0.1.3" + resolved "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2" + integrity sha1-71WKyrjeJSBs1xOQbXTlaTDrafI= + dependencies: + type-detect "0.1.1" + +deep-eql@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df" + integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw== + dependencies: + type-detect "^4.0.0" + +deep-extend@^0.6.0: + version "0.6.0" + resolved "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" + integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== + +deep-is@~0.1.3: + version "0.1.3" + resolved "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" + integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= + +defaults@^1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d" + integrity sha1-xlYFHpgX2f8I7YgUd/P+QBnz730= + dependencies: + clone "^1.0.2" + +define-properties@^1.1.2: + version "1.1.3" + resolved "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1" + integrity sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ== + dependencies: + object-keys "^1.0.12" + +define-property@^0.2.5: + version "0.2.5" + resolved "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz#c35b1ef918ec3c990f9a5bc57be04aacec5c8116" + integrity sha1-w1se+RjsPJkPmlvFe+BKrOxcgRY= + dependencies: + is-descriptor "^0.1.0" + +define-property@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz#769ebaaf3f4a63aad3af9e8d304c9bbe79bfb0e6" + integrity sha1-dp66rz9KY6rTr56NMEybvnm/sOY= + dependencies: + is-descriptor "^1.0.0" + +define-property@^2.0.2: + version "2.0.2" + resolved "https://registry.npmjs.org/define-property/-/define-property-2.0.2.tgz#d459689e8d654ba77e02a817f8710d702cb16e9d" + integrity sha512-jwK2UV4cnPpbcG7+VRARKTZPUWowwXA8bzH5NP6ud0oeAxyYPuGZUAC7hMugpCdz4BeSZl2Dl9k66CHJ/46ZYQ== + dependencies: + is-descriptor "^1.0.2" + isobject "^3.0.1" + +delayed-stream@0.0.5: + version "0.0.5" + resolved "https://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz#d4b1f43a93e8296dfe02694f4680bc37a313c73f" + integrity sha1-1LH0OpPoKW3+AmlPRoC8N6MTxz8= + +delegates@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" + integrity sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o= + +depd@~1.1.2: + version "1.1.2" + resolved "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" + integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak= + +destroy@~1.0.4: + version "1.0.4" + resolved "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" + integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA= + +detect-file@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/detect-file/-/detect-file-1.0.0.tgz#f0d66d03672a825cb1b73bdb3fe62310c8e552b7" + integrity sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc= + +detect-indent@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz#f76d064352cdf43a1cb6ce619c4ee3a9475de208" + integrity sha1-920GQ1LN9Docts5hnE7jqUdd4gg= + dependencies: + repeating "^2.0.0" + +detect-indent@^5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d" + integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50= + +diff@3.5.0: + version "3.5.0" + resolved "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" + integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA== + +diff@^4.0.1: + version "4.0.1" + resolved "https://registry.npmjs.org/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff" + integrity sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q== + +doctrine@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961" + integrity sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w== + dependencies: + esutils "^2.0.2" + +dot-prop@^4.1.0: + version "4.2.0" + resolved "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57" + integrity sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ== + dependencies: + is-obj "^1.0.0" + +duplex@~1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/duplex/-/duplex-1.0.0.tgz#6abc5c16ec17e4c578578727126700590d3a2dda" + integrity sha1-arxcFuwX5MV4V4cnEmcAWQ06Ldo= + +duplexer3@^0.1.4: + version "0.1.4" + resolved "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" + integrity sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI= + +editions@^1.1.1: + version "1.3.4" + resolved "https://registry.npmjs.org/editions/-/editions-1.3.4.tgz#3662cb592347c3168eb8e498a0ff73271d67f50b" + integrity sha512-gzao+mxnYDzIysXKMQi/+M1mjy/rjestjg6OPoYTtI+3Izp23oiGZitsl9lPDPiTGXbcSIk1iJWhliSaglxnUg== + +ee-first@1.1.1: + version "1.1.1" + resolved "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" + integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= + +electron-to-chromium@^1.3.113, electron-to-chromium@^1.3.47: + version "1.3.113" + resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.113.tgz#b1ccf619df7295aea17bc6951dc689632629e4a9" + integrity sha512-De+lPAxEcpxvqPTyZAXELNpRZXABRxf+uL/rSykstQhzj/B0l1150G/ExIIxKc16lI89Hgz81J0BHAcbTqK49g== + +ember-assign-polyfill@^2.6.0: + version "2.6.0" + resolved "https://registry.npmjs.org/ember-assign-polyfill/-/ember-assign-polyfill-2.6.0.tgz#07847e3357ee35b33f886a0b5fbec6873f6860eb" + integrity sha512-Y8NzOmHI/g4PuJ+xC14eTYiQbigNYddyHB8FY2kuQMxThTEIDE7SJtgttJrYYcPciOu0Tnb5ff36iO46LeiXkw== + dependencies: + ember-cli-babel "^6.16.0" + ember-cli-version-checker "^2.0.0" + +ember-cli-app-version@^3.2.0: + version "3.2.0" + resolved "https://registry.npmjs.org/ember-cli-app-version/-/ember-cli-app-version-3.2.0.tgz#7b9ad0e1b63ae0518648356ee24c703e922bc26e" + integrity sha512-fHWOJElSw8JL03FNCHrT0RdWhGpWEQ4VQ10unEwwhVZ+OANNcOLz8O2dA3D5iuB4bb0fMLwjEwYZGM62+TBs1Q== + dependencies: + ember-cli-babel "^6.12.0" + git-repo-version "^1.0.2" + +ember-cli-babel-plugin-helpers@^1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/ember-cli-babel-plugin-helpers/-/ember-cli-babel-plugin-helpers-1.0.2.tgz#d4bec0f32febc530e621ea8d66d3365727cb5e6c" + integrity sha512-tTWmHiIvadgtu0i+Zlb5Jnue69qO6dtACcddkRhhV+m9NfAr+2XNoTKRSeGL8QyRDhfWeo4rsK9dqPrU4PQ+8g== + +ember-cli-babel@^6.0.0-beta.4, ember-cli-babel@^6.0.0-beta.7, ember-cli-babel@^6.12.0, ember-cli-babel@^6.16.0, ember-cli-babel@^6.6.0, ember-cli-babel@^6.8.1, ember-cli-babel@^6.8.2, ember-cli-babel@^6.9.0: + version "6.18.0" + resolved "https://registry.npmjs.org/ember-cli-babel/-/ember-cli-babel-6.18.0.tgz#3f6435fd275172edeff2b634ee7b29ce74318957" + integrity sha512-7ceC8joNYxY2wES16iIBlbPSxwKDBhYwC8drU3ZEvuPDMwVv1KzxCNu1fvxyFEBWhwaRNTUxSCsEVoTd9nosGA== + dependencies: + amd-name-resolver "1.2.0" + babel-plugin-debug-macros "^0.2.0-beta.6" + babel-plugin-ember-modules-api-polyfill "^2.6.0" + babel-plugin-transform-es2015-modules-amd "^6.24.0" + babel-polyfill "^6.26.0" + babel-preset-env "^1.7.0" + broccoli-babel-transpiler "^6.5.0" + broccoli-debug "^0.6.4" + broccoli-funnel "^2.0.0" + broccoli-source "^1.1.0" + clone "^2.0.0" + ember-cli-version-checker "^2.1.2" + semver "^5.5.0" + +ember-cli-babel@^7.0.0, ember-cli-babel@^7.1.3, ember-cli-babel@^7.1.4, ember-cli-babel@^7.2.0, ember-cli-babel@^7.4.3, ember-cli-babel@^7.5.0: + version "7.5.0" + resolved "https://registry.npmjs.org/ember-cli-babel/-/ember-cli-babel-7.5.0.tgz#af654dcef23630391d2efe85aaa3bdf8b6ca17b7" + integrity sha512-wWXqPPQNRxCtEHvYaLBNiIVgCVCy8YqZ0tM8Dpql1D5nGnPDbaK073sS1vlOYBP7xe5Ab2nXhvQkFwUxFacJ2g== + dependencies: + "@babel/core" "^7.0.0" + "@babel/plugin-transform-modules-amd" "^7.0.0" + "@babel/plugin-transform-runtime" "^7.2.0" + "@babel/polyfill" "^7.0.0" + "@babel/preset-env" "^7.0.0" + "@babel/runtime" "^7.2.0" + amd-name-resolver "^1.2.1" + babel-plugin-debug-macros "^0.3.0" + babel-plugin-ember-modules-api-polyfill "^2.7.0" + babel-plugin-module-resolver "^3.1.1" + broccoli-babel-transpiler "^7.1.2" + broccoli-debug "^0.6.4" + broccoli-funnel "^2.0.1" + broccoli-source "^1.1.0" + clone "^2.1.2" + ember-cli-version-checker "^2.1.2" + ensure-posix-path "^1.0.2" + semver "^5.5.0" + +ember-cli-blueprint-test-helpers@^0.19.1: + version "0.19.2" + resolved "https://registry.npmjs.org/ember-cli-blueprint-test-helpers/-/ember-cli-blueprint-test-helpers-0.19.2.tgz#9e563cd81ab39931253ced0982c5d02475895401" + integrity sha512-otCKdGcNFK0+MkQo+LLjYbRD9EerApH6Z/odvvlL1hxrN+owHMV5E+jI2rbtdvNEH0/6w5ZqjH4kS232fvtCxQ== + dependencies: + chai "^4.1.0" + chai-as-promised "^7.0.0" + chai-files "^1.0.0" + debug "^4.1.0" + ember-cli-internal-test-helpers "^0.9.1" + fs-extra "^7.0.0" + testdouble "^3.2.6" + tmp-sync "^1.0.0" + +ember-cli-broccoli-sane-watcher@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/ember-cli-broccoli-sane-watcher/-/ember-cli-broccoli-sane-watcher-3.0.0.tgz#dc1812c047e1ceec4413d3c41b51a9ffc61b4cfe" + integrity sha512-sLn+wy6FJpGMHtSwAGUjQK3nJFvw2b6H8bR2EgMIXxkUI3DYFLi6Xnyxm02XlMTcfTxF10yHFhHJe0O+PcJM7A== + dependencies: + broccoli-slow-trees "^3.0.1" + heimdalljs "^0.2.1" + heimdalljs-logger "^0.1.7" + rsvp "^3.0.18" + sane "^4.0.0" + +ember-cli-dependency-checker@^3.1.0: + version "3.1.0" + resolved "https://registry.npmjs.org/ember-cli-dependency-checker/-/ember-cli-dependency-checker-3.1.0.tgz#b39c6b537a1457d77892edf5ddcfa025cd1401e2" + integrity sha512-Y/V2senOyIjQnZohYeZeXs59rWHI2m8KRF9IesMv1ypLRSc/h/QS6UX51wAyaZnxcgU6ljFXpqL5x38UxM3XzA== + dependencies: + chalk "^2.3.0" + find-yarn-workspace-root "^1.1.0" + is-git-url "^1.0.0" + resolve "^1.5.0" + semver "^5.3.0" + +ember-cli-get-component-path-option@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/ember-cli-get-component-path-option/-/ember-cli-get-component-path-option-1.0.0.tgz#0d7b595559e2f9050abed804f1d8eff1b08bc771" + integrity sha1-DXtZVVni+QUKvtgE8djv8bCLx3E= + +ember-cli-htmlbars-inline-precompile@^2.0.0, ember-cli-htmlbars-inline-precompile@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/ember-cli-htmlbars-inline-precompile/-/ember-cli-htmlbars-inline-precompile-2.1.0.tgz#61b91ff1879d44ae504cadb46fb1f2604995ae08" + integrity sha512-BylIHduwQkncPhnj0ZyorBuljXbTzLgRo6kuHf1W+IHFxThFl2xG+r87BVwsqx4Mn9MTgW9SE0XWjwBJcSWd6Q== + dependencies: + babel-plugin-htmlbars-inline-precompile "^1.0.0" + ember-cli-version-checker "^2.1.2" + hash-for-dep "^1.2.3" + heimdalljs-logger "^0.1.9" + silent-error "^1.1.0" + +ember-cli-htmlbars@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/ember-cli-htmlbars/-/ember-cli-htmlbars-3.0.1.tgz#01e21f0fd05e0a6489154f26614b1041769e3e58" + integrity sha512-pyyB2s52vKTXDC5svU3IjU7GRLg2+5O81o9Ui0ZSiBS14US/bZl46H2dwcdSJAK+T+Za36ZkQM9eh1rNwOxfoA== + dependencies: + broccoli-persistent-filter "^1.4.3" + hash-for-dep "^1.2.3" + json-stable-stringify "^1.0.0" + strip-bom "^3.0.0" + +ember-cli-inject-live-reload@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/ember-cli-inject-live-reload/-/ember-cli-inject-live-reload-2.0.1.tgz#1bf3a6ea1747bceddc9f62f7ca8575de6b53ddaf" + integrity sha512-vrW/3KSrku+Prqmp7ZkpCxYkabnLrTHDEvV9B1yphTP++dhiV7n7Dv9NrmyubkoF3Inm0xrbbhB5mScvvuTQSg== + dependencies: + clean-base-url "^1.0.0" + ember-cli-version-checker "^2.1.2" + +ember-cli-internal-test-helpers@^0.9.1: + version "0.9.1" + resolved "https://registry.npmjs.org/ember-cli-internal-test-helpers/-/ember-cli-internal-test-helpers-0.9.1.tgz#d54a9124bb6408ceba83f049ba8479f4b96cdd19" + integrity sha1-1UqRJLtkCM66g/BJuoR59Lls3Rk= + dependencies: + chai "^3.3.0" + chai-as-promised "^6.0.0" + chai-files "^1.1.0" + chalk "^1.1.1" + debug "^2.2.0" + exists-sync "0.0.3" + fs-extra "^0.30.0" + lodash "^4.0.0" + rsvp "^3.0.17" + symlink-or-copy "^1.0.1" + through "^2.3.8" + walk-sync "^0.3.1" + +ember-cli-is-package-missing@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/ember-cli-is-package-missing/-/ember-cli-is-package-missing-1.0.0.tgz#6e6184cafb92635dd93ca6c946b104292d4e3390" + integrity sha1-bmGEyvuSY13ZPKbJRrEEKS1OM5A= + +ember-cli-lodash-subset@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/ember-cli-lodash-subset/-/ember-cli-lodash-subset-2.0.1.tgz#20cb68a790fe0fde2488ddfd8efbb7df6fe766f2" + integrity sha1-IMtop5D+D94kiN39jvu332/nZvI= + +ember-cli-normalize-entity-name@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/ember-cli-normalize-entity-name/-/ember-cli-normalize-entity-name-1.0.0.tgz#0b14f7bcbc599aa117b5fddc81e4fd03c4bad5b7" + integrity sha1-CxT3vLxZmqEXtf3cgeT9A8S61bc= + dependencies: + silent-error "^1.0.0" + +ember-cli-path-utils@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/ember-cli-path-utils/-/ember-cli-path-utils-1.0.0.tgz#4e39af8b55301cddc5017739b77a804fba2071ed" + integrity sha1-Tjmvi1UwHN3FAXc5t3qAT7ogce0= + +ember-cli-preprocess-registry@^3.1.2: + version "3.2.2" + resolved "https://registry.npmjs.org/ember-cli-preprocess-registry/-/ember-cli-preprocess-registry-3.2.2.tgz#5d076ebeee9e28ccfc13c87c715b4330bb8d324c" + integrity sha512-Yp6gjErRyKigwYblhTHL/QduXbg9RbeEe9bGEv98eGcJKkNFHCl/l8o3yhPlGACmq5yK0QFgekNYki80aArsrg== + dependencies: + broccoli-clean-css "^1.1.0" + broccoli-funnel "^2.0.1" + debug "^3.0.1" + process-relative-require "^1.0.0" + +ember-cli-pretender@^3.1.1: + version "3.1.1" + resolved "https://registry.npmjs.org/ember-cli-pretender/-/ember-cli-pretender-3.1.1.tgz#289c41683de266fec8bfaf5b7b7f6026aaefc8cf" + integrity sha512-RGGj9la0138bgHUxyaGDHCZydmdpW+BFN9v0vMBzNPeXsaexCZotaFTIZDCNcKWPx8jtRHR8AXf318VRGXLJsw== + dependencies: + abortcontroller-polyfill "^1.1.9" + broccoli-funnel "^2.0.1" + broccoli-merge-trees "^3.0.0" + ember-cli-babel "^6.6.0" + fake-xml-http-request "^2.0.0" + pretender "^2.1.0" + route-recognizer "^0.3.3" + whatwg-fetch "^3.0.0" + +ember-cli-shims@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/ember-cli-shims/-/ember-cli-shims-1.2.0.tgz#0f53aff0aab80b5f29da3a9731bac56169dd941f" + integrity sha1-D1Ov8Kq4C18p2jqXMbrFYWndlB8= + dependencies: + broccoli-file-creator "^1.1.1" + broccoli-merge-trees "^2.0.0" + ember-cli-version-checker "^2.0.0" + ember-rfc176-data "^0.3.1" + silent-error "^1.0.1" + +ember-cli-sri@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/ember-cli-sri/-/ember-cli-sri-2.1.1.tgz#971620934a4b9183cf7923cc03e178b83aa907fd" + integrity sha1-lxYgk0pLkYPPeSPMA+F4uDqpB/0= + dependencies: + broccoli-sri-hash "^2.1.0" + +ember-cli-string-utils@^1.0.0, ember-cli-string-utils@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/ember-cli-string-utils/-/ember-cli-string-utils-1.1.0.tgz#39b677fc2805f55173735376fcef278eaa4452a1" + integrity sha1-ObZ3/CgF9VFzc1N2/O8njqpEUqE= + +ember-cli-test-info@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/ember-cli-test-info/-/ember-cli-test-info-1.0.0.tgz#ed4e960f249e97523cf891e4aed2072ce84577b4" + integrity sha1-7U6WDySel1I8+JHkrtIHLOhFd7Q= + dependencies: + ember-cli-string-utils "^1.0.0" + +ember-cli-test-loader@^2.2.0: + version "2.2.0" + resolved "https://registry.npmjs.org/ember-cli-test-loader/-/ember-cli-test-loader-2.2.0.tgz#3fb8d5d1357e4460d3f0a092f5375e71b6f7c243" + integrity sha512-mlSXX9SciIRwGkFTX6XGyJYp4ry6oCFZRxh5jJ7VH8UXLTNx2ZACtDTwaWtNhYrWXgKyiDUvmD8enD56aePWRA== + dependencies: + ember-cli-babel "^6.8.1" + +ember-cli-typescript-blueprints@^2.0.0-beta.1: + version "2.0.0-beta.1" + resolved "https://registry.npmjs.org/ember-cli-typescript-blueprints/-/ember-cli-typescript-blueprints-2.0.0-beta.1.tgz#2db2e34ad01b5a50a4459c2f7cfc8f132b21fcea" + integrity sha512-tU1hN9Wj/nzWrSArogr/n9j8kfsv+2wueRuaIr7X+h4klb/Vb92bVkyW1xx8SW9hsWkv8n7ct8PzMmW033ws8g== + dependencies: + chalk "^2.4.1" + ember-cli-babel "^6.6.0" + ember-cli-get-component-path-option "^1.0.0" + ember-cli-is-package-missing "^1.0.0" + ember-cli-normalize-entity-name "^1.0.0" + ember-cli-path-utils "^1.0.0" + ember-cli-string-utils "^1.1.0" + ember-cli-test-info "^1.0.0" + ember-cli-valid-component-name "^1.0.0" + ember-cli-version-checker "^2.1.2" + ember-router-generator "^1.2.3" + exists-sync "^0.1.0" + fs-extra "^7.0.0" + inflection "^1.12.0" + silent-error "^1.1.0" + +ember-cli-typescript@^2.0.0-beta.2: + version "2.0.0-rc.2" + resolved "https://registry.npmjs.org/ember-cli-typescript/-/ember-cli-typescript-2.0.0-rc.2.tgz#d8253097279ed292c20e739ee72f8fb994dbb6b7" + integrity sha512-u4mhdt/R0ip5s1H93aXtGJ/tnZ/3LsIOhKmaPylvlAVW/HtgPk+j/9sFHT4YmFUKMWPP2gXExtDkYNbz81XWzw== + dependencies: + "@babel/plugin-proposal-class-properties" "^7.1.0" + "@babel/plugin-transform-typescript" "^7.1.0" + ansi-to-html "^0.6.6" + debug "^4.0.0" + ember-cli-babel-plugin-helpers "^1.0.0" + execa "^1.0.0" + fs-extra "^7.0.0" + resolve "^1.5.0" + rsvp "^4.8.1" + semver "^5.5.1" + stagehand "^1.0.0" + walk-sync "^1.0.0" + +ember-cli-uglify@2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/ember-cli-uglify/-/ember-cli-uglify-2.1.0.tgz#4a0641fe4768d7ab7d4807aca9924cc77c544184" + integrity sha512-lDzdAUfhGx5AMBsgyR54ibENVp/LRQuHNWNaP2SDjkAXDyuYFgW0iXIAfGbxF6+nYaesJ9Tr9AKOfTPlwxZDSg== + dependencies: + broccoli-uglify-sourcemap "^2.1.1" + lodash.defaultsdeep "^4.6.0" + +ember-cli-valid-component-name@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/ember-cli-valid-component-name/-/ember-cli-valid-component-name-1.0.0.tgz#71550ce387e0233065f30b30b1510aa2dfbe87ef" + integrity sha1-cVUM44fgIzBl8wswsVEKot++h+8= + dependencies: + silent-error "^1.0.0" + +ember-cli-version-checker@^2.0.0, ember-cli-version-checker@^2.1.0, ember-cli-version-checker@^2.1.1, ember-cli-version-checker@^2.1.2: + version "2.2.0" + resolved "https://registry.npmjs.org/ember-cli-version-checker/-/ember-cli-version-checker-2.2.0.tgz#47771b731fe0962705e27c8199a9e3825709f3b3" + integrity sha512-G+KtYIVlSOWGcNaTFHk76xR4GdzDLzAS4uxZUKdASuFX0KJE43C6DaqL+y3VTpUFLI2FIkAS6HZ4I1YBi+S3hg== + dependencies: + resolve "^1.3.3" + semver "^5.3.0" + +ember-cli-version-checker@^3.0.0, ember-cli-version-checker@^3.1.2: + version "3.1.2" + resolved "https://registry.npmjs.org/ember-cli-version-checker/-/ember-cli-version-checker-3.1.2.tgz#baee5cc621d5259d9011b5ef60fe6fbe61bd57c7" + integrity sha512-SNY7757cqj5GmES9dlWb43aWoGUcc+keniu+Rvsl/C/TnSK99edgL6eG4+Zr0ESeJ1hEcI3UrHN/8GIcK5eJUQ== + dependencies: + resolve-package-path "^1.1.1" + semver "^5.6.0" + +ember-cli-yuidoc@^0.8.8: + version "0.8.8" + resolved "https://registry.npmjs.org/ember-cli-yuidoc/-/ember-cli-yuidoc-0.8.8.tgz#3858baaf85388a976024f9de40f1075fea58f606" + integrity sha1-OFi6r4U4ipdgJPneQPEHX+pY9gY= + dependencies: + broccoli-caching-writer "~2.0.4" + broccoli-merge-trees "^1.1.1" + git-repo-version "0.2.0" + rsvp "3.0.14" + yuidocjs "^0.10.0" + +ember-cli@^3.8.1: + version "3.8.1" + resolved "https://registry.npmjs.org/ember-cli/-/ember-cli-3.8.1.tgz#2a4f66cf9da3c9665658690e615479af32749807" + integrity sha512-cg8Ug60lbNPQVGjHnO66cmrgFXxlFFdkDp+//e58Kgl9mz17cQIbU1TD1pMaW0dYi+2/XADeftHBULs3ejQBSA== + dependencies: + "@babel/core" "^7.0.0" + "@babel/plugin-transform-modules-amd" "^7.2.0" + amd-name-resolver "^1.3.1" + babel-plugin-module-resolver "^3.1.1" + bower-config "^1.3.0" + bower-endpoint-parser "0.2.2" + broccoli "^2.0.0" + broccoli-amd-funnel "^2.0.1" + broccoli-babel-transpiler "^7.1.1" + broccoli-builder "^0.18.14" + broccoli-concat "^3.7.3" + broccoli-config-loader "^1.0.1" + broccoli-config-replace "^1.1.2" + broccoli-debug "^0.6.4" + broccoli-funnel "^2.0.1" + broccoli-funnel-reducer "^1.0.0" + broccoli-merge-trees "^3.0.0" + broccoli-middleware "^2.0.1" + broccoli-module-normalizer "^1.3.0" + broccoli-module-unification-reexporter "^1.0.0" + broccoli-source "^1.1.0" + broccoli-stew "^2.0.0" + calculate-cache-key-for-tree "^1.1.0" + capture-exit "^2.0.0" + chalk "^2.4.2" + ci-info "^2.0.0" + clean-base-url "^1.0.0" + compression "^1.7.3" + configstore "^4.0.0" + console-ui "^3.0.0" + core-object "^3.1.5" + dag-map "^2.0.2" + diff "^4.0.1" + ember-cli-broccoli-sane-watcher "^3.0.0" + ember-cli-is-package-missing "^1.0.0" + ember-cli-lodash-subset "^2.0.1" + ember-cli-normalize-entity-name "^1.0.0" + ember-cli-preprocess-registry "^3.1.2" + ember-cli-string-utils "^1.1.0" + ember-source-channel-url "^1.1.0" + ensure-posix-path "^1.0.2" + execa "^1.0.0" + exit "^0.1.2" + express "^4.16.3" + filesize "^3.6.1" + find-up "^3.0.0" + find-yarn-workspace-root "^1.1.0" + fs-extra "^7.0.0" + fs-tree-diff "^1.0.0" + get-caller-file "^2.0.0" + git-repo-info "^2.0.0" + glob "^7.1.2" + heimdalljs "^0.2.5" + heimdalljs-fs-monitor "^0.2.2" + heimdalljs-graph "^0.3.4" + heimdalljs-logger "^0.1.9" + http-proxy "^1.17.0" + inflection "^1.12.0" + is-git-url "^1.0.0" + isbinaryfile "^3.0.3" + js-yaml "^3.12.1" + json-stable-stringify "^1.0.1" + leek "0.0.24" + lodash.template "^4.4.0" + markdown-it "^8.4.2" + markdown-it-terminal "0.1.0" + minimatch "^3.0.4" + morgan "^1.9.0" + node-modules-path "^1.0.1" + nopt "^3.0.6" + npm-package-arg "^6.1.0" + portfinder "^1.0.15" + promise-map-series "^0.2.3" + quick-temp "^0.1.8" + resolve "^1.8.1" + rsvp "^4.8.3" + sane "^4.0.0" + semver "^5.5.0" + silent-error "^1.1.0" + sort-package-json "^1.15.0" + symlink-or-copy "^1.2.0" + temp "0.9.0" + testem "^2.9.2" + tiny-lr "^1.1.1" + tree-sync "^1.2.2" + uuid "^3.3.2" + validate-npm-package-name "^3.0.0" + walk-sync "^1.0.0" + watch-detector "^0.1.0" + yam "^1.0.0" + +ember-compatibility-helpers@^1.1.1, ember-compatibility-helpers@^1.1.2: + version "1.2.0" + resolved "https://registry.npmjs.org/ember-compatibility-helpers/-/ember-compatibility-helpers-1.2.0.tgz#feee16c5e9ef1b1f1e53903b241740ad4b01097e" + integrity sha512-pUW4MzJdcaQtwGsErYmitFRs0rlCYBAnunVzlFFUBr4xhjlCjgHJo0b53gFnhTgenNM3d3/NqLarzRhDTjXRTg== + dependencies: + babel-plugin-debug-macros "^0.2.0" + ember-cli-version-checker "^2.1.1" + semver "^5.4.1" + +ember-decorators@^5.1.4: + version "5.1.4" + resolved "https://registry.npmjs.org/ember-decorators/-/ember-decorators-5.1.4.tgz#d574fbfab85bb3938f1dd18f5a0b1569ea0eb4cb" + integrity sha512-0qpN65A4lr0NBkkdWUJGn6VlaA6WoFXAUrgWruF53UK3tszb0nVK/EPN2zRU06I/7WgroI69VywdVPe3TRQ/iw== + dependencies: + "@ember-decorators/component" "^5.1.4" + "@ember-decorators/controller" "^5.1.4" + "@ember-decorators/data" "^5.1.4" + "@ember-decorators/object" "^5.1.4" + "@ember-decorators/service" "^5.1.4" + ember-cli-babel "^7.1.3" + semver "^5.5.0" + +ember-disable-prototype-extensions@^1.1.3: + version "1.1.3" + resolved "https://registry.npmjs.org/ember-disable-prototype-extensions/-/ember-disable-prototype-extensions-1.1.3.tgz#1969135217654b5e278f9fe2d9d4e49b5720329e" + integrity sha1-GWkTUhdlS14nj5/i2dTkm1cgMp4= + +ember-export-application-global@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/ember-export-application-global/-/ember-export-application-global-2.0.0.tgz#8d6d7619ac8a1a3f8c43003549eb21ebed685bd2" + integrity sha1-jW12GayKGj+MQwA1Sesh6+1oW9I= + dependencies: + ember-cli-babel "^6.0.0-beta.7" + +ember-fetch@^6.5.0: + version "6.5.0" + resolved "https://registry.yarnpkg.com/ember-fetch/-/ember-fetch-6.5.0.tgz#efed80b3dd2259b52efce7498659e9125235bfb7" + integrity sha512-B9KSeeO3xDNMQ22JqNwbmgnOprBzc8kNVfQMtzkAmugMb2aCmBZohAlQlwUUX5ODz8fHq2xfuZXDHD81Dzb0vg== + dependencies: + abortcontroller-polyfill "^1.2.5" + broccoli-concat "^3.2.2" + broccoli-debug "^0.6.5" + broccoli-merge-trees "^3.0.0" + broccoli-rollup "^2.1.1" + broccoli-stew "^2.0.0" + broccoli-templater "^2.0.1" + calculate-cache-key-for-tree "^1.1.0" + caniuse-api "^3.0.0" + ember-cli-babel "^6.8.2" + node-fetch "^2.3.0" + whatwg-fetch "^3.0.0" + +ember-inflector@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/ember-inflector/-/ember-inflector-3.0.0.tgz#7e1ee8aaa0fa773ba0905d8b7c0786354d890ee1" + integrity sha512-tLWfYolZAkLnkTvvBkjizy4Wmj8yI8wqHZFK+leh0iScHiC3r1Yh5C4qO+OMGiBTMLwfTy+YqVoE/Nu3hGNkcA== + dependencies: + ember-cli-babel "^6.6.0" + +ember-load-initializers@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/ember-load-initializers/-/ember-load-initializers-2.0.0.tgz#d4b3108dd14edb0f9dc3735553cc96dadd8a80cb" + integrity sha512-GQ0x7jGcPovmIFsLQO0dFERHCjkFNAWeuVErXHR466oPHvi479in/WtSJK707pmr3GA5QXXRJy6U8fAdJeJcxA== + dependencies: + ember-cli-babel "^7.0.0" + +ember-maybe-import-regenerator@^0.1.6: + version "0.1.6" + resolved "https://registry.npmjs.org/ember-maybe-import-regenerator/-/ember-maybe-import-regenerator-0.1.6.tgz#35d41828afa6d6a59bc0da3ce47f34c573d776ca" + integrity sha1-NdQYKK+m1qWbwNo85H80xXPXdso= + dependencies: + broccoli-funnel "^1.0.1" + broccoli-merge-trees "^1.0.0" + ember-cli-babel "^6.0.0-beta.4" + regenerator-runtime "^0.9.5" + +ember-qunit-assert-helpers@^0.2.2: + version "0.2.2" + resolved "https://registry.npmjs.org/ember-qunit-assert-helpers/-/ember-qunit-assert-helpers-0.2.2.tgz#6fec8a33fd0d2c3fb6202f849291a309581727a4" + integrity sha512-P5eAqD753+p/qEeBi6OGpl2EzRxx8O9dUnr6HgyxU9fqQsSNQkJNGZ+ajbtePI8oMDGm+X7uOnf1+BgQ7eJ7qg== + dependencies: + broccoli-filter "^1.0.1" + ember-cli-babel "^6.9.0" + +ember-qunit@^4.4.1: + version "4.4.1" + resolved "https://registry.npmjs.org/ember-qunit/-/ember-qunit-4.4.1.tgz#3654cadf9fa7e2287fe7b61fc7f19c3eb06222b5" + integrity sha512-RYyEqn3UpwLri4+lL9sFdDp1uPa0AfN587661iKm7r3kTAzYHxZE7jRsBDIejhgSH2kVSky0+Q9Y7oLULYiM/Q== + dependencies: + "@ember/test-helpers" "^1.5.0" + broccoli-funnel "^2.0.2" + broccoli-merge-trees "^3.0.2" + common-tags "^1.4.0" + ember-cli-babel "^7.5.0" + ember-cli-test-loader "^2.2.0" + qunit "^2.9.2" + +ember-resolver@^5.0.1: + version "5.1.3" + resolved "https://registry.npmjs.org/ember-resolver/-/ember-resolver-5.1.3.tgz#d2a5a856d53911552c022649cdc7b0408a7908ae" + integrity sha512-ud7Sw8R3hcGnGSvom96p56zdLEqEgVQEAo4HySJjBP0n7JT1lWSvLb7JrJwAZ7d9g1c2tm5ZlxBPUDwQrwMOuQ== + dependencies: + "@glimmer/resolver" "^0.4.1" + babel-plugin-debug-macros "^0.1.10" + broccoli-funnel "^2.0.2" + broccoli-merge-trees "^3.0.0" + ember-cli-babel "^6.16.0" + ember-cli-version-checker "^3.0.0" + resolve "^1.10.0" + +ember-rfc176-data@^0.3.1, ember-rfc176-data@^0.3.7: + version "0.3.7" + resolved "https://registry.npmjs.org/ember-rfc176-data/-/ember-rfc176-data-0.3.7.tgz#ecff7d74987d09296d3703343fed934515a4be33" + integrity sha512-AbTlD+q7sfyrD4diZqE7r9Y9/Je+HntVn7TlpHAe+nP5BNXxUXJIfDs5w5e3MxPcMs6Dz/yY90YfW8h1oKEvGg== + +ember-router-generator@^1.2.3: + version "1.2.3" + resolved "https://registry.npmjs.org/ember-router-generator/-/ember-router-generator-1.2.3.tgz#8ed2ca86ff323363120fc14278191e9e8f1315ee" + integrity sha1-jtLKhv8yM2MSD8FCeBkeno8TFe4= + dependencies: + recast "^0.11.3" + +ember-source-channel-url@^1.0.1, ember-source-channel-url@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/ember-source-channel-url/-/ember-source-channel-url-1.1.0.tgz#73de5cc6ebc25b2120e932ec1d8f82677bfaf6ef" + integrity sha512-y1RVXmyqrdX6zq9ZejpPt7ohKNGuLMBEKaOUyxFWcYAM5gvLuo6xFerwNmXEBbu4e3//GaoasjodXi6Cl+ddUQ== + dependencies: + got "^8.0.1" + +ember-source@~3.8.0: + version "3.8.0" + resolved "https://registry.npmjs.org/ember-source/-/ember-source-3.8.0.tgz#b84ba995d5049514a146c6df20c2fe20de08f211" + integrity sha512-iar9EL0AglbwgsLl8jeh++2mnnpBL2u/JUttP6jjkN/pItHfBGlgBtQ3GH0xyG37DH2SbP5bsj3pBM3xm7rTdA== + dependencies: + broccoli-funnel "^2.0.1" + broccoli-merge-trees "^3.0.2" + chalk "^2.3.0" + ember-cli-babel "^7.2.0" + ember-cli-get-component-path-option "^1.0.0" + ember-cli-is-package-missing "^1.0.0" + ember-cli-normalize-entity-name "^1.0.0" + ember-cli-path-utils "^1.0.0" + ember-cli-string-utils "^1.1.0" + ember-cli-version-checker "^2.1.0" + ember-router-generator "^1.2.3" + inflection "^1.12.0" + jquery "^3.3.1" + resolve "^1.9.0" + +ember-try-config@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/ember-try-config/-/ember-try-config-3.0.0.tgz#012d8c90cae9eb624e2b62040bf7e76a1aa58edc" + integrity sha512-pNwHS29O1ACczkrxBKRtDY0TzTb7uPnA5eHEe+4NF6qpLK5FVnL3EtgZ8+yVYtnm1If5mZ07rIubw45vaSek7w== + dependencies: + ember-source-channel-url "^1.0.1" + lodash "^4.6.1" + package-json "^4.0.1" + remote-git-tags "^2.0.0" + rsvp "^4.8.1" + semver "^5.5.0" + +ember-try@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/ember-try/-/ember-try-1.1.0.tgz#194d5843a79b5a9fc0e4c07445ebc18c08a91e78" + integrity sha512-NL1rKPz2LuyVEqwoNV+SQD4c2w1/A0rrdeT6jqTYqlt/P7y3+SWcsxyReBnImebaIu7Drtz6p9yiAsrJq5Chyg== + dependencies: + chalk "^2.3.0" + cli-table3 "^0.5.1" + core-object "^3.1.5" + debug "^3.1.0" + ember-try-config "^3.0.0" + execa "^1.0.0" + extend "^3.0.0" + fs-extra "^5.0.0" + promise-map-series "^0.2.1" + resolve "^1.1.6" + rimraf "^2.3.2" + rsvp "^4.7.0" + walk-sync "^0.3.3" + +emit-function@0.0.2: + version "0.0.2" + resolved "https://registry.npmjs.org/emit-function/-/emit-function-0.0.2.tgz#e3a50b3d61be1bf8ca88b924bf713157a5bec124" + integrity sha1-46ULPWG+G/jKiLkkv3ExV6W+wSQ= + +emoji-regex@^7.0.1: + version "7.0.3" + resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" + integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA== + +encodeurl@~1.0.1, encodeurl@~1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" + integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k= + +end-of-stream@^1.1.0: + version "1.4.1" + resolved "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz#ed29634d19baba463b6ce6b80a37213eab71ec43" + integrity sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q== + dependencies: + once "^1.4.0" + +engine.io-client@~3.3.1: + version "3.3.2" + resolved "https://registry.npmjs.org/engine.io-client/-/engine.io-client-3.3.2.tgz#04e068798d75beda14375a264bb3d742d7bc33aa" + integrity sha512-y0CPINnhMvPuwtqXfsGuWE8BB66+B6wTtCofQDRecMQPYX3MYUZXFNKDhdrSe3EVjgOu4V3rxdeqN/Tr91IgbQ== + dependencies: + component-emitter "1.2.1" + component-inherit "0.0.3" + debug "~3.1.0" + engine.io-parser "~2.1.1" + has-cors "1.1.0" + indexof "0.0.1" + parseqs "0.0.5" + parseuri "0.0.5" + ws "~6.1.0" + xmlhttprequest-ssl "~1.5.4" + yeast "0.1.2" + +engine.io-parser@~2.1.0, engine.io-parser@~2.1.1: + version "2.1.3" + resolved "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-2.1.3.tgz#757ab970fbf2dfb32c7b74b033216d5739ef79a6" + integrity sha512-6HXPre2O4Houl7c4g7Ic/XzPnHBvaEmN90vtRO9uLmwtRqQmTOw0QMevL1TOfL2Cpu1VzsaTmMotQgMdkzGkVA== + dependencies: + after "0.8.2" + arraybuffer.slice "~0.0.7" + base64-arraybuffer "0.1.5" + blob "0.0.5" + has-binary2 "~1.0.2" + +engine.io@~3.3.1: + version "3.3.2" + resolved "https://registry.npmjs.org/engine.io/-/engine.io-3.3.2.tgz#18cbc8b6f36e9461c5c0f81df2b830de16058a59" + integrity sha512-AsaA9KG7cWPXWHp5FvHdDWY3AMWeZ8x+2pUVLcn71qE5AtAzgGbxuclOytygskw8XGmiQafTmnI9Bix3uihu2w== + dependencies: + accepts "~1.3.4" + base64id "1.0.0" + cookie "0.3.1" + debug "~3.1.0" + engine.io-parser "~2.1.0" + ws "~6.1.0" + +ensure-posix-path@^1.0.0, ensure-posix-path@^1.0.1, ensure-posix-path@^1.0.2, ensure-posix-path@^1.1.0: + version "1.1.1" + resolved "https://registry.npmjs.org/ensure-posix-path/-/ensure-posix-path-1.1.1.tgz#3c62bdb19fa4681544289edb2b382adc029179ce" + integrity sha512-VWU0/zXzVbeJNXvME/5EmLuEj2TauvoaTz6aFYK1Z92JCBlDlZ3Gu0tuGR42kpW1754ywTs+QB0g5TP0oj9Zaw== + +entities@^1.1.1, entities@~1.1.1: + version "1.1.2" + resolved "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56" + integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w== + +error@^7.0.0: + version "7.0.2" + resolved "https://registry.npmjs.org/error/-/error-7.0.2.tgz#a5f75fff4d9926126ddac0ea5dc38e689153cb02" + integrity sha1-pfdf/02ZJhJt2sDqXcOOaJFTywI= + dependencies: + string-template "~0.2.1" + xtend "~4.0.0" + +es-abstract@^1.5.1, es-abstract@^1.9.0: + version "1.13.0" + resolved "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz#ac86145fdd5099d8dd49558ccba2eaf9b88e24e9" + integrity sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg== + dependencies: + es-to-primitive "^1.2.0" + function-bind "^1.1.1" + has "^1.0.3" + is-callable "^1.1.4" + is-regex "^1.0.4" + object-keys "^1.0.12" + +es-to-primitive@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz#edf72478033456e8dda8ef09e00ad9650707f377" + integrity sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg== + dependencies: + is-callable "^1.1.4" + is-date-object "^1.0.1" + is-symbol "^1.0.2" + +escape-html@~1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" + integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg= + +escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: + version "1.0.5" + resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= + +eslint-config-prettier@^4.1.0: + version "4.1.0" + resolved "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-4.1.0.tgz#181364895899fff9fd3605fecb5c4f20e7d5f395" + integrity sha512-zILwX9/Ocz4SV2vX7ox85AsrAgXV3f2o2gpIicdMIOra48WYqgUnWNH/cR/iHtmD2Vb3dLSC3LiEJnS05Gkw7w== + dependencies: + get-stdin "^6.0.0" + +eslint-plugin-es@^1.3.1: + version "1.4.0" + resolved "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-1.4.0.tgz#475f65bb20c993fc10e8c8fe77d1d60068072da6" + integrity sha512-XfFmgFdIUDgvaRAlaXUkxrRg5JSADoRC8IkKLc/cISeR3yHVMefFHQZpcyXXEUUPHfy5DwviBcrfqlyqEwlQVw== + dependencies: + eslint-utils "^1.3.0" + regexpp "^2.0.1" + +eslint-plugin-node@^8.0.0: + version "8.0.1" + resolved "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-8.0.1.tgz#55ae3560022863d141fa7a11799532340a685964" + integrity sha512-ZjOjbjEi6jd82rIpFSgagv4CHWzG9xsQAVp1ZPlhRnnYxcTgENUVBvhYmkQ7GvT1QFijUSo69RaiOJKhMu6i8w== + dependencies: + eslint-plugin-es "^1.3.1" + eslint-utils "^1.3.1" + ignore "^5.0.2" + minimatch "^3.0.4" + resolve "^1.8.1" + semver "^5.5.0" + +eslint-plugin-prettier@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.0.1.tgz#19d521e3981f69dd6d14f64aec8c6a6ac6eb0b0d" + integrity sha512-/PMttrarPAY78PLvV3xfWibMOdMDl57hmlQ2XqFeA37wd+CJ7WSxV7txqjVPHi/AAFKd2lX0ZqfsOc/i5yFCSQ== + dependencies: + prettier-linter-helpers "^1.0.0" + +eslint-scope@3.7.1: + version "3.7.1" + resolved "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8" + integrity sha1-PWPD7f2gLgbgGkUq2IyqzHzctug= + dependencies: + esrecurse "^4.1.0" + estraverse "^4.1.1" + +eslint-scope@^4.0.2: + version "4.0.2" + resolved "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.2.tgz#5f10cd6cabb1965bf479fa65745673439e21cb0e" + integrity sha512-5q1+B/ogmHl8+paxtOKx38Z8LtWkVGuNt3+GQNErqwLl6ViNp/gdJGMCjZNxZ8j/VYjDNZ2Fo+eQc1TAVPIzbg== + dependencies: + esrecurse "^4.1.0" + estraverse "^4.1.1" + +eslint-utils@^1.3.0, eslint-utils@^1.3.1: + version "1.3.1" + resolved "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz#9a851ba89ee7c460346f97cf8939c7298827e512" + integrity sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q== + +eslint-visitor-keys@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d" + integrity sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ== + +eslint@^5.15.1: + version "5.15.1" + resolved "https://registry.npmjs.org/eslint/-/eslint-5.15.1.tgz#8266b089fd5391e0009a047050795b1d73664524" + integrity sha512-NTcm6vQ+PTgN3UBsALw5BMhgO6i5EpIjQF/Xb5tIh3sk9QhrFafujUOczGz4J24JBlzWclSB9Vmx8d+9Z6bFCg== + dependencies: + "@babel/code-frame" "^7.0.0" + ajv "^6.9.1" + chalk "^2.1.0" + cross-spawn "^6.0.5" + debug "^4.0.1" + doctrine "^3.0.0" + eslint-scope "^4.0.2" + eslint-utils "^1.3.1" + eslint-visitor-keys "^1.0.0" + espree "^5.0.1" + esquery "^1.0.1" + esutils "^2.0.2" + file-entry-cache "^5.0.1" + functional-red-black-tree "^1.0.1" + glob "^7.1.2" + globals "^11.7.0" + ignore "^4.0.6" + import-fresh "^3.0.0" + imurmurhash "^0.1.4" + inquirer "^6.2.2" + js-yaml "^3.12.0" + json-stable-stringify-without-jsonify "^1.0.1" + levn "^0.3.0" + lodash "^4.17.11" + minimatch "^3.0.4" + mkdirp "^0.5.1" + natural-compare "^1.4.0" + optionator "^0.8.2" + path-is-inside "^1.0.2" + progress "^2.0.0" + regexpp "^2.0.1" + semver "^5.5.1" + strip-ansi "^4.0.0" + strip-json-comments "^2.0.1" + table "^5.2.3" + text-table "^0.2.0" + +esm@^3.2.4: + version "3.2.14" + resolved "https://registry.npmjs.org/esm/-/esm-3.2.14.tgz#567f65e9433bb0873eb92ed5e92e876c3ec2a212" + integrity sha512-uQq8DK0HB0n2Ze9gshhxGQa60caKmwNH7tKxALAT6wxYGfQCdEMXA3MV3z1rh8TSmQIVFYbltm9Xe1ghusnCqw== + +espree@^5.0.1: + version "5.0.1" + resolved "https://registry.npmjs.org/espree/-/espree-5.0.1.tgz#5d6526fa4fc7f0788a5cf75b15f30323e2f81f7a" + integrity sha512-qWAZcWh4XE/RwzLJejfcofscgMc9CamR6Tn1+XRXNzrvUSSbiAjGOI/fggztjIi7y9VLPqnICMIPiGyr8JaZ0A== + dependencies: + acorn "^6.0.7" + acorn-jsx "^5.0.0" + eslint-visitor-keys "^1.0.0" + +esprima@^4.0.0: + version "4.0.1" + resolved "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" + integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== + +esprima@~3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/esprima/-/esprima-3.0.0.tgz#53cf247acda77313e551c3aa2e73342d3fb4f7d9" + integrity sha1-U88kes2ncxPlUcOqLnM0LT+099k= + +esprima@~3.1.0: + version "3.1.3" + resolved "https://registry.npmjs.org/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" + integrity sha1-/cpRzuYTOJXjyI1TXOSdv/YqRjM= + +esprimaq@^0.0.1: + version "0.0.1" + resolved "https://registry.npmjs.org/esprimaq/-/esprimaq-0.0.1.tgz#3ea3a41f55ba0ab98fc3564c875818bd890aa2a3" + integrity sha1-PqOkH1W6CrmPw1ZMh1gYvYkKoqM= + +esquery@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz#406c51658b1f5991a5f9b62b1dc25b00e3e5c708" + integrity sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA== + dependencies: + estraverse "^4.0.0" + +esrecurse@^4.1.0: + version "4.2.1" + resolved "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz#007a3b9fdbc2b3bb87e4879ea19c92fdbd3942cf" + integrity sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ== + dependencies: + estraverse "^4.1.0" + +estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1: + version "4.2.0" + resolved "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13" + integrity sha1-De4/7TH81GlhjOc0IJn8GvoL2xM= + +estree-walker@^0.6.0: + version "0.6.0" + resolved "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.0.tgz#5d865327c44a618dde5699f763891ae31f257dae" + integrity sha512-peq1RfVAVzr3PU/jL31RaOjUKLoZJpObQWJJ+LgfcxDUifyLZ1RjPQZTl0pzj2uJ45b7A7XpyppXvxdEqzo4rw== + +esutils@^2.0.2: + version "2.0.2" + resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" + integrity sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs= + +etag@~1.8.1: + version "1.8.1" + resolved "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" + integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc= + +eventemitter3@^3.0.0: + version "3.1.0" + resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163" + integrity sha512-ivIvhpq/Y0uSjcHDcOIccjmYjGLcP09MFGE7ysAwkAvkXfpZlC985pH2/ui64DKazbTW/4kN3yqozUxlXzI6cA== + +events-to-array@^1.0.1: + version "1.1.2" + resolved "https://registry.npmjs.org/events-to-array/-/events-to-array-1.1.2.tgz#2d41f563e1fe400ed4962fe1a4d5c6a7539df7f6" + integrity sha1-LUH1Y+H+QA7Uli/hpNXGp1Od9/Y= + +exec-sh@^0.3.2: + version "0.3.2" + resolved "https://registry.npmjs.org/exec-sh/-/exec-sh-0.3.2.tgz#6738de2eb7c8e671d0366aea0b0db8c6f7d7391b" + integrity sha512-9sLAvzhI5nc8TpuQUh4ahMdCrWT00wPWz7j47/emR5+2qEfoZP5zzUXvx+vdx+H6ohhnsYC31iX04QLYJK8zTg== + +execa@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz#c6236a5bb4df6d6f15e88e7f017798216749ddd8" + integrity sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA== + dependencies: + cross-spawn "^6.0.0" + get-stream "^4.0.0" + is-stream "^1.1.0" + npm-run-path "^2.0.0" + p-finally "^1.0.0" + signal-exit "^3.0.0" + strip-eof "^1.0.0" + +exists-sync@0.0.3: + version "0.0.3" + resolved "https://registry.npmjs.org/exists-sync/-/exists-sync-0.0.3.tgz#b910000bedbb113b378b82f5f5a7638107622dcf" + integrity sha1-uRAAC+27ETs3i4L19adjgQdiLc8= + +exists-sync@0.0.4: + version "0.0.4" + resolved "https://registry.npmjs.org/exists-sync/-/exists-sync-0.0.4.tgz#9744c2c428cc03b01060db454d4b12f0ef3c8879" + integrity sha1-l0TCxCjMA7AQYNtFTUsS8O88iHk= + +exists-sync@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/exists-sync/-/exists-sync-0.1.0.tgz#318d545213d2b2a31499e92c35f74c94196a22f7" + integrity sha512-qEfFekfBVid4b14FNug/RNY1nv+BADnlzKGHulc+t6ZLqGY4kdHGh1iFha8lnE3sJU/1WzMzKRNxS6EvSakJUg== + +exit@^0.1.2: + version "0.1.2" + resolved "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c" + integrity sha1-BjJjj42HfMghB9MKD/8aF8uhzQw= + +expand-brackets@^2.1.4: + version "2.1.4" + resolved "https://registry.npmjs.org/expand-brackets/-/expand-brackets-2.1.4.tgz#b77735e315ce30f6b6eff0f83b04151a22449622" + integrity sha1-t3c14xXOMPa27/D4OwQVGiJEliI= + dependencies: + debug "^2.3.3" + define-property "^0.2.5" + extend-shallow "^2.0.1" + posix-character-classes "^0.1.0" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.1" + +expand-tilde@^2.0.0, expand-tilde@^2.0.2: + version "2.0.2" + resolved "https://registry.npmjs.org/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502" + integrity sha1-l+gBqgUt8CRU3kawK/YhZCzchQI= + dependencies: + homedir-polyfill "^1.0.1" + +express@^4.10.7, express@^4.13.1, express@^4.16.3: + version "4.16.4" + resolved "https://registry.npmjs.org/express/-/express-4.16.4.tgz#fddef61926109e24c515ea97fd2f1bdbf62df12e" + integrity sha512-j12Uuyb4FMrd/qQAm6uCHAkPtO8FDTRJZBDd5D2KOL2eLaz1yUNdUB/NOIyq0iU4q4cFarsUCrnFDPBcnksuOg== + dependencies: + accepts "~1.3.5" + array-flatten "1.1.1" + body-parser "1.18.3" + content-disposition "0.5.2" + content-type "~1.0.4" + cookie "0.3.1" + cookie-signature "1.0.6" + debug "2.6.9" + depd "~1.1.2" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + finalhandler "1.1.1" + fresh "0.5.2" + merge-descriptors "1.0.1" + methods "~1.1.2" + on-finished "~2.3.0" + parseurl "~1.3.2" + path-to-regexp "0.1.7" + proxy-addr "~2.0.4" + qs "6.5.2" + range-parser "~1.2.0" + safe-buffer "5.1.2" + send "0.16.2" + serve-static "1.13.2" + setprototypeof "1.1.0" + statuses "~1.4.0" + type-is "~1.6.16" + utils-merge "1.0.1" + vary "~1.1.2" + +extend-shallow@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f" + integrity sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8= + dependencies: + is-extendable "^0.1.0" + +extend-shallow@^3.0.0, extend-shallow@^3.0.2: + version "3.0.2" + resolved "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz#26a71aaf073b39fb2127172746131c2704028db8" + integrity sha1-Jqcarwc7OfshJxcnRhMcJwQCjbg= + dependencies: + assign-symbols "^1.0.0" + is-extendable "^1.0.1" + +extend@3, extend@^3.0.0, extend@~3.0.0: + version "3.0.2" + resolved "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" + integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== + +external-editor@^3.0.3: + version "3.0.3" + resolved "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz#5866db29a97826dbe4bf3afd24070ead9ea43a27" + integrity sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA== + dependencies: + chardet "^0.7.0" + iconv-lite "^0.4.24" + tmp "^0.0.33" + +extglob@^2.0.4: + version "2.0.4" + resolved "https://registry.npmjs.org/extglob/-/extglob-2.0.4.tgz#ad00fe4dc612a9232e8718711dc5cb5ab0285543" + integrity sha512-Nmb6QXkELsuBr24CJSkilo6UHHgbekK5UiZgfE6UHD3Eb27YC6oD+bhcT+tJ6cl8dmsgdQxnWlcry8ksBIBLpw== + dependencies: + array-unique "^0.3.2" + define-property "^1.0.0" + expand-brackets "^2.1.4" + extend-shallow "^2.0.1" + fragment-cache "^0.2.1" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.1" + +fake-xml-http-request@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/fake-xml-http-request/-/fake-xml-http-request-2.0.0.tgz#41a92f0ca539477700cb1dafd2df251d55dac8ff" + integrity sha512-UjNnynb6eLAB0lyh2PlTEkjRJORnNsVF1hbzU+PQv89/cyBV9GDRCy7JAcLQgeCLYT+3kaumWWZKEJvbaK74eQ== + +fast-deep-equal@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" + integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk= + +fast-diff@^1.1.2: + version "1.2.0" + resolved "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03" + integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w== + +fast-json-stable-stringify@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" + integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I= + +fast-levenshtein@~2.0.4: + version "2.0.6" + resolved "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" + integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= + +fast-ordered-set@^1.0.0, fast-ordered-set@^1.0.2: + version "1.0.3" + resolved "https://registry.npmjs.org/fast-ordered-set/-/fast-ordered-set-1.0.3.tgz#3fbb36634f7be79e4f7edbdb4a357dee25d184eb" + integrity sha1-P7s2Y097555PftvbSjV97iXRhOs= + dependencies: + blank-object "^1.0.1" + +fast-sourcemap-concat@^1.4.0: + version "1.4.0" + resolved "https://registry.npmjs.org/fast-sourcemap-concat/-/fast-sourcemap-concat-1.4.0.tgz#122c330d4a2afaff16ad143bc9674b87cd76c8ad" + integrity sha512-x90Wlx/2C83lfyg7h4oguTZN4MyaVfaiUSJQNpU+YEA0Odf9u659Opo44b0LfoVg9G/bOE++GdID/dkyja+XcA== + dependencies: + chalk "^2.0.0" + fs-extra "^5.0.0" + heimdalljs-logger "^0.1.9" + memory-streams "^0.1.3" + mkdirp "^0.5.0" + source-map "^0.4.2" + source-map-url "^0.3.0" + sourcemap-validator "^1.1.0" + +faye-websocket@~0.10.0: + version "0.10.0" + resolved "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.10.0.tgz#4e492f8d04dfb6f89003507f6edbf2d501e7c6f4" + integrity sha1-TkkvjQTftviQA1B/btvy1QHnxvQ= + dependencies: + websocket-driver ">=0.5.1" + +fb-watchman@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.0.tgz#54e9abf7dfa2f26cd9b1636c588c1afc05de5d58" + integrity sha1-VOmr99+i8mzZsWNsWIwa/AXeXVg= + dependencies: + bser "^2.0.0" + +figures@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962" + integrity sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI= + dependencies: + escape-string-regexp "^1.0.5" + +file-entry-cache@^5.0.1: + version "5.0.1" + resolved "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz#ca0f6efa6dd3d561333fb14515065c2fafdf439c" + integrity sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g== + dependencies: + flat-cache "^2.0.1" + +filesize@^3.6.1: + version "3.6.1" + resolved "https://registry.npmjs.org/filesize/-/filesize-3.6.1.tgz#090bb3ee01b6f801a8a8be99d31710b3422bb317" + integrity sha512-7KjR1vv6qnicaPMi1iiTcI85CyYwRO/PSFCu6SvqL8jN2Wjt/NIYQTFtFs7fSDCYOstUkEWIQGFUg5YZQfjlcg== + +fill-range@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" + integrity sha1-1USBHUKPmOsGpj3EAtJAPDKMOPc= + dependencies: + extend-shallow "^2.0.1" + is-number "^3.0.0" + repeat-string "^1.6.1" + to-regex-range "^2.1.0" + +finalhandler@1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.0.tgz#ce0b6855b45853e791b2fcc680046d88253dd7f5" + integrity sha1-zgtoVbRYU+eRsvzGgARtiCU91/U= + dependencies: + debug "2.6.9" + encodeurl "~1.0.1" + escape-html "~1.0.3" + on-finished "~2.3.0" + parseurl "~1.3.2" + statuses "~1.3.1" + unpipe "~1.0.0" + +finalhandler@1.1.1: + version "1.1.1" + resolved "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz#eebf4ed840079c83f4249038c9d703008301b105" + integrity sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg== + dependencies: + debug "2.6.9" + encodeurl "~1.0.2" + escape-html "~1.0.3" + on-finished "~2.3.0" + parseurl "~1.3.2" + statuses "~1.4.0" + unpipe "~1.0.0" + +find-babel-config@^1.1.0: + version "1.2.0" + resolved "https://registry.npmjs.org/find-babel-config/-/find-babel-config-1.2.0.tgz#a9b7b317eb5b9860cda9d54740a8c8337a2283a2" + integrity sha512-jB2CHJeqy6a820ssiqwrKMeyC6nNdmrcgkKWJWmpoxpE8RKciYJXCcXRq1h2AzCo5I5BJeN2tkGEO3hLTuePRA== + dependencies: + json5 "^0.5.1" + path-exists "^3.0.0" + +find-index@^1.1.0: + version "1.1.1" + resolved "https://registry.npmjs.org/find-index/-/find-index-1.1.1.tgz#4b221f8d46b7f8bea33d8faed953f3ca7a081cbc" + integrity sha512-XYKutXMrIK99YMUPf91KX5QVJoG31/OsgftD6YoTPAObfQIxM4ziA9f0J1AsqKhJmo+IeaIPP0CFopTD4bdUBw== + +find-up@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7" + integrity sha1-RdG35QbHF93UgndaK3eSCjwMV6c= + dependencies: + locate-path "^2.0.0" + +find-up@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73" + integrity sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg== + dependencies: + locate-path "^3.0.0" + +find-yarn-workspace-root@^1.1.0: + version "1.2.1" + resolved "https://registry.npmjs.org/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db" + integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q== + dependencies: + fs-extra "^4.0.3" + micromatch "^3.1.4" + +findup-sync@2.0.0, findup-sync@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/findup-sync/-/findup-sync-2.0.0.tgz#9326b1488c22d1a6088650a86901b2d9a90a2cbc" + integrity sha1-kyaxSIwi0aYIhlCoaQGy2akKLLw= + dependencies: + detect-file "^1.0.0" + is-glob "^3.1.0" + micromatch "^3.0.4" + resolve-dir "^1.0.1" + +fireworm@^0.7.0: + version "0.7.1" + resolved "https://registry.npmjs.org/fireworm/-/fireworm-0.7.1.tgz#ccf20f7941f108883fcddb99383dbe6e1861c758" + integrity sha1-zPIPeUHxCIg/zduZOD2+bhhhx1g= + dependencies: + async "~0.2.9" + is-type "0.0.1" + lodash.debounce "^3.1.1" + lodash.flatten "^3.0.2" + minimatch "^3.0.2" + +fixturify@^0.3.2: + version "0.3.4" + resolved "https://registry.npmjs.org/fixturify/-/fixturify-0.3.4.tgz#c676de404a7f8ee8e64d0b76118e62ec95ab7b25" + integrity sha512-Gx+KSB25b6gMc4bf7UFRTA85uE0iZR+RYur0JHh6dg4AGBh0EksOv4FCHyM7XpGmiJO7Bc7oV7vxENQBT+2WEQ== + dependencies: + fs-extra "^0.30.0" + matcher-collection "^1.0.4" + +flat-cache@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0" + integrity sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA== + dependencies: + flatted "^2.0.0" + rimraf "2.6.3" + write "1.0.3" + +flat@^4.1.0: + version "4.1.0" + resolved "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz#090bec8b05e39cba309747f1d588f04dbaf98db2" + integrity sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw== + dependencies: + is-buffer "~2.0.3" + +flatted@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/flatted/-/flatted-2.0.0.tgz#55122b6536ea496b4b44893ee2608141d10d9916" + integrity sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg== + +follow-redirects@0.0.7: + version "0.0.7" + resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-0.0.7.tgz#34b90bab2a911aa347571da90f22bd36ecd8a919" + integrity sha1-NLkLqyqRGqNHVx2pDyK9NuzYqRk= + dependencies: + debug "^2.2.0" + stream-consume "^0.1.0" + +follow-redirects@^1.0.0: + version "1.7.0" + resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz#489ebc198dc0e7f64167bd23b03c4c19b5784c76" + integrity sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ== + dependencies: + debug "^3.2.6" + +for-in@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" + integrity sha1-gQaNKVqBQuwKxybG4iAMMPttXoA= + +forever-agent@~0.5.0: + version "0.5.2" + resolved "https://registry.npmjs.org/forever-agent/-/forever-agent-0.5.2.tgz#6d0e09c4921f94a27f63d3b49c5feff1ea4c5130" + integrity sha1-bQ4JxJIflKJ/Y9O0nF/v8epMUTA= + +form-data@~0.1.0: + version "0.1.4" + resolved "https://registry.npmjs.org/form-data/-/form-data-0.1.4.tgz#91abd788aba9702b1aabfa8bc01031a2ac9e3b12" + integrity sha1-kavXiKupcCsaq/qLwBAxoqyeOxI= + dependencies: + async "~0.9.0" + combined-stream "~0.0.4" + mime "~1.2.11" + +forwarded@~0.1.2: + version "0.1.2" + resolved "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84" + integrity sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ= + +fragment-cache@^0.2.1: + version "0.2.1" + resolved "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19" + integrity sha1-QpD60n8T6Jvn8zeZxrxaCr//DRk= + dependencies: + map-cache "^0.2.2" + +fresh@0.5.2: + version "0.5.2" + resolved "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" + integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac= + +from2@^2.1.1: + version "2.3.0" + resolved "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz#8bfb5502bde4a4d36cfdeea007fcca21d7e382af" + integrity sha1-i/tVAr3kpNNs/e6gB/zKIdfjgq8= + dependencies: + inherits "^2.0.1" + readable-stream "^2.0.0" + +fs-extra@^0.24.0: + version "0.24.0" + resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-0.24.0.tgz#d4e4342a96675cb7846633a6099249332b539952" + integrity sha1-1OQ0KpZnXLeEZjOmCZJJMytTmVI= + dependencies: + graceful-fs "^4.1.2" + jsonfile "^2.1.0" + path-is-absolute "^1.0.0" + rimraf "^2.2.8" + +fs-extra@^0.30.0: + version "0.30.0" + resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz#f233ffcc08d4da7d432daa449776989db1df93f0" + integrity sha1-8jP/zAjU2n1DLapEl3aYnbHfk/A= + dependencies: + graceful-fs "^4.1.2" + jsonfile "^2.1.0" + klaw "^1.0.0" + path-is-absolute "^1.0.0" + rimraf "^2.2.8" + +fs-extra@^4.0.2, fs-extra@^4.0.3: + version "4.0.3" + resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94" + integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg== + dependencies: + graceful-fs "^4.1.2" + jsonfile "^4.0.0" + universalify "^0.1.0" + +fs-extra@^5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd" + integrity sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ== + dependencies: + graceful-fs "^4.1.2" + jsonfile "^4.0.0" + universalify "^0.1.0" + +fs-extra@^6.0.1: + version "6.0.1" + resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-6.0.1.tgz#8abc128f7946e310135ddc93b98bddb410e7a34b" + integrity sha512-GnyIkKhhzXZUWFCaJzvyDLEEgDkPfb4/TPvJCJVuS8MWZgoSsErf++QpiAlDnKFcqhRlm+tIOcencCjyJE6ZCA== + dependencies: + graceful-fs "^4.1.2" + jsonfile "^4.0.0" + universalify "^0.1.0" + +fs-extra@^7.0.0: + version "7.0.1" + resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" + integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== + dependencies: + graceful-fs "^4.1.2" + jsonfile "^4.0.0" + universalify "^0.1.0" + +fs-sync@^1.0.4: + version "1.0.6" + resolved "https://registry.npmjs.org/fs-sync/-/fs-sync-1.0.6.tgz#13f1d33a82edf441805fcc7cf6fabe246936166d" + integrity sha512-OgbfyvmGVryknZfDXVVhua6OW8946R+AF3O2xxrCW/XFxCYZ4CO2Jrl7kYhrpjZLYvB9gxvWpLikEc9YL9HzCA== + dependencies: + glob "^7.1.0" + iconv-lite "^0.4.13" + lodash "^4.16.1" + mkdirp "^0.5.1" + rimraf "^2.1.4" + +fs-tree-diff@^0.5.2, fs-tree-diff@^0.5.3, fs-tree-diff@^0.5.4, fs-tree-diff@^0.5.6, fs-tree-diff@^0.5.7, fs-tree-diff@^0.5.9: + version "0.5.9" + resolved "https://registry.npmjs.org/fs-tree-diff/-/fs-tree-diff-0.5.9.tgz#a4ec6182c2f5bd80b9b83c8e23e4522e6f5fd946" + integrity sha512-872G8ax0kHh01m9n/2KDzgYwouKza0Ad9iFltBpNykvROvf2AGtoOzPJgGx125aolGPER3JuC7uZFrQ7bG1AZw== + dependencies: + heimdalljs-logger "^0.1.7" + object-assign "^4.1.0" + path-posix "^1.0.0" + symlink-or-copy "^1.1.8" + +fs-tree-diff@^1.0.0, fs-tree-diff@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/fs-tree-diff/-/fs-tree-diff-1.0.2.tgz#0e2931733a85b55feb3472c0b89a20b0c03ac0de" + integrity sha512-Zro2ACaPVDgVOx9+s5s5AfPlAD0kMJdbwGvTGF6KC1SjxjiGWxJvV4mUTDkFVSy3OUw2C/f1qpdjF81hGqSBAw== + dependencies: + heimdalljs-logger "^0.1.7" + object-assign "^4.1.0" + path-posix "^1.0.0" + symlink-or-copy "^1.1.8" + +fs-updater@^1.0.4: + version "1.0.4" + resolved "https://registry.npmjs.org/fs-updater/-/fs-updater-1.0.4.tgz#2329980f99ae9176e9a0e84f7637538a182ce63b" + integrity sha512-0pJX4mJF/qLsNEwTct8CdnnRdagfb+LmjRPJ8sO+nCnAZLW0cTmz4rTgU25n+RvTuWSITiLKrGVJceJPBIPlKg== + dependencies: + can-symlink "^1.0.0" + clean-up-path "^1.0.0" + heimdalljs "^0.2.5" + heimdalljs-logger "^0.1.9" + rimraf "^2.6.2" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= + +function-bind@^1.1.1: + version "1.1.1" + resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" + integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== + +functional-red-black-tree@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" + integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= + +gauge@~2.7.3: + version "2.7.4" + resolved "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7" + integrity sha1-LANAXHU4w51+s3sxcCLjJfsBi/c= + dependencies: + aproba "^1.0.3" + console-control-strings "^1.0.0" + has-unicode "^2.0.0" + object-assign "^4.1.0" + signal-exit "^3.0.0" + string-width "^1.0.1" + strip-ansi "^3.0.1" + wide-align "^1.1.0" + +get-caller-file@^1.0.1: + version "1.0.3" + resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" + integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w== + +get-caller-file@^2.0.0: + version "2.0.5" + resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + +get-func-name@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" + integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE= + +get-stdin@^4.0.1: + version "4.0.1" + resolved "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" + integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4= + +get-stdin@^6.0.0: + version "6.0.0" + resolved "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" + integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g== + +get-stream@3.0.0, get-stream@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" + integrity sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ= + +get-stream@^4.0.0: + version "4.1.0" + resolved "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5" + integrity sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w== + dependencies: + pump "^3.0.0" + +get-value@^2.0.3, get-value@^2.0.6: + version "2.0.6" + resolved "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" + integrity sha1-3BXKHGcjh8p2vTesCjlbogQqLCg= + +git-fetch-pack@^0.1.1: + version "0.1.1" + resolved "https://registry.npmjs.org/git-fetch-pack/-/git-fetch-pack-0.1.1.tgz#7703a32cf0db80f060d2766a34ac00d02cebcdf5" + integrity sha1-dwOjLPDbgPBg0nZqNKwA0CzrzfU= + dependencies: + bops "0.0.3" + emit-function "0.0.2" + git-packed-ref-parse "0.0.0" + through "~2.2.7" + +git-packed-ref-parse@0.0.0: + version "0.0.0" + resolved "https://registry.npmjs.org/git-packed-ref-parse/-/git-packed-ref-parse-0.0.0.tgz#b85046931f3e4a65679b5de54af3a5d3df372646" + integrity sha1-uFBGkx8+SmVnm13lSvOl0983JkY= + dependencies: + line-stream "0.0.0" + through "~2.2.7" + +git-read-pkt-line@0.0.8: + version "0.0.8" + resolved "https://registry.npmjs.org/git-read-pkt-line/-/git-read-pkt-line-0.0.8.tgz#494037854ed57bd90cd55676540d86ab0cb36caa" + integrity sha1-SUA3hU7Ve9kM1VZ2VA2GqwyzbKo= + dependencies: + bops "0.0.3" + through "~2.2.7" + +git-repo-info@^1.0.4, git-repo-info@^1.4.1: + version "1.4.1" + resolved "https://registry.npmjs.org/git-repo-info/-/git-repo-info-1.4.1.tgz#2a072823254aaf62fcf0766007d7b6651bd41943" + integrity sha1-KgcoIyVKr2L88HZgB9e2ZRvUGUM= + +git-repo-info@^2.0.0: + version "2.1.0" + resolved "https://registry.npmjs.org/git-repo-info/-/git-repo-info-2.1.0.tgz#13d1f753c75bc2994432e65a71e35377ff563813" + integrity sha512-+kigfDB7j3W80f74BoOUX+lKOmf4pR3/i2Ww6baKTCPe2hD4FRdjhV3s4P5Dy0Tak1uY1891QhKoYNtnyX2VvA== + +git-repo-version@0.2.0: + version "0.2.0" + resolved "https://registry.npmjs.org/git-repo-version/-/git-repo-version-0.2.0.tgz#9a1d0019a50fc9e623c43d1c0fcc437391207d0d" + integrity sha1-mh0AGaUPyeYjxD0cD8xDc5EgfQ0= + dependencies: + git-repo-info "^1.0.4" + +git-repo-version@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/git-repo-version/-/git-repo-version-1.0.2.tgz#2c8e9bee5d970cafc0dd58480f9dc56d9afe8e4f" + integrity sha512-OPtwtHx9E8/rTMcWT+BU6GNj6Kq/O40bHJZaZAGy+pN2RXGmeKcfr0ix4M+SQuFY8vl5L/wfPSGOAtvUT/e3Qg== + dependencies: + git-repo-info "^1.4.1" + +git-transport-protocol@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/git-transport-protocol/-/git-transport-protocol-0.1.0.tgz#99f4dd6389b9161eded74a9e617d6ba5ed0a6c2c" + integrity sha1-mfTdY4m5Fh7e10qeYX1rpe0KbCw= + dependencies: + duplex "~1.0.0" + emit-function "0.0.2" + git-read-pkt-line "0.0.8" + git-write-pkt-line "0.1.0" + through "~2.2.7" + +git-write-pkt-line@0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/git-write-pkt-line/-/git-write-pkt-line-0.1.0.tgz#a84c1856c09011908389b2f06f911d91f6394694" + integrity sha1-qEwYVsCQEZCDibLwb5EdkfY5RpQ= + dependencies: + bops "0.0.3" + through "~2.2.7" + +github@^1.1.1: + version "1.4.0" + resolved "https://registry.npmjs.org/github/-/github-1.4.0.tgz#60aed8f16ffe381a3ca6dc6dba5bdd64445b7856" + integrity sha1-YK7Y8W/+OBo8ptxtulvdZERbeFY= + dependencies: + follow-redirects "0.0.7" + https-proxy-agent "^1.0.0" + mime "^1.2.11" + +glob@7.1.3, glob@^7.0.4, glob@^7.1.0, glob@^7.1.2, glob@^7.1.3: + version "7.1.3" + resolved "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1" + integrity sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +glob@^4.3.2: + version "4.5.3" + resolved "https://registry.npmjs.org/glob/-/glob-4.5.3.tgz#c6cb73d3226c1efef04de3c56d012f03377ee15f" + integrity sha1-xstz0yJsHv7wTePFbQEvAzd+4V8= + dependencies: + inflight "^1.0.4" + inherits "2" + minimatch "^2.0.1" + once "^1.3.0" + +glob@^5.0.10: + version "5.0.15" + resolved "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1" + integrity sha1-G8k2ueAvSmA/zCIuz3Yz0wuLk7E= + dependencies: + inflight "^1.0.4" + inherits "2" + minimatch "2 || 3" + once "^1.3.0" + path-is-absolute "^1.0.0" + +global-modules@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/global-modules/-/global-modules-1.0.0.tgz#6d770f0eb523ac78164d72b5e71a8877265cc3ea" + integrity sha512-sKzpEkf11GpOFuw0Zzjzmt4B4UZwjOcG757PPvrfhxcLFbq0wpsgpOqxpxtxFiCG4DtG93M6XRVbF2oGdev7bg== + dependencies: + global-prefix "^1.0.1" + is-windows "^1.0.1" + resolve-dir "^1.0.0" + +global-prefix@^1.0.1: + version "1.0.2" + resolved "https://registry.npmjs.org/global-prefix/-/global-prefix-1.0.2.tgz#dbf743c6c14992593c655568cb66ed32c0122ebe" + integrity sha1-2/dDxsFJklk8ZVVoy2btMsASLr4= + dependencies: + expand-tilde "^2.0.2" + homedir-polyfill "^1.0.1" + ini "^1.3.4" + is-windows "^1.0.1" + which "^1.2.14" + +globals@^11.1.0, globals@^11.7.0: + version "11.11.0" + resolved "https://registry.npmjs.org/globals/-/globals-11.11.0.tgz#dcf93757fa2de5486fbeed7118538adf789e9c2e" + integrity sha512-WHq43gS+6ufNOEqlrDBxVEbb8ntfXrfAUU2ZOpCxrBdGKW3gyv8mCxAfIBD0DroPKGrJ2eSsXsLtY9MPntsyTw== + +globals@^9.18.0: + version "9.18.0" + resolved "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" + integrity sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ== + +got@^6.7.1: + version "6.7.1" + resolved "https://registry.npmjs.org/got/-/got-6.7.1.tgz#240cd05785a9a18e561dc1b44b41c763ef1e8db0" + integrity sha1-JAzQV4WpoY5WHcG0S0HHY+8ejbA= + dependencies: + create-error-class "^3.0.0" + duplexer3 "^0.1.4" + get-stream "^3.0.0" + is-redirect "^1.0.0" + is-retry-allowed "^1.0.0" + is-stream "^1.0.0" + lowercase-keys "^1.0.0" + safe-buffer "^5.0.1" + timed-out "^4.0.0" + unzip-response "^2.0.1" + url-parse-lax "^1.0.0" + +got@^8.0.1: + version "8.3.2" + resolved "https://registry.npmjs.org/got/-/got-8.3.2.tgz#1d23f64390e97f776cac52e5b936e5f514d2e937" + integrity sha512-qjUJ5U/hawxosMryILofZCkm3C84PLJS/0grRIpjAwu+Lkxxj5cxeCU25BG0/3mDSpXKTyZr8oh8wIgLaH0QCw== + dependencies: + "@sindresorhus/is" "^0.7.0" + cacheable-request "^2.1.1" + decompress-response "^3.3.0" + duplexer3 "^0.1.4" + get-stream "^3.0.0" + into-stream "^3.1.0" + is-retry-allowed "^1.1.0" + isurl "^1.0.0-alpha5" + lowercase-keys "^1.0.0" + mimic-response "^1.0.0" + p-cancelable "^0.4.0" + p-timeout "^2.0.1" + pify "^3.0.0" + safe-buffer "^5.1.1" + timed-out "^4.0.1" + url-parse-lax "^3.0.0" + url-to-options "^1.0.1" + +graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.1.9: + version "4.1.15" + resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00" + integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA== + +"graceful-readlink@>= 1.0.0": + version "1.0.1" + resolved "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" + integrity sha1-TK+tdrxi8C+gObL5Tpo906ORpyU= + +growl@1.10.5: + version "1.10.5" + resolved "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e" + integrity sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA== + +growly@^1.3.0: + version "1.3.0" + resolved "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" + integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE= + +handlebars@^4.0.11, handlebars@^4.0.4: + version "4.1.0" + resolved "https://registry.npmjs.org/handlebars/-/handlebars-4.1.0.tgz#0d6a6f34ff1f63cecec8423aa4169827bf787c3a" + integrity sha512-l2jRuU1NAWK6AW5qqcTATWQJvNPEwkM7NEKSiv/gqOsoSQbVoWyqVEY5GS+XPQ88zLNmqASRpzfdm8d79hJS+w== + dependencies: + async "^2.5.0" + optimist "^0.6.1" + source-map "^0.6.1" + optionalDependencies: + uglify-js "^3.1.4" + +has-ansi@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" + integrity sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE= + dependencies: + ansi-regex "^2.0.0" + +has-binary2@~1.0.2: + version "1.0.3" + resolved "https://registry.npmjs.org/has-binary2/-/has-binary2-1.0.3.tgz#7776ac627f3ea77250cfc332dab7ddf5e4f5d11d" + integrity sha512-G1LWKhDSvhGeAQ8mPVQlqNcOB2sJdwATtZKl2pDKKHfpf/rYj24lkinxf69blJbnsvtqqNU+L3SL50vzZhXOnw== + dependencies: + isarray "2.0.1" + +has-cors@1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz#5e474793f7ea9843d1bb99c23eef49ff126fff39" + integrity sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk= + +has-flag@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" + integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0= + +has-symbol-support-x@^1.4.1: + version "1.4.2" + resolved "https://registry.npmjs.org/has-symbol-support-x/-/has-symbol-support-x-1.4.2.tgz#1409f98bc00247da45da67cee0a36f282ff26455" + integrity sha512-3ToOva++HaW+eCpgqZrCfN51IPB+7bJNVT6CUATzueB5Heb8o6Nam0V3HG5dlDvZU1Gn5QLcbahiKw/XVk5JJw== + +has-symbols@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz#ba1a8f1af2a0fc39650f5c850367704122063b44" + integrity sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q= + +has-to-string-tag-x@^1.2.0: + version "1.4.1" + resolved "https://registry.npmjs.org/has-to-string-tag-x/-/has-to-string-tag-x-1.4.1.tgz#a045ab383d7b4b2012a00148ab0aa5f290044d4d" + integrity sha512-vdbKfmw+3LoOYVr+mtxHaX5a96+0f3DljYd8JOqvOLsf5mw2Otda2qCDT9qRqLAhrjyQ0h7ual5nOiASpsGNFw== + dependencies: + has-symbol-support-x "^1.4.1" + +has-unicode@^2.0.0: + version "2.0.1" + resolved "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" + integrity sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk= + +has-value@^0.3.1: + version "0.3.1" + resolved "https://registry.npmjs.org/has-value/-/has-value-0.3.1.tgz#7b1f58bada62ca827ec0a2078025654845995e1f" + integrity sha1-ex9YutpiyoJ+wKIHgCVlSEWZXh8= + dependencies: + get-value "^2.0.3" + has-values "^0.1.4" + isobject "^2.0.0" + +has-value@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/has-value/-/has-value-1.0.0.tgz#18b281da585b1c5c51def24c930ed29a0be6b177" + integrity sha1-GLKB2lhbHFxR3vJMkw7SmgvmsXc= + dependencies: + get-value "^2.0.6" + has-values "^1.0.0" + isobject "^3.0.0" + +has-values@^0.1.4: + version "0.1.4" + resolved "https://registry.npmjs.org/has-values/-/has-values-0.1.4.tgz#6d61de95d91dfca9b9a02089ad384bff8f62b771" + integrity sha1-bWHeldkd/Km5oCCJrThL/49it3E= + +has-values@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/has-values/-/has-values-1.0.0.tgz#95b0b63fec2146619a6fe57fe75628d5a39efe4f" + integrity sha1-lbC2P+whRmGab+V/51Yo1aOe/k8= + dependencies: + is-number "^3.0.0" + kind-of "^4.0.0" + +has@^1.0.1, has@^1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== + dependencies: + function-bind "^1.1.1" + +hash-for-dep@^1.0.2, hash-for-dep@^1.2.3, hash-for-dep@^1.4.7, hash-for-dep@^1.5.0: + version "1.5.0" + resolved "https://registry.npmjs.org/hash-for-dep/-/hash-for-dep-1.5.0.tgz#02dacb5a3ee14e45d06f5aa039d142c970940476" + integrity sha512-Jtp264IRh25UmNHBNjB9jgYQGOpUVFMzt8E2MS6dJyR5uAO14bq4B9q5znOStkKpOpcxNUrYtg3hgpOSjQSONw== + dependencies: + broccoli-kitchen-sink-helpers "^0.3.1" + heimdalljs "^0.2.3" + heimdalljs-logger "^0.1.7" + path-root "^0.1.1" + resolve "^1.10.0" + resolve-package-path "^1.0.11" + +hawk@1.1.1: + version "1.1.1" + resolved "https://registry.npmjs.org/hawk/-/hawk-1.1.1.tgz#87cd491f9b46e4e2aeaca335416766885d2d1ed9" + integrity sha1-h81JH5tG5OKurKM1QWdmiF0tHtk= + dependencies: + boom "0.4.x" + cryptiles "0.2.x" + hoek "0.9.x" + sntp "0.2.x" + +he@1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" + integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== + +heimdalljs-fs-monitor@^0.2.2: + version "0.2.2" + resolved "https://registry.npmjs.org/heimdalljs-fs-monitor/-/heimdalljs-fs-monitor-0.2.2.tgz#a76d98f52dbf3aa1b7c20cebb0132e2f5eeb9204" + integrity sha512-R/VhkWs8tm4x+ekLIp+oieR8b3xYK0oFDumEraGnwNMixpiKwO3+Ms5MJzDP5W5Ui1+H/57nGW5L3lHbxi20GA== + dependencies: + heimdalljs "^0.2.3" + heimdalljs-logger "^0.1.7" + +heimdalljs-graph@^0.3.4: + version "0.3.5" + resolved "https://registry.npmjs.org/heimdalljs-graph/-/heimdalljs-graph-0.3.5.tgz#420fbbc8fc3aec5963ddbbf1a5fb47921c4a5927" + integrity sha512-szOy9WZUc7eUInEBQEsoa1G2d+oYHrn6ndZPf76eh8A9ID1zWUCEEsxP3F+CvQx9+EDrg1srdyLUmfVAr8EB4g== + +heimdalljs-logger@^0.1.7, heimdalljs-logger@^0.1.9: + version "0.1.10" + resolved "https://registry.npmjs.org/heimdalljs-logger/-/heimdalljs-logger-0.1.10.tgz#90cad58aabb1590a3c7e640ddc6a4cd3a43faaf7" + integrity sha512-pO++cJbhIufVI/fmB/u2Yty3KJD0TqNPecehFae0/eps0hkZ3b4Zc/PezUMOpYuHFQbA7FxHZxa305EhmjLj4g== + dependencies: + debug "^2.2.0" + heimdalljs "^0.2.6" + +heimdalljs@^0.2.0, heimdalljs@^0.2.1, heimdalljs@^0.2.3, heimdalljs@^0.2.5, heimdalljs@^0.2.6: + version "0.2.6" + resolved "https://registry.npmjs.org/heimdalljs/-/heimdalljs-0.2.6.tgz#b0eebabc412813aeb9542f9cc622cb58dbdcd9fe" + integrity sha512-o9bd30+5vLBvBtzCPwwGqpry2+n0Hi6H1+qwt6y+0kwRHGGF8TFIhJPmnuM0xO97zaKrDZMwO/V56fAnn8m/tA== + dependencies: + rsvp "~3.2.1" + +heimdalljs@^0.3.0: + version "0.3.3" + resolved "https://registry.npmjs.org/heimdalljs/-/heimdalljs-0.3.3.tgz#e92d2c6f77fd46d5bf50b610d28ad31755054d0b" + integrity sha1-6S0sb3f9RtW/ULYQ0orTF1UFTQs= + dependencies: + rsvp "~3.2.1" + +hoek@0.9.x: + version "0.9.1" + resolved "https://registry.npmjs.org/hoek/-/hoek-0.9.1.tgz#3d322462badf07716ea7eb85baf88079cddce505" + integrity sha1-PTIkYrrfB3Fup+uFuviAec3c5QU= + +home-or-tmp@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8" + integrity sha1-42w/LSyufXRqhX440Y1fMqeILbg= + dependencies: + os-homedir "^1.0.0" + os-tmpdir "^1.0.1" + +homedir-polyfill@^1.0.1: + version "1.0.3" + resolved "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz#743298cef4e5af3e194161fbadcc2151d3a058e8" + integrity sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA== + dependencies: + parse-passwd "^1.0.0" + +hosted-git-info@^2.6.0: + version "2.7.1" + resolved "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz#97f236977bd6e125408930ff6de3eec6281ec047" + integrity sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w== + +http-cache-semantics@3.8.1: + version "3.8.1" + resolved "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-3.8.1.tgz#39b0e16add9b605bf0a9ef3d9daaf4843b4cacd2" + integrity sha512-5ai2iksyV8ZXmnZhHH4rWPoxxistEexSi5936zIQ1bnNTW5VnA85B6P/VpXiRM017IgRvb2kKo1a//y+0wSp3w== + +http-errors@1.6.3, http-errors@~1.6.2, http-errors@~1.6.3: + version "1.6.3" + resolved "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz#8b55680bb4be283a0b5bf4ea2e38580be1d9320d" + integrity sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0= + dependencies: + depd "~1.1.2" + inherits "2.0.3" + setprototypeof "1.1.0" + statuses ">= 1.4.0 < 2" + +http-parser-js@>=0.4.0: + version "0.5.0" + resolved "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.5.0.tgz#d65edbede84349d0dc30320815a15d39cc3cbbd8" + integrity sha512-cZdEF7r4gfRIq7ezX9J0T+kQmJNOub71dWbgAXVHDct80TKP4MCETtZQ31xyv38UwgzkWPYF/Xc0ge55dW9Z9w== + +http-proxy@^1.13.1, http-proxy@^1.17.0: + version "1.17.0" + resolved "https://registry.npmjs.org/http-proxy/-/http-proxy-1.17.0.tgz#7ad38494658f84605e2f6db4436df410f4e5be9a" + integrity sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g== + dependencies: + eventemitter3 "^3.0.0" + follow-redirects "^1.0.0" + requires-port "^1.0.0" + +http-signature@~0.10.0: + version "0.10.1" + resolved "https://registry.npmjs.org/http-signature/-/http-signature-0.10.1.tgz#4fbdac132559aa8323121e540779c0a012b27e66" + integrity sha1-T72sEyVZqoMjEh5UB3nAoBKyfmY= + dependencies: + asn1 "0.1.11" + assert-plus "^0.1.5" + ctype "0.5.3" + +https-proxy-agent@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-1.0.0.tgz#35f7da6c48ce4ddbfa264891ac593ee5ff8671e6" + integrity sha1-NffabEjOTdv6JkiRrFk+5f+GceY= + dependencies: + agent-base "2" + debug "2" + extend "3" + +iconv-lite@0.4.23: + version "0.4.23" + resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz#297871f63be507adcfbfca715d0cd0eed84e9a63" + integrity sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + +iconv-lite@^0.4.13, iconv-lite@^0.4.24: + version "0.4.24" + resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" + integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + +ignore@^4.0.6: + version "4.0.6" + resolved "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" + integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== + +ignore@^5.0.2: + version "5.0.5" + resolved "https://registry.npmjs.org/ignore/-/ignore-5.0.5.tgz#c663c548d6ce186fb33616a8ccb5d46e56bdbbf9" + integrity sha512-kOC8IUb8HSDMVcYrDVezCxpJkzSQWTAzf3olpKM6o9rM5zpojx23O0Fl8Wr4+qJ6ZbPEHqf1fdwev/DS7v7pmA== + +import-fresh@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/import-fresh/-/import-fresh-3.0.0.tgz#a3d897f420cab0e671236897f75bc14b4885c390" + integrity sha512-pOnA9tfM3Uwics+SaBLCNyZZZbK+4PTu0OPZtLlMIrv17EdBoC15S9Kn8ckJ9TZTyKb3ywNE5y1yeDxxGA7nTQ== + dependencies: + parent-module "^1.0.0" + resolve-from "^4.0.0" + +imurmurhash@^0.1.4: + version "0.1.4" + resolved "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" + integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= + +indexof@0.0.1: + version "0.0.1" + resolved "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" + integrity sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10= + +inflection@^1.12.0: + version "1.12.0" + resolved "https://registry.npmjs.org/inflection/-/inflection-1.12.0.tgz#a200935656d6f5f6bc4dc7502e1aecb703228416" + integrity sha1-ogCTVlbW9fa8TcdQLhrstwMihBY= + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2, inherits@2.0.3, inherits@^2.0.1, inherits@~2.0.1, inherits@~2.0.3: + version "2.0.3" + resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= + +ini@^1.3.4, ini@~1.3.0: + version "1.3.5" + resolved "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" + integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== + +inline-source-map-comment@^1.0.5: + version "1.0.5" + resolved "https://registry.npmjs.org/inline-source-map-comment/-/inline-source-map-comment-1.0.5.tgz#50a8a44c2a790dfac441b5c94eccd5462635faf6" + integrity sha1-UKikTCp5DfrEQbXJTszVRiY1+vY= + dependencies: + chalk "^1.0.0" + get-stdin "^4.0.1" + minimist "^1.1.1" + sum-up "^1.0.1" + xtend "^4.0.0" + +inquirer@^6, inquirer@^6.2.2: + version "6.2.2" + resolved "https://registry.npmjs.org/inquirer/-/inquirer-6.2.2.tgz#46941176f65c9eb20804627149b743a218f25406" + integrity sha512-Z2rREiXA6cHRR9KBOarR3WuLlFzlIfAEIiB45ll5SSadMg7WqOh1MKEjjndfuH5ewXdixWCxqnVfGOQzPeiztA== + dependencies: + ansi-escapes "^3.2.0" + chalk "^2.4.2" + cli-cursor "^2.1.0" + cli-width "^2.0.0" + external-editor "^3.0.3" + figures "^2.0.0" + lodash "^4.17.11" + mute-stream "0.0.7" + run-async "^2.2.0" + rxjs "^6.4.0" + string-width "^2.1.0" + strip-ansi "^5.0.0" + through "^2.3.6" + +into-stream@^3.1.0: + version "3.1.0" + resolved "https://registry.npmjs.org/into-stream/-/into-stream-3.1.0.tgz#96fb0a936c12babd6ff1752a17d05616abd094c6" + integrity sha1-lvsKk2wSur1v8XUqF9BWFqvQlMY= + dependencies: + from2 "^2.1.1" + p-is-promise "^1.1.0" + +invariant@^2.2.2: + version "2.2.4" + resolved "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" + integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA== + dependencies: + loose-envify "^1.0.0" + +invert-kv@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02" + integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA== + +ip-regex@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9" + integrity sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk= + +ipaddr.js@1.8.0: + version "1.8.0" + resolved "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz#eaa33d6ddd7ace8f7f6fe0c9ca0440e706738b1e" + integrity sha1-6qM9bd16zo9/b+DJygRA5wZzix4= + +is-accessor-descriptor@^0.1.6: + version "0.1.6" + resolved "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz#a9e12cb3ae8d876727eeef3843f8a0897b5c98d6" + integrity sha1-qeEss66Nh2cn7u84Q/igiXtcmNY= + dependencies: + kind-of "^3.0.2" + +is-accessor-descriptor@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz#169c2f6d3df1f992618072365c9b0ea1f6878656" + integrity sha512-m5hnHTkcVsPfqx3AKlyttIPb7J+XykHvJP2B9bZDjlhLIoEq4XoK64Vg7boZlVWYK6LUY94dYPEE7Lh0ZkZKcQ== + dependencies: + kind-of "^6.0.0" + +is-buffer@^1.1.5: + version "1.1.6" + resolved "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" + integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== + +is-buffer@~2.0.3: + version "2.0.3" + resolved "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725" + integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw== + +is-callable@^1.1.4: + version "1.1.4" + resolved "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75" + integrity sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA== + +is-data-descriptor@^0.1.4: + version "0.1.4" + resolved "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56" + integrity sha1-C17mSDiOLIYCgueT8YVv7D8wG1Y= + dependencies: + kind-of "^3.0.2" + +is-data-descriptor@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-1.0.0.tgz#d84876321d0e7add03990406abbbbd36ba9268c7" + integrity sha512-jbRXy1FmtAoCjQkVmIVYwuuqDFUbaOeDjmed1tOGPrsMhtJA4rD9tkgA0F1qJ3gRFRXcHYVkdeaP50Q5rE/jLQ== + dependencies: + kind-of "^6.0.0" + +is-date-object@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz#9aa20eb6aeebbff77fbd33e74ca01b33581d3a16" + integrity sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY= + +is-descriptor@^0.1.0: + version "0.1.6" + resolved "https://registry.npmjs.org/is-descriptor/-/is-descriptor-0.1.6.tgz#366d8240dde487ca51823b1ab9f07a10a78251ca" + integrity sha512-avDYr0SB3DwO9zsMov0gKCESFYqCnE4hq/4z3TdUlukEy5t9C0YRq7HLrsN52NAcqXKaepeCD0n+B0arnVG3Hg== + dependencies: + is-accessor-descriptor "^0.1.6" + is-data-descriptor "^0.1.4" + kind-of "^5.0.0" + +is-descriptor@^1.0.0, is-descriptor@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/is-descriptor/-/is-descriptor-1.0.2.tgz#3b159746a66604b04f8c81524ba365c5f14d86ec" + integrity sha512-2eis5WqQGV7peooDyLmNEPUrps9+SXX5c9pL3xEB+4e9HnGuDa7mB7kHxHw4CbqS9k1T2hOH3miL8n8WtiYVtg== + dependencies: + is-accessor-descriptor "^1.0.0" + is-data-descriptor "^1.0.0" + kind-of "^6.0.2" + +is-extendable@^0.1.0, is-extendable@^0.1.1: + version "0.1.1" + resolved "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" + integrity sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik= + +is-extendable@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/is-extendable/-/is-extendable-1.0.1.tgz#a7470f9e426733d81bd81e1155264e3a3507cab4" + integrity sha512-arnXMxT1hhoKo9k1LZdmlNyJdDDfy2v0fXjFlmok4+i8ul/6WlbVge9bhM74OpNPQPMGUToDtz+KXa1PneJxOA== + dependencies: + is-plain-object "^2.0.4" + +is-extglob@^2.1.0: + version "2.1.1" + resolved "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" + integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI= + +is-finite@^1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz#cc6677695602be550ef11e8b4aa6305342b6d0aa" + integrity sha1-zGZ3aVYCvlUO8R6LSqYwU0K20Ko= + dependencies: + number-is-nan "^1.0.0" + +is-fullwidth-code-point@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz#ef9e31386f031a7f0d643af82fde50c457ef00cb" + integrity sha1-754xOG8DGn8NZDr4L95QxFfvAMs= + dependencies: + number-is-nan "^1.0.0" + +is-fullwidth-code-point@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" + integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8= + +is-git-url@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/is-git-url/-/is-git-url-1.0.0.tgz#53f684cd143285b52c3244b4e6f28253527af66b" + integrity sha1-U/aEzRQyhbUsMkS05vKCU1J69ms= + +is-glob@^3.1.0: + version "3.1.0" + resolved "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz#7ba5ae24217804ac70707b96922567486cc3e84a" + integrity sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo= + dependencies: + is-extglob "^2.1.0" + +is-number@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" + integrity sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU= + dependencies: + kind-of "^3.0.2" + +is-obj@^1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f" + integrity sha1-PkcprB9f3gJc19g6iW2rn09n2w8= + +is-object@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/is-object/-/is-object-1.0.1.tgz#8952688c5ec2ffd6b03ecc85e769e02903083470" + integrity sha1-iVJojF7C/9awPsyF52ngKQMINHA= + +is-plain-obj@^1.0.0: + version "1.1.0" + resolved "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e" + integrity sha1-caUMhCnfync8kqOQpKA7OfzVHT4= + +is-plain-object@^2.0.1, is-plain-object@^2.0.3, is-plain-object@^2.0.4: + version "2.0.4" + resolved "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677" + integrity sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og== + dependencies: + isobject "^3.0.1" + +is-promise@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa" + integrity sha1-eaKp7OfwlugPNtKy87wWwf9L8/o= + +is-redirect@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/is-redirect/-/is-redirect-1.0.0.tgz#1d03dded53bd8db0f30c26e4f95d36fc7c87dc24" + integrity sha1-HQPd7VO9jbDzDCbk+V02/HyH3CQ= + +is-reference@^1.1.0: + version "1.1.1" + resolved "https://registry.npmjs.org/is-reference/-/is-reference-1.1.1.tgz#bf2cda150a877f04d48caaf8fd70c03d8bed5e2d" + integrity sha512-URlByVARcyP2E2GC7d3Ur702g3vqW391VKCHuF5Goo/M8IT97k4RU/+56OYImwDdX1J/V/VRxECE/wJqB0I2tg== + dependencies: + "@types/estree" "0.0.39" + +is-regex@^1.0.4: + version "1.0.4" + resolved "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491" + integrity sha1-VRdIm1RwkbCTDglWVM7SXul+lJE= + dependencies: + has "^1.0.1" + +is-regexp@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/is-regexp/-/is-regexp-1.0.0.tgz#fd2d883545c46bac5a633e7b9a09e87fa2cb5069" + integrity sha1-/S2INUXEa6xaYz57mgnof6LLUGk= + +is-retry-allowed@^1.0.0, is-retry-allowed@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-1.1.0.tgz#11a060568b67339444033d0125a61a20d564fb34" + integrity sha1-EaBgVotnM5REAz0BJaYaINVk+zQ= + +is-stream@^1.0.0, is-stream@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" + integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= + +is-symbol@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz#a055f6ae57192caee329e7a860118b497a950f38" + integrity sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw== + dependencies: + has-symbols "^1.0.0" + +is-type@0.0.1: + version "0.0.1" + resolved "https://registry.npmjs.org/is-type/-/is-type-0.0.1.tgz#f651d85c365d44955d14a51d8d7061f3f6b4779c" + integrity sha1-9lHYXDZdRJVdFKUdjXBh8/a0d5w= + dependencies: + core-util-is "~1.0.0" + +is-windows@^1.0.1, is-windows@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" + integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== + +is-wsl@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d" + integrity sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0= + +isarray@0.0.1: + version "0.0.1" + resolved "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" + integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= + +isarray@1.0.0, isarray@~1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" + integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= + +isarray@2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz#a37d94ed9cda2d59865c9f76fe596ee1f338741e" + integrity sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4= + +isbinaryfile@^3.0.3: + version "3.0.3" + resolved "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-3.0.3.tgz#5d6def3edebf6e8ca8cae9c30183a804b5f8be80" + integrity sha512-8cJBL5tTd2OS0dM4jz07wQd5g0dCCqIhUxPIGtZfa5L6hWlvV5MHTITy/DBAsF+Oe2LS1X3krBUhNwaGUWpWxw== + dependencies: + buffer-alloc "^1.2.0" + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= + +isobject@^2.0.0: + version "2.1.0" + resolved "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89" + integrity sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk= + dependencies: + isarray "1.0.0" + +isobject@^3.0.0, isobject@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" + integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8= + +istextorbinary@2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/istextorbinary/-/istextorbinary-2.1.0.tgz#dbed2a6f51be2f7475b68f89465811141b758874" + integrity sha1-2+0qb1G+L3R1to+JRlgRFBt1iHQ= + dependencies: + binaryextensions "1 || 2" + editions "^1.1.1" + textextensions "1 || 2" + +isurl@^1.0.0-alpha5: + version "1.0.0" + resolved "https://registry.npmjs.org/isurl/-/isurl-1.0.0.tgz#b27f4f49f3cdaa3ea44a0a5b7f3462e6edc39d67" + integrity sha512-1P/yWsxPlDtn7QeRD+ULKQPaIaN6yF368GZ2vDfv0AL0NwpStafjWCDDdn0k8wgFMWpVAqG7oJhxHnlud42i9w== + dependencies: + has-to-string-tag-x "^1.2.0" + is-object "^1.0.1" + +jquery@^3.3.1: + version "3.3.1" + resolved "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz#958ce29e81c9790f31be7792df5d4d95fc57fbca" + integrity sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg== + +js-levenshtein@^1.1.3: + version "1.1.6" + resolved "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz#c6cee58eb3550372df8deb85fad5ce66ce01d59d" + integrity sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g== + +js-reporters@1.2.1: + version "1.2.1" + resolved "https://registry.npmjs.org/js-reporters/-/js-reporters-1.2.1.tgz#f88c608e324a3373a95bcc45ad305e5c979c459b" + integrity sha1-+IxgjjJKM3OpW8xFrTBeXJecRZs= + +"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" + integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== + +js-tokens@^3.0.2: + version "3.0.2" + resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" + integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls= + +js-yaml@3.12.0: + version "3.12.0" + resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1" + integrity sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A== + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + +js-yaml@^3.12.0, js-yaml@^3.12.1, js-yaml@^3.2.5, js-yaml@^3.2.7: + version "3.12.2" + resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.2.tgz#ef1d067c5a9d9cb65bd72f285b5d8105c77f14fc" + integrity sha512-QHn/Lh/7HhZ/Twc7vJYQTkjuCa0kaCcDcjK5Zlk2rvnUpy7DxMJ23+Jc2dcyvltwQVg1nygAVlB2oRDFHoRS5Q== + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + +jsesc@^1.3.0: + version "1.3.0" + resolved "https://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b" + integrity sha1-RsP+yMGJKxKwgz25vHYiF226s0s= + +jsesc@^2.5.1: + version "2.5.2" + resolved "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4" + integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== + +jsesc@~0.3.x: + version "0.3.0" + resolved "https://registry.npmjs.org/jsesc/-/jsesc-0.3.0.tgz#1bf5ee63b4539fe2e26d0c1e99c240b97a457972" + integrity sha1-G/XuY7RTn+LibQwemcJAuXpFeXI= + +jsesc@~0.5.0: + version "0.5.0" + resolved "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" + integrity sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0= + +json-buffer@3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz#5b1f397afc75d677bde8bcfc0e47e1f9a3d9a898" + integrity sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg= + +json-schema-traverse@^0.4.1: + version "0.4.1" + resolved "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" + integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== + +json-stable-stringify-without-jsonify@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" + integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE= + +json-stable-stringify@^1.0.0, json-stable-stringify@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af" + integrity sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8= + dependencies: + jsonify "~0.0.0" + +json-stringify-safe@~5.0.0: + version "5.0.1" + resolved "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" + integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= + +json-typescript@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/json-typescript/-/json-typescript-1.1.0.tgz#5369013526d516b13bde1ae2bbc541386dd12c72" + integrity sha512-6BzXAzBSfO4L3+IdCLISVQUzR4Wq946Xk2u7ChUAnvftyj/Ec1YgRmBOjw9Rw4wpdtvX678HPIYtYaGYr9fb9w== + +json5@^0.5.1: + version "0.5.1" + resolved "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" + integrity sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE= + +json5@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/json5/-/json5-2.1.0.tgz#e7a0c62c48285c628d20a10b85c89bb807c32850" + integrity sha512-8Mh9h6xViijj36g7Dxi+Y4S6hNGV96vcJZr/SrlHh1LR/pEn/8j/+qIBbs44YKl69Lrfctp4QD+AdWLTMqEZAQ== + dependencies: + minimist "^1.2.0" + +jsonfile@^2.1.0: + version "2.4.0" + resolved "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8" + integrity sha1-NzaitCi4e72gzIO1P6PWM6NcKug= + optionalDependencies: + graceful-fs "^4.1.6" + +jsonfile@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" + integrity sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss= + optionalDependencies: + graceful-fs "^4.1.6" + +jsonify@~0.0.0: + version "0.0.0" + resolved "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" + integrity sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM= + +keyv@3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/keyv/-/keyv-3.0.0.tgz#44923ba39e68b12a7cec7df6c3268c031f2ef373" + integrity sha512-eguHnq22OE3uVoSYG0LVWNP+4ppamWr9+zWBe1bsNcovIMy6huUJFPgy4mGwCd/rnl3vOLGW1MTlu4c57CT1xA== + dependencies: + json-buffer "3.0.0" + +kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0: + version "3.2.2" + resolved "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" + integrity sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ= + dependencies: + is-buffer "^1.1.5" + +kind-of@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/kind-of/-/kind-of-4.0.0.tgz#20813df3d712928b207378691a45066fae72dd57" + integrity sha1-IIE989cSkosgc3hpGkUGb65y3Vc= + dependencies: + is-buffer "^1.1.5" + +kind-of@^5.0.0: + version "5.1.0" + resolved "https://registry.npmjs.org/kind-of/-/kind-of-5.1.0.tgz#729c91e2d857b7a419a1f9aa65685c4c33f5845d" + integrity sha512-NGEErnH6F2vUuXDh+OlbcKW7/wOcfdRHaZ7VWtqCztfHri/++YKmP51OdWeGPuqCOba6kk2OTe5d02VmTB80Pw== + +kind-of@^6.0.0, kind-of@^6.0.2: + version "6.0.2" + resolved "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051" + integrity sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA== + +klaw@^1.0.0: + version "1.3.1" + resolved "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439" + integrity sha1-QIhDO0azsbolnXh4XY6W9zugJDk= + optionalDependencies: + graceful-fs "^4.1.9" + +lcid@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz#6ef5d2df60e52f82eb228a4c373e8d1f397253cf" + integrity sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA== + dependencies: + invert-kv "^2.0.0" + +leek@0.0.24: + version "0.0.24" + resolved "https://registry.npmjs.org/leek/-/leek-0.0.24.tgz#e400e57f0e60d8ef2bd4d068dc428a54345dbcda" + integrity sha1-5ADlfw5g2O8r1NBo3EKKVDRdvNo= + dependencies: + debug "^2.1.0" + lodash.assign "^3.2.0" + rsvp "^3.0.21" + +levn@^0.3.0, levn@~0.3.0: + version "0.3.0" + resolved "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" + integrity sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4= + dependencies: + prelude-ls "~1.1.2" + type-check "~0.3.2" + +line-stream@0.0.0: + version "0.0.0" + resolved "https://registry.npmjs.org/line-stream/-/line-stream-0.0.0.tgz#888b7cc7951c6a05ce4d696dd1e6b8262371bb45" + integrity sha1-iIt8x5UcagXOTWlt0ea4JiNxu0U= + dependencies: + through "~2.2.0" + +linkify-it@^2.0.0: + version "2.1.0" + resolved "https://registry.npmjs.org/linkify-it/-/linkify-it-2.1.0.tgz#c4caf38a6cd7ac2212ef3c7d2bde30a91561f9db" + integrity sha512-4REs8/062kV2DSHxNfq5183zrqXMl7WP0WzABH9IeJI+NLm429FgE1PDecltYfnOoFDFlZGh2T8PfZn0r+GTRg== + dependencies: + uc.micro "^1.0.1" + +linkify-it@~1.2.0: + version "1.2.4" + resolved "https://registry.npmjs.org/linkify-it/-/linkify-it-1.2.4.tgz#0773526c317c8fd13bd534ee1d180ff88abf881a" + integrity sha1-B3NSbDF8j9E71TTuHRgP+Iq/iBo= + dependencies: + uc.micro "^1.0.1" + +livereload-js@^2.3.0: + version "2.4.0" + resolved "https://registry.npmjs.org/livereload-js/-/livereload-js-2.4.0.tgz#447c31cf1ea9ab52fc20db615c5ddf678f78009c" + integrity sha512-XPQH8Z2GDP/Hwz2PCDrh2mth4yFejwA1OZ/81Ti3LgKyhDcEjsSsqFWZojHG0va/duGd+WyosY7eXLDoOyqcPw== + +loader.js@^4.7.0: + version "4.7.0" + resolved "https://registry.npmjs.org/loader.js/-/loader.js-4.7.0.tgz#a1a52902001c83631efde9688b8ab3799325ef1f" + integrity sha512-9M2KvGT6duzGMgkOcTkWb+PR/Q2Oe54df/tLgHGVmFpAmtqJ553xJh6N63iFYI2yjo2PeJXbS5skHi/QpJq4vA== + +locate-character@^2.0.5: + version "2.0.5" + resolved "https://registry.npmjs.org/locate-character/-/locate-character-2.0.5.tgz#f2d2614d49820ecb3c92d80d193b8db755f74c0f" + integrity sha512-n2GmejDXtOPBAZdIiEFy5dJ5N38xBCXLNOtw2WpB9kGh6pnrEuKlwYI+Tkpofc4wDtVXHtoAOJaMRlYG/oYaxg== + +locate-path@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" + integrity sha1-K1aLJl7slExtnA3pw9u7ygNUzY4= + dependencies: + p-locate "^2.0.0" + path-exists "^3.0.0" + +locate-path@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e" + integrity sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A== + dependencies: + p-locate "^3.0.0" + path-exists "^3.0.0" + +lodash-node@^3.2.0: + version "3.10.2" + resolved "https://registry.npmjs.org/lodash-node/-/lodash-node-3.10.2.tgz#2598d5b1b54e6a68b4cb544e5c730953cbf632f7" + integrity sha1-JZjVsbVOami0y1ROXHMJU8v2Mvc= + +lodash._baseassign@^3.0.0: + version "3.2.0" + resolved "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e" + integrity sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4= + dependencies: + lodash._basecopy "^3.0.0" + lodash.keys "^3.0.0" + +lodash._basebind@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._basebind/-/lodash._basebind-2.3.0.tgz#2b5bc452a0e106143b21869f233bdb587417d248" + integrity sha1-K1vEUqDhBhQ7IYafIzvbWHQX0kg= + dependencies: + lodash._basecreate "~2.3.0" + lodash._setbinddata "~2.3.0" + lodash.isobject "~2.3.0" + +lodash._basecopy@^3.0.0: + version "3.0.1" + resolved "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36" + integrity sha1-jaDmqHbPNEwK2KVIghEd08XHyjY= + +lodash._basecreate@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-2.3.0.tgz#9b88a86a4dcff7b7f3c61d83a2fcfc0671ec9de0" + integrity sha1-m4ioak3P97fzxh2Dovz8BnHsneA= + dependencies: + lodash._renative "~2.3.0" + lodash.isobject "~2.3.0" + lodash.noop "~2.3.0" + +lodash._basecreatecallback@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._basecreatecallback/-/lodash._basecreatecallback-2.3.0.tgz#37b2ab17591a339e988db3259fcd46019d7ac362" + integrity sha1-N7KrF1kaM56YjbMln81GAZ16w2I= + dependencies: + lodash._setbinddata "~2.3.0" + lodash.bind "~2.3.0" + lodash.identity "~2.3.0" + lodash.support "~2.3.0" + +lodash._basecreatewrapper@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._basecreatewrapper/-/lodash._basecreatewrapper-2.3.0.tgz#aa0c61ad96044c3933376131483a9759c3651247" + integrity sha1-qgxhrZYETDkzN2ExSDqXWcNlEkc= + dependencies: + lodash._basecreate "~2.3.0" + lodash._setbinddata "~2.3.0" + lodash._slice "~2.3.0" + lodash.isobject "~2.3.0" + +lodash._baseflatten@^3.0.0: + version "3.1.4" + resolved "https://registry.npmjs.org/lodash._baseflatten/-/lodash._baseflatten-3.1.4.tgz#0770ff80131af6e34f3b511796a7ba5214e65ff7" + integrity sha1-B3D/gBMa9uNPO1EXlqe6UhTmX/c= + dependencies: + lodash.isarguments "^3.0.0" + lodash.isarray "^3.0.0" + +lodash._bindcallback@^3.0.0: + version "3.0.1" + resolved "https://registry.npmjs.org/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" + integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4= + +lodash._createassigner@^3.0.0: + version "3.1.1" + resolved "https://registry.npmjs.org/lodash._createassigner/-/lodash._createassigner-3.1.1.tgz#838a5bae2fdaca63ac22dee8e19fa4e6d6970b11" + integrity sha1-g4pbri/aymOsIt7o4Z+k5taXCxE= + dependencies: + lodash._bindcallback "^3.0.0" + lodash._isiterateecall "^3.0.0" + lodash.restparam "^3.0.0" + +lodash._createwrapper@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._createwrapper/-/lodash._createwrapper-2.3.0.tgz#d1aae1102dadf440e8e06fc133a6edd7fe146075" + integrity sha1-0arhEC2t9EDo4G/BM6bt1/4UYHU= + dependencies: + lodash._basebind "~2.3.0" + lodash._basecreatewrapper "~2.3.0" + lodash.isfunction "~2.3.0" + +lodash._escapehtmlchar@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._escapehtmlchar/-/lodash._escapehtmlchar-2.3.0.tgz#d03da6bd82eedf38dc0a5b503d740ecd0e894592" + integrity sha1-0D2mvYLu3zjcCltQPXQOzQ6JRZI= + dependencies: + lodash._htmlescapes "~2.3.0" + +lodash._escapestringchar@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._escapestringchar/-/lodash._escapestringchar-2.3.0.tgz#cce73ae60fc6da55d2bf8a0679c23ca2bab149fc" + integrity sha1-zOc65g/G2lXSv4oGecI8orqxSfw= + +lodash._getnative@^3.0.0: + version "3.9.1" + resolved "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" + integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U= + +lodash._htmlescapes@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._htmlescapes/-/lodash._htmlescapes-2.3.0.tgz#1ca98863cadf1fa1d82c84f35f31e40556a04f3a" + integrity sha1-HKmIY8rfH6HYLITzXzHkBVagTzo= + +lodash._isiterateecall@^3.0.0: + version "3.0.9" + resolved "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz#5203ad7ba425fae842460e696db9cf3e6aac057c" + integrity sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw= + +lodash._objecttypes@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._objecttypes/-/lodash._objecttypes-2.3.0.tgz#6a3ea3987dd6eeb8021b2d5c9c303549cc2bae1e" + integrity sha1-aj6jmH3W7rgCGy1cnDA1Scwrrh4= + +lodash._reinterpolate@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-2.3.0.tgz#03ee9d85c0e55cbd590d71608a295bdda51128ec" + integrity sha1-A+6dhcDlXL1ZDXFgiilb3aURKOw= + +lodash._reinterpolate@~3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" + integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0= + +lodash._renative@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._renative/-/lodash._renative-2.3.0.tgz#77d8edd4ced26dd5971f9e15a5f772e4e317fbd3" + integrity sha1-d9jt1M7SbdWXH54Vpfdy5OMX+9M= + +lodash._reunescapedhtml@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._reunescapedhtml/-/lodash._reunescapedhtml-2.3.0.tgz#db920b55ac7f3ff825939aceb9ba2c231713d24d" + integrity sha1-25ILVax/P/glk5rOubosIxcT0k0= + dependencies: + lodash._htmlescapes "~2.3.0" + lodash.keys "~2.3.0" + +lodash._setbinddata@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._setbinddata/-/lodash._setbinddata-2.3.0.tgz#e5610490acd13277d59858d95b5f2727f1508f04" + integrity sha1-5WEEkKzRMnfVmFjZW18nJ/FQjwQ= + dependencies: + lodash._renative "~2.3.0" + lodash.noop "~2.3.0" + +lodash._shimkeys@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._shimkeys/-/lodash._shimkeys-2.3.0.tgz#611f93149e3e6c721096b48769ef29537ada8ba9" + integrity sha1-YR+TFJ4+bHIQlrSHae8pU3rai6k= + dependencies: + lodash._objecttypes "~2.3.0" + +lodash._slice@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash._slice/-/lodash._slice-2.3.0.tgz#147198132859972e4680ca29a5992c855669aa5c" + integrity sha1-FHGYEyhZly5GgMoppZkshVZpqlw= + +lodash.assign@^3.2.0: + version "3.2.0" + resolved "https://registry.npmjs.org/lodash.assign/-/lodash.assign-3.2.0.tgz#3ce9f0234b4b2223e296b8fa0ac1fee8ebca64fa" + integrity sha1-POnwI0tLIiPilrj6CsH+6OvKZPo= + dependencies: + lodash._baseassign "^3.0.0" + lodash._createassigner "^3.0.0" + lodash.keys "^3.0.0" + +lodash.assignin@^4.1.0: + version "4.2.0" + resolved "https://registry.npmjs.org/lodash.assignin/-/lodash.assignin-4.2.0.tgz#ba8df5fb841eb0a3e8044232b0e263a8dc6a28a2" + integrity sha1-uo31+4QesKPoBEIysOJjqNxqKKI= + +lodash.bind@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.bind/-/lodash.bind-2.3.0.tgz#c2a8e18b68e5ecc152e2b168266116fea5b016cc" + integrity sha1-wqjhi2jl7MFS4rFoJmEW/qWwFsw= + dependencies: + lodash._createwrapper "~2.3.0" + lodash._renative "~2.3.0" + lodash._slice "~2.3.0" + +lodash.castarray@^4.4.0: + version "4.4.0" + resolved "https://registry.npmjs.org/lodash.castarray/-/lodash.castarray-4.4.0.tgz#c02513515e309daddd4c24c60cfddcf5976d9115" + integrity sha1-wCUTUV4wna3dTCTGDP3c9ZdtkRU= + +lodash.clonedeep@^4.4.1: + version "4.5.0" + resolved "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" + integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8= + +lodash.debounce@^3.1.1: + version "3.1.1" + resolved "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-3.1.1.tgz#812211c378a94cc29d5aa4e3346cf0bfce3a7df5" + integrity sha1-gSIRw3ipTMKdWqTjNGzwv846ffU= + dependencies: + lodash._getnative "^3.0.0" + +lodash.defaults@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-2.3.0.tgz#a832b001f138f3bb9721c2819a2a7cc5ae21ed25" + integrity sha1-qDKwAfE487uXIcKBmip8xa4h7SU= + dependencies: + lodash._objecttypes "~2.3.0" + lodash.keys "~2.3.0" + +lodash.defaultsdeep@^4.6.0: + version "4.6.0" + resolved "https://registry.npmjs.org/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.0.tgz#bec1024f85b1bd96cbea405b23c14ad6443a6f81" + integrity sha1-vsECT4WxvZbL6kBbI8FK1kQ6b4E= + +lodash.escape@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.escape/-/lodash.escape-2.3.0.tgz#844c38c58f844e1362ebe96726159b62cf5f2a58" + integrity sha1-hEw4xY+EThNi6+lnJhWbYs9fKlg= + dependencies: + lodash._escapehtmlchar "~2.3.0" + lodash._reunescapedhtml "~2.3.0" + lodash.keys "~2.3.0" + +lodash.find@^4.5.1: + version "4.6.0" + resolved "https://registry.npmjs.org/lodash.find/-/lodash.find-4.6.0.tgz#cb0704d47ab71789ffa0de8b97dd926fb88b13b1" + integrity sha1-ywcE1Hq3F4n/oN6Ll92Sb7iLE7E= + +lodash.flatten@^3.0.2: + version "3.0.2" + resolved "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-3.0.2.tgz#de1cf57758f8f4479319d35c3e9cc60c4501938c" + integrity sha1-3hz1d1j49EeTGdNcPpzGDEUBk4w= + dependencies: + lodash._baseflatten "^3.0.0" + lodash._isiterateecall "^3.0.0" + +lodash.foreach@~2.3.x: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.foreach/-/lodash.foreach-2.3.0.tgz#083404c91e846ee77245fdf9d76519c68b2af168" + integrity sha1-CDQEyR6EbudyRf3512UZxosq8Wg= + dependencies: + lodash._basecreatecallback "~2.3.0" + lodash.forown "~2.3.0" + +lodash.forown@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.forown/-/lodash.forown-2.3.0.tgz#24fb4aaf800d45fc2dc60bfec3ce04c836a3ad7f" + integrity sha1-JPtKr4ANRfwtxgv+w84EyDajrX8= + dependencies: + lodash._basecreatecallback "~2.3.0" + lodash._objecttypes "~2.3.0" + lodash.keys "~2.3.0" + +lodash.identity@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.identity/-/lodash.identity-2.3.0.tgz#6b01a210c9485355c2a913b48b6711219a173ded" + integrity sha1-awGiEMlIU1XCqRO0i2cRIZoXPe0= + +lodash.isarguments@^3.0.0: + version "3.1.0" + resolved "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" + integrity sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo= + +lodash.isarray@^3.0.0: + version "3.0.4" + resolved "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" + integrity sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U= + +lodash.isfunction@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.isfunction/-/lodash.isfunction-2.3.0.tgz#6b2973e47a647cf12e70d676aea13643706e5267" + integrity sha1-aylz5HpkfPEucNZ2rqE2Q3BuUmc= + +lodash.isobject@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.isobject/-/lodash.isobject-2.3.0.tgz#2e16d3fc583da9831968953f2d8e6d73434f6799" + integrity sha1-LhbT/Fg9qYMZaJU/LY5tc0NPZ5k= + dependencies: + lodash._objecttypes "~2.3.0" + +lodash.keys@^3.0.0: + version "3.1.2" + resolved "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" + integrity sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo= + dependencies: + lodash._getnative "^3.0.0" + lodash.isarguments "^3.0.0" + lodash.isarray "^3.0.0" + +lodash.keys@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.keys/-/lodash.keys-2.3.0.tgz#b350f4f92caa9f45a4a2ecf018454cf2f28ae253" + integrity sha1-s1D0+Syqn0WkouzwGEVM8vKK4lM= + dependencies: + lodash._renative "~2.3.0" + lodash._shimkeys "~2.3.0" + lodash.isobject "~2.3.0" + +lodash.memoize@^4.1.2: + version "4.1.2" + resolved "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" + integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4= + +lodash.merge@^4.3.1, lodash.merge@^4.6.0: + version "4.6.1" + resolved "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54" + integrity sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ== + +lodash.noop@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.noop/-/lodash.noop-2.3.0.tgz#3059d628d51bbf937cd2a0b6fc3a7f212a669c2c" + integrity sha1-MFnWKNUbv5N80qC2/Dp/ISpmnCw= + +lodash.omit@^4.1.0: + version "4.5.0" + resolved "https://registry.npmjs.org/lodash.omit/-/lodash.omit-4.5.0.tgz#6eb19ae5a1ee1dd9df0b969e66ce0b7fa30b5e60" + integrity sha1-brGa5aHuHdnfC5aeZs4Lf6MLXmA= + +lodash.restparam@^3.0.0: + version "3.6.1" + resolved "https://registry.npmjs.org/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" + integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU= + +lodash.support@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.support/-/lodash.support-2.3.0.tgz#7eaf038af4f0d6aab776b44aa6dcfc80334c9bfd" + integrity sha1-fq8DivTw1qq3drRKptz8gDNMm/0= + dependencies: + lodash._renative "~2.3.0" + +lodash.template@^4.4.0: + version "4.4.0" + resolved "https://registry.npmjs.org/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0" + integrity sha1-5zoDhcg1VZF0bgILmWecaQ5o+6A= + dependencies: + lodash._reinterpolate "~3.0.0" + lodash.templatesettings "^4.0.0" + +lodash.template@~2.3.x: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.template/-/lodash.template-2.3.0.tgz#4e3e29c433b4cfea675ec835e6f12391c61fd22b" + integrity sha1-Tj4pxDO0z+pnXsg15vEjkcYf0is= + dependencies: + lodash._escapestringchar "~2.3.0" + lodash._reinterpolate "~2.3.0" + lodash.defaults "~2.3.0" + lodash.escape "~2.3.0" + lodash.keys "~2.3.0" + lodash.templatesettings "~2.3.0" + lodash.values "~2.3.0" + +lodash.templatesettings@^4.0.0: + version "4.1.0" + resolved "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-4.1.0.tgz#2b4d4e95ba440d915ff08bc899e4553666713316" + integrity sha1-K01OlbpEDZFf8IvImeRVNmZxMxY= + dependencies: + lodash._reinterpolate "~3.0.0" + +lodash.templatesettings@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-2.3.0.tgz#303d132c342710040d5a18efaa2d572fd03f8cdc" + integrity sha1-MD0TLDQnEAQNWhjvqi1XL9A/jNw= + dependencies: + lodash._reinterpolate "~2.3.0" + lodash.escape "~2.3.0" + +lodash.uniq@^4.2.0, lodash.uniq@^4.5.0: + version "4.5.0" + resolved "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" + integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= + +lodash.uniqby@^4.7.0: + version "4.7.0" + resolved "https://registry.npmjs.org/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz#d99c07a669e9e6d24e1362dfe266c67616af1302" + integrity sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI= + +lodash.values@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/lodash.values/-/lodash.values-2.3.0.tgz#ca96fbe60a20b0b0ec2ba2ba5fc6a765bd14a3ba" + integrity sha1-ypb75gogsLDsK6K6X8anZb0Uo7o= + dependencies: + lodash.keys "~2.3.0" + +lodash@^4.0.0, lodash@^4.16.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.6.1: + version "4.17.11" + resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" + integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== + +log-symbols@2.2.0, log-symbols@^2.2.0: + version "2.2.0" + resolved "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a" + integrity sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg== + dependencies: + chalk "^2.0.1" + +loose-envify@^1.0.0: + version "1.4.0" + resolved "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" + integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== + dependencies: + js-tokens "^3.0.0 || ^4.0.0" + +lowercase-keys@1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.0.tgz#4e3366b39e7f5457e35f1324bdf6f88d0bfc7306" + integrity sha1-TjNms55/VFfjXxMkvfb4jQv8cwY= + +lowercase-keys@^1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f" + integrity sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA== + +magic-string@^0.24.0: + version "0.24.1" + resolved "https://registry.npmjs.org/magic-string/-/magic-string-0.24.1.tgz#7e38e5f126cae9f15e71f0cf8e450818ca7d5a8f" + integrity sha512-YBfNxbJiixMzxW40XqJEIldzHyh5f7CZKalo1uZffevyrPEX8Qgo9s0dmcORLHdV47UyvJg8/zD+6hQG3qvJrA== + dependencies: + sourcemap-codec "^1.4.1" + +make-dir@^1.0.0: + version "1.3.0" + resolved "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz#79c1033b80515bd6d24ec9933e860ca75ee27f0c" + integrity sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ== + dependencies: + pify "^3.0.0" + +makeerror@1.0.x: + version "1.0.11" + resolved "https://registry.npmjs.org/makeerror/-/makeerror-1.0.11.tgz#e01a5c9109f2af79660e4e8b9587790184f5a96c" + integrity sha1-4BpckQnyr3lmDk6LlYd5AYT1qWw= + dependencies: + tmpl "1.0.x" + +map-age-cleaner@^0.1.1: + version "0.1.3" + resolved "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a" + integrity sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w== + dependencies: + p-defer "^1.0.0" + +map-cache@^0.2.2: + version "0.2.2" + resolved "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" + integrity sha1-wyq9C9ZSXZsFFkW7TyasXcmKDb8= + +map-visit@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f" + integrity sha1-7Nyo8TFE5mDxtb1B8S80edmN+48= + dependencies: + object-visit "^1.0.0" + +markdown-it-terminal@0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/markdown-it-terminal/-/markdown-it-terminal-0.1.0.tgz#545abd8dd01c3d62353bfcea71db580b51d22bd9" + integrity sha1-VFq9jdAcPWI1O/zqcdtYC1HSK9k= + dependencies: + ansi-styles "^3.0.0" + cardinal "^1.0.0" + cli-table "^0.3.1" + lodash.merge "^4.6.0" + markdown-it "^8.3.1" + +markdown-it@^4.3.0: + version "4.4.0" + resolved "https://registry.npmjs.org/markdown-it/-/markdown-it-4.4.0.tgz#3df373dbea587a9a7fef3e56311b68908f75c414" + integrity sha1-PfNz2+pYepp/7z5WMRtokI91xBQ= + dependencies: + argparse "~1.0.2" + entities "~1.1.1" + linkify-it "~1.2.0" + mdurl "~1.0.0" + uc.micro "^1.0.0" + +markdown-it@^8.3.1, markdown-it@^8.4.2: + version "8.4.2" + resolved "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54" + integrity sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ== + dependencies: + argparse "^1.0.7" + entities "~1.1.1" + linkify-it "^2.0.0" + mdurl "^1.0.1" + uc.micro "^1.0.5" + +matcher-collection@^1.0.0, matcher-collection@^1.0.4, matcher-collection@^1.0.5, matcher-collection@^1.1.1: + version "1.1.2" + resolved "https://registry.npmjs.org/matcher-collection/-/matcher-collection-1.1.2.tgz#1076f506f10ca85897b53d14ef54f90a5c426838" + integrity sha512-YQ/teqaOIIfUHedRam08PB3NK7Mjct6BvzRnJmpGDm8uFXpNr1sbY4yuflI5JcEs6COpYA0FpRQhSDBf1tT95g== + dependencies: + minimatch "^3.0.2" + +mdn-links@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/mdn-links/-/mdn-links-0.1.0.tgz#e24c83b97cb4c5886cc39f2f780705fbfe273aa5" + integrity sha1-4kyDuXy0xYhsw58veAcF+/4nOqU= + +mdurl@^1.0.1, mdurl@~1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e" + integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4= + +media-typer@0.3.0: + version "0.3.0" + resolved "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" + integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= + +mem@^4.0.0: + version "4.1.0" + resolved "https://registry.npmjs.org/mem/-/mem-4.1.0.tgz#aeb9be2d21f47e78af29e4ac5978e8afa2ca5b8a" + integrity sha512-I5u6Q1x7wxO0kdOpYBB28xueHADYps5uty/zg936CiG8NTe5sJL8EjrCuLneuDW3PlMdZBGDIn8BirEVdovZvg== + dependencies: + map-age-cleaner "^0.1.1" + mimic-fn "^1.0.0" + p-is-promise "^2.0.0" + +memory-streams@^0.1.3: + version "0.1.3" + resolved "https://registry.npmjs.org/memory-streams/-/memory-streams-0.1.3.tgz#d9b0017b4b87f1d92f55f2745c9caacb1dc93ceb" + integrity sha512-qVQ/CjkMyMInPaaRMrwWNDvf6boRZXaT/DbQeMYcCWuXPEBf1v8qChOc9OlEVQp2uOvRXa1Qu30fLmKhY6NipA== + dependencies: + readable-stream "~1.0.2" + +merge-descriptors@1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" + integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E= + +merge-trees@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/merge-trees/-/merge-trees-1.0.1.tgz#ccbe674569787f9def17fd46e6525f5700bbd23e" + integrity sha1-zL5nRWl4f53vF/1G5lJfVwC70j4= + dependencies: + can-symlink "^1.0.0" + fs-tree-diff "^0.5.4" + heimdalljs "^0.2.1" + heimdalljs-logger "^0.1.7" + rimraf "^2.4.3" + symlink-or-copy "^1.0.0" + +merge-trees@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/merge-trees/-/merge-trees-2.0.0.tgz#a560d796e566c5d9b2c40472a2967cca48d85161" + integrity sha512-5xBbmqYBalWqmhYm51XlohhkmVOua3VAUrrWh8t9iOkaLpS6ifqm/UVuUjQCeDVJ9Vx3g2l6ihfkbLSTeKsHbw== + dependencies: + fs-updater "^1.0.4" + heimdalljs "^0.2.5" + +methods@~1.1.2: + version "1.1.2" + resolved "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" + integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4= + +micromatch@^3.0.4, micromatch@^3.1.10, micromatch@^3.1.4: + version "3.1.10" + resolved "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" + integrity sha512-MWikgl9n9M3w+bpsY3He8L+w9eF9338xRl8IAO5viDizwSzziFEyUzo2xrrloB64ADbTf8uA8vRqqttDTOmccg== + dependencies: + arr-diff "^4.0.0" + array-unique "^0.3.2" + braces "^2.3.1" + define-property "^2.0.2" + extend-shallow "^3.0.2" + extglob "^2.0.4" + fragment-cache "^0.2.1" + kind-of "^6.0.2" + nanomatch "^1.2.9" + object.pick "^1.3.0" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.2" + +"mime-db@>= 1.38.0 < 2", mime-db@~1.38.0: + version "1.38.0" + resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.38.0.tgz#1a2aab16da9eb167b49c6e4df2d9c68d63d8e2ad" + integrity sha512-bqVioMFFzc2awcdJZIzR3HjZFX20QhilVS7hytkKrv7xFAn8bM1gzc/FOX2awLISvWe0PV8ptFKcon+wZ5qYkg== + +mime-types@^2.1.18, mime-types@^2.1.19, mime-types@~2.1.18: + version "2.1.22" + resolved "https://registry.npmjs.org/mime-types/-/mime-types-2.1.22.tgz#fe6b355a190926ab7698c9a0556a11199b2199bd" + integrity sha512-aGl6TZGnhm/li6F7yx82bJiBZwgiEa4Hf6CNr8YO+r5UHr53tSTYZb102zyU50DOWWKeOv0uQLRL0/9EiKWCog== + dependencies: + mime-db "~1.38.0" + +mime-types@~1.0.1: + version "1.0.2" + resolved "https://registry.npmjs.org/mime-types/-/mime-types-1.0.2.tgz#995ae1392ab8affcbfcb2641dd054e943c0d5dce" + integrity sha1-mVrhOSq4r/y/yyZB3QVOlDwNXc4= + +mime@1.4.1: + version "1.4.1" + resolved "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6" + integrity sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ== + +mime@^1.2.11: + version "1.6.0" + resolved "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" + integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== + +mime@~1.2.11: + version "1.2.11" + resolved "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz#58203eed86e3a5ef17aed2b7d9ebd47f0a60dd10" + integrity sha1-WCA+7Ybjpe8XrtK32evUfwpg3RA= + +mimic-fn@^1.0.0: + version "1.2.0" + resolved "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" + integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ== + +mimic-response@^1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b" + integrity sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ== + +"minimatch@2 || 3", minimatch@3.0.4, minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== + dependencies: + brace-expansion "^1.1.7" + +minimatch@^2.0.1: + version "2.0.10" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz#8d087c39c6b38c001b97fca7ce6d0e1e80afbac7" + integrity sha1-jQh8OcazjAAbl/ynzm0OHoCvusc= + dependencies: + brace-expansion "^1.0.0" + +minimist@0.0.8: + version "0.0.8" + resolved "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= + +minimist@^1.1.1, minimist@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" + integrity sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ= + +minimist@~0.0.1: + version "0.0.10" + resolved "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" + integrity sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8= + +minipass@^2.2.0: + version "2.3.5" + resolved "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz#cacebe492022497f656b0f0f51e2682a9ed2d848" + integrity sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA== + dependencies: + safe-buffer "^5.1.2" + yallist "^3.0.0" + +mixin-deep@^1.2.0: + version "1.3.1" + resolved "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe" + integrity sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ== + dependencies: + for-in "^1.0.2" + is-extendable "^1.0.1" + +mkdirp@0.5.1, mkdirp@0.5.x, mkdirp@^0.5.0, mkdirp@^0.5.1: + version "0.5.1" + resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" + integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM= + dependencies: + minimist "0.0.8" + +mktemp@~0.4.0: + version "0.4.0" + resolved "https://registry.npmjs.org/mktemp/-/mktemp-0.4.0.tgz#6d0515611c8a8c84e484aa2000129b98e981ff0b" + integrity sha1-bQUVYRyKjITkhKogABKbmOmB/ws= + +mocha-only-detector@1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/mocha-only-detector/-/mocha-only-detector-1.0.0.tgz#183c710afffcca79df172daf76c45afca3b8e37d" + integrity sha1-GDxxCv/8ynnfFy2vdsRa/KO4430= + dependencies: + esprima "^4.0.0" + esprimaq "^0.0.1" + glob "^4.3.2" + +mocha@^6.0.2: + version "6.0.2" + resolved "https://registry.npmjs.org/mocha/-/mocha-6.0.2.tgz#cdc1a6fdf66472c079b5605bac59d29807702d2c" + integrity sha512-RtTJsmmToGyeTznSOMoM6TPEk1A84FQaHIciKrRqARZx+B5ccJ5tXlmJzEKGBxZdqk9UjpRsesZTUkZmR5YnuQ== + dependencies: + ansi-colors "3.2.3" + browser-stdout "1.3.1" + debug "3.2.6" + diff "3.5.0" + escape-string-regexp "1.0.5" + findup-sync "2.0.0" + glob "7.1.3" + growl "1.10.5" + he "1.2.0" + js-yaml "3.12.0" + log-symbols "2.2.0" + minimatch "3.0.4" + mkdirp "0.5.1" + ms "2.1.1" + node-environment-flags "1.0.4" + object.assign "4.1.0" + strip-json-comments "2.0.1" + supports-color "6.0.0" + which "1.3.1" + wide-align "1.1.3" + yargs "12.0.5" + yargs-parser "11.1.1" + yargs-unparser "1.5.0" + +morgan@^1.9.0: + version "1.9.1" + resolved "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz#0a8d16734a1d9afbc824b99df87e738e58e2da59" + integrity sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA== + dependencies: + basic-auth "~2.0.0" + debug "2.6.9" + depd "~1.1.2" + on-finished "~2.3.0" + on-headers "~1.0.1" + +mout@^1.0.0: + version "1.1.0" + resolved "https://registry.npmjs.org/mout/-/mout-1.1.0.tgz#0b29d41e6a80fa9e2d4a5be9d602e1d9d02177f6" + integrity sha512-XsP0vf4As6BfqglxZqbqQ8SR6KQot2AgxvR0gG+WtUkf90vUXchMOZQtPf/Hml1rEffJupqL/tIrU6EYhsUQjw== + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= + +ms@2.1.1, ms@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" + integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== + +mustache@^3.0.0: + version "3.0.1" + resolved "https://registry.npmjs.org/mustache/-/mustache-3.0.1.tgz#873855f23aa8a95b150fb96d9836edbc5a1d248a" + integrity sha512-jFI/4UVRsRYdUbuDTKT7KzfOp7FiD5WzYmmwNwXyUVypC0xjoTL78Fqc0jHUPIvvGD+6DQSPHIt1NE7D1ArsqA== + +mute-stream@0.0.7: + version "0.0.7" + resolved "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" + integrity sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s= + +nanomatch@^1.2.9: + version "1.2.13" + resolved "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" + integrity sha512-fpoe2T0RbHwBTBUOftAfBPaDEi06ufaUai0mE6Yn1kacc3SnTErfb/h+X94VXzI64rKFHYImXSvdwGGCmwOqCA== + dependencies: + arr-diff "^4.0.0" + array-unique "^0.3.2" + define-property "^2.0.2" + extend-shallow "^3.0.2" + fragment-cache "^0.2.1" + is-windows "^1.0.2" + kind-of "^6.0.2" + object.pick "^1.3.0" + regex-not "^1.0.0" + snapdragon "^0.8.1" + to-regex "^3.0.1" + +natural-compare@^1.4.0: + version "1.4.0" + resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" + integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= + +negotiator@0.6.1: + version "0.6.1" + resolved "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9" + integrity sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk= + +nice-try@^1.0.4: + version "1.0.5" + resolved "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" + integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== + +node-environment-flags@1.0.4: + version "1.0.4" + resolved "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.4.tgz#0b784a6551426bfc16d3b2208424dcbc2b2ff038" + integrity sha512-M9rwCnWVLW7PX+NUWe3ejEdiLYinRpsEre9hMkU/6NS4h+EEulYaDH1gCEZ2gyXsmw+RXYDaV2JkkTNcsPDJ0Q== + dependencies: + object.getownpropertydescriptors "^2.0.3" + +node-fetch@^2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5" + integrity sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA== + +node-int64@^0.4.0: + version "0.4.0" + resolved "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" + integrity sha1-h6kGXNs1XTGC2PlM4RGIuCXGijs= + +node-modules-path@^1.0.0, node-modules-path@^1.0.1: + version "1.0.2" + resolved "https://registry.npmjs.org/node-modules-path/-/node-modules-path-1.0.2.tgz#e3acede9b7baf4bc336e3496b58e5b40d517056e" + integrity sha512-6Gbjq+d7uhkO7epaKi5DNgUJn7H0gEyA4Jg0Mo1uQOi3Rk50G83LtmhhFyw0LxnAFhtlspkiiw52ISP13qzcBg== + +node-notifier@^5.0.1: + version "5.4.0" + resolved "https://registry.npmjs.org/node-notifier/-/node-notifier-5.4.0.tgz#7b455fdce9f7de0c63538297354f3db468426e6a" + integrity sha512-SUDEb+o71XR5lXSTyivXd9J7fCloE3SyP4lSgt3lU2oSANiox+SxlNRGPjDKrwU1YN3ix2KN/VGGCg0t01rttQ== + dependencies: + growly "^1.3.0" + is-wsl "^1.1.0" + semver "^5.5.0" + shellwords "^0.1.1" + which "^1.3.0" + +node-releases@^1.1.8: + version "1.1.10" + resolved "https://registry.npmjs.org/node-releases/-/node-releases-1.1.10.tgz#5dbeb6bc7f4e9c85b899e2e7adcc0635c9b2adf7" + integrity sha512-KbUPCpfoBvb3oBkej9+nrU0/7xPlVhmhhUJ1PZqwIP5/1dJkRWKWD3OONjo6M2J7tSCBtDCumLwwqeI+DWWaLQ== + dependencies: + semver "^5.3.0" + +node-uuid@~1.4.0: + version "1.4.8" + resolved "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.8.tgz#b040eb0923968afabf8d32fb1f17f1167fdab907" + integrity sha1-sEDrCSOWivq/jTL7HxfxFn/auQc= + +node-watch@0.6.0: + version "0.6.0" + resolved "https://registry.npmjs.org/node-watch/-/node-watch-0.6.0.tgz#ab0703b60cd270783698e57a428faa0010ed8fd0" + integrity sha512-XAgTL05z75ptd7JSVejH1a2Dm1zmXYhuDr9l230Qk6Z7/7GPcnAs/UyJJ4ggsXSvWil8iOzwQLW0zuGUvHpG8g== + +nopt@^3.0.6: + version "3.0.6" + resolved "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9" + integrity sha1-xkZdvwirzU2zWTF/eaxopkayj/k= + dependencies: + abbrev "1" + +normalize-path@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9" + integrity sha1-GrKLVW4Zg2Oowab35vogE3/mrtk= + dependencies: + remove-trailing-separator "^1.0.1" + +normalize-url@2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/normalize-url/-/normalize-url-2.0.1.tgz#835a9da1551fa26f70e92329069a23aa6574d7e6" + integrity sha512-D6MUW4K/VzoJ4rJ01JFKxDrtY1v9wrgzCX5f2qj/lzH1m/lW6MhUZFKerVsnyjOhOsYzI9Kqqak+10l4LvLpMw== + dependencies: + prepend-http "^2.0.0" + query-string "^5.0.1" + sort-keys "^2.0.0" + +npm-git-info@^1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/npm-git-info/-/npm-git-info-1.0.3.tgz#a933c42ec321e80d3646e0d6e844afe94630e1d5" + integrity sha1-qTPELsMh6A02RuDW6ESv6UYw4dU= + +npm-package-arg@^6.1.0: + version "6.1.0" + resolved "https://registry.npmjs.org/npm-package-arg/-/npm-package-arg-6.1.0.tgz#15ae1e2758a5027efb4c250554b85a737db7fcc1" + integrity sha512-zYbhP2k9DbJhA0Z3HKUePUgdB1x7MfIfKssC+WLPFMKTBZKpZh5m13PgexJjCq6KW7j17r0jHWcCpxEqnnncSA== + dependencies: + hosted-git-info "^2.6.0" + osenv "^0.1.5" + semver "^5.5.0" + validate-npm-package-name "^3.0.0" + +npm-run-path@^2.0.0: + version "2.0.2" + resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f" + integrity sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8= + dependencies: + path-key "^2.0.0" + +npmlog@^4.0.0: + version "4.1.2" + resolved "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" + integrity sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg== + dependencies: + are-we-there-yet "~1.1.2" + console-control-strings "~1.1.0" + gauge "~2.7.3" + set-blocking "~2.0.0" + +number-is-nan@^1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" + integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0= + +oauth-sign@~0.3.0: + version "0.3.0" + resolved "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.3.0.tgz#cb540f93bb2b22a7d5941691a288d60e8ea9386e" + integrity sha1-y1QPk7srIqfVlBaRoojWDo6pOG4= + +object-assign@4.1.1, object-assign@^4.1.0: + version "4.1.1" + resolved "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" + integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= + +object-component@0.0.3: + version "0.0.3" + resolved "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz#f0c69aa50efc95b866c186f400a33769cb2f1291" + integrity sha1-8MaapQ78lbhmwYb0AKM3acsvEpE= + +object-copy@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz#7e7d858b781bd7c991a41ba975ed3812754e998c" + integrity sha1-fn2Fi3gb18mRpBupde04EnVOmYw= + dependencies: + copy-descriptor "^0.1.0" + define-property "^0.2.5" + kind-of "^3.0.3" + +object-hash@^1.3.1: + version "1.3.1" + resolved "https://registry.npmjs.org/object-hash/-/object-hash-1.3.1.tgz#fde452098a951cb145f039bb7d455449ddc126df" + integrity sha512-OSuu/pU4ENM9kmREg0BdNrUDIl1heYa4mBZacJc+vVWz4GtAwu7jO8s4AIt2aGRUTqxykpWzI3Oqnsm13tTMDA== + +object-keys@^1.0.11, object-keys@^1.0.12: + version "1.1.0" + resolved "https://registry.npmjs.org/object-keys/-/object-keys-1.1.0.tgz#11bd22348dd2e096a045ab06f6c85bcc340fa032" + integrity sha512-6OO5X1+2tYkNyNEx6TsCxEqFfRWaqx6EtMiSbGrw8Ob8v9Ne+Hl8rBAgLBZn5wjEz3s/s6U1WXFUFOcxxAwUpg== + +object-visit@^1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/object-visit/-/object-visit-1.0.1.tgz#f79c4493af0c5377b59fe39d395e41042dd045bb" + integrity sha1-95xEk68MU3e1n+OdOV5BBC3QRbs= + dependencies: + isobject "^3.0.0" + +object.assign@4.1.0: + version "4.1.0" + resolved "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz#968bf1100d7956bb3ca086f006f846b3bc4008da" + integrity sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w== + dependencies: + define-properties "^1.1.2" + function-bind "^1.1.1" + has-symbols "^1.0.0" + object-keys "^1.0.11" + +object.getownpropertydescriptors@^2.0.3: + version "2.0.3" + resolved "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz#8758c846f5b407adab0f236e0986f14b051caa16" + integrity sha1-h1jIRvW0B62rDyNuCYbxSwUcqhY= + dependencies: + define-properties "^1.1.2" + es-abstract "^1.5.1" + +object.pick@^1.3.0: + version "1.3.0" + resolved "https://registry.npmjs.org/object.pick/-/object.pick-1.3.0.tgz#87a10ac4c1694bd2e1cbf53591a66141fb5dd747" + integrity sha1-h6EKxMFpS9Lhy/U1kaZhQftd10c= + dependencies: + isobject "^3.0.1" + +on-finished@~2.3.0: + version "2.3.0" + resolved "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947" + integrity sha1-IPEzZIGwg811M3mSoWlxqi2QaUc= + dependencies: + ee-first "1.1.1" + +on-headers@~1.0.1: + version "1.0.2" + resolved "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz#772b0ae6aaa525c399e489adfad90c403eb3c28f" + integrity sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA== + +once@^1.3.0, once@^1.3.1, once@^1.4.0: + version "1.4.0" + resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= + dependencies: + wrappy "1" + +onetime@^2.0.0: + version "2.0.1" + resolved "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4" + integrity sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ= + dependencies: + mimic-fn "^1.0.0" + +optimist@^0.6.1: + version "0.6.1" + resolved "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" + integrity sha1-2j6nRob6IaGaERwybpDrFaAZZoY= + dependencies: + minimist "~0.0.1" + wordwrap "~0.0.2" + +optionator@^0.8.2: + version "0.8.2" + resolved "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64" + integrity sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q= + dependencies: + deep-is "~0.1.3" + fast-levenshtein "~2.0.4" + levn "~0.3.0" + prelude-ls "~1.1.2" + type-check "~0.3.2" + wordwrap "~1.0.0" + +ora@^3.0.0: + version "3.2.0" + resolved "https://registry.npmjs.org/ora/-/ora-3.2.0.tgz#67e98a7e11f7f0ac95deaaaf11bb04de3d09e481" + integrity sha512-XHMZA5WieCbtg+tu0uPF8CjvwQdNzKCX6BVh3N6GFsEXH40mTk5dsw/ya1lBTUGJslcEFJFQ8cBhOgkkZXQtMA== + dependencies: + chalk "^2.4.2" + cli-cursor "^2.1.0" + cli-spinners "^2.0.0" + log-symbols "^2.2.0" + strip-ansi "^5.0.0" + wcwidth "^1.0.1" + +os-homedir@^1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" + integrity sha1-/7xJiDNuDoM94MFox+8VISGqf7M= + +os-locale@^3.0.0: + version "3.1.0" + resolved "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz#a802a6ee17f24c10483ab9935719cef4ed16bf1a" + integrity sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q== + dependencies: + execa "^1.0.0" + lcid "^2.0.0" + mem "^4.0.0" + +os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.1, os-tmpdir@~1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" + integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= + +osenv@^0.1.0, osenv@^0.1.3, osenv@^0.1.5: + version "0.1.5" + resolved "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz#85cdfafaeb28e8677f416e287592b5f3f49ea410" + integrity sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g== + dependencies: + os-homedir "^1.0.0" + os-tmpdir "^1.0.0" + +p-cancelable@^0.4.0: + version "0.4.1" + resolved "https://registry.npmjs.org/p-cancelable/-/p-cancelable-0.4.1.tgz#35f363d67d52081c8d9585e37bcceb7e0bbcb2a0" + integrity sha512-HNa1A8LvB1kie7cERyy21VNeHb2CWJJYqyyC2o3klWFfMGlFmWv2Z7sFgZH8ZiaYL95ydToKTFVXgMV/Os0bBQ== + +p-defer@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c" + integrity sha1-n26xgvbJqozXQwBKfU+WsZaw+ww= + +p-finally@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" + integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4= + +p-is-promise@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz#9c9456989e9f6588017b0434d56097675c3da05e" + integrity sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4= + +p-is-promise@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.0.0.tgz#7554e3d572109a87e1f3f53f6a7d85d1b194f4c5" + integrity sha512-pzQPhYMCAgLAKPWD2jC3Se9fEfrD9npNos0y150EeqZll7akhEgGhTW/slB6lHku8AvYGiJ+YJ5hfHKePPgFWg== + +p-limit@^1.1.0: + version "1.3.0" + resolved "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8" + integrity sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q== + dependencies: + p-try "^1.0.0" + +p-limit@^2.0.0: + version "2.2.0" + resolved "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz#417c9941e6027a9abcba5092dd2904e255b5fbc2" + integrity sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ== + dependencies: + p-try "^2.0.0" + +p-locate@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" + integrity sha1-IKAQOyIqcMj9OcwuWAaA893l7EM= + dependencies: + p-limit "^1.1.0" + +p-locate@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4" + integrity sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ== + dependencies: + p-limit "^2.0.0" + +p-timeout@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/p-timeout/-/p-timeout-2.0.1.tgz#d8dd1979595d2dc0139e1fe46b8b646cb3cdf038" + integrity sha512-88em58dDVB/KzPEx1X0N3LwFfYZPyDc4B6eF38M1rk9VTZMbxXXgjugz8mmwpS9Ox4BDZ+t6t3QP5+/gazweIA== + dependencies: + p-finally "^1.0.0" + +p-try@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" + integrity sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M= + +p-try@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz#85080bb87c64688fa47996fe8f7dfbe8211760b1" + integrity sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ== + +package-json@^4.0.1: + version "4.0.1" + resolved "https://registry.npmjs.org/package-json/-/package-json-4.0.1.tgz#8869a0401253661c4c4ca3da6c2121ed555f5eed" + integrity sha1-iGmgQBJTZhxMTKPabCEh7VVfXu0= + dependencies: + got "^6.7.1" + registry-auth-token "^3.0.1" + registry-url "^3.0.3" + semver "^5.1.0" + +parent-module@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/parent-module/-/parent-module-1.0.0.tgz#df250bdc5391f4a085fb589dad761f5ad6b865b5" + integrity sha512-8Mf5juOMmiE4FcmzYc4IaiS9L3+9paz2KOiXzkRviCP6aDmN49Hz6EMWz0lGNp9pX80GvvAuLADtyGfW/Em3TA== + dependencies: + callsites "^3.0.0" + +parse-ms@^1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/parse-ms/-/parse-ms-1.0.1.tgz#56346d4749d78f23430ca0c713850aef91aa361d" + integrity sha1-VjRtR0nXjyNDDKDHE4UK75GqNh0= + +parse-passwd@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6" + integrity sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY= + +parseqs@0.0.5: + version "0.0.5" + resolved "https://registry.npmjs.org/parseqs/-/parseqs-0.0.5.tgz#d5208a3738e46766e291ba2ea173684921a8b89d" + integrity sha1-1SCKNzjkZ2bikbouoXNoSSGouJ0= + dependencies: + better-assert "~1.0.0" + +parseuri@0.0.5: + version "0.0.5" + resolved "https://registry.npmjs.org/parseuri/-/parseuri-0.0.5.tgz#80204a50d4dbb779bfdc6ebe2778d90e4bce320a" + integrity sha1-gCBKUNTbt3m/3G6+J3jZDkvOMgo= + dependencies: + better-assert "~1.0.0" + +parseurl@~1.3.2: + version "1.3.2" + resolved "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3" + integrity sha1-/CidTtiZMRlGDBViUyYs3I3mW/M= + +pascalcase@^0.1.1: + version "0.1.1" + resolved "https://registry.npmjs.org/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" + integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ= + +path-exists@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" + integrity sha1-zg6+ql94yxiSXqfYENe1mwEP1RU= + +path-is-absolute@1.0.1, path-is-absolute@^1.0.0, path-is-absolute@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= + +path-is-inside@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53" + integrity sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM= + +path-key@^2.0.0, path-key@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" + integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A= + +path-parse@^1.0.6: + version "1.0.6" + resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" + integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + +path-posix@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/path-posix/-/path-posix-1.0.0.tgz#06b26113f56beab042545a23bfa88003ccac260f" + integrity sha1-BrJhE/Vr6rBCVFojv6iAA8ysJg8= + +path-root-regex@^0.1.0: + version "0.1.2" + resolved "https://registry.npmjs.org/path-root-regex/-/path-root-regex-0.1.2.tgz#bfccdc8df5b12dc52c8b43ec38d18d72c04ba96d" + integrity sha1-v8zcjfWxLcUsi0PsONGNcsBLqW0= + +path-root@^0.1.1: + version "0.1.1" + resolved "https://registry.npmjs.org/path-root/-/path-root-0.1.1.tgz#9a4a6814cac1c0cd73360a95f32083c8ea4745b7" + integrity sha1-mkpoFMrBwM1zNgqV8yCDyOpHRbc= + dependencies: + path-root-regex "^0.1.0" + +path-to-regexp@0.1.7: + version "0.1.7" + resolved "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" + integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w= + +pathval@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0" + integrity sha1-uULm1L3mUwBe9rcTYd74cn0GReA= + +pify@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" + integrity sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY= + +pinkie-promise@^2.0.0: + version "2.0.1" + resolved "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa" + integrity sha1-ITXW36ejWMBprJsXh3YogihFD/o= + dependencies: + pinkie "^2.0.0" + +pinkie@^2.0.0: + version "2.0.4" + resolved "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" + integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA= + +pkg-up@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/pkg-up/-/pkg-up-2.0.0.tgz#c819ac728059a461cab1c3889a2be3c49a004d7f" + integrity sha1-yBmscoBZpGHKscOImivjxJoATX8= + dependencies: + find-up "^2.1.0" + +portfinder@^1.0.15: + version "1.0.20" + resolved "https://registry.npmjs.org/portfinder/-/portfinder-1.0.20.tgz#bea68632e54b2e13ab7b0c4775e9b41bf270e44a" + integrity sha512-Yxe4mTyDzTd59PZJY4ojZR8F+E5e97iq2ZOHPz3HDgSvYC5siNad2tLooQ5y5QHyQhc3xVqvyk/eNA3wuoa7Sw== + dependencies: + async "^1.5.2" + debug "^2.2.0" + mkdirp "0.5.x" + +posix-character-classes@^0.1.0: + version "0.1.1" + resolved "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" + integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs= + +prelude-ls@~1.1.2: + version "1.1.2" + resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" + integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= + +prepend-http@^1.0.1: + version "1.0.4" + resolved "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc" + integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw= + +prepend-http@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" + integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc= + +pretender@^2.1.0: + version "2.1.1" + resolved "https://registry.npmjs.org/pretender/-/pretender-2.1.1.tgz#5085f0a1272c31d5b57c488386f69e6ca207cb35" + integrity sha512-IkidsJzaroAanw3I43tKCFm2xCpurkQr9aPXv5/jpN+LfCwDaeI8rngVWtQZTx4qqbhc5zJspnLHJ4N/25KvDQ== + dependencies: + "@xg-wang/whatwg-fetch" "^3.0.0" + fake-xml-http-request "^2.0.0" + route-recognizer "^0.3.3" + +prettier-linter-helpers@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" + integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w== + dependencies: + fast-diff "^1.1.2" + +prettier@^1.15.3: + version "1.16.4" + resolved "https://registry.npmjs.org/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717" + integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g== + +pretty-ms@^3.1.0: + version "3.2.0" + resolved "https://registry.npmjs.org/pretty-ms/-/pretty-ms-3.2.0.tgz#87a8feaf27fc18414d75441467d411d6e6098a25" + integrity sha512-ZypexbfVUGTFxb0v+m1bUyy92DHe5SyYlnyY0msyms5zd3RwyvNgyxZZsXXgoyzlxjx5MiqtXUdhUfvQbe0A2Q== + dependencies: + parse-ms "^1.0.0" + +printf@^0.5.1: + version "0.5.1" + resolved "https://registry.npmjs.org/printf/-/printf-0.5.1.tgz#e0466788260859ed153006dc6867f09ddf240cf3" + integrity sha512-UaE/jO0hNsrvPGQEb4LyNzcrJv9Z00tsreBduOSxMtrebvoUhxiEJ4YCHX8YHf6akwfKsC2Gyv5zv47UXhMiLg== + +private@^0.1.6, private@^0.1.8, private@~0.1.5: + version "0.1.8" + resolved "https://registry.npmjs.org/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" + integrity sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg== + +process-nextick-args@~2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz#a37d732f4271b4ab1ad070d35508e8290788ffaa" + integrity sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw== + +process-relative-require@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/process-relative-require/-/process-relative-require-1.0.0.tgz#1590dfcf5b8f2983ba53e398446b68240b4cc68a" + integrity sha1-FZDfz1uPKYO6U+OYRGtoJAtMxoo= + dependencies: + node-modules-path "^1.0.0" + +progress@^2.0.0: + version "2.0.3" + resolved "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" + integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== + +promise-map-series@^0.2.1, promise-map-series@^0.2.3: + version "0.2.3" + resolved "https://registry.npmjs.org/promise-map-series/-/promise-map-series-0.2.3.tgz#c2d377afc93253f6bd03dbb77755eb88ab20a847" + integrity sha1-wtN3r8kyU/a9A9u3d1XriKsgqEc= + dependencies: + rsvp "^3.0.14" + +promise.prototype.finally@^3.1.0: + version "3.1.0" + resolved "https://registry.npmjs.org/promise.prototype.finally/-/promise.prototype.finally-3.1.0.tgz#66f161b1643636e50e7cf201dc1b84a857f3864e" + integrity sha512-7p/K2f6dI+dM8yjRQEGrTQs5hTQixUAdOGpMEA3+pVxpX5oHKRSKAXyLw9Q9HUWDTdwtoo39dSHGQtN90HcEwQ== + dependencies: + define-properties "^1.1.2" + es-abstract "^1.9.0" + function-bind "^1.1.1" + +proxy-addr@~2.0.4: + version "2.0.4" + resolved "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz#ecfc733bf22ff8c6f407fa275327b9ab67e48b93" + integrity sha512-5erio2h9jp5CHGwcybmxmVqHmnCBZeewlfJ0pex+UW7Qny7OOZXTtH56TGNyBizkgiOwhJtMKrVzDTeKcySZwA== + dependencies: + forwarded "~0.1.2" + ipaddr.js "1.8.0" + +psl@^1.1.28: + version "1.1.31" + resolved "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz#e9aa86d0101b5b105cbe93ac6b784cd547276184" + integrity sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw== + +pump@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64" + integrity sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww== + dependencies: + end-of-stream "^1.1.0" + once "^1.3.1" + +punycode@^2.1.0, punycode@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" + integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== + +qs@6.5.2: + version "6.5.2" + resolved "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" + integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== + +qs@^6.4.0: + version "6.6.0" + resolved "https://registry.npmjs.org/qs/-/qs-6.6.0.tgz#a99c0f69a8d26bf7ef012f871cdabb0aee4424c2" + integrity sha512-KIJqT9jQJDQx5h5uAVPimw6yVg2SekOKu959OCtktD3FjzbpvaPr8i4zzg07DOMz+igA4W/aNM7OV8H37pFYfA== + +qs@~1.0.0: + version "1.0.2" + resolved "https://registry.npmjs.org/qs/-/qs-1.0.2.tgz#50a93e2b5af6691c31bcea5dae78ee6ea1903768" + integrity sha1-UKk+K1r2aRwxvOpdrnjubqGQN2g= + +query-string@^5.0.1: + version "5.1.1" + resolved "https://registry.npmjs.org/query-string/-/query-string-5.1.1.tgz#a78c012b71c17e05f2e3fa2319dd330682efb3cb" + integrity sha512-gjWOsm2SoGlgLEdAGt7a6slVOk9mGiXmPFMqrEhLQ68rhQuBnpfs3+EmlvqKyxnCo9/PPlF+9MtY02S1aFg+Jw== + dependencies: + decode-uri-component "^0.2.0" + object-assign "^4.1.0" + strict-uri-encode "^1.0.0" + +quibble@^0.5.5: + version "0.5.5" + resolved "https://registry.npmjs.org/quibble/-/quibble-0.5.5.tgz#669fb731520a923e0a98f8076b7eb55e409f73f9" + integrity sha512-cIePu3BtGlaTW1bjFgBcLT6QMxD8PtnZDCmPJUzO+RepIz8GuXsmZIEPGFjlPxzG9zfIj4nNLPxBDlUbvr9ESg== + dependencies: + lodash "^4.17.2" + resolve "^1.7.1" + +quick-temp@^0.1.2, quick-temp@^0.1.3, quick-temp@^0.1.5, quick-temp@^0.1.8: + version "0.1.8" + resolved "https://registry.npmjs.org/quick-temp/-/quick-temp-0.1.8.tgz#bab02a242ab8fb0dd758a3c9776b32f9a5d94408" + integrity sha1-urAqJCq4+w3XWKPJd2sy+aXZRAg= + dependencies: + mktemp "~0.4.0" + rimraf "^2.5.4" + underscore.string "~3.3.4" + +qunit@^2.9.2: + version "2.9.2" + resolved "https://registry.npmjs.org/qunit/-/qunit-2.9.2.tgz#97919440c9c0ae838bcd3c33a2ee42f35c5ef4a0" + integrity sha512-wTOYHnioWHcx5wa85Wl15IE7D6zTZe2CQlsodS14yj7s2FZ3MviRnQluspBZsueIDEO7doiuzKlv05yfky1R7w== + dependencies: + commander "2.12.2" + js-reporters "1.2.1" + minimatch "3.0.4" + node-watch "0.6.0" + resolve "1.9.0" + +range-parser@~1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" + integrity sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4= + +raw-body@2.3.3: + version "2.3.3" + resolved "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz#1b324ece6b5706e153855bc1148c65bb7f6ea0c3" + integrity sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw== + dependencies: + bytes "3.0.0" + http-errors "1.6.3" + iconv-lite "0.4.23" + unpipe "1.0.0" + +raw-body@~1.1.0: + version "1.1.7" + resolved "https://registry.npmjs.org/raw-body/-/raw-body-1.1.7.tgz#1d027c2bfa116acc6623bca8f00016572a87d425" + integrity sha1-HQJ8K/oRasxmI7yo8AAWVyqH1CU= + dependencies: + bytes "1" + string_decoder "0.10" + +rc@^1.0.1, rc@^1.1.6: + version "1.2.8" + resolved "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" + integrity sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw== + dependencies: + deep-extend "^0.6.0" + ini "~1.3.0" + minimist "^1.2.0" + strip-json-comments "~2.0.1" + +readable-stream@^2.0.0, readable-stream@^2.0.6: + version "2.3.6" + resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" + integrity sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw== + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.3" + isarray "~1.0.0" + process-nextick-args "~2.0.0" + safe-buffer "~5.1.1" + string_decoder "~1.1.1" + util-deprecate "~1.0.1" + +readable-stream@~1.0.2: + version "1.0.34" + resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c" + integrity sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw= + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + +recast@^0.11.3: + version "0.11.23" + resolved "https://registry.npmjs.org/recast/-/recast-0.11.23.tgz#451fd3004ab1e4df9b4e4b66376b2a21912462d3" + integrity sha1-RR/TAEqx5N+bTktmN2sqIZEkYtM= + dependencies: + ast-types "0.9.6" + esprima "~3.1.0" + private "~0.1.5" + source-map "~0.5.0" + +redeyed@~1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/redeyed/-/redeyed-1.0.1.tgz#e96c193b40c0816b00aec842698e61185e55498a" + integrity sha1-6WwZO0DAgWsArshCaY5hGF5VSYo= + dependencies: + esprima "~3.0.0" + +regenerate-unicode-properties@^8.0.1: + version "8.0.1" + resolved "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-8.0.1.tgz#58a4a74e736380a7ab3c5f7e03f303a941b31289" + integrity sha512-HTjMafphaH5d5QDHuwW8Me6Hbc/GhXg8luNqTkPVwZ/oCZhnoifjWhGYsu2BzepMELTlbnoVcXvV0f+2uDDvoQ== + dependencies: + regenerate "^1.4.0" + +regenerate@^1.2.1, regenerate@^1.4.0: + version "1.4.0" + resolved "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" + integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg== + +regenerator-runtime@^0.10.5: + version "0.10.5" + resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658" + integrity sha1-M2w+/BIgrc7dosn6tntaeVWjNlg= + +regenerator-runtime@^0.11.0: + version "0.11.1" + resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" + integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg== + +regenerator-runtime@^0.12.0: + version "0.12.1" + resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de" + integrity sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg== + +regenerator-runtime@^0.9.5: + version "0.9.6" + resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.9.6.tgz#d33eb95d0d2001a4be39659707c51b0cb71ce029" + integrity sha1-0z65XQ0gAaS+OWWXB8UbDLcc4Ck= + +regenerator-transform@^0.10.0: + version "0.10.1" + resolved "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.10.1.tgz#1e4996837231da8b7f3cf4114d71b5691a0680dd" + integrity sha512-PJepbvDbuK1xgIgnau7Y90cwaAmO/LCLMI2mPvaXq2heGMR3aWW5/BQvYrhJ8jgmQjXewXvBjzfqKcVOmhjZ6Q== + dependencies: + babel-runtime "^6.18.0" + babel-types "^6.19.0" + private "^0.1.6" + +regenerator-transform@^0.13.4: + version "0.13.4" + resolved "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.13.4.tgz#18f6763cf1382c69c36df76c6ce122cc694284fb" + integrity sha512-T0QMBjK3J0MtxjPmdIMXm72Wvj2Abb0Bd4HADdfijwMdoIsyQZ6fWC7kDFhk2YinBBEMZDL7Y7wh0J1sGx3S4A== + dependencies: + private "^0.1.6" + +regex-not@^1.0.0, regex-not@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c" + integrity sha512-J6SDjUgDxQj5NusnOtdFxDwN/+HWykR8GELwctJ7mdqhcyy1xEc4SRFHUXvxTp661YaVKAjfRLZ9cCqS6tn32A== + dependencies: + extend-shallow "^3.0.2" + safe-regex "^1.1.0" + +regexp-tree@^0.1.0: + version "0.1.5" + resolved "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.5.tgz#7cd71fca17198d04b4176efd79713f2998009397" + integrity sha512-nUmxvfJyAODw+0B13hj8CFVAxhe7fDEAgJgaotBu3nnR+IgGgZq59YedJP5VYTlkEfqjuK6TuRpnymKdatLZfQ== + +regexpp@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" + integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw== + +regexpu-core@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/regexpu-core/-/regexpu-core-2.0.0.tgz#49d038837b8dcf8bfa5b9a42139938e6ea2ae240" + integrity sha1-SdA4g3uNz4v6W5pCE5k45uoq4kA= + dependencies: + regenerate "^1.2.1" + regjsgen "^0.2.0" + regjsparser "^0.1.4" + +regexpu-core@^4.1.3, regexpu-core@^4.2.0: + version "4.5.3" + resolved "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.5.3.tgz#72f572e03bb8b9f4f4d895a0ccc57e707f4af2e4" + integrity sha512-LON8666bTAlViVEPXMv65ZqiaR3rMNLz36PIaQ7D+er5snu93k0peR7FSvO0QteYbZ3GOkvfHKbGr/B1xDu9FA== + dependencies: + regenerate "^1.4.0" + regenerate-unicode-properties "^8.0.1" + regjsgen "^0.5.0" + regjsparser "^0.6.0" + unicode-match-property-ecmascript "^1.0.4" + unicode-match-property-value-ecmascript "^1.1.0" + +registry-auth-token@^3.0.1: + version "3.3.2" + resolved "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-3.3.2.tgz#851fd49038eecb586911115af845260eec983f20" + integrity sha512-JL39c60XlzCVgNrO+qq68FoNb56w/m7JYvGR2jT5iR1xBrUA3Mfx5Twk5rqTThPmQKMWydGmq8oFtDlxfrmxnQ== + dependencies: + rc "^1.1.6" + safe-buffer "^5.0.1" + +registry-url@^3.0.3: + version "3.1.0" + resolved "https://registry.npmjs.org/registry-url/-/registry-url-3.1.0.tgz#3d4ef870f73dde1d77f0cf9a381432444e174942" + integrity sha1-PU74cPc93h138M+aOBQyRE4XSUI= + dependencies: + rc "^1.0.1" + +regjsgen@^0.2.0: + version "0.2.0" + resolved "https://registry.npmjs.org/regjsgen/-/regjsgen-0.2.0.tgz#6c016adeac554f75823fe37ac05b92d5a4edb1f7" + integrity sha1-bAFq3qxVT3WCP+N6wFuS1aTtsfc= + +regjsgen@^0.5.0: + version "0.5.0" + resolved "https://registry.npmjs.org/regjsgen/-/regjsgen-0.5.0.tgz#a7634dc08f89209c2049adda3525711fb97265dd" + integrity sha512-RnIrLhrXCX5ow/E5/Mh2O4e/oa1/jW0eaBKTSy3LaCj+M3Bqvm97GWDp2yUtzIs4LEn65zR2yiYGFqb2ApnzDA== + +regjsparser@^0.1.4: + version "0.1.5" + resolved "https://registry.npmjs.org/regjsparser/-/regjsparser-0.1.5.tgz#7ee8f84dc6fa792d3fd0ae228d24bd949ead205c" + integrity sha1-fuj4Tcb6eS0/0K4ijSS9lJ6tIFw= + dependencies: + jsesc "~0.5.0" + +regjsparser@^0.6.0: + version "0.6.0" + resolved "https://registry.npmjs.org/regjsparser/-/regjsparser-0.6.0.tgz#f1e6ae8b7da2bae96c99399b868cd6c933a2ba9c" + integrity sha512-RQ7YyokLiQBomUJuUG8iGVvkgOLxwyZM8k6d3q5SAXpg4r5TZJZigKFvC6PpD+qQ98bCDC5YelPeA3EucDoNeQ== + dependencies: + jsesc "~0.5.0" + +remote-git-tags@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/remote-git-tags/-/remote-git-tags-2.0.0.tgz#1152f39cf8b5268ae0e4307636ef741ec341664c" + integrity sha1-EVLznPi1Jorg5DB2Nu90HsNBZkw= + dependencies: + git-fetch-pack "^0.1.1" + git-transport-protocol "^0.1.0" + +remove-trailing-separator@^1.0.1: + version "1.1.0" + resolved "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef" + integrity sha1-wkvOKig62tW8P1jg1IJJuSN52O8= + +repeat-element@^1.1.2: + version "1.1.3" + resolved "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.3.tgz#782e0d825c0c5a3bb39731f84efee6b742e6b1ce" + integrity sha512-ahGq0ZnV5m5XtZLMb+vP76kcAM5nkLqk0lpqAuojSKGgQtn4eRi4ZZGm2olo2zKFH+sMsWaqOCW1dqAnOru72g== + +repeat-string@^1.6.1: + version "1.6.1" + resolved "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637" + integrity sha1-jcrkcOHIirwtYA//Sndihtp15jc= + +repeating@^2.0.0: + version "2.0.1" + resolved "https://registry.npmjs.org/repeating/-/repeating-2.0.1.tgz#5214c53a926d3552707527fbab415dbc08d06dda" + integrity sha1-UhTFOpJtNVJwdSf7q0FdvAjQbdo= + dependencies: + is-finite "^1.0.0" + +request@~2.40.0: + version "2.40.0" + resolved "https://registry.npmjs.org/request/-/request-2.40.0.tgz#4dd670f696f1e6e842e66b4b5e839301ab9beb67" + integrity sha1-TdZw9pbx5uhC5mtLXoOTAaub62c= + dependencies: + forever-agent "~0.5.0" + json-stringify-safe "~5.0.0" + mime-types "~1.0.1" + node-uuid "~1.4.0" + qs "~1.0.0" + optionalDependencies: + aws-sign2 "~0.5.0" + form-data "~0.1.0" + hawk "1.1.1" + http-signature "~0.10.0" + oauth-sign "~0.3.0" + stringstream "~0.0.4" + tough-cookie ">=0.12.0" + tunnel-agent "~0.4.0" + +require-directory@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" + integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I= + +require-main-filename@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" + integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE= + +require-relative@^0.8.7: + version "0.8.7" + resolved "https://registry.npmjs.org/require-relative/-/require-relative-0.8.7.tgz#7999539fc9e047a37928fa196f8e1563dabd36de" + integrity sha1-eZlTn8ngR6N5KPoZb44VY9q9Nt4= + +requires-port@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" + integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= + +reselect@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/reselect/-/reselect-3.0.1.tgz#efdaa98ea7451324d092b2b2163a6a1d7a9a2147" + integrity sha1-79qpjqdFEyTQkrKyFjpqHXqaIUc= + +resolve-dir@^1.0.0, resolve-dir@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/resolve-dir/-/resolve-dir-1.0.1.tgz#79a40644c362be82f26effe739c9bb5382046f43" + integrity sha1-eaQGRMNivoLybv/nOcm7U4IEb0M= + dependencies: + expand-tilde "^2.0.0" + global-modules "^1.0.0" + +resolve-from@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" + integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== + +resolve-package-path@^1.0.11, resolve-package-path@^1.1.1: + version "1.2.4" + resolved "https://registry.npmjs.org/resolve-package-path/-/resolve-package-path-1.2.4.tgz#814c5fcfb5f6e4151d95ec6e5653707c43706670" + integrity sha512-AOIfR/AauBM1w1Oq9swqGxUjL4PW7bMztN7UCQ4KWg9AR2t03bGb9faegZbE0meAOHlntAni/4kXkcsQ7dWLPQ== + dependencies: + path-root "^0.1.1" + resolve "^1.10.0" + +resolve-path@^1.4.0: + version "1.4.0" + resolved "https://registry.npmjs.org/resolve-path/-/resolve-path-1.4.0.tgz#c4bda9f5efb2fce65247873ab36bb4d834fe16f7" + integrity sha1-xL2p9e+y/OZSR4c6s2u02DT+Fvc= + dependencies: + http-errors "~1.6.2" + path-is-absolute "1.0.1" + +resolve-url@^0.2.1: + version "0.2.1" + resolved "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" + integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo= + +resolve@1.9.0: + version "1.9.0" + resolved "https://registry.npmjs.org/resolve/-/resolve-1.9.0.tgz#a14c6fdfa8f92a7df1d996cb7105fa744658ea06" + integrity sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ== + dependencies: + path-parse "^1.0.6" + +resolve@^1.1.6, resolve@^1.10.0, resolve@^1.3.2, resolve@^1.3.3, resolve@^1.4.0, resolve@^1.5.0, resolve@^1.7.1, resolve@^1.8.1, resolve@^1.9.0: + version "1.10.0" + resolved "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz#3bdaaeaf45cc07f375656dfd2e54ed0810b101ba" + integrity sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg== + dependencies: + path-parse "^1.0.6" + +responselike@1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz#918720ef3b631c5642be068f15ade5a46f4ba1e7" + integrity sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec= + dependencies: + lowercase-keys "^1.0.0" + +restore-cursor@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf" + integrity sha1-n37ih/gv0ybU/RYpI9YhKe7g368= + dependencies: + onetime "^2.0.0" + signal-exit "^3.0.2" + +ret@~0.1.10: + version "0.1.15" + resolved "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" + integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg== + +rimraf@2.6.3, rimraf@^2.1.4, rimraf@^2.2.8, rimraf@^2.3.2, rimraf@^2.3.4, rimraf@^2.4.1, rimraf@^2.4.3, rimraf@^2.4.4, rimraf@^2.5.3, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@~2.6.2: + version "2.6.3" + resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" + integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== + dependencies: + glob "^7.1.3" + +rollup-pluginutils@^2.0.1: + version "2.4.1" + resolved "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.4.1.tgz#de43ab54965bbf47843599a7f3adceb723de38db" + integrity sha512-wesMQ9/172IJDIW/lYWm0vW0LiKe5Ekjws481R7z9WTRtmO59cqyM/2uUlxvf6yzm/fElFmHUobeQOYz46dZJw== + dependencies: + estree-walker "^0.6.0" + micromatch "^3.1.10" + +rollup@^0.57.1: + version "0.57.1" + resolved "https://registry.npmjs.org/rollup/-/rollup-0.57.1.tgz#0bb28be6151d253f67cf4a00fea48fb823c74027" + integrity sha512-I18GBqP0qJoJC1K1osYjreqA8VAKovxuI3I81RSk0Dmr4TgloI0tAULjZaox8OsJ+n7XRrhH6i0G2By/pj1LCA== + dependencies: + "@types/acorn" "^4.0.3" + acorn "^5.5.3" + acorn-dynamic-import "^3.0.0" + date-time "^2.1.0" + is-reference "^1.1.0" + locate-character "^2.0.5" + pretty-ms "^3.1.0" + require-relative "^0.8.7" + rollup-pluginutils "^2.0.1" + signal-exit "^3.0.2" + sourcemap-codec "^1.4.1" + +route-recognizer@^0.3.3: + version "0.3.4" + resolved "https://registry.npmjs.org/route-recognizer/-/route-recognizer-0.3.4.tgz#39ab1ffbce1c59e6d2bdca416f0932611e4f3ca3" + integrity sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g== + +rsvp@3.0.14: + version "3.0.14" + resolved "https://registry.npmjs.org/rsvp/-/rsvp-3.0.14.tgz#9d2968cf36d878d3bb9a9a5a4b8e1ff55a76dd31" + integrity sha1-nSlozzbYeNO7mppaS44f9Vp23TE= + +rsvp@^3.0.14, rsvp@^3.0.17, rsvp@^3.0.18, rsvp@^3.0.21, rsvp@^3.1.0, rsvp@^3.3.3: + version "3.6.2" + resolved "https://registry.npmjs.org/rsvp/-/rsvp-3.6.2.tgz#2e96491599a96cde1b515d5674a8f7a91452926a" + integrity sha512-OfWGQTb9vnwRjwtA2QwpG2ICclHC3pgXZO5xt8H2EfgDquO0qVdSb5T88L4qJVAEugbS56pAuV4XZM58UX8ulw== + +rsvp@^4.7.0, rsvp@^4.8.1, rsvp@^4.8.2, rsvp@^4.8.3, rsvp@^4.8.4: + version "4.8.4" + resolved "https://registry.npmjs.org/rsvp/-/rsvp-4.8.4.tgz#b50e6b34583f3dd89329a2f23a8a2be072845911" + integrity sha512-6FomvYPfs+Jy9TfXmBpBuMWNH94SgCsZmJKcanySzgNNP6LjWxBvyLTa9KaMfDDM5oxRfrKDB0r/qeRsLwnBfA== + +rsvp@~3.2.1: + version "3.2.1" + resolved "https://registry.npmjs.org/rsvp/-/rsvp-3.2.1.tgz#07cb4a5df25add9e826ebc67dcc9fd89db27d84a" + integrity sha1-B8tKXfJa3Z6Cbrxn3Mn9idsn2Eo= + +run-async@^2.2.0: + version "2.3.0" + resolved "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0" + integrity sha1-A3GrSuC91yDUFm19/aZP96RFpsA= + dependencies: + is-promise "^2.1.0" + +rxjs@^6.4.0: + version "6.4.0" + resolved "https://registry.npmjs.org/rxjs/-/rxjs-6.4.0.tgz#f3bb0fe7bda7fb69deac0c16f17b50b0b8790504" + integrity sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw== + dependencies: + tslib "^1.9.0" + +safe-buffer@5.1.2, safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: + version "5.1.2" + resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" + integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== + +safe-json-parse@~1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/safe-json-parse/-/safe-json-parse-1.0.1.tgz#3e76723e38dfdda13c9b1d29a1e07ffee4b30b57" + integrity sha1-PnZyPjjf3aE8mx0poeB//uSzC1c= + +safe-regex@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz#40a3669f3b077d1e943d44629e157dd48023bf2e" + integrity sha1-QKNmnzsHfR6UPURinhV91IAjvy4= + dependencies: + ret "~0.1.10" + +"safer-buffer@>= 2.1.2 < 3": + version "2.1.2" + resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + +sane@^4.0.0: + version "4.0.3" + resolved "https://registry.npmjs.org/sane/-/sane-4.0.3.tgz#e878c3f19e25cc57fbb734602f48f8a97818b181" + integrity sha512-hSLkC+cPHiBQs7LSyXkotC3UUtyn8C4FMn50TNaacRyvBlI+3ebcxMpqckmTdtXVtel87YS7GXN3UIOj7NiGVQ== + dependencies: + "@cnakazawa/watch" "^1.0.3" + anymatch "^2.0.0" + capture-exit "^1.2.0" + exec-sh "^0.3.2" + execa "^1.0.0" + fb-watchman "^2.0.0" + micromatch "^3.1.4" + minimist "^1.1.1" + walker "~1.0.5" + +semver@^5.1.0, semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0: + version "5.6.0" + resolved "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004" + integrity sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg== + +semver@~5.0.1: + version "5.0.3" + resolved "https://registry.npmjs.org/semver/-/semver-5.0.3.tgz#77466de589cd5d3c95f138aa78bc569a3cb5d27a" + integrity sha1-d0Zt5YnNXTyV8TiqeLxWmjy10no= + +send@0.16.2: + version "0.16.2" + resolved "https://registry.npmjs.org/send/-/send-0.16.2.tgz#6ecca1e0f8c156d141597559848df64730a6bbc1" + integrity sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw== + dependencies: + debug "2.6.9" + depd "~1.1.2" + destroy "~1.0.4" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + fresh "0.5.2" + http-errors "~1.6.2" + mime "1.4.1" + ms "2.0.0" + on-finished "~2.3.0" + range-parser "~1.2.0" + statuses "~1.4.0" + +serve-static@1.13.2: + version "1.13.2" + resolved "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz#095e8472fd5b46237db50ce486a43f4b86c6cec1" + integrity sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw== + dependencies: + encodeurl "~1.0.2" + escape-html "~1.0.3" + parseurl "~1.3.2" + send "0.16.2" + +set-blocking@^2.0.0, set-blocking@~2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" + integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= + +set-value@^0.4.3: + version "0.4.3" + resolved "https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz#7db08f9d3d22dc7f78e53af3c3bf4666ecdfccf1" + integrity sha1-fbCPnT0i3H945Trzw79GZuzfzPE= + dependencies: + extend-shallow "^2.0.1" + is-extendable "^0.1.1" + is-plain-object "^2.0.1" + to-object-path "^0.3.0" + +set-value@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/set-value/-/set-value-2.0.0.tgz#71ae4a88f0feefbbf52d1ea604f3fb315ebb6274" + integrity sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg== + dependencies: + extend-shallow "^2.0.1" + is-extendable "^0.1.1" + is-plain-object "^2.0.3" + split-string "^3.0.1" + +setprototypeof@1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz#d0bd85536887b6fe7c0d818cb962d9d91c54e656" + integrity sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ== + +shebang-command@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" + integrity sha1-RKrGW2lbAzmJaMOfNj/uXer98eo= + dependencies: + shebang-regex "^1.0.0" + +shebang-regex@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" + integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= + +shellwords@^0.1.1: + version "0.1.1" + resolved "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" + integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww== + +signal-exit@^3.0.0, signal-exit@^3.0.2: + version "3.0.2" + resolved "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" + integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= + +silent-error@^1.0.0, silent-error@^1.0.1, silent-error@^1.1.0, silent-error@^1.1.1: + version "1.1.1" + resolved "https://registry.npmjs.org/silent-error/-/silent-error-1.1.1.tgz#f72af5b0d73682a2ba1778b7e32cd8aa7c2d8662" + integrity sha512-n4iEKyNcg4v6/jpb3c0/iyH2G1nzUNl7Gpqtn/mHIJK9S/q/7MCfoO4rwVOoO59qPFIc0hVHvMbiOJ0NdtxKKw== + dependencies: + debug "^2.2.0" + +slash@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" + integrity sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU= + +slice-ansi@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz#cacd7693461a637a5788d92a7dd4fba068e81636" + integrity sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ== + dependencies: + ansi-styles "^3.2.0" + astral-regex "^1.0.0" + is-fullwidth-code-point "^2.0.0" + +snapdragon-node@^2.0.1: + version "2.1.1" + resolved "https://registry.npmjs.org/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" + integrity sha512-O27l4xaMYt/RSQ5TR3vpWCAB5Kb/czIcqUFOM/C4fYcLnbZUc1PkjTAMjof2pBWaSTwOUd6qUHcFGVGj7aIwnw== + dependencies: + define-property "^1.0.0" + isobject "^3.0.0" + snapdragon-util "^3.0.1" + +snapdragon-util@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/snapdragon-util/-/snapdragon-util-3.0.1.tgz#f956479486f2acd79700693f6f7b805e45ab56e2" + integrity sha512-mbKkMdQKsjX4BAL4bRYTj21edOf8cN7XHdYUJEe+Zn99hVEYcMvKPct1IqNe7+AZPirn8BCDOQBHQZknqmKlZQ== + dependencies: + kind-of "^3.2.0" + +snapdragon@^0.8.1: + version "0.8.2" + resolved "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz#64922e7c565b0e14204ba1aa7d6964278d25182d" + integrity sha512-FtyOnWN/wCHTVXOMwvSv26d+ko5vWlIDD6zoUJ7LW8vh+ZBC8QdljveRP+crNrtBwioEUWy/4dMtbBjA4ioNlg== + dependencies: + base "^0.11.1" + debug "^2.2.0" + define-property "^0.2.5" + extend-shallow "^2.0.1" + map-cache "^0.2.2" + source-map "^0.5.6" + source-map-resolve "^0.5.0" + use "^3.1.0" + +sntp@0.2.x: + version "0.2.4" + resolved "https://registry.npmjs.org/sntp/-/sntp-0.2.4.tgz#fb885f18b0f3aad189f824862536bceeec750900" + integrity sha1-+4hfGLDzqtGJ+CSGJTa87ux1CQA= + dependencies: + hoek "0.9.x" + +socket.io-adapter@~1.1.0: + version "1.1.1" + resolved "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-1.1.1.tgz#2a805e8a14d6372124dd9159ad4502f8cb07f06b" + integrity sha1-KoBeihTWNyEk3ZFZrUUC+MsH8Gs= + +socket.io-client@2.2.0: + version "2.2.0" + resolved "https://registry.npmjs.org/socket.io-client/-/socket.io-client-2.2.0.tgz#84e73ee3c43d5020ccc1a258faeeb9aec2723af7" + integrity sha512-56ZrkTDbdTLmBIyfFYesgOxsjcLnwAKoN4CiPyTVkMQj3zTUh0QAx3GbvIvLpFEOvQWu92yyWICxB0u7wkVbYA== + dependencies: + backo2 "1.0.2" + base64-arraybuffer "0.1.5" + component-bind "1.0.0" + component-emitter "1.2.1" + debug "~3.1.0" + engine.io-client "~3.3.1" + has-binary2 "~1.0.2" + has-cors "1.1.0" + indexof "0.0.1" + object-component "0.0.3" + parseqs "0.0.5" + parseuri "0.0.5" + socket.io-parser "~3.3.0" + to-array "0.1.4" + +socket.io-parser@~3.3.0: + version "3.3.0" + resolved "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.3.0.tgz#2b52a96a509fdf31440ba40fed6094c7d4f1262f" + integrity sha512-hczmV6bDgdaEbVqhAeVMM/jfUfzuEZHsQg6eOmLgJht6G3mPKMxYm75w2+qhAQZ+4X+1+ATZ+QFKeOZD5riHng== + dependencies: + component-emitter "1.2.1" + debug "~3.1.0" + isarray "2.0.1" + +socket.io@^2.1.0: + version "2.2.0" + resolved "https://registry.npmjs.org/socket.io/-/socket.io-2.2.0.tgz#f0f633161ef6712c972b307598ecd08c9b1b4d5b" + integrity sha512-wxXrIuZ8AILcn+f1B4ez4hJTPG24iNgxBBDaJfT6MsyOhVYiTXWexGoPkd87ktJG8kQEcL/NBvRi64+9k4Kc0w== + dependencies: + debug "~4.1.0" + engine.io "~3.3.1" + has-binary2 "~1.0.2" + socket.io-adapter "~1.1.0" + socket.io-client "2.2.0" + socket.io-parser "~3.3.0" + +sort-keys@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/sort-keys/-/sort-keys-2.0.0.tgz#658535584861ec97d730d6cf41822e1f56684128" + integrity sha1-ZYU1WEhh7JfXMNbPQYIuH1ZoQSg= + dependencies: + is-plain-obj "^1.0.0" + +sort-object-keys@^1.1.2: + version "1.1.2" + resolved "https://registry.npmjs.org/sort-object-keys/-/sort-object-keys-1.1.2.tgz#d3a6c48dc2ac97e6bc94367696e03f6d09d37952" + integrity sha1-06bEjcKsl+a8lDZ2luA/bQnTeVI= + +sort-package-json@^1.15.0: + version "1.21.0" + resolved "https://registry.npmjs.org/sort-package-json/-/sort-package-json-1.21.0.tgz#9501273da130693b4dd1ebe68882d1d289119546" + integrity sha512-G920kGKROov3kS32jnmf03YolcGTkdONKbOv+Hi1Db7D9lBXhNU5aNMZCE0j/hfDqd/zmPVmpSiuhSOt3Lv+4A== + dependencies: + detect-indent "^5.0.0" + sort-object-keys "^1.1.2" + +source-map-resolve@^0.5.0: + version "0.5.2" + resolved "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.5.2.tgz#72e2cc34095543e43b2c62b2c4c10d4a9054f259" + integrity sha512-MjqsvNwyz1s0k81Goz/9vRBe9SZdB09Bdw+/zYyO+3CuPk6fouTaxscHkgtE8jKvf01kVfl8riHzERQ/kefaSA== + dependencies: + atob "^2.1.1" + decode-uri-component "^0.2.0" + resolve-url "^0.2.1" + source-map-url "^0.4.0" + urix "^0.1.0" + +source-map-support@^0.4.15: + version "0.4.18" + resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f" + integrity sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA== + dependencies: + source-map "^0.5.6" + +source-map-support@~0.5.9: + version "0.5.10" + resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.10.tgz#2214080bc9d51832511ee2bab96e3c2f9353120c" + integrity sha512-YfQ3tQFTK/yzlGJuX8pTwa4tifQj4QS2Mj7UegOu8jAz59MqIiMGPXxQhVQiIMNzayuUSF/jEuVnfFF5JqybmQ== + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + +source-map-url@^0.3.0: + version "0.3.0" + resolved "https://registry.npmjs.org/source-map-url/-/source-map-url-0.3.0.tgz#7ecaf13b57bcd09da8a40c5d269db33799d4aaf9" + integrity sha1-fsrxO1e80J2opAxdJp2zN5nUqvk= + +source-map-url@^0.4.0: + version "0.4.0" + resolved "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" + integrity sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM= + +source-map@0.4.x, source-map@^0.4.2: + version "0.4.4" + resolved "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b" + integrity sha1-66T12pwNyZneaAMti092FzZSA2s= + dependencies: + amdefine ">=0.0.4" + +source-map@^0.5.0, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.0: + version "0.5.7" + resolved "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" + integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= + +source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: + version "0.6.1" + resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" + integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== + +source-map@~0.1.x: + version "0.1.43" + resolved "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz#c24bc146ca517c1471f5dacbe2571b2b7f9e3346" + integrity sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y= + dependencies: + amdefine ">=0.0.4" + +sourcemap-codec@^1.4.1: + version "1.4.4" + resolved "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.4.tgz#c63ea927c029dd6bd9a2b7fa03b3fec02ad56e9f" + integrity sha512-CYAPYdBu34781kLHkaW3m6b/uUSyMOC2R61gcYMWooeuaGtjof86ZA/8T+qVPPt7np1085CR9hmMGrySwEc8Xg== + +sourcemap-validator@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/sourcemap-validator/-/sourcemap-validator-1.1.0.tgz#00454547d1682186e1498a7208e022e8dfa8738f" + integrity sha512-Hmdu39KL+EoAAZ69OTk7RXXJdPRRizJvOZOWhCW9jLGfEQflCNPTlSoCXFPdKWFwwf0uzLcGR/fc7EP/PT8vRQ== + dependencies: + jsesc "~0.3.x" + lodash.foreach "~2.3.x" + lodash.template "~2.3.x" + source-map "~0.1.x" + +spawn-args@^0.2.0: + version "0.2.0" + resolved "https://registry.npmjs.org/spawn-args/-/spawn-args-0.2.0.tgz#fb7d0bd1d70fd4316bd9e3dec389e65f9d6361bb" + integrity sha1-+30L0dcP1DFr2ePew4nmX51jYbs= + +split-string@^3.0.1, split-string@^3.0.2: + version "3.1.0" + resolved "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2" + integrity sha512-NzNVhJDYpwceVVii8/Hu6DKfD2G+NrQHlS/V/qgv763EYudVwEcMQNxd2lh+0VrUByXN/oJkl5grOhYWvQUYiw== + dependencies: + extend-shallow "^3.0.0" + +sprintf-js@^1.0.3: + version "1.1.2" + resolved "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz#da1765262bf8c0f571749f2ad6c26300207ae673" + integrity sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug== + +sprintf-js@~1.0.2: + version "1.0.3" + resolved "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" + integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= + +sri-toolbox@^0.2.0: + version "0.2.0" + resolved "https://registry.npmjs.org/sri-toolbox/-/sri-toolbox-0.2.0.tgz#a7fea5c3fde55e675cf1c8c06f3ebb5c2935835e" + integrity sha1-p/6lw/3lXmdc8cjAbz67XCk1g14= + +stagehand@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/stagehand/-/stagehand-1.0.0.tgz#79515e2ad3a02c63f8720c7df9b6077ae14276d9" + integrity sha512-zrXl0QixAtSHFyN1iv04xOBgplbT4HgC8T7g+q8ESZbDNi5uZbMtxLukFVXPJ5Nl7zCYvYcrT3Mj24WYCH93hw== + dependencies: + debug "^4.1.0" + +static-extend@^0.1.1: + version "0.1.2" + resolved "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" + integrity sha1-YICcOcv/VTNyJv1eC1IPNB8ftcY= + dependencies: + define-property "^0.2.5" + object-copy "^0.1.0" + +"statuses@>= 1.4.0 < 2": + version "1.5.0" + resolved "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" + integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow= + +statuses@~1.3.1: + version "1.3.1" + resolved "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e" + integrity sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4= + +statuses@~1.4.0: + version "1.4.0" + resolved "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087" + integrity sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew== + +stream-consume@^0.1.0: + version "0.1.1" + resolved "https://registry.npmjs.org/stream-consume/-/stream-consume-0.1.1.tgz#d3bdb598c2bd0ae82b8cac7ac50b1107a7996c48" + integrity sha512-tNa3hzgkjEP7XbCkbRXe1jpg+ievoa0O4SCFlMOYEscGSS4JJsckGL8swUyAa/ApGU3Ae4t6Honor4HhL+tRyg== + +strict-uri-encode@^1.0.0: + version "1.1.0" + resolved "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713" + integrity sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM= + +string-template@~0.2.1: + version "0.2.1" + resolved "https://registry.npmjs.org/string-template/-/string-template-0.2.1.tgz#42932e598a352d01fc22ec3367d9d84eec6c9add" + integrity sha1-QpMuWYo1LQH8IuwzZ9nYTuxsmt0= + +string-width@^1.0.1: + version "1.0.2" + resolved "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" + integrity sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M= + dependencies: + code-point-at "^1.0.0" + is-fullwidth-code-point "^1.0.0" + strip-ansi "^3.0.0" + +"string-width@^1.0.2 || 2", string-width@^2.0.0, string-width@^2.1.0, string-width@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" + integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw== + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^4.0.0" + +string-width@^3.0.0: + version "3.1.0" + resolved "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" + integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w== + dependencies: + emoji-regex "^7.0.1" + is-fullwidth-code-point "^2.0.0" + strip-ansi "^5.1.0" + +string_decoder@0.10, string_decoder@~0.10.x: + version "0.10.31" + resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + integrity sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ= + +string_decoder@~1.1.1: + version "1.1.1" + resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" + integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg== + dependencies: + safe-buffer "~5.1.0" + +stringify-object-es5@^2.5.0: + version "2.5.0" + resolved "https://registry.npmjs.org/stringify-object-es5/-/stringify-object-es5-2.5.0.tgz#057c3c9a90a127339bb9d1704a290bb7bd0a1ec5" + integrity sha1-BXw8mpChJzObudFwSikLt70KHsU= + dependencies: + is-plain-obj "^1.0.0" + is-regexp "^1.0.0" + +stringstream@~0.0.4: + version "0.0.6" + resolved "https://registry.npmjs.org/stringstream/-/stringstream-0.0.6.tgz#7880225b0d4ad10e30927d167a1d6f2fd3b33a72" + integrity sha512-87GEBAkegbBcweToUrdzf3eLhWNg06FJTebl4BVJz/JgWy8CvEr9dRtX5qWphiynMSQlxxi+QqN0z5T32SLlhA== + +strip-ansi@^3.0.0, strip-ansi@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" + integrity sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8= + dependencies: + ansi-regex "^2.0.0" + +strip-ansi@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" + integrity sha1-qEeQIusaw2iocTibY1JixQXuNo8= + dependencies: + ansi-regex "^3.0.0" + +strip-ansi@^5.0.0, strip-ansi@^5.1.0: + version "5.1.0" + resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.1.0.tgz#55aaa54e33b4c0649a7338a43437b1887d153ec4" + integrity sha512-TjxrkPONqO2Z8QDCpeE2j6n0M6EwxzyDgzEeGp+FbdvaJAt//ClYi6W5my+3ROlC/hZX2KACUwDfK49Ka5eDvg== + dependencies: + ansi-regex "^4.1.0" + +strip-bom@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" + integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM= + +strip-eof@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" + integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8= + +strip-json-comments@2.0.1, strip-json-comments@^2.0.1, strip-json-comments@~2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" + integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo= + +styled_string@0.0.1: + version "0.0.1" + resolved "https://registry.npmjs.org/styled_string/-/styled_string-0.0.1.tgz#d22782bd81295459bc4f1df18c4bad8e94dd124a" + integrity sha1-0ieCvYEpVFm8Tx3xjEutjpTdEko= + +sum-up@^1.0.1: + version "1.0.3" + resolved "https://registry.npmjs.org/sum-up/-/sum-up-1.0.3.tgz#1c661f667057f63bcb7875aa1438bc162525156e" + integrity sha1-HGYfZnBX9jvLeHWqFDi8FiUlFW4= + dependencies: + chalk "^1.0.0" + +supports-color@6.0.0: + version "6.0.0" + resolved "https://registry.npmjs.org/supports-color/-/supports-color-6.0.0.tgz#76cfe742cf1f41bb9b1c29ad03068c05b4c0e40a" + integrity sha512-on9Kwidc1IUQo+bQdhi8+Tijpo0e1SS6RoGo2guUwn5vdaxw8RXOF9Vb2ws+ihWOmh4JnCJOvaziZWP1VABaLg== + dependencies: + has-flag "^3.0.0" + +supports-color@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" + integrity sha1-U10EXOa2Nj+kARcIRimZXp3zJMc= + +supports-color@^5.3.0: + version "5.5.0" + resolved "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" + integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow== + dependencies: + has-flag "^3.0.0" + +symlink-or-copy@^1.0.0, symlink-or-copy@^1.0.1, symlink-or-copy@^1.1.8, symlink-or-copy@^1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/symlink-or-copy/-/symlink-or-copy-1.2.0.tgz#5d49108e2ab824a34069b68974486c290020b393" + integrity sha512-W31+GLiBmU/ZR02Ii0mVZICuNEN9daZ63xZMPDsYgPgNjMtg+atqLEGI7PPI936jYSQZxoLb/63xos8Adrx4Eg== + +table@^5.2.3: + version "5.2.3" + resolved "https://registry.npmjs.org/table/-/table-5.2.3.tgz#cde0cc6eb06751c009efab27e8c820ca5b67b7f2" + integrity sha512-N2RsDAMvDLvYwFcwbPyF3VmVSSkuF+G1e+8inhBLtHpvwXGw4QRPEZhihQNeEN0i1up6/f6ObCJXNdlRG3YVyQ== + dependencies: + ajv "^6.9.1" + lodash "^4.17.11" + slice-ansi "^2.1.0" + string-width "^3.0.0" + +tap-parser@^7.0.0: + version "7.0.0" + resolved "https://registry.npmjs.org/tap-parser/-/tap-parser-7.0.0.tgz#54db35302fda2c2ccc21954ad3be22b2cba42721" + integrity sha512-05G8/LrzqOOFvZhhAk32wsGiPZ1lfUrl+iV7+OkKgfofZxiceZWMHkKmow71YsyVQ8IvGBP2EjcIjE5gL4l5lA== + dependencies: + events-to-array "^1.0.1" + js-yaml "^3.2.7" + minipass "^2.2.0" + +temp@0.9.0: + version "0.9.0" + resolved "https://registry.npmjs.org/temp/-/temp-0.9.0.tgz#61391795a11bd9738d4c4d7f55f012cb8f55edaa" + integrity sha512-YfUhPQCJoNQE5N+FJQcdPz63O3x3sdT4Xju69Gj4iZe0lBKOtnAMi0SLj9xKhGkcGhsxThvTJ/usxtFPo438zQ== + dependencies: + rimraf "~2.6.2" + +terser@^3.16.1, terser@^3.7.5: + version "3.16.1" + resolved "https://registry.npmjs.org/terser/-/terser-3.16.1.tgz#5b0dd4fa1ffd0b0b43c2493b2c364fd179160493" + integrity sha512-JDJjgleBROeek2iBcSNzOHLKsB/MdDf+E/BOAJ0Tk9r7p9/fVobfv7LMJ/g/k3v9SXdmjZnIlFd5nfn/Rt0Xow== + dependencies: + commander "~2.17.1" + source-map "~0.6.1" + source-map-support "~0.5.9" + +testdouble@^3.2.6: + version "3.11.0" + resolved "https://registry.npmjs.org/testdouble/-/testdouble-3.11.0.tgz#17d3c3afa21acd2e8144c86f8a0708d49a81a695" + integrity sha512-hmF04fDUiTHy8yVQx6mucpOeyH5qElb3UtMos4xWZtJR2MsS/nzLEN+5wQ4QiGS4TV1X32eMSzLgh53uKg9ufA== + dependencies: + lodash "^4.17.11" + quibble "^0.5.5" + stringify-object-es5 "^2.5.0" + theredoc "^1.0.0" + +testem@^2.9.2: + version "2.14.0" + resolved "https://registry.npmjs.org/testem/-/testem-2.14.0.tgz#418a9a15843f68381659c6a486abb4ea48d06c29" + integrity sha512-tldpNPCzXfibmxOoTMGOfr8ztUiHf9292zSXCu7SitBx9dCK83k7vEoa77qJBS9t3RGCQCRF+GNMUuiFw//Mbw== + dependencies: + backbone "^1.1.2" + bluebird "^3.4.6" + charm "^1.0.0" + commander "^2.6.0" + consolidate "^0.15.1" + execa "^1.0.0" + express "^4.10.7" + fireworm "^0.7.0" + glob "^7.0.4" + http-proxy "^1.13.1" + js-yaml "^3.2.5" + lodash.assignin "^4.1.0" + lodash.castarray "^4.4.0" + lodash.clonedeep "^4.4.1" + lodash.find "^4.5.1" + lodash.uniqby "^4.7.0" + mkdirp "^0.5.1" + mustache "^3.0.0" + node-notifier "^5.0.1" + npmlog "^4.0.0" + printf "^0.5.1" + rimraf "^2.4.4" + socket.io "^2.1.0" + spawn-args "^0.2.0" + styled_string "0.0.1" + tap-parser "^7.0.0" + tmp "0.0.33" + xmldom "^0.1.19" + +text-table@^0.2.0: + version "0.2.0" + resolved "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" + integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= + +"textextensions@1 || 2": + version "2.4.0" + resolved "https://registry.npmjs.org/textextensions/-/textextensions-2.4.0.tgz#6a143a985464384cc2cff11aea448cd5b018e72b" + integrity sha512-qftQXnX1DzpSV8EddtHIT0eDDEiBF8ywhFYR2lI9xrGtxqKN+CvLXhACeCIGbCpQfxxERbrkZEFb8cZcDKbVZA== + +theredoc@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/theredoc/-/theredoc-1.0.0.tgz#bcace376af6feb1873efbdd0f91ed026570ff062" + integrity sha512-KU3SA3TjRRM932jpNfD3u4Ec3bSvedyo5ITPI7zgWYnKep7BwQQaxlhI9qbO+lKJoRnoAbEVfMcAHRuKVYikDA== + +through@^2.3.6, through@^2.3.8: + version "2.3.8" + resolved "https://registry.npmjs.org/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" + integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= + +through@~2.2.0, through@~2.2.7: + version "2.2.7" + resolved "https://registry.npmjs.org/through/-/through-2.2.7.tgz#6e8e21200191d4eb6a99f6f010df46aa1c6eb2bd" + integrity sha1-bo4hIAGR1OtqmfbwEN9Gqhxusr0= + +time-zone@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/time-zone/-/time-zone-1.0.0.tgz#99c5bf55958966af6d06d83bdf3800dc82faec5d" + integrity sha1-mcW/VZWJZq9tBtg73zgA3IL67F0= + +timed-out@^4.0.0, timed-out@^4.0.1: + version "4.0.1" + resolved "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f" + integrity sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8= + +tiny-lr@^1.1.1: + version "1.1.1" + resolved "https://registry.npmjs.org/tiny-lr/-/tiny-lr-1.1.1.tgz#9fa547412f238fedb068ee295af8b682c98b2aab" + integrity sha512-44yhA3tsaRoMOjQQ+5v5mVdqef+kH6Qze9jTpqtVufgYjYt08zyZAwNwwVBj3i1rJMnR52IxOW0LK0vBzgAkuA== + dependencies: + body "^5.1.0" + debug "^3.1.0" + faye-websocket "~0.10.0" + livereload-js "^2.3.0" + object-assign "^4.1.0" + qs "^6.4.0" + +tmp-sync@^1.0.0: + version "1.1.2" + resolved "https://registry.npmjs.org/tmp-sync/-/tmp-sync-1.1.2.tgz#ba04d94a8ed9c0f35a54739970792f997a6cc1c8" + integrity sha1-ugTZSo7ZwPNaVHOZcHkvmXpswcg= + dependencies: + fs-sync "^1.0.4" + osenv "^0.1.0" + +tmp@0.0.28: + version "0.0.28" + resolved "https://registry.npmjs.org/tmp/-/tmp-0.0.28.tgz#172735b7f614ea7af39664fa84cf0de4e515d120" + integrity sha1-Fyc1t/YU6nrzlmT6hM8N5OUV0SA= + dependencies: + os-tmpdir "~1.0.1" + +tmp@0.0.33, tmp@^0.0.33: + version "0.0.33" + resolved "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" + integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== + dependencies: + os-tmpdir "~1.0.2" + +tmpl@1.0.x: + version "1.0.4" + resolved "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1" + integrity sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE= + +to-array@0.1.4: + version "0.1.4" + resolved "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz#17e6c11f73dd4f3d74cda7a4ff3238e9ad9bf890" + integrity sha1-F+bBH3PdTz10zaek/zI46a2b+JA= + +to-fast-properties@^1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" + integrity sha1-uDVx+k2MJbguIxsG46MFXeTKGkc= + +to-fast-properties@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" + integrity sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4= + +to-object-path@^0.3.0: + version "0.3.0" + resolved "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af" + integrity sha1-KXWIt7Dn4KwI4E5nL4XB9JmeF68= + dependencies: + kind-of "^3.0.2" + +to-regex-range@^2.1.0: + version "2.1.1" + resolved "https://registry.npmjs.org/to-regex-range/-/to-regex-range-2.1.1.tgz#7c80c17b9dfebe599e27367e0d4dd5590141db38" + integrity sha1-fIDBe53+vlmeJzZ+DU3VWQFB2zg= + dependencies: + is-number "^3.0.0" + repeat-string "^1.6.1" + +to-regex@^3.0.1, to-regex@^3.0.2: + version "3.0.2" + resolved "https://registry.npmjs.org/to-regex/-/to-regex-3.0.2.tgz#13cfdd9b336552f30b51f33a8ae1b42a7a7599ce" + integrity sha512-FWtleNAtZ/Ki2qtqej2CXTOayOH9bHDQF+Q48VpWyDXjbYxA4Yz8iDB31zXOBUlOHHKidDbqGVrTUvQMPmBGBw== + dependencies: + define-property "^2.0.2" + extend-shallow "^3.0.2" + regex-not "^1.0.2" + safe-regex "^1.1.0" + +to-utf8@0.0.1: + version "0.0.1" + resolved "https://registry.npmjs.org/to-utf8/-/to-utf8-0.0.1.tgz#d17aea72ff2fba39b9e43601be7b3ff72e089852" + integrity sha1-0Xrqcv8vujm55DYBvns/9y4ImFI= + +tough-cookie@>=0.12.0: + version "3.0.1" + resolved "https://registry.npmjs.org/tough-cookie/-/tough-cookie-3.0.1.tgz#9df4f57e739c26930a018184887f4adb7dca73b2" + integrity sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg== + dependencies: + ip-regex "^2.1.0" + psl "^1.1.28" + punycode "^2.1.1" + +tree-sync@^1.2.2: + version "1.4.0" + resolved "https://registry.npmjs.org/tree-sync/-/tree-sync-1.4.0.tgz#314598d13abaf752547d9335b8f95d9a137100d6" + integrity sha512-YvYllqh3qrR5TAYZZTXdspnIhlKAYezPYw11ntmweoceu4VK+keN356phHRIIo1d+RDmLpHZrUlmxga2gc9kSQ== + dependencies: + debug "^2.2.0" + fs-tree-diff "^0.5.6" + mkdirp "^0.5.1" + quick-temp "^0.1.5" + walk-sync "^0.3.3" + +trim-right@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" + integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM= + +tslib@^1.9.0: + version "1.9.3" + resolved "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" + integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ== + +tunnel-agent@~0.4.0: + version "0.4.3" + resolved "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.4.3.tgz#6373db76909fe570e08d73583365ed828a74eeeb" + integrity sha1-Y3PbdpCf5XDgjXNYM2Xtgop07us= + +type-check@~0.3.2: + version "0.3.2" + resolved "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" + integrity sha1-WITKtRLPHTVeP7eE8wgEsrUg23I= + dependencies: + prelude-ls "~1.1.2" + +type-detect@0.1.1: + version "0.1.1" + resolved "https://registry.npmjs.org/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822" + integrity sha1-C6XsKohWQORw6k6FBZcZANrFiCI= + +type-detect@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2" + integrity sha1-diIXzAbbJY7EiQihKY6LlRIejqI= + +type-detect@^4.0.0, type-detect@^4.0.5: + version "4.0.8" + resolved "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" + integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== + +type-is@~1.6.16: + version "1.6.16" + resolved "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz#f89ce341541c672b25ee7ae3c73dee3b2be50194" + integrity sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q== + dependencies: + media-typer "0.3.0" + mime-types "~2.1.18" + +typescript@~3.3.3: + version "3.3.3333" + resolved "https://registry.npmjs.org/typescript/-/typescript-3.3.3333.tgz#171b2c5af66c59e9431199117a3bcadc66fdcfd6" + integrity sha512-JjSKsAfuHBE/fB2oZ8NxtRTk5iGcg6hkYXMnZ3Wc+b2RSqejEqTaem11mHASMnFilHrax3sLK0GDzcJrekZYLw== + +uc.micro@^1.0.0, uc.micro@^1.0.1, uc.micro@^1.0.5: + version "1.0.6" + resolved "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac" + integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA== + +uglify-js@^3.1.4: + version "3.4.9" + resolved "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3" + integrity sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q== + dependencies: + commander "~2.17.1" + source-map "~0.6.1" + +underscore.string@^3.2.2, underscore.string@~3.3.4: + version "3.3.5" + resolved "https://registry.npmjs.org/underscore.string/-/underscore.string-3.3.5.tgz#fc2ad255b8bd309e239cbc5816fd23a9b7ea4023" + integrity sha512-g+dpmgn+XBneLmXXo+sGlW5xQEt4ErkS3mgeN2GFbremYeMBSJKr9Wf2KJplQVaiPY/f7FN6atosWYNm9ovrYg== + dependencies: + sprintf-js "^1.0.3" + util-deprecate "^1.0.2" + +underscore@>=1.8.3: + version "1.9.1" + resolved "https://registry.npmjs.org/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961" + integrity sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg== + +unicode-canonical-property-names-ecmascript@^1.0.4: + version "1.0.4" + resolved "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818" + integrity sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ== + +unicode-match-property-ecmascript@^1.0.4: + version "1.0.4" + resolved "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz#8ed2a32569961bce9227d09cd3ffbb8fed5f020c" + integrity sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg== + dependencies: + unicode-canonical-property-names-ecmascript "^1.0.4" + unicode-property-aliases-ecmascript "^1.0.4" + +unicode-match-property-value-ecmascript@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.1.0.tgz#5b4b426e08d13a80365e0d657ac7a6c1ec46a277" + integrity sha512-hDTHvaBk3RmFzvSl0UVrUmC3PuW9wKVnpoUDYH0JDkSIovzw+J5viQmeYHxVSBptubnr7PbH2e0fnpDRQnQl5g== + +unicode-property-aliases-ecmascript@^1.0.4: + version "1.0.5" + resolved "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.5.tgz#a9cc6cc7ce63a0a3023fc99e341b94431d405a57" + integrity sha512-L5RAqCfXqAwR3RriF8pM0lU0w4Ryf/GgzONwi6KnL1taJQa7x1TCxdJnILX59WIGOwR57IVxn7Nej0fz1Ny6fw== + +union-value@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4" + integrity sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ= + dependencies: + arr-union "^3.1.0" + get-value "^2.0.6" + is-extendable "^0.1.1" + set-value "^0.4.3" + +unique-string@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/unique-string/-/unique-string-1.0.0.tgz#9e1057cca851abb93398f8b33ae187b99caec11a" + integrity sha1-nhBXzKhRq7kzmPizOuGHuZyuwRo= + dependencies: + crypto-random-string "^1.0.0" + +universalify@^0.1.0: + version "0.1.2" + resolved "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" + integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== + +unpipe@1.0.0, unpipe@~1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" + integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw= + +unset-value@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559" + integrity sha1-g3aHP30jNRef+x5vw6jtDfyKtVk= + dependencies: + has-value "^0.3.1" + isobject "^3.0.0" + +untildify@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/untildify/-/untildify-2.1.0.tgz#17eb2807987f76952e9c0485fc311d06a826a2e0" + integrity sha1-F+soB5h/dpUunASF/DEdBqgmouA= + dependencies: + os-homedir "^1.0.0" + +unzip-response@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97" + integrity sha1-0vD3N9FrBhXnKmk17QQhRXLVb5c= + +uri-js@^4.2.2: + version "4.2.2" + resolved "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0" + integrity sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ== + dependencies: + punycode "^2.1.0" + +urix@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" + integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI= + +url-parse-lax@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-1.0.0.tgz#7af8f303645e9bd79a272e7a14ac68bc0609da73" + integrity sha1-evjzA2Rem9eaJy56FKxovAYJ2nM= + dependencies: + prepend-http "^1.0.1" + +url-parse-lax@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz#16b5cafc07dbe3676c1b1999177823d6503acb0c" + integrity sha1-FrXK/Afb42dsGxmZF3gj1lA6yww= + dependencies: + prepend-http "^2.0.0" + +url-to-options@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/url-to-options/-/url-to-options-1.0.1.tgz#1505a03a289a48cbd7a434efbaeec5055f5633a9" + integrity sha1-FQWgOiiaSMvXpDTvuu7FBV9WM6k= + +use@^3.1.0: + version "3.1.1" + resolved "https://registry.npmjs.org/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" + integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ== + +username-sync@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/username-sync/-/username-sync-1.0.2.tgz#0a3697909fb7b5768d29e2921f573acfdd427592" + integrity sha512-ayNkOJdoNSGNDBE46Nkc+l6IXmeugbzahZLSMkwvgRWv5y5ZqNY2IrzcgmkR4z32sj1W3tM3TuTUMqkqBzO+RA== + +util-deprecate@^1.0.2, util-deprecate@~1.0.1: + version "1.0.2" + resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= + +utils-merge@1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" + integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM= + +uuid@^3.3.2: + version "3.3.2" + resolved "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" + integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA== + +validate-npm-package-name@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz#5fa912d81eb7d0c74afc140de7317f0ca7df437e" + integrity sha1-X6kS2B630MdK/BQN5zF/DKffQ34= + dependencies: + builtins "^1.0.3" + +vary@~1.1.2: + version "1.1.2" + resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" + integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw= + +walk-sync@^0.2.0, walk-sync@^0.2.5: + version "0.2.7" + resolved "https://registry.npmjs.org/walk-sync/-/walk-sync-0.2.7.tgz#b49be4ee6867657aeb736978b56a29d10fa39969" + integrity sha1-tJvk7mhnZXrrc2l4tWop0Q+jmWk= + dependencies: + ensure-posix-path "^1.0.0" + matcher-collection "^1.0.0" + +walk-sync@^0.3.0, walk-sync@^0.3.1, walk-sync@^0.3.2, walk-sync@^0.3.3: + version "0.3.4" + resolved "https://registry.npmjs.org/walk-sync/-/walk-sync-0.3.4.tgz#cf78486cc567d3a96b5b2237c6108017a5ffb9a4" + integrity sha512-ttGcuHA/OBnN2pcM6johpYlEms7XpO5/fyKIr48541xXedan4roO8cS1Q2S/zbbjGH/BarYDAMeS2Mi9HE5Tig== + dependencies: + ensure-posix-path "^1.0.0" + matcher-collection "^1.0.0" + +walk-sync@^1.0.0, walk-sync@^1.1.3: + version "1.1.3" + resolved "https://registry.npmjs.org/walk-sync/-/walk-sync-1.1.3.tgz#3b7b6468f068b5eba2278c931c57db3d39092969" + integrity sha512-23ivbET0Q/389y3EHpiIgxx881AS2mwdXA7iBqUDNSymoTPYb2jWlF3gkuuAP1iLgdNXmiHw/kZ/wZwrELU6Ag== + dependencies: + "@types/minimatch" "^3.0.3" + ensure-posix-path "^1.1.0" + matcher-collection "^1.1.1" + +walker@~1.0.5: + version "1.0.7" + resolved "https://registry.npmjs.org/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb" + integrity sha1-L3+bj9ENZ3JisYqITijRlhjgKPs= + dependencies: + makeerror "1.0.x" + +watch-detector@^0.1.0: + version "0.1.0" + resolved "https://registry.npmjs.org/watch-detector/-/watch-detector-0.1.0.tgz#e37b410d149e2a8bf263a4f8b71e2f667633dbf8" + integrity sha512-vfzMMfpjQc88xjETwl2HuE6PjEuxCBeyC4bQmqrHrofdfYWi/4mEJklYbNgSzpqM9PxubsiPIrE5SZ1FDyiQ2w== + dependencies: + heimdalljs-logger "^0.1.9" + quick-temp "^0.1.8" + rsvp "^4.7.0" + semver "^5.4.1" + silent-error "^1.1.0" + +wcwidth@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8" + integrity sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g= + dependencies: + defaults "^1.0.3" + +websocket-driver@>=0.5.1: + version "0.7.0" + resolved "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.0.tgz#0caf9d2d755d93aee049d4bdd0d3fe2cca2a24eb" + integrity sha1-DK+dLXVdk67gSdS90NP+LMoqJOs= + dependencies: + http-parser-js ">=0.4.0" + websocket-extensions ">=0.1.1" + +websocket-extensions@>=0.1.1: + version "0.1.3" + resolved "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.3.tgz#5d2ff22977003ec687a4b87073dfbbac146ccf29" + integrity sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg== + +whatwg-fetch@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb" + integrity sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q== + +which-module@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" + integrity sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho= + +which@1.3.1, which@^1.2.14, which@^1.2.9, which@^1.3.0: + version "1.3.1" + resolved "https://registry.npmjs.org/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" + integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== + dependencies: + isexe "^2.0.0" + +wide-align@1.1.3, wide-align@^1.1.0: + version "1.1.3" + resolved "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457" + integrity sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA== + dependencies: + string-width "^1.0.2 || 2" + +wordwrap@~0.0.2: + version "0.0.3" + resolved "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" + integrity sha1-o9XabNXAvAAI03I0u68b7WMFkQc= + +wordwrap@~1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus= + +workerpool@^2.3.0: + version "2.3.3" + resolved "https://registry.npmjs.org/workerpool/-/workerpool-2.3.3.tgz#49a70089bd55e890d68cc836a19419451d7c81d7" + integrity sha512-L1ovlYHp6UObYqElXXpbd214GgbEKDED0d3sj7pRdFXjNkb2+un/AUcCkceHizO0IVI6SOGGncrcjozruCkRgA== + dependencies: + object-assign "4.1.1" + +workerpool@^3.1.1: + version "3.1.1" + resolved "https://registry.npmjs.org/workerpool/-/workerpool-3.1.1.tgz#9decea76b73c2f91de1b5bec1019f8a474b3a620" + integrity sha512-VzYD/kM3Gk9L7GR0LtrcyiZA8+h8Fse503aq4WkYwRBXreHTixVEcqKLjiFS6gM0fyaEt0pjSLf1ANGQXM27cg== + dependencies: + object-assign "4.1.1" + +wrap-ansi@^2.0.0: + version "2.1.0" + resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" + integrity sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU= + dependencies: + string-width "^1.0.1" + strip-ansi "^3.0.1" + +wrappy@1: + version "1.0.2" + resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= + +write-file-atomic@^2.0.0: + version "2.4.2" + resolved "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.2.tgz#a7181706dfba17855d221140a9c06e15fcdd87b9" + integrity sha512-s0b6vB3xIVRLWywa6X9TOMA7k9zio0TMOsl9ZnDkliA/cfJlpHXAscj0gbHVJiTdIuAYpIyqS5GW91fqm6gG5g== + dependencies: + graceful-fs "^4.1.11" + imurmurhash "^0.1.4" + signal-exit "^3.0.2" + +write@1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/write/-/write-1.0.3.tgz#0800e14523b923a387e415123c865616aae0f5c3" + integrity sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig== + dependencies: + mkdirp "^0.5.1" + +ws@~6.1.0: + version "6.1.4" + resolved "https://registry.npmjs.org/ws/-/ws-6.1.4.tgz#5b5c8800afab925e94ccb29d153c8d02c1776ef9" + integrity sha512-eqZfL+NE/YQc1/ZynhojeV8q+H050oR8AZ2uIev7RU10svA9ZnJUddHcOUZTJLinZ9yEfdA2kSATS2qZK5fhJA== + dependencies: + async-limiter "~1.0.0" + +xdg-basedir@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4" + integrity sha1-SWsswQnsqNus/i3HK2A8F8WHCtQ= + +xmldom@^0.1.19: + version "0.1.27" + resolved "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz#d501f97b3bdb403af8ef9ecc20573187aadac0e9" + integrity sha1-1QH5ezvbQDr4757MIFcxh6rawOk= + +xmlhttprequest-ssl@~1.5.4: + version "1.5.5" + resolved "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e" + integrity sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4= + +xtend@^4.0.0, xtend@~4.0.0: + version "4.0.1" + resolved "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" + integrity sha1-pcbVMr5lbiPbgg77lDofBJmNY68= + +"y18n@^3.2.1 || ^4.0.0": + version "4.0.0" + resolved "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" + integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w== + +yallist@^3.0.0: + version "3.0.3" + resolved "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9" + integrity sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A== + +yam@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/yam/-/yam-1.0.0.tgz#7f6c91dc0f5de75a031e6da6b3907c3d25ab0de5" + integrity sha512-Hv9xxHtsJ9228wNhk03xnlDReUuWVvHwM4rIbjdAXYvHLs17xjuyF50N6XXFMN6N0omBaqgOok/MCK3At9fTAg== + dependencies: + fs-extra "^4.0.2" + lodash.merge "^4.6.0" + +yargs-parser@11.1.1, yargs-parser@^11.1.1: + version "11.1.1" + resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-11.1.1.tgz#879a0865973bca9f6bab5cbdf3b1c67ec7d3bcf4" + integrity sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + +yargs-unparser@1.5.0: + version "1.5.0" + resolved "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.5.0.tgz#f2bb2a7e83cbc87bb95c8e572828a06c9add6e0d" + integrity sha512-HK25qidFTCVuj/D1VfNiEndpLIeJN78aqgR23nL3y4N0U/91cOAzqfHlF8n2BvoNDcZmJKin3ddNSvOxSr8flw== + dependencies: + flat "^4.1.0" + lodash "^4.17.11" + yargs "^12.0.5" + +yargs@12.0.5, yargs@^12.0.5: + version "12.0.5" + resolved "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz#05f5997b609647b64f66b81e3b4b10a368e7ad13" + integrity sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw== + dependencies: + cliui "^4.0.0" + decamelize "^1.2.0" + find-up "^3.0.0" + get-caller-file "^1.0.1" + os-locale "^3.0.0" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^2.0.0" + which-module "^2.0.0" + y18n "^3.2.1 || ^4.0.0" + yargs-parser "^11.1.1" + +yeast@0.1.2: + version "0.1.2" + resolved "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" + integrity sha1-AI4G2AlDIMNy28L47XagymyKxBk= + +yui@^3.18.1: + version "3.18.1" + resolved "https://registry.npmjs.org/yui/-/yui-3.18.1.tgz#e000269ec0a7b6fbc741cbb8fcbd0e65117b014c" + integrity sha1-4AAmnsCntvvHQcu4/L0OZRF7AUw= + dependencies: + request "~2.40.0" + +yuidocjs@^0.10.0: + version "0.10.2" + resolved "https://registry.npmjs.org/yuidocjs/-/yuidocjs-0.10.2.tgz#33924967ce619024cd70ef694e267d2f988f73f6" + integrity sha1-M5JJZ85hkCTNcO9pTiZ9L5iPc/Y= + dependencies: + express "^4.13.1" + graceful-fs "^4.1.2" + markdown-it "^4.3.0" + mdn-links "^0.1.0" + minimatch "^3.0.2" + rimraf "^2.4.1" + yui "^3.18.1" diff --git a/yuidoc.json b/yuidoc.json new file mode 100644 index 00000000000..c77156e0d5a --- /dev/null +++ b/yuidoc.json @@ -0,0 +1,15 @@ +{ + "name": "The ember-data API", + "description": "The ember-data API: a data persistence library for Ember.js", + "url": "https://github.com/emberjs/data", + "options": { + "enabledEnvironments": ["production"], + "extension": ".js,.ts", + "paths": [ + "addon", + "node_modules/ember-inflector/addon" + ], + "exclude": "vendor", + "outdir": "docs" + } +}