Skip to content

Commit 73db3f9

Browse files
committed
Let's get ready for stable and tested 1.0.0!!!
1 parent 4e8f522 commit 73db3f9

29 files changed

Lines changed: 2309 additions & 821 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Test
2-
on: push
2+
on:
3+
push:
4+
branches: [main]
35
jobs:
46
test:
57
name: Test
@@ -9,11 +11,13 @@ jobs:
911
uses: actions/checkout@v5
1012
- name: setup Node.js
1113
uses: actions/setup-node@v6
12-
with:
14+
with:
1315
node-version: 25
1416
- name: Setup Bun
1517
uses: oven-sh/setup-bun@v2
1618
- name: install deps
17-
run: bun install
19+
run: bun ci
20+
- name: build
21+
run: bun run trick-tsd && bun run build
1822
- name: run test
19-
run: bun x vitest run
23+
run: bun run test

.github/workflows/release.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
name: Test
1+
name: Test and publish
22
on:
33
release:
44
types: [created]
5+
permissions:
6+
id-token: write
7+
contents: read
58
jobs:
69
test:
710
name: Test
@@ -11,27 +14,15 @@ jobs:
1114
uses: actions/checkout@v5
1215
- name: setup Node.js
1316
uses: actions/setup-node@v6
14-
with:
17+
with:
1518
node-version: 25
1619
- name: Setup Bun
1720
uses: oven-sh/setup-bun@v2
1821
- name: install deps
1922
run: bun install
20-
- name: run test
21-
run: bun x vitest run
22-
deploy:
23-
needs: test
24-
name: Deploy on npm
25-
runs-on: ubuntu-latest
26-
steps:
27-
- name: Checkout repo
28-
uses: actions/checkout@v5
29-
- name: Install Node.js
30-
uses: actions/setup-node@v6
31-
with:
32-
node-version: 25
33-
registry-url: https://registry.npmjs.org
23+
- name: build
24+
run: bun run trick-tsd && bun run build
25+
- name: test
26+
run: mkdir tmp && bun run test:base && bun run test:load && rm -rf tmp
3427
- name: Publish to npm
3528
run: npm publish
36-
env:
37-
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
package-lock.json
2-
bun.*
31
build
2+
coverage
43
node_modules
5-
uploads
4+
tmp
5+
dist

.npmignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,53 @@
1-
![ublitzjs](https://github.com/ublitzjs/core/blob/main/logo.png)
1+
# @ublitzjs/payload package for receiving request payloads
22

3-
# @ublitzjs/req-body package for parsing request payloads
3+
![µBlitz.js](https://github.com/ublitzjs/core/blob/main/logo.png)
4+
This module provides you with efficient utilities to simplify accumulating payload and receive multipart requests (busboy under the hood).
45

5-
This package lets you parse payload coming from http requests ( + multipart). Functions are of 2 types - simple and 'basic' (has little more functionality).
66

7-
## parseSimpleBody and parseFormDataBody
7+
## parseFormDataBody
8+
This utility lets you parse multipart/form-data and application/x-www-form-urlencoded
9+
```typescript
10+
import {registerAbort} from "@ublitzjs/core"
11+
import {parseFormDataBody} from "@ublitzjs/payload"
12+
server.post("/", async (res, req)=>{
13+
registerAbort(res);
14+
var result = await parseFormDataBody(
15+
{
16+
res, CT: req.getHeader("content-type"),
17+
outDir: "tmp",
18+
parseLimits: {
19+
//busboy limits. If exceeded - reverts all disk changes and return error message
20+
fileSize: 1024*1024
21+
}
22+
},
23+
// mode "memory" | "disk"
24+
"disk",
25+
// whether to accept repeated files/fields
26+
false
27+
);
28+
if(!result.ok) {
29+
// all saved files get auto-deleted
30+
// errCode as "400" | "500" (if disk failed)
31+
if(!res.aborted) return res.writeStatus(res.errCode).end(res.data) // as string, error message
32+
}
33+
console.log("Files data", result.data.files)
34+
console.log("Fields", result.data.fields)
35+
res.end("OK")
36+
})
37+
```
838

9-
(sorry, docs are now incomplete. Look into <a href="./index.d.ts">TS declaration file</a> for more)
1039

11-
(and also importing "@ublitzjs/payload/ws" gives you 2 special high-performant cross-platform functions for easier handling of websocket messages)
40+
## accumulateBody
41+
Manually writing "res.onData" handling annoys, that's why here is a solution.
42+
43+
```typescript
44+
import {accumulateBody} from "@ublitzjs/payload"
45+
import {registerAbort} from "@ublitzjs/core"
46+
server.post("/", async (res, req)=>{
47+
var CL = Number(req.getHeader("content-length"))
48+
if(CL > yourMaxBody) return res.writeStatus("413").end("too large")
49+
var result = await accumulateBody(res, CL) //CL lets preallocate memory
50+
if(res.aborted) return;
51+
console.log("Got payload", result.toString())
52+
})
53+
```

babel.config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": [
3+
[
4+
"@babel/plugin-transform-modules-commonjs",
5+
{ "importInterop": "node" }
6+
]
7+
]
8+
}

bun.lock

Lines changed: 904 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cjs/index.cjs

Lines changed: 0 additions & 241 deletions
This file was deleted.

0 commit comments

Comments
 (0)