Skip to content

Commit ed1d522

Browse files
committed
[add] Observable.fromStream() for Async Iterable transforming
[optimize] upgrade to PNPM 9, Husky 9 & other Upstream packages [optimize] support NPM provenance
1 parent 01ee217 commit ed1d522

File tree

10 files changed

+3738
-3293
lines changed

10 files changed

+3738
-3293
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ on:
66
jobs:
77
Build-and-Publish:
88
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
id-token: write
912
steps:
1013
- uses: actions/checkout@v3
1114

1215
- uses: pnpm/action-setup@v2
1316
with:
14-
version: 8
17+
version: 9
1518
- uses: actions/setup-node@v3
1619
with:
1720
node-version: 18
@@ -24,7 +27,7 @@ jobs:
2427
run: npm publish
2528
env:
2629
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
27-
30+
2831
- name: Update document
2932
uses: peaceiris/actions-gh-pages@v3
3033
with:

.husky/pre-commit

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
#!/bin/sh
2-
3-
. "$(dirname "$0")/_/husky.sh"
4-
51
npm test

.husky/pre-push

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
#!/bin/sh
2-
3-
. "$(dirname "$0")/_/husky.sh"
4-
51
npm run build

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
provenance = true
12
auto-install-peers = false

ReadMe.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const observable = new Observable(({ next, complete }) => {
2323
() => (++count < 5 ? next(count) : complete(count)),
2424
0
2525
);
26-
2726
return () => clearInterval(timer);
2827
});
2928

@@ -36,22 +35,39 @@ const observable = new Observable(({ next, complete }) => {
3635

3736
### Enhance Run-time platforms
3837

38+
#### Transform events
39+
3940
```javascript
4041
import { Observable } from 'iterable-observer';
4142

4243
const reader = new FileReader(),
43-
{
44-
files: [file]
45-
} = document.querySelector('input[type="file"]');
44+
{ files } = document.querySelector('input[type="file"]');
4645

47-
reader.readAsBlob(file);
46+
reader.readAsBlob(files[0]);
4847

4948
(async () => {
5049
for await (const { loaded } of Observable.fromEvent(reader, 'progress'))
5150
console.log((loaded / file.size) * 100 + '%');
5251
})();
5352
```
5453

54+
#### Transform streams
55+
56+
```typescript
57+
import { Observable } from 'iterable-observer';
58+
59+
(async () => {
60+
const { body } = await fetch('https://example.com/path/to/blob'),
61+
chunks: Uint8Array[] = [];
62+
63+
for await (const chunk of Observable.fromStream(body)) chunks.push(chunk);
64+
65+
const blob = new Blob(chunks);
66+
67+
console.log(blob);
68+
}();
69+
```
70+
5571
### Concurrent Task to Serial Queue
5672
5773
```javascript
@@ -63,11 +79,8 @@ const { process, observable } = createQueue(),
6379
app = new Koa();
6480

6581
(async () => {
66-
for await (const {
67-
defer: { resolve },
68-
data
69-
} of observable)
70-
resolve(JSON.stringify(data));
82+
for await (const { defer, data } of observable)
83+
defer.resolve(JSON.stringify(data));
7184
})();
7285

7386
app.use(BodyParser)

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iterable-observer",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"license": "LGPL-3.0",
55
"author": "shiy2008@gmail.com",
66
"description": "Observable Proposal implement based on Async Generator (ES 2018) & TypeScript",
@@ -26,23 +26,23 @@
2626
"module": "dist/index.esm.js",
2727
"main": "dist/index.js",
2828
"dependencies": {
29-
"@swc/helpers": "^0.5.2"
29+
"@swc/helpers": "^0.5.12"
3030
},
3131
"devDependencies": {
32-
"@parcel/packager-ts": "~2.9.3",
33-
"@parcel/transformer-typescript-types": "~2.9.3",
34-
"@types/jest": "^29.5.5",
35-
"@types/node": "^18.18.3",
36-
"husky": "^8.0.3",
32+
"@parcel/packager-ts": "~2.12.0",
33+
"@parcel/transformer-typescript-types": "~2.12.0",
34+
"@types/jest": "^29.5.12",
35+
"@types/node": "^18.19.44",
36+
"husky": "^9.1.4",
3737
"jest": "^29.7.0",
38-
"lint-staged": "^14.0.1",
39-
"open-cli": "^7.2.0",
40-
"parcel": "~2.9.3",
41-
"prettier": "^3.0.3",
42-
"ts-jest": "^29.1.1",
43-
"typedoc": "^0.25.1",
44-
"typedoc-plugin-mdn-links": "^3.1.0",
45-
"typescript": "~5.2.2"
38+
"lint-staged": "^15.2.9",
39+
"open-cli": "^8.0.0",
40+
"parcel": "~2.12.0",
41+
"prettier": "^3.3.3",
42+
"ts-jest": "^29.2.4",
43+
"typedoc": "^0.26.5",
44+
"typedoc-plugin-mdn-links": "^3.2.8",
45+
"typescript": "~5.5.4"
4646
},
4747
"prettier": {
4848
"singleQuote": true,
@@ -64,7 +64,7 @@
6464
}
6565
},
6666
"scripts": {
67-
"prepare": "husky install",
67+
"prepare": "husky",
6868
"test": "lint-staged && jest --no-cache",
6969
"pack-docs": "typedoc source/",
7070
"build": "rm -rf dist/ docs/ && parcel build && npm run pack-docs",

0 commit comments

Comments
 (0)