diff --git a/.changeset/spicy-garlics-look.md b/.changeset/spicy-garlics-look.md new file mode 100644 index 00000000..602782ec --- /dev/null +++ b/.changeset/spicy-garlics-look.md @@ -0,0 +1,6 @@ +--- +"@tus/server": major +"@tus/utils": minor +--- + +- `POST_RECEIVE_V2` has been renamed to `POST_RECEIVE`. The deprecated version of `POST_RECEIVE` has been removed. diff --git a/package-lock.json b/package-lock.json index fce9c90f..adc36295 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6282,7 +6282,11 @@ "@types/debug": "^4.1.12", "@types/lodash.throttle": "^4.1.9", "@types/mocha": "^10.0.6", +<<<<<<< HEAD + "@types/node": "^22.10.1", +======= "@types/node": "^22.13.7", +>>>>>>> main "@types/set-cookie-parser": "^2.4.10", "@types/sinon": "^17.0.3", "@types/supertest": "^2.0.16", diff --git a/packages/server/README.md b/packages/server/README.md index cc347ac5..6e705707 100644 --- a/packages/server/README.md +++ b/packages/server/README.md @@ -82,7 +82,7 @@ Sends the client's origin back in `Access-Control-Allow-Origin` if it matches. #### `options.postReceiveInterval` Interval in milliseconds for sending progress of an upload over -[`POST_RECEIVE_V2`](#eventspost_receive_v2) (`number`). +[`POST_RECEIVE`](#eventspost_receive) (`number`). #### `options.relativeLocation` @@ -255,21 +255,6 @@ server.on(EVENTS.POST_CREATE, (req, res, upload => {}) #### `POST_RECEIVE` -**Deprecated**. - -Called every time an upload finished writing to the store. This event is emitted whenever -the request handling is completed (which is the same as `onUploadFinish`, almost the same -as `POST_FINISH`), whereas the `POST_RECEIVE_V2` event is emitted _while_ the request is -being handled. - -```js -const {EVENTS} = require('@tus/server') -// ... -server.on(EVENTS.POST_RECEIVE, (req, res, upload => {}) -``` - -#### `POST_RECEIVE_V2` - Called every [`postReceiveInterval`](#optionspostreceiveinterval) milliseconds for every upload while it‘s being written to the store. @@ -283,7 +268,7 @@ Use `POST_FINISH` if you need to know when an upload is done. ```js const {EVENTS} = require('@tus/server') // ... -server.on(EVENTS.POST_RECEIVE_V2, (req, upload => {}) +server.on(EVENTS.POST_RECEIVE, (req, upload => {}) ``` #### `POST_FINISH` diff --git a/packages/server/src/handlers/BaseHandler.ts b/packages/server/src/handlers/BaseHandler.ts index 5e7856a5..e52f5eae 100644 --- a/packages/server/src/handlers/BaseHandler.ts +++ b/packages/server/src/handlers/BaseHandler.ts @@ -161,7 +161,7 @@ export class BaseHandler extends EventEmitter { const postReceive = throttle( (offset: number) => { - this.emit(EVENTS.POST_RECEIVE_V2, data, {...upload, offset}) + this.emit(EVENTS.POST_RECEIVE, data, {...upload, offset}) }, this.options.postReceiveInterval, {leading: false} diff --git a/packages/server/src/handlers/PatchHandler.ts b/packages/server/src/handlers/PatchHandler.ts index da6e9ba6..429fe139 100644 --- a/packages/server/src/handlers/PatchHandler.ts +++ b/packages/server/src/handlers/PatchHandler.ts @@ -107,7 +107,6 @@ export class PatchHandler extends BaseHandler { } upload.offset = newOffset - this.emit(EVENTS.POST_RECEIVE, req, upload) //Recommended response defaults const responseData = { diff --git a/packages/server/src/server.ts b/packages/server/src/server.ts index c9252d07..2b3dae7a 100644 --- a/packages/server/src/server.ts +++ b/packages/server/src/server.ts @@ -28,9 +28,7 @@ type Handlers = { interface TusEvents { [EVENTS.POST_CREATE]: (req: Request, upload: Upload, url: string) => void - /** @deprecated this is almost the same as POST_FINISH, use POST_RECEIVE_V2 instead */ [EVENTS.POST_RECEIVE]: (req: Request, upload: Upload) => void - [EVENTS.POST_RECEIVE_V2]: (req: Request, upload: Upload) => void [EVENTS.POST_FINISH]: (req: Request, res: Response, upload: Upload) => void [EVENTS.POST_TERMINATE]: (req: Request, res: Response, id: string) => void } diff --git a/packages/server/src/types.ts b/packages/server/src/types.ts index 863c6b4b..438bd8ad 100644 --- a/packages/server/src/types.ts +++ b/packages/server/src/types.ts @@ -41,7 +41,7 @@ export type ServerOptions = { allowedOrigins?: string[] /** - * Interval in milliseconds for sending progress of an upload over `EVENTS.POST_RECEIVE_V2` + * Interval in milliseconds for sending progress of an upload over `EVENTS.POST_RECEIVE` */ postReceiveInterval?: number diff --git a/packages/server/test/PatchHandler.test.ts b/packages/server/test/PatchHandler.test.ts index 4882e4c9..b59e23bd 100644 --- a/packages/server/test/PatchHandler.test.ts +++ b/packages/server/test/PatchHandler.test.ts @@ -6,7 +6,7 @@ import type http from 'node:http' import sinon from 'sinon' import {PatchHandler} from '../src/handlers/PatchHandler' -import {EVENTS, Upload, DataStore, type CancellationContext} from '@tus/utils' +import {Upload, DataStore, type CancellationContext} from '@tus/utils' import {MemoryLocker} from '../src' import streamP from 'node:stream/promises' import stream, {PassThrough} from 'node:stream' @@ -190,19 +190,6 @@ describe('PatchHandler', () => { }) }) - it('should emit POST_RECEIVE event', async () => { - req.headers.set('upload-offset', '0') - req.headers.set('content-type', 'application/offset+octet-stream') - - store.getUpload.resolves(new Upload({id: '1234', offset: 0, size: 1024})) - store.write.resolves(10) - handler.on(EVENTS.POST_RECEIVE, sinon.spy()) - - await handler.send(req, context) - - assert.equal(true, true) // The event emitter is not directly testable in this context - }) - it('should throw max size exceeded error when upload-length is higher then the maxSize', async () => { const handler = new PatchHandler(store, { path, diff --git a/packages/server/test/Server.test.ts b/packages/server/test/Server.test.ts index 06eaab68..48b0ba01 100644 --- a/packages/server/test/Server.test.ts +++ b/packages/server/test/Server.test.ts @@ -457,7 +457,7 @@ describe('Server', () => { }) const size = 1024 * 1024 let received = 0 - server.on(EVENTS.POST_RECEIVE_V2, () => { + server.on(EVENTS.POST_RECEIVE, () => { received++ }) diff --git a/packages/utils/src/constants.ts b/packages/utils/src/constants.ts index def7cba6..83d58b63 100644 --- a/packages/utils/src/constants.ts +++ b/packages/utils/src/constants.ts @@ -100,16 +100,12 @@ export const ERRORS = { } as const export const POST_CREATE = 'POST_CREATE' as const -/** @deprecated this is almost the same as POST_FINISH, use POST_RECEIVE_V2 instead */ export const POST_RECEIVE = 'POST_RECEIVE' as const -export const POST_RECEIVE_V2 = 'POST_RECEIVE_V2' as const export const POST_FINISH = 'POST_FINISH' as const export const POST_TERMINATE = 'POST_TERMINATE' as const export const EVENTS = { POST_CREATE, - /** @deprecated this is almost the same as POST_FINISH, use POST_RECEIVE_V2 instead */ POST_RECEIVE, - POST_RECEIVE_V2, POST_FINISH, POST_TERMINATE, } as const