Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE immutable documents #4189

Merged
merged 35 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bbf38fe
CHANGE immutable documents step1
pubkey Dec 20, 2022
78f10da
FIX tests
pubkey Dec 20, 2022
398ca2c
FIX more tests
pubkey Dec 20, 2022
b6df263
FIX more tests
pubkey Dec 20, 2022
dd33908
FIX more tests
pubkey Dec 20, 2022
b1b83ca
FIX more tests
pubkey Dec 20, 2022
0a3605c
FIX tests
pubkey Dec 20, 2022
4dd66d2
FIX tests
pubkey Dec 20, 2022
f4bb9d9
FIX docs
pubkey Dec 20, 2022
4a7f792
FIX tests
pubkey Dec 20, 2022
1f08e77
FIX tests
pubkey Dec 20, 2022
b384048
ADD changelog
pubkey Dec 20, 2022
6bada0c
FIX tests
pubkey Dec 20, 2022
4641809
FIX types
pubkey Dec 20, 2022
613b588
FIX deps
pubkey Dec 20, 2022
35a16dc
UPDATE typescript
pubkey Dec 20, 2022
79a3acc
UPDATE angular
pubkey Dec 20, 2022
0e82a94
UPDATE typescript
pubkey Dec 20, 2022
c18ed66
FIX typos
pubkey Dec 20, 2022
80e3bd5
UPDATE node
pubkey Dec 20, 2022
5ff0bf2
FIX angular
pubkey Dec 21, 2022
e021cc1
UPDATE @types/node
pubkey Dec 21, 2022
c5288df
REMOVE unmaintained babel-plugin-transform-async-to-promises
pubkey Dec 21, 2022
e317303
FIX angular tests
pubkey Dec 21, 2022
a84a575
FIX babel confict
pubkey Dec 21, 2022
4992d9b
ADD changelog
pubkey Dec 21, 2022
48af9f8
REMOVE comment
pubkey Dec 21, 2022
09e324e
UPDATE testcafe
pubkey Dec 21, 2022
5d38f38
TRY fix tests
pubkey Dec 21, 2022
46e14d9
FIX run headless
pubkey Dec 21, 2022
3dac600
TRY fix stuff
pubkey Dec 21, 2022
4c998d6
TRY ajax timeout
pubkey Dec 21, 2022
484a2ba
IMPROVE error log
pubkey Dec 21, 2022
23a2633
FIX stuff
pubkey Dec 21, 2022
fa2ff94
FIX closing of replication
pubkey Dec 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 9 additions & 37 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,6 @@ jobs:
- name: test:typings
run: npm run test:typings

storage-pouchdb:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set node version
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'

- name: Reuse npm cache folder
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: |
~/.npm
./node_modules
key: ${{ runner.os }}-npm-storage-pouchdb-x7-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-npm-storage-pouchdb-x7-

- name: install npm dependencies
run: npm install

- name: build
run: npm run build

- name: node example
working-directory: ./examples/node
run: |
npm install
npm run test


# run the node tests for the LokiJS RxStorage
storage-lokijs:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -174,6 +140,12 @@ jobs:

- run: npm run test:performance:memory:node

- name: node example
working-directory: ./examples/node
run: |
npm install
npm run test


storage-remote:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -335,7 +307,7 @@ jobs:
- run: npm run test:performance:foundationdb

angular:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
#- name: install dependencies
Expand Down Expand Up @@ -375,9 +347,9 @@ jobs:

- name: angular test
# uses: DevExpress/testcafe-action@latest
uses: GabrielBB/xvfb-action@v1
uses: GabrielBB/xvfb-action@v1.6
with:
working-directory: ./examples/angular #optional
working-directory: ./examples/angular
run: npm run test:build

- name: angular test ssr
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.4.0
v18.12.1
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
- FIX CouchDB replication: Use correct default fetch method.
- CHANGE use plain json errors inside of RxError parameters to make debugging easier.
- CHANGE crunch multiple incremental (aka 'atomic') operations into a single database write. Also batch writes to multiple documents into a single write.
- CHANGE Make RxDocuments immutable
- ADD `RxDocument.getLatest()`
- REMOVE deprecated `babel-plugin-transform-async-to-promises` plugin.

<!-- ADD new changes here! -->

Expand Down
19 changes: 2 additions & 17 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,8 @@ const plugins = [
'@babel/transform-block-scoping',
'@babel/plugin-transform-member-expression-literals',
'@babel/transform-property-literals',

/**
* Transpile async/await to promises instead of generators.
* This has shown to be 10% smaller build size and also be a bit faster.
*
*/
['babel-plugin-transform-async-to-promises', {
/**
* TODO use externalHelpers instead of inlineHelpers,
* but we have to wait for this bug to be fixed:
* @link https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/62
* @link https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/78
*/
externalHelpers: false,
inlineHelpers: true
}],

'@babel/transform-async-to-generator',
'@babel/transform-regenerator',
['@babel/transform-runtime', {
'regenerator': true
}],
Expand Down
2 changes: 1 addition & 1 deletion docs-src/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import '@babel/polyfill';

## Polyfill the `global` variable

When you use RxDB with **angular** or other **webpack** based frameworks, you might get the error <span style="color: red;">Uncaught ReferenceError: global is not defined</span>. This is because pouchdb assumes a nodejs-specific `global` variable that is not added to browser runtimes by some bundlers.
When you use RxDB with **angular** or other **webpack** based frameworks, you might get the error <span style="color: red;">Uncaught ReferenceError: global is not defined</span>. This is because some dependencies of RxDB assume a Node.js-specific `global` variable that is not added to browser runtimes by some bundlers.
You have to add them by your own, like we do [here](https://github.com/pubkey/rxdb/blob/master/examples/angular/src/polyfills.ts).

```ts
Expand Down
15 changes: 15 additions & 0 deletions docs-src/rx-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ console.log(myDocument.name); // 'Steve'
```


### getLatest()

Returns the latest known state of the `RxDocument`.

```js
const myDocument = await myCollection.findOne('foobar').exec();
const docAfterEdit = await myDocument.atomicPatch({
age: 10
});
const latestDoc = myDocument.getLatest();
console.log(docAfterEdit === latestDoc); // > true
```



### Observe $
Calling this will return an [rxjs-Observable](http://reactivex.io/rxjs/manual/overview.html#observable) which emits all change-Events belonging to this document.

Expand Down
13 changes: 13 additions & 0 deletions docs-src/tutorials/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,16 @@ console.log(amount);
myDatabase.destroy();
```



## Known Problems

RxDB uses the [WeakRef API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef). If your typescript bundler throws the error `TS2304: Cannot find name 'WeakRef'`, you have to add `ES2021.WeakRef` to `compilerOptions.lib` in your `tsconfig.json`.

```json
{
"compilerOptions": {
"lib": ["ES2020", "ES2021.WeakRef"]
}
}
```
47 changes: 23 additions & 24 deletions examples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build:serve9000": "ws -p 9000 -d dist/angular/",
"build:copy": "cp test/multitab.html dist/angular/browser/multitab.html",
"test": "testcafe chromium -e test/e2e.test.js --hostname localhost --selector-timeout 30000",
"test:ci": "testcafe chrome -e test/e2e.test.js --hostname localhost --selector-timeout 30000",
"test:ci": "testcafe chrome -e test/e2e.test.js --hostname localhost --selector-timeout 30000 --ajax-request-timeout 1000",
"test:build": "concurrently \"npm run server\" \"npm run build:serve\" \"npm run test:ci\" --kill-others --success first",
"// test:ssr": "TODO use npm run serve:ssr instead when bug is fixed",
"test:ssr": "concurrently \"npm run server\" \"npm run dev:ssr\" \"sleep 20 && ts-mocha --bail --exit ./test/ssr.test.ts\" --kill-others --success first",
Expand All @@ -34,24 +34,23 @@
"author": "pubkey",
"license": "MIT",
"dependencies": {
"@angular/animations": "14.2.12",
"@angular/cdk": "14.2.7",
"@angular/common": "14.2.12",
"@angular/compiler": "14.2.12",
"@angular/core": "14.2.12",
"@angular/forms": "14.2.12",
"@angular/material": "14.2.7",
"@angular/platform-browser": "14.2.12",
"@angular/platform-browser-dynamic": "14.2.12",
"@angular/platform-server": "14.2.12",
"@angular/pwa": "14.2.10",
"@angular/router": "14.2.12",
"@angular/service-worker": "14.2.12",
"@nguniversal/express-engine": "14.2.3",
"@angular/animations": "15.0.4",
"@angular/cdk": "15.0.3",
"@angular/common": "15.0.4",
"@angular/compiler": "15.0.4",
"@angular/core": "15.0.4",
"@angular/forms": "15.0.4",
"@angular/material": "15.0.3",
"@angular/platform-browser": "15.0.4",
"@angular/platform-browser-dynamic": "15.0.4",
"@angular/platform-server": "15.0.4",
"@angular/pwa": "15.0.4",
"@angular/router": "15.0.4",
"@angular/service-worker": "15.0.4",
"@nguniversal/express-engine": "15.0.0",
"assert": "2.0.0",
"express": "4.17.3",
"font-awesome": "4.7.0",
"material-design-icons": "3.0.1",
"mocha": "9.0.2",
"pouchdb-server": "4.2.0",
"roboto-npm-webfont": "1.0.1",
Expand All @@ -63,24 +62,24 @@
"zone.js": "0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "14.2.10",
"@angular/cli": "14.2.10",
"@angular/compiler-cli": "14.2.12",
"@angular/language-service": "14.2.12",
"@nguniversal/builders": "14.2.3",
"@angular-devkit/build-angular": "15.0.4",
"@angular/cli": "15.0.4",
"@angular/compiler-cli": "15.0.4",
"@angular/language-service": "15.0.4",
"@nguniversal/builders": "15.0.0",
"@types/express": "4.17.13",
"@types/mocha": "8.2.3",
"@types/node": "14.18.35",
"@types/node": "18.11.17",
"async-test-util": "2.0.0",
"concurrently": "7.6.0",
"copyfiles": "2.4.1",
"got": "11.8.6",
"local-web-server": "5.2.1",
"testcafe": "1.20.1",
"testcafe": "2.1.0",
"ts-mocha": "8.0.0",
"ts-node": "10.9.1",
"tslint": "6.1.3",
"typescript": "4.8.4",
"typescript": "4.9.4",
"webpack-bundle-analyzer": "4.5.0"
}
}
1 change: 1 addition & 0 deletions examples/angular/src/app/services/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ async function _create(): Promise<RxHeroesDatabase> {
ongoingReplication.error$.subscribe(err => {
console.log('Got replication error:');
console.dir(err);
console.error(err);
});
}

Expand Down
22 changes: 12 additions & 10 deletions examples/angular/test/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import AsyncTestUtil from 'async-test-util';

console.log('open page');

fixture `Example page`
.page `http://0.0.0.0:8888/`;
fixture`Example page`
.page`http://0.0.0.0:8888/`;


test.page('http://0.0.0.0:8888/')('insert/edit/remove a hero', async t => {
// clear previous heroes
const heroElements = Selector('.hero-list-component .mat-list-item');
const heroElements = Selector('.hero-list-component mat-list-item');
const amount = heroElements.count;
for (let i = 0; i < amount; i++) {
await t.click('.delete-button');
Expand All @@ -35,7 +35,7 @@ test.page('http://0.0.0.0:8888/')('insert/edit/remove a hero', async t => {
await t.click('.hero-insert-component button');
await AsyncTestUtil.wait(200);

const heroListElement = Selector('.hero-list-component .mat-list-item');
const heroListElement = Selector('.hero-list-component mat-list-item');
await t.expect(heroListElement.textContent).contains('Kelso', 'list-item contains name');


Expand All @@ -44,10 +44,10 @@ test.page('http://0.0.0.0:8888/')('insert/edit/remove a hero', async t => {

// set value
await t
.click('hero-edit .mat-input-element')
.click('hero-edit input[type=number]')
.pressKey('ctrl+a delete');
await t.typeText('hero-edit .mat-input-element', '11');
await t.click('.submitButton');
await t.typeText('hero-edit input[type=number]', '11');
await t.click('hero-edit .submitButton');
await AsyncTestUtil.wait(100);

// edit form should be closed
Expand Down Expand Up @@ -77,10 +77,10 @@ test.page('http://0.0.0.0:8888/multitab.html?frames=2')('multitab: insert hero a
// check if in other iframe
await t.switchToIframe('#frame_1');
await AsyncTestUtil.wait(100);
const heroElements = Selector('.hero-list-component .mat-list-item');
const heroElements = Selector('.hero-list-component mat-list-item');
await t.expect(heroElements.count).eql(1);

const heroListElement = Selector('.hero-list-component .mat-list-item:last-of-type');
const heroListElement = Selector('.hero-list-component mat-list-item:last-of-type');
await t.expect(heroListElement.textContent).contains('Irwin', 'list-item contains name');
});

Expand All @@ -90,13 +90,15 @@ test.page('http://0.0.0.0:8888/multitab.html?frames=' + tabsAmount)('leader-elec
// wait until last tab loaded
await t.switchToIframe('#frame_' + (tabsAmount - 1));
await AsyncTestUtil.wait(1000);
console.log('insert !!!');
const heroNameInput = Selector('.hero-insert-component #insert-name');
await t.typeText(heroNameInput, 'foobar');
await t.switchToMainWindow();

// wait until at least one becomes leader
let currentLeader = null;
await AsyncTestUtil.waitUntil(async () => {
console.log('await leader once!');
let ret = false;
for (let i = 0; i < tabsAmount; i++) {
await t.switchToIframe('#frame_' + i);
Expand All @@ -108,7 +110,7 @@ test.page('http://0.0.0.0:8888/multitab.html?frames=' + tabsAmount)('leader-elec
await t.switchToMainWindow();
}
return ret;
});
}, 10 * 1000, 100);

await AsyncTestUtil.wait(200); // w8 a bit
// ensure still only one is leader
Expand Down
17 changes: 13 additions & 4 deletions examples/angular/test/multitab.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,36 @@
height: 30%;
min-height: 500px;
}

</style>
</head>

<body>


<script>
window.removeFrame = function() {
window.removeFrame = function () {
var id = document.querySelector('#removeId').value;
var frame = document.querySelector('#frame_' + id);
console.log(frame);
frame.parentNode.removeChild(frame);
}
</script>
<input type="number" id="removeId" />
<input type="submit" id="submit" onclick="removeFrame();" />
<input
type="number"
id="removeId"
/>
<input
type="submit"
id="submit"
onclick="removeFrame();"
/>

<script>
var amount = parseInt(window.location.search.split('=')[1], 10);
if (isNaN(amount))
if (isNaN(amount)) {
amount = 2;
}
console.log(amount);
var t = 0;
while (t < amount) {
Expand Down
3 changes: 2 additions & 1 deletion examples/angular/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
],
"lib": [
"es2018",
"dom"
"dom",
"ES2021.WeakRef"
]
},
"angularCompilerOptions": {
Expand Down
2 changes: 1 addition & 1 deletion examples/supabase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"testcafe": "1.20.1",
"testcafe-hammerhead": "24.7.4",
"ts-loader": "9.3.1",
"typescript": "4.8.4",
"typescript": "4.9.4",
"webpack": "5.74.0",
"webpack-cli": "4.10.0",
"webpack-dev-server": "4.10.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/svelte/scripts/setupTypeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, {
"svelte-check": "^2.0.0",
"svelte-preprocess": "^4.0.0",
"@rollup/plugin-typescript": "^8.0.0",
"typescript": "^4.0.0",
"typescript": "4.9.4",
"tslib": "^2.0.0",
"@tsconfig/svelte": "^2.0.0"
})
Expand Down
Loading