Skip to content

Commit

Permalink
[add] Observable.fromStream() for Async Iterable transforming
Browse files Browse the repository at this point in the history
[optimize] upgrade to PNPM 9, Husky 9 & other Upstream packages
[optimize] support NPM provenance
  • Loading branch information
TechQuery committed Aug 16, 2024
1 parent 01ee217 commit ed1d522
Show file tree
Hide file tree
Showing 10 changed files with 3,738 additions and 3,293 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ on:
jobs:
Build-and-Publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8
version: 9
- uses: actions/setup-node@v3
with:
node-version: 18
Expand All @@ -24,7 +27,7 @@ jobs:
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Update document
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
4 changes: 0 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
#!/bin/sh

. "$(dirname "$0")/_/husky.sh"

npm test
4 changes: 0 additions & 4 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
#!/bin/sh

. "$(dirname "$0")/_/husky.sh"

npm run build
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
provenance = true
auto-install-peers = false
33 changes: 23 additions & 10 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const observable = new Observable(({ next, complete }) => {
() => (++count < 5 ? next(count) : complete(count)),
0
);

return () => clearInterval(timer);
});

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

### Enhance Run-time platforms

#### Transform events

```javascript
import { Observable } from 'iterable-observer';

const reader = new FileReader(),
{
files: [file]
} = document.querySelector('input[type="file"]');
{ files } = document.querySelector('input[type="file"]');

reader.readAsBlob(file);
reader.readAsBlob(files[0]);

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

#### Transform streams

```typescript
import { Observable } from 'iterable-observer';

(async () => {
const { body } = await fetch('https://example.com/path/to/blob'),
chunks: Uint8Array[] = [];

for await (const chunk of Observable.fromStream(body)) chunks.push(chunk);

const blob = new Blob(chunks);

console.log(blob);
}();
```
### Concurrent Task to Serial Queue
```javascript
Expand All @@ -63,11 +79,8 @@ const { process, observable } = createQueue(),
app = new Koa();

(async () => {
for await (const {
defer: { resolve },
data
} of observable)
resolve(JSON.stringify(data));
for await (const { defer, data } of observable)
defer.resolve(JSON.stringify(data));
})();

app.use(BodyParser)
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iterable-observer",
"version": "1.0.1",
"version": "1.1.0",
"license": "LGPL-3.0",
"author": "[email protected]",
"description": "Observable Proposal implement based on Async Generator (ES 2018) & TypeScript",
Expand All @@ -26,23 +26,23 @@
"module": "dist/index.esm.js",
"main": "dist/index.js",
"dependencies": {
"@swc/helpers": "^0.5.2"
"@swc/helpers": "^0.5.12"
},
"devDependencies": {
"@parcel/packager-ts": "~2.9.3",
"@parcel/transformer-typescript-types": "~2.9.3",
"@types/jest": "^29.5.5",
"@types/node": "^18.18.3",
"husky": "^8.0.3",
"@parcel/packager-ts": "~2.12.0",
"@parcel/transformer-typescript-types": "~2.12.0",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.44",
"husky": "^9.1.4",
"jest": "^29.7.0",
"lint-staged": "^14.0.1",
"open-cli": "^7.2.0",
"parcel": "~2.9.3",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"typedoc": "^0.25.1",
"typedoc-plugin-mdn-links": "^3.1.0",
"typescript": "~5.2.2"
"lint-staged": "^15.2.9",
"open-cli": "^8.0.0",
"parcel": "~2.12.0",
"prettier": "^3.3.3",
"ts-jest": "^29.2.4",
"typedoc": "^0.26.5",
"typedoc-plugin-mdn-links": "^3.2.8",
"typescript": "~5.5.4"
},
"prettier": {
"singleQuote": true,
Expand All @@ -64,7 +64,7 @@
}
},
"scripts": {
"prepare": "husky install",
"prepare": "husky",
"test": "lint-staged && jest --no-cache",
"pack-docs": "typedoc source/",
"build": "rm -rf dist/ docs/ && parcel build && npm run pack-docs",
Expand Down
Loading

0 comments on commit ed1d522

Please sign in to comment.