Skip to content

Commit

Permalink
Merge pull request #66 from basics/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
StephanGerbeth authored Oct 24, 2024
2 parents 32b937d + ea7ef96 commit 2c72f7f
Show file tree
Hide file tree
Showing 38 changed files with 1,398 additions and 269 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
/.env
/.DS_Store
.env
.DS_Store

/coverage
/.github_old
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/*
stable
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default [
languageOptions: {
globals: {
...globals.browser,
expect: 'readonly'
expect: 'readonly',
global: 'readonly'
}
},
plugins: {
Expand Down
946 changes: 775 additions & 171 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@
"@semantic-release/changelog": "6.0.3",
"@semantic-release/commit-analyzer": "13.0.0",
"@semantic-release/git": "10.0.1",
"@semantic-release/github": "10.3.4",
"@semantic-release/github": "10.3.5",
"@semantic-release/npm": "12.0.1",
"@semantic-release/release-notes-generator": "14.0.1",
"@vitest/coverage-v8": "2.1.1",
"commitlint": "19.5.0",
"eslint": "9.10.0",
"eslint": "9.11.1",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-no-secrets": "1.0.2",
"eslint-plugin-perfectionist": "3.6.0",
"eslint-plugin-perfectionist": "3.8.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-security": "3.0.1",
"eslint-plugin-vitest": "0.5.4",
"fetch-mock": "11.1.3",
"fetch-mock": "12.0.0",
"happy-dom": "15.7.4",
"husky": "9.1.6",
"lint-staged": "15.2.10",
"prettier": "3.3.3",
"semantic-release": "24.1.1",
"semantic-release": "24.1.2",
"semantic-release-monorepo": "8.0.2",
"vitest": "2.1.1"
}
Expand Down
10 changes: 1 addition & 9 deletions packages/observables/.releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "./packages/observables/",
"label": "observables"
}
]
}
"@semantic-release/github"
]
],
"extends": "semantic-release-monorepo"
Expand Down
7 changes: 7 additions & 0 deletions packages/observables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Project Changelog

# [@rxjs-collection/observables-v1.0.4-beta.1](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/observables-v1.0.3...@rxjs-collection/observables-v1.0.4-beta.1) (2024-10-24)


### Bug Fixes

* **fetch:** added fetch operators ([e248db8](https://github.com/basics/rxjs-collection/commit/e248db81cd681366c0654f30a2b0f664e1e30a5c))

# [@rxjs-collection/observables-v1.0.3](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/observables-v1.0.2...@rxjs-collection/observables-v1.0.3) (2024-09-20)


Expand Down
2 changes: 1 addition & 1 deletion packages/observables/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxjs-collection/observables",
"version": "1.0.3",
"version": "1.0.4-beta.1",
"description": "rxjs observables",
"license": "MIT",
"contributors": [
Expand Down
9 changes: 0 additions & 9 deletions packages/observables/src/fetch/request.http

This file was deleted.

8 changes: 0 additions & 8 deletions packages/observables/src/fetch/request.js

This file was deleted.

34 changes: 0 additions & 34 deletions packages/observables/src/fetch/request.test.js

This file was deleted.

20 changes: 20 additions & 0 deletions packages/operators/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Project Changelog

# [@rxjs-collection/operators-v1.0.3-beta.2](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/operators-v1.0.3-beta.1...@rxjs-collection/operators-v1.0.3-beta.2) (2024-10-24)


### Bug Fixes

* **deps:** pin dependencies ([dfd1950](https://github.com/basics/rxjs-collection/commit/dfd1950821e2a1436bcd0dfde45b5b07c63dd2b8))

# [@rxjs-collection/operators-v1.0.3-beta.1](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/operators-v1.0.2...@rxjs-collection/operators-v1.0.3-beta.1) (2024-10-24)


### Bug Fixes

* **fetch:** added fetch operators ([e248db8](https://github.com/basics/rxjs-collection/commit/e248db81cd681366c0654f30a2b0f664e1e30a5c))
* **fetch:** added logs and cleanup ([025ea93](https://github.com/basics/rxjs-collection/commit/025ea930df68d7eb1cc28cd64c642e51f498c69c))
* **fetch:** added logs to test and cleanup ([3ef05aa](https://github.com/basics/rxjs-collection/commit/3ef05aa55345da1dd4dec416bb17554d5c457743))
* **fetch:** cleanup ([522f2ca](https://github.com/basics/rxjs-collection/commit/522f2ca06ea0d1141d596f31e9b626cfb71e8f31))
* **fetch:** cleanup ([c56babb](https://github.com/basics/rxjs-collection/commit/c56babbc77214eb589f5c0ef2e4ed8e854f0892c))
* **fetch:** cleanup tests ([3d20b2e](https://github.com/basics/rxjs-collection/commit/3d20b2e2daa5d64b708418dc7a694ad3ec47f0be))
* **fetch:** polling completed and cleanup of operators ([cc64c16](https://github.com/basics/rxjs-collection/commit/cc64c1631007c1ab659a4f559b4e946dc3f682ab))

# [@rxjs-collection/operators-v1.0.2](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/operators-v1.0.1...@rxjs-collection/operators-v1.0.2) (2024-09-20)


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion packages/operators/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxjs-collection/operators",
"version": "1.0.2",
"version": "1.0.3-beta.2",
"description": "rxjs operators",
"license": "MIT",
"contributors": [
Expand All @@ -19,6 +19,10 @@
},
"dependencies": {
"@rxjs-collection/observables": "*",
"fast-equals": "5.0.1",
"rxjs": "7.8.1"
},
"devDependencies": {
"node-fetch": "3.3.2"
}
}
21 changes: 21 additions & 0 deletions packages/operators/src/fetch/autoPagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { concatMap, expand, filter, from, map } from 'rxjs';

import { download } from './download';

export const autoPagination = ({ resolveRoute }) => {
return source =>
source.pipe(
concatMap(({ url }) => {
return from(resolveRoute(url)).pipe(
download(),
expand(resp =>
from(resolveRoute(url, resp)).pipe(
filter(url => !!url),
download()
)
)
);
}),
map(resp => resp.clone())
);
};
42 changes: 42 additions & 0 deletions packages/operators/src/fetch/autoPagination.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { concatAll, map, of } from 'rxjs';
import { beforeEach, describe, expect, test } from 'vitest';

Check warning on line 2 in packages/operators/src/fetch/autoPagination.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

'expect' is defined but never used

import { log } from '../log';
import { autoPagination } from './autoPagination';
import { resolveJSON } from './resolve';

describe('auto pagination', function () {
beforeEach(function () {
//
});

test('auto pagination', async function () {
return new Promise(done => {
return of({ url: new URL('https://dummyjson.com/products') })
.pipe(
autoPagination({
resolveRoute: async (url, resp) => {
const data = (await resp?.json()) || { skip: -10, limit: 10 };

if (!data.total || data.total > data.skip + data.limit) {
const newUrl = new URL(`${url}`);
newUrl.searchParams.set('skip', data.skip + data.limit);
newUrl.searchParams.set('limit', data.limit);
newUrl.searchParams.set('select', 'title,price');
return newUrl;
}
}
}),
log(false),
resolveJSON(),
log(false),
map(({ products }) => products),
concatAll()
)
.subscribe({
next: e => console.log(e),

Check warning on line 37 in packages/operators/src/fetch/autoPagination.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement
complete: () => done()
});
});
});
});
7 changes: 7 additions & 0 deletions packages/operators/src/fetch/concurrentDownload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { mergeMap, of } from 'rxjs';

import { download } from './download';

export const concurrentDownload = (concurrent = 1) => {
return source => source.pipe(mergeMap(url => of(url).pipe(download()), concurrent));
};
40 changes: 40 additions & 0 deletions packages/operators/src/fetch/concurrentDownload.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { concatAll, map, of } from 'rxjs';
import { beforeEach, describe, expect, test } from 'vitest';

Check warning on line 2 in packages/operators/src/fetch/concurrentDownload.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

'expect' is defined but never used

import { log } from '../log';
import { concurrentDownload } from './concurrentDownload';
import { resolveJSON } from './resolve';

describe('multi fetch', function () {
beforeEach(function () {
//
});

test('request pagination', async function () {
return new Promise(done => {
of(
new URL('https://dummyjson.com/products?limit=10&skip=0&select=title,price'),
new URL('https://dummyjson.com/products?limit=10&skip=10&select=title,price'),
new URL('https://dummyjson.com/products?limit=10&skip=20&select=title,price'),
new URL('https://dummyjson.com/products?limit=10&skip=30&select=title,price'),
new URL('https://dummyjson.com/products?limit=10&skip=40&select=title,price'),
new URL('https://dummyjson.com/products?limit=10&skip=50&select=title,price'),
new URL('https://dummyjson.com/products?limit=10&skip=60&select=title,price'),
new URL('https://dummyjson.com/products?limit=10&skip=70&select=title,price'),
new URL('https://dummyjson.com/products?limit=10&skip=80&select=title,price')
)
.pipe(
concurrentDownload(4),
log(false),
resolveJSON(),
log(false),
map(({ products }) => products),
concatAll()
)
.subscribe({
next: e => console.log(e),

Check warning on line 35 in packages/operators/src/fetch/concurrentDownload.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement
complete: () => done()
});
});
});
});
18 changes: 18 additions & 0 deletions packages/operators/src/fetch/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { request } from './request';
import { resolveBlob, resolveJSON, resolveText } from './resolve';

export const download = () => {
return source => source.pipe(request());
};

export const downloadJSON = () => {
return source => source.pipe(download(), resolveJSON());
};

export const downloadText = () => {
return source => source.pipe(download(), resolveText());
};

export const downloadBlob = () => {
return source => source.pipe(download(), resolveBlob());
};
46 changes: 46 additions & 0 deletions packages/operators/src/fetch/download.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import fetchMock from 'fetch-mock';
import { of } from 'rxjs';
import { afterEach, test, describe, beforeEach, expect } from 'vitest';

import { log } from '../log.js';
import { download, downloadJSON } from './download.js';
import { resolveJSON } from './resolve.js';

describe('download operator', function () {
beforeEach(function () {
fetchMock.mockGlobal().get(
'https://httpbin.org/my-url-fast',
() => {
return new Response(JSON.stringify({ hello: 'fast world' }), {
status: 200,
headers: { 'Content-type': 'application/json' }
});
},
{ delay: 1000 }
);
});

afterEach(function () {
fetchMock.unmockGlobal();
});

test('successfull download - indirect json resolve', () =>
new Promise(done => {
of('https://httpbin.org/my-url-fast')
.pipe(download(), log(false), resolveJSON(), log(false))
.subscribe({
next: data => expect(data).deep.equal({ hello: 'fast world' }),
complete: () => done()
});
}));

test('successfull download - direct json resolve', () =>
new Promise(done => {
of('https://httpbin.org/my-url-fast')
.pipe(downloadJSON(), log(false))
.subscribe({
next: data => expect(data).deep.equal({ hello: 'fast world' }),
complete: () => done()
});
}));
});
15 changes: 15 additions & 0 deletions packages/operators/src/fetch/lazyPagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { concatMap, map } from 'rxjs';

import { concurrentDownload } from './concurrentDownload';

export const lazyPagination = ({ resolveRoute }) => {
return source =>
source.pipe(
concatMap(({ url, pager, concurrent }) => {
return pager.pipe(
map(options => resolveRoute(url, options)),
concurrentDownload(concurrent)
);
})
);
};
Loading

0 comments on commit 2c72f7f

Please sign in to comment.