-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from basics/beta
Beta
- Loading branch information
Showing
38 changed files
with
1,398 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
lts/* | ||
stable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
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), | ||
complete: () => done() | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
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), | ||
complete: () => done() | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
}) | ||
); | ||
}; |
Oops, something went wrong.