Skip to content

Commit f190875

Browse files
authored
Rename POST_RECEIVE_V2 to POST_RECEIVE (#724)
1 parent 51419da commit f190875

File tree

10 files changed

+16
-41
lines changed

10 files changed

+16
-41
lines changed

.changeset/spicy-garlics-look.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tus/server": major
3+
"@tus/utils": minor
4+
---
5+
6+
- `POST_RECEIVE_V2` has been renamed to `POST_RECEIVE`. The deprecated version of `POST_RECEIVE` has been removed.

package-lock.json

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

packages/server/README.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Sends the client's origin back in `Access-Control-Allow-Origin` if it matches.
8282
#### `options.postReceiveInterval`
8383

8484
Interval in milliseconds for sending progress of an upload over
85-
[`POST_RECEIVE_V2`](#eventspost_receive_v2) (`number`).
85+
[`POST_RECEIVE`](#eventspost_receive) (`number`).
8686

8787
#### `options.relativeLocation`
8888

@@ -255,21 +255,6 @@ server.on(EVENTS.POST_CREATE, (req, res, upload => {})
255255
256256
#### `POST_RECEIVE`
257257
258-
**Deprecated**.
259-
260-
Called every time an upload finished writing to the store. This event is emitted whenever
261-
the request handling is completed (which is the same as `onUploadFinish`, almost the same
262-
as `POST_FINISH`), whereas the `POST_RECEIVE_V2` event is emitted _while_ the request is
263-
being handled.
264-
265-
```js
266-
const {EVENTS} = require('@tus/server')
267-
// ...
268-
server.on(EVENTS.POST_RECEIVE, (req, res, upload => {})
269-
```
270-
271-
#### `POST_RECEIVE_V2`
272-
273258
Called every [`postReceiveInterval`](#optionspostreceiveinterval) milliseconds for every
274259
upload while it‘s being written to the store.
275260
@@ -283,7 +268,7 @@ Use `POST_FINISH` if you need to know when an upload is done.
283268
```js
284269
const {EVENTS} = require('@tus/server')
285270
// ...
286-
server.on(EVENTS.POST_RECEIVE_V2, (req, upload => {})
271+
server.on(EVENTS.POST_RECEIVE, (req, upload => {})
287272
```
288273
289274
#### `POST_FINISH`

packages/server/src/handlers/BaseHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class BaseHandler extends EventEmitter {
161161

162162
const postReceive = throttle(
163163
(offset: number) => {
164-
this.emit(EVENTS.POST_RECEIVE_V2, data, {...upload, offset})
164+
this.emit(EVENTS.POST_RECEIVE, data, {...upload, offset})
165165
},
166166
this.options.postReceiveInterval,
167167
{leading: false}

packages/server/src/handlers/PatchHandler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ export class PatchHandler extends BaseHandler {
107107
}
108108

109109
upload.offset = newOffset
110-
this.emit(EVENTS.POST_RECEIVE, req, upload)
111110

112111
//Recommended response defaults
113112
const responseData = {

packages/server/src/server.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ type Handlers = {
2828

2929
interface TusEvents {
3030
[EVENTS.POST_CREATE]: (req: Request, upload: Upload, url: string) => void
31-
/** @deprecated this is almost the same as POST_FINISH, use POST_RECEIVE_V2 instead */
3231
[EVENTS.POST_RECEIVE]: (req: Request, upload: Upload) => void
33-
[EVENTS.POST_RECEIVE_V2]: (req: Request, upload: Upload) => void
3432
[EVENTS.POST_FINISH]: (req: Request, res: Response, upload: Upload) => void
3533
[EVENTS.POST_TERMINATE]: (req: Request, res: Response, id: string) => void
3634
}

packages/server/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export type ServerOptions = {
4141
allowedOrigins?: string[]
4242

4343
/**
44-
* Interval in milliseconds for sending progress of an upload over `EVENTS.POST_RECEIVE_V2`
44+
* Interval in milliseconds for sending progress of an upload over `EVENTS.POST_RECEIVE`
4545
*/
4646
postReceiveInterval?: number
4747

packages/server/test/PatchHandler.test.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type http from 'node:http'
66
import sinon from 'sinon'
77

88
import {PatchHandler} from '../src/handlers/PatchHandler'
9-
import {EVENTS, Upload, DataStore, type CancellationContext} from '@tus/utils'
9+
import {Upload, DataStore, type CancellationContext} from '@tus/utils'
1010
import {MemoryLocker} from '../src'
1111
import streamP from 'node:stream/promises'
1212
import stream, {PassThrough} from 'node:stream'
@@ -190,19 +190,6 @@ describe('PatchHandler', () => {
190190
})
191191
})
192192

193-
it('should emit POST_RECEIVE event', async () => {
194-
req.headers.set('upload-offset', '0')
195-
req.headers.set('content-type', 'application/offset+octet-stream')
196-
197-
store.getUpload.resolves(new Upload({id: '1234', offset: 0, size: 1024}))
198-
store.write.resolves(10)
199-
handler.on(EVENTS.POST_RECEIVE, sinon.spy())
200-
201-
await handler.send(req, context)
202-
203-
assert.equal(true, true) // The event emitter is not directly testable in this context
204-
})
205-
206193
it('should throw max size exceeded error when upload-length is higher then the maxSize', async () => {
207194
const handler = new PatchHandler(store, {
208195
path,

packages/server/test/Server.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ describe('Server', () => {
457457
})
458458
const size = 1024 * 1024
459459
let received = 0
460-
server.on(EVENTS.POST_RECEIVE_V2, () => {
460+
server.on(EVENTS.POST_RECEIVE, () => {
461461
received++
462462
})
463463

packages/utils/src/constants.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,12 @@ export const ERRORS = {
100100
} as const
101101

102102
export const POST_CREATE = 'POST_CREATE' as const
103-
/** @deprecated this is almost the same as POST_FINISH, use POST_RECEIVE_V2 instead */
104103
export const POST_RECEIVE = 'POST_RECEIVE' as const
105-
export const POST_RECEIVE_V2 = 'POST_RECEIVE_V2' as const
106104
export const POST_FINISH = 'POST_FINISH' as const
107105
export const POST_TERMINATE = 'POST_TERMINATE' as const
108106
export const EVENTS = {
109107
POST_CREATE,
110-
/** @deprecated this is almost the same as POST_FINISH, use POST_RECEIVE_V2 instead */
111108
POST_RECEIVE,
112-
POST_RECEIVE_V2,
113109
POST_FINISH,
114110
POST_TERMINATE,
115111
} as const

0 commit comments

Comments
 (0)