From 563b94d98dd82a5e9b7d3625cb6d507939aa8cce Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Mon, 20 Jun 2022 10:03:36 +0200 Subject: [PATCH 01/14] added indexeddb adapter instead of idb --- addon/pouchdb.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/addon/pouchdb.js b/addon/pouchdb.js index b7b6a04..fe97a5a 100644 --- a/addon/pouchdb.js +++ b/addon/pouchdb.js @@ -1,7 +1,18 @@ -import PouchDB from 'pouchdb-browser'; +import PouchDB from 'pouchdb-core'; import PouchDBFind from 'pouchdb-find'; import PouchDBRelational from 'relational-pouch'; +import indexeddb from 'pouchdb-adapter-indexeddb'; +import HttpPouch from 'pouchdb-adapter-http'; +import mapreduce from 'pouchdb-mapreduce'; +import replication from 'pouchdb-replication'; -PouchDB.plugin(PouchDBFind).plugin(PouchDBRelational); +PouchDB + .plugin(PouchDBFind) + .plugin(PouchDBRelational) + .plugin(indexeddb) + .plugin(HttpPouch) + .plugin(mapreduce) + .plugin(replication) + ; export default PouchDB; From 09f1cd2cffb02fbf64befb1e2569545feb6987c8 Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Mon, 28 Nov 2022 17:21:46 +0100 Subject: [PATCH 02/14] default blueprint to generate adapters/application.js with new PouchDB.plugin setup and addPackagesToProject to install required npm packages --- blueprints/ember-pouch/index.js | 24 +++++++++++++++++++ .../files/__root__/adapters/__name__.js | 18 +++++++++++++- package.json | 12 ++++++---- tests/dummy/app/adapters/application.js | 2 +- tests/dummy/app/adapters/taco-salad.js | 2 +- {addon => tests/dummy/app}/pouchdb.js | 0 6 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 blueprints/ember-pouch/index.js rename {addon => tests/dummy/app}/pouchdb.js (100%) diff --git a/blueprints/ember-pouch/index.js b/blueprints/ember-pouch/index.js new file mode 100644 index 0000000..0054ab6 --- /dev/null +++ b/blueprints/ember-pouch/index.js @@ -0,0 +1,24 @@ + +const path = require('path'); + +module.exports = { + normalizeEntityName() { + return 'application'; + }, + + filesPath() { + return path.join(this.path, '../pouch-adapter/files'); + }, + + afterInstall: function(options) { + this.addPackagesToProject([ + { name: 'pouchdb-core' }, + { name: 'pouchdb-adapter-indexeddb' }, + { name: 'pouchdb-adapter-http' }, + { name: 'pouchdb-mapreduce' }, + { name: 'pouchdb-replication' }, + { name: 'pouchdb-find' }, + { name: 'relational-pouch' }, + ]); + }, +}; diff --git a/blueprints/pouch-adapter/files/__root__/adapters/__name__.js b/blueprints/pouch-adapter/files/__root__/adapters/__name__.js index d47d7da..464af1e 100644 --- a/blueprints/pouch-adapter/files/__root__/adapters/__name__.js +++ b/blueprints/pouch-adapter/files/__root__/adapters/__name__.js @@ -1,9 +1,25 @@ import config from '<%= dasherizedPackageName %>/config/environment'; -import PouchDB from 'ember-pouch/pouchdb'; import { Adapter } from 'ember-pouch'; import { assert } from '@ember/debug'; import { isEmpty } from '@ember/utils'; +import PouchDB from 'pouchdb-core'; +import PouchDBFind from 'pouchdb-find'; +import PouchDBRelational from 'relational-pouch'; +import indexeddb from 'pouchdb-adapter-indexeddb'; +import HttpPouch from 'pouchdb-adapter-http'; +import mapreduce from 'pouchdb-mapreduce'; +import replication from 'pouchdb-replication'; + +PouchDB + .plugin(PouchDBFind) + .plugin(PouchDBRelational) + .plugin(indexeddb) + .plugin(HttpPouch) + .plugin(mapreduce) + .plugin(replication) + ; + export default class ApplicationAdapter extends Adapter { constructor() { diff --git a/package.json b/package.json index 7c6f2bb..34818d7 100644 --- a/package.json +++ b/package.json @@ -40,10 +40,7 @@ }, "dependencies": { "ember-auto-import": "~2.4.2", - "ember-cli-babel": "^7.26.11", - "pouchdb-browser": "^7.3.0", - "pouchdb-find": "^7.3.0", - "relational-pouch": "^4.0.0" + "ember-cli-babel": "^7.26.11" }, "devDependencies": { "@ember/optional-features": "^2.0.0", @@ -83,6 +80,13 @@ "license-checker": "^25.0.1", "loader.js": "^4.7.0", "npm-run-all": "^4.1.5", + "pouchdb-core": "^7.3.1", + "pouchdb-adapter-indexeddb": "^7.3.1", + "pouchdb-adapter-http": "^7.3.1", + "pouchdb-mapreduce": "^7.3.1", + "pouchdb-replication": "^7.3.1", + "pouchdb-find": "^7.3.1", + "relational-pouch": "^4.0.1", "prettier": "^2.6.1", "qunit": "^2.18.0", "qunit-dom": "^2.0.0", diff --git a/tests/dummy/app/adapters/application.js b/tests/dummy/app/adapters/application.js index 67082b0..695a07c 100644 --- a/tests/dummy/app/adapters/application.js +++ b/tests/dummy/app/adapters/application.js @@ -2,7 +2,7 @@ import { defer } from 'rsvp'; import { assert } from '@ember/debug'; import { isEmpty } from '@ember/utils'; import { Adapter } from 'ember-pouch'; -import PouchDB from 'ember-pouch/pouchdb'; +import PouchDB from 'dummy/pouchdb'; import config from 'dummy/config/environment'; function createDb() { diff --git a/tests/dummy/app/adapters/taco-salad.js b/tests/dummy/app/adapters/taco-salad.js index 5d1fd19..7c94759 100644 --- a/tests/dummy/app/adapters/taco-salad.js +++ b/tests/dummy/app/adapters/taco-salad.js @@ -2,7 +2,7 @@ import { run } from '@ember/runloop'; import { assert } from '@ember/debug'; import { isEmpty } from '@ember/utils'; import { Adapter } from 'ember-pouch'; -import PouchDB from 'ember-pouch/pouchdb'; +import PouchDB from 'dummy/pouchdb'; import config from 'dummy/config/environment'; function createDb() { diff --git a/addon/pouchdb.js b/tests/dummy/app/pouchdb.js similarity index 100% rename from addon/pouchdb.js rename to tests/dummy/app/pouchdb.js From 387777e3ae671c80921cc8d41f66f120e0f91e98 Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Tue, 29 Nov 2022 11:52:24 +0100 Subject: [PATCH 03/14] Document changes in version 8 --- README.md | 32 +++++++++++++++++++++++++++----- package.json | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e9ae5d9..0f5696c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Ember Pouch [![Build Status](https://travis-ci.org/pouchdb-community/ember-pouch.svg)](https://travis-ci.org/pouchdb-community/ember-pouch) [![GitHub version](https://badge.fury.io/gh/pouchdb-community%2Fember-pouch.svg)](https://badge.fury.io/gh/pouchdb-community%2Fember-pouch) [![Ember Observer Score](https://emberobserver.com/badges/ember-pouch.svg)](https://emberobserver.com/addons/ember-pouch) -[**Changelog**](#changelog) +- [**Changelog**](#changelog) +- [**Upgrading**](#upgrading) Ember Pouch is a PouchDB/CouchDB adapter for Ember Data 3.16+. For older Ember Data versions down to 2.0+ use Ember Pouch version 7.0 For Ember Data versions lower than 2.0+ use Ember Pouch version 3.2.2. @@ -36,7 +37,6 @@ npm install ember-pouch@3.2.2 --save-dev This provides -- `import PouchDB from 'ember-pouch/pouchdb';` - `import {Model, Adapter, Serializer} from 'ember-pouch'` `Ember-Pouch` requires you to add a `@attr('string') rev` field to all your models. This is for PouchDB/CouchDB to handle revisions: @@ -67,6 +67,9 @@ export default class TodoModel extends Model { } ``` +The installation creates a file `adapters/application.js` that you can use by default to setup the database connection. Look at the [Adapter blueprint](#adapter) section to see the settings that you have to set in your config file to work with this adapter. +It also installs the required packages. + ## Configuring /app/adapters/application.js A local PouchDB that syncs with a remote CouchDB looks like this: @@ -119,10 +122,10 @@ Replace `` with the name of your model and the file will automatical ### Adapter -You can now create an adapter using ember-cli's blueprint functionality. Once you've installed `ember-pouch` into your ember-cli app you can run the following command to automatically generate an application adapter. +You can now create an adapter using ember-cli's blueprint functionality. Once you've installed `ember-pouch` into your ember-cli app you can run the following command to automatically generate an adapter. ``` -ember g pouch-adapter application +ember g pouch-adapter foo ``` Now you can store your localDb and remoteDb names in your ember-cli's config. Just add the following keys to the `ENV` object: @@ -132,6 +135,10 @@ ENV.emberPouch.localDb = 'test'; ENV.emberPouch.remoteDb = 'http://localhost:5984/my_couch'; ``` +This blueprint is run on installation for the `application` adapter. + +You can use multiple adapters, but be warned that doing the `.plugin` calls in multiple adapter files will result in errors: `TypeError: Cannot redefine property: replicate`. In this case it is better to move the `PouchDB.plugin` calls to a separate file. + ## Relationships EmberPouch supports both `hasMany` and `belongsTo` relationships. @@ -544,6 +551,18 @@ Following the CouchDB consistency model, we have introduced `ENV.emberPouch.even `findRecord` now returns a long running Promise if the record is not found. It only rejects the promise if a deletion of the record is found. Otherwise this promise will wait for eternity to resolve. This makes sure that belongsTo relations that have been loaded in an unexpected order will still resolve correctly. This makes sure that ember-data does not set the belongsTo to null if the Pouch replicate would have loaded the related object later on. (This only works for async belongsTo, sync versions will need this to be implemented in relational-pouch) +## Upgrading + +### Version 8 + +Version 8 introduces the custom PouchDB setup in the adapter instead of having a default setup in `addon/pouchdb.js`. So if you used `import PouchDB from 'ember-pouch/pouchdb'` in your files, you now have to make your own 'PouchDB bundle' in the same way we do it in the default adapter blueprint. The simplest way to do this is to run the blueprint by doing `ember g ember-pouch` (which will overwrite your application adapter, so make sure to commit that file first) and take the `import PouchDB from...` until the final `.plugin(...)` line and put that into your original adapter (or a separate file if you use more than one adapter). +You can also copy the lines from [the blueprint file in git](https://github.com/pouchdb-community/ember-pouch/blob/master/blueprints/pouch-adapter/files/__root__/adapters/__name__.js) + +We also removed the pouchdb-browser package and relational-pouch as a package.json dependency, so you will have to install the packages since the lines above depend upon. +`npm install pouchdb-core pouchdb-adapter-indexeddb pouchdb-adapter-http pouchdb-mapreduce pouchdb-replication pouchdb-find relational-pouch --save-dev` + +This way you can now decide for yourself which PouchDB plugins you want to use. You can even remove the http or indexeddb ones if you just want to work offline or online. + ## Installation - `git clone` this repository @@ -572,7 +591,10 @@ This project was originally based on the [ember-data-hal-adapter](https://github And of course thanks to all our wonderful contributors, [here](https://github.com/pouchdb-community/ember-pouch/graphs/contributors) and [in Relational Pouch](https://github.com/pouchdb-community/relational-pouch/graphs/contributors)! ## Changelog - +- **8.0.0-beta.2** + - Set PouchDb indexeddb adapter as default instead of idb adapter to use native views + - Generate adapters/application.js at installation + - move package.json dependencies to default blueprint - **8.0.0-beta.1** - Updated to support latest Ember 4.x (fixed isDeleted issues) - Switch to PouchDB 7.3.0. Getting ready to use the indexeddb-adapter diff --git a/package.json b/package.json index 34818d7..363c8e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ember-pouch", - "version": "8.0.0-beta.1", + "version": "8.0.0-beta.2", "description": "PouchDB adapter for Ember Data", "keywords": [ "ember-addon", From 07f9128413eec780ae87bf3e6529e090fb319f8c Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Tue, 29 Nov 2022 12:29:58 +0100 Subject: [PATCH 04/14] linting --- blueprints/ember-pouch/index.js | 5 ++--- .../pouch-adapter/files/__root__/adapters/__name__.js | 6 ++---- tests/dummy/app/pouchdb.js | 6 ++---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/blueprints/ember-pouch/index.js b/blueprints/ember-pouch/index.js index 0054ab6..e281cb2 100644 --- a/blueprints/ember-pouch/index.js +++ b/blueprints/ember-pouch/index.js @@ -1,16 +1,15 @@ - const path = require('path'); module.exports = { normalizeEntityName() { return 'application'; }, - + filesPath() { return path.join(this.path, '../pouch-adapter/files'); }, - afterInstall: function(options) { + afterInstall(/*options*/) { this.addPackagesToProject([ { name: 'pouchdb-core' }, { name: 'pouchdb-adapter-indexeddb' }, diff --git a/blueprints/pouch-adapter/files/__root__/adapters/__name__.js b/blueprints/pouch-adapter/files/__root__/adapters/__name__.js index 464af1e..185578b 100644 --- a/blueprints/pouch-adapter/files/__root__/adapters/__name__.js +++ b/blueprints/pouch-adapter/files/__root__/adapters/__name__.js @@ -11,14 +11,12 @@ import HttpPouch from 'pouchdb-adapter-http'; import mapreduce from 'pouchdb-mapreduce'; import replication from 'pouchdb-replication'; -PouchDB - .plugin(PouchDBFind) +PouchDB.plugin(PouchDBFind) .plugin(PouchDBRelational) .plugin(indexeddb) .plugin(HttpPouch) .plugin(mapreduce) - .plugin(replication) - ; + .plugin(replication); export default class ApplicationAdapter extends Adapter { diff --git a/tests/dummy/app/pouchdb.js b/tests/dummy/app/pouchdb.js index fe97a5a..e4e0df2 100644 --- a/tests/dummy/app/pouchdb.js +++ b/tests/dummy/app/pouchdb.js @@ -6,13 +6,11 @@ import HttpPouch from 'pouchdb-adapter-http'; import mapreduce from 'pouchdb-mapreduce'; import replication from 'pouchdb-replication'; -PouchDB - .plugin(PouchDBFind) +PouchDB.plugin(PouchDBFind) .plugin(PouchDBRelational) .plugin(indexeddb) .plugin(HttpPouch) .plugin(mapreduce) - .plugin(replication) - ; + .plugin(replication); export default PouchDB; From 65b72d67f75b060a86700734e5df3ce2eb3b23fd Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Wed, 30 Nov 2022 17:21:42 +0100 Subject: [PATCH 05/14] new ember-data delete fix --- addon/adapters/pouch.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index 1eaeebc..5e2da28 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -135,13 +135,22 @@ export default class PouchAdapter extends RESTAdapter.extend({ if (change.deleted) { if (this.fixDeleteBug) { - if ( - recordInStore._internalModel._recordData && - recordInStore._internalModel._recordData.setIsDeleted - ) { - recordInStore._internalModel._recordData.setIsDeleted(true); + if (recordInStore._internalModel) { + if ( + recordInStore._internalModel._recordData && + recordInStore._internalModel._recordData.setIsDeleted + ) { + recordInStore._internalModel._recordData.setIsDeleted(true); + } + recordInStore._internalModel.transitionTo('deleted.saved'); //work around ember-data bug + } else if (recordInStore.___recordState && + recordInStore.___recordState.recordData && + recordInStore.___recordState.recordData.setIsDeleted && + recordInStore.store._join) { + recordInStore.___recordState.recordData.setIsDeleted(true); + + recordInStore.store._join(() => recordInStore.___recordState.recordData.didCommit(null)); } - recordInStore._internalModel.transitionTo('deleted.saved'); //work around ember-data bug } else { store.unloadRecord(recordInStore); } From 4a846f3a840ebef224c8cb06fe291c1c7451daef Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Wed, 30 Nov 2022 17:22:06 +0100 Subject: [PATCH 06/14] npm with ember-try --- config/ember-try.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/ember-try.js b/config/ember-try.js index ea9377f..f45f55c 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -5,7 +5,7 @@ const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup'); module.exports = async function () { return { - useYarn: true, + useYarn: false, scenarios: [ { name: 'ember-lts-3.16', From 374e5649673adf47df4b45c19d9126613dc8b102 Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Wed, 30 Nov 2022 17:27:38 +0100 Subject: [PATCH 07/14] lint --- addon/adapters/pouch.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index 5e2da28..c419fc0 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -143,13 +143,17 @@ export default class PouchAdapter extends RESTAdapter.extend({ recordInStore._internalModel._recordData.setIsDeleted(true); } recordInStore._internalModel.transitionTo('deleted.saved'); //work around ember-data bug - } else if (recordInStore.___recordState && - recordInStore.___recordState.recordData && - recordInStore.___recordState.recordData.setIsDeleted && - recordInStore.store._join) { + } else if ( + recordInStore.___recordState && + recordInStore.___recordState.recordData && + recordInStore.___recordState.recordData.setIsDeleted && + recordInStore.store._join + ) { recordInStore.___recordState.recordData.setIsDeleted(true); - - recordInStore.store._join(() => recordInStore.___recordState.recordData.didCommit(null)); + + recordInStore.store._join(() => + recordInStore.___recordState.recordData.didCommit(null) + ); } } else { store.unloadRecord(recordInStore); From 42732e4a3da651c1a18a4db68b54e34d713aa625 Mon Sep 17 00:00:00 2001 From: jlami Date: Mon, 5 Dec 2022 09:55:23 +0100 Subject: [PATCH 08/14] node 12 -> 14 --- .github/workflows/node.js.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 636818f..d096b6d 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -23,7 +23,7 @@ jobs: - name: Install Nod uses: actions/setup-node@v3 with: - node-version: 12.x + node-version: 14.x # cache: npm - name: Install dependencies run: | @@ -47,7 +47,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 12.x + node-version: 14.x # cache: npm - name: Install Dependencies run: npm install --no-shrinkwrap @@ -78,7 +78,7 @@ jobs: - name: Install Node uses: actions/setup-node@v3 with: - node-version: 12.x + node-version: 14.x # cache: npm - name: Install dependencies run: | @@ -90,4 +90,4 @@ jobs: npm i fi - name: Run Tests - run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }} \ No newline at end of file + run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }} From 7ff8f6e84eb22aa33ffd518a7b1485666a125f20 Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Mon, 5 Dec 2022 10:26:49 +0100 Subject: [PATCH 09/14] client destroyRecord with custom adapterOption serverPush instead of custom hacks for server side deletes --- addon/adapters/pouch.js | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index c419fc0..490d5ee 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -134,30 +134,7 @@ export default class PouchAdapter extends RESTAdapter.extend({ } if (change.deleted) { - if (this.fixDeleteBug) { - if (recordInStore._internalModel) { - if ( - recordInStore._internalModel._recordData && - recordInStore._internalModel._recordData.setIsDeleted - ) { - recordInStore._internalModel._recordData.setIsDeleted(true); - } - recordInStore._internalModel.transitionTo('deleted.saved'); //work around ember-data bug - } else if ( - recordInStore.___recordState && - recordInStore.___recordState.recordData && - recordInStore.___recordState.recordData.setIsDeleted && - recordInStore.store._join - ) { - recordInStore.___recordState.recordData.setIsDeleted(true); - - recordInStore.store._join(() => - recordInStore.___recordState.recordData.didCommit(null) - ); - } - } else { - store.unloadRecord(recordInStore); - } + recordInStore.destroyRecord({adapterOptions: { serverPush: true }}); } else { recordInStore.reload(); } @@ -574,6 +551,8 @@ export default class PouchAdapter extends RESTAdapter.extend({ }, deleteRecord: async function (store, type, record) { + if (record.adapterOptions.serverPush) return; + await this._init(store, type); var data = this._recordToData(store, type, record); return this.db.rel From afe51a47c5e80b2e86cef5da6dccdc27c3168a79 Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Mon, 5 Dec 2022 10:54:29 +0100 Subject: [PATCH 10/14] ember-try 4.4 lts --- .github/workflows/node.js.yml | 1 + config/ember-try.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index d096b6d..79dd583 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -66,6 +66,7 @@ jobs: - ember-lts-3.16 - ember-lts-3.24 - ember-lts-3.28 + - ember-lts-4.4 - ember-release - ember-beta - ember-canary diff --git a/config/ember-try.js b/config/ember-try.js index f45f55c..40bb1ae 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -34,6 +34,15 @@ module.exports = async function () { }, }, }, + { + name: 'ember-lts-4.4', + npm: { + devDependencies: { + 'ember-source': '~4.4.0', + 'ember-data': '~4.4.0', + }, + }, + }, { name: 'ember-release', npm: { From f0420a921aff717204ab5388806fde00b8d1ef19 Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Mon, 5 Dec 2022 10:58:41 +0100 Subject: [PATCH 11/14] linting --- addon/adapters/pouch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index 490d5ee..99fb82b 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -134,7 +134,7 @@ export default class PouchAdapter extends RESTAdapter.extend({ } if (change.deleted) { - recordInStore.destroyRecord({adapterOptions: { serverPush: true }}); + recordInStore.destroyRecord({ adapterOptions: { serverPush: true } }); } else { recordInStore.reload(); } @@ -552,7 +552,7 @@ export default class PouchAdapter extends RESTAdapter.extend({ deleteRecord: async function (store, type, record) { if (record.adapterOptions.serverPush) return; - + await this._init(store, type); var data = this._recordToData(store, type, record); return this.db.rel From 93755865acb5598ece73175166530e21da4d574d Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Mon, 5 Dec 2022 11:20:42 +0100 Subject: [PATCH 12/14] onChange returns promise so test adapter can wait for it --- addon/adapters/pouch.js | 8 +++++--- tests/dummy/app/adapters/application.js | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index 99fb82b..ac008cb 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -134,9 +134,11 @@ export default class PouchAdapter extends RESTAdapter.extend({ } if (change.deleted) { - recordInStore.destroyRecord({ adapterOptions: { serverPush: true } }); + return recordInStore.destroyRecord({ + adapterOptions: { serverPush: true }, + }); } else { - recordInStore.reload(); + return recordInStore.reload(); } }, @@ -551,7 +553,7 @@ export default class PouchAdapter extends RESTAdapter.extend({ }, deleteRecord: async function (store, type, record) { - if (record.adapterOptions.serverPush) return; + if (record.adapterOptions && record.adapterOptions.serverPush) return; await this._init(store, type); var data = this._recordToData(store, type, record); diff --git a/tests/dummy/app/adapters/application.js b/tests/dummy/app/adapters/application.js index 695a07c..cb2c152 100644 --- a/tests/dummy/app/adapters/application.js +++ b/tests/dummy/app/adapters/application.js @@ -43,9 +43,9 @@ export default class ApplicationAdapter extends Adapter { } onChangeListenerTest = null; - onChange() { + async onChange() { if (super.onChange) { - super.onChange(...arguments); + await super.onChange(...arguments); } if (this.onChangeListenerTest) { this.onChangeListenerTest(...arguments); From 29e86df42106081051bb086fabf0969184fae6ec Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Mon, 5 Dec 2022 11:46:13 +0100 Subject: [PATCH 13/14] only delete record in onChange if not already deleted (ember-data 3.16 and 3.24) --- addon/adapters/pouch.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index ac008cb..beaac29 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -134,9 +134,10 @@ export default class PouchAdapter extends RESTAdapter.extend({ } if (change.deleted) { - return recordInStore.destroyRecord({ - adapterOptions: { serverPush: true }, - }); + if (!recordInStore.isSaving && !recordInStore.isDeleted) + return recordInStore.destroyRecord({ + adapterOptions: { serverPush: true }, + }); } else { return recordInStore.reload(); } From 872f36d0ab332dbca01e36c2c556ee2014dfe2eb Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Mon, 5 Dec 2022 12:11:18 +0100 Subject: [PATCH 14/14] document fixDeleteBug remove ember-auto-import from devDependencies --- README.md | 1 + addon/adapters/pouch.js | 1 - package.json | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f5696c..8b8b9ce 100644 --- a/README.md +++ b/README.md @@ -595,6 +595,7 @@ And of course thanks to all our wonderful contributors, [here](https://github.co - Set PouchDb indexeddb adapter as default instead of idb adapter to use native views - Generate adapters/application.js at installation - move package.json dependencies to default blueprint + - removed Adapter `fixDeleteBug` flag. We now do a client side `destroyRecord` with custom `adapterOptions` to signal to the ember-data store that the record is deleted. So no more hacking ember-data is needed in the addon to support the server pushed deletes. - **8.0.0-beta.1** - Updated to support latest Ember 4.x (fixed isDeleted issues) - Switch to PouchDB 7.3.0. Getting ready to use the indexeddb-adapter diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index beaac29..ad8bf0f 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -25,7 +25,6 @@ import { //}); export default class PouchAdapter extends RESTAdapter.extend({ - fixDeleteBug: true, coalesceFindRequests: false, // The change listener ensures that individual records are kept up to date diff --git a/package.json b/package.json index 363c8e5..d716d10 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,6 @@ "@glimmer/tracking": "^1.0.4", "babel-eslint": "^10.1.0", "broccoli-asset-rev": "^3.0.0", - "ember-auto-import": "~2.4.2", "ember-cli": "~4.3.0", "ember-cli-app-version": "~5.0.0", "ember-cli-dependency-checker": "^3.2.0",