Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce @tus/utils to simplify building/publishing #567

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-fishes-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tus/utils': minor
---

Introduce @tus/utils for code sharing between packages
8 changes: 8 additions & 0 deletions .changeset/stale-bobcats-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@tus/file-store': minor
'@tus/gcs-store': minor
'@tus/s3-store': minor
'@tus/server': minor
---

Add new @tus/utils dependency to replace @tus/server peer dependency
48 changes: 0 additions & 48 deletions packages/file-store/configstores/FileConfigstore.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/file-store/configstores/MemoryConfigstore.ts

This file was deleted.

40 changes: 0 additions & 40 deletions packages/file-store/configstores/RedisConfigstore.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/file-store/configstores/Types.ts

This file was deleted.

10 changes: 6 additions & 4 deletions packages/file-store/configstores/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export {FileConfigstore} from './FileConfigstore'
export {MemoryConfigstore} from './MemoryConfigstore'
export {RedisConfigstore} from './RedisConfigstore'
export {Configstore} from './Types'
export {
FileKvStore as FileConfigstore,
MemoryKvStore as MemoryConfigstore,
RedisKvStore as RedisConfigstore,
KvStore as Configstore,
} from '@tus/utils'
2 changes: 1 addition & 1 deletion packages/file-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import http from 'node:http'
import debug from 'debug'

import {Configstore, FileConfigstore} from './configstores'
import {DataStore, Upload, ERRORS} from '@tus/server'
import {DataStore, Upload, ERRORS} from '@tus/utils'

export * from './configstores'

Expand Down
5 changes: 1 addition & 4 deletions packages/file-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"test": "mocha test.ts --exit --extension ts --require ts-node/register"
},
"dependencies": {
"@tus/utils": "workspace:*",
"debug": "^4.3.4"
},
"devDependencies": {
"@tus/server": "workspace:^",
"@types/debug": "^4.1.12",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.5",
Expand All @@ -34,9 +34,6 @@
"should": "^13.2.3",
"typescript": "^5.3.3"
},
"peerDependencies": {
"@tus/server": "workspace:^"
},
"optionalDependencies": {
"@redis/client": "^1.5.13"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/file-store/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from 'node:path'
import sinon from 'sinon'

import {FileStore, FileConfigstore} from './'
import {Upload} from '@tus/server'
import {Upload} from '@tus/utils'

import * as shared from '../../test/stores.test'

Expand Down
3 changes: 1 addition & 2 deletions packages/gcs-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import stream from 'node:stream'
import http from 'node:http'
import debug from 'debug'

import {ERRORS, TUS_RESUMABLE} from '@tus/server'
import {Upload, DataStore} from '@tus/server'
import {ERRORS, TUS_RESUMABLE, Upload, DataStore} from '@tus/utils'

const log = debug('tus-node-server:stores:gcsstore')

Expand Down
4 changes: 2 additions & 2 deletions packages/gcs-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"test": "mocha test.ts --timeout 30000 --exit --extension ts --require ts-node/register"
},
"dependencies": {
"@tus/utils": "workspace:*",
"debug": "^4.3.4"
},
"devDependencies": {
Expand All @@ -36,8 +37,7 @@
"typescript": "^5.3.3"
},
"peerDependencies": {
"@google-cloud/storage": "*",
"@tus/server": "workspace:^"
"@google-cloud/storage": "*"
},
"engines": {
"node": ">=16"
Expand Down
2 changes: 1 addition & 1 deletion packages/s3-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TUS_RESUMABLE,
KvStore,
MemoryKvStore,
} from '@tus/server'
} from '@tus/utils'

const log = debug('tus-node-server:stores:s3store')

Expand Down
5 changes: 1 addition & 4 deletions packages/s3-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
},
"dependencies": {
"@aws-sdk/client-s3": "^3.490.0",
"@tus/utils": "workspace:*",
"debug": "^4.3.4"
},
"devDependencies": {
"@tus/server": "workspace:^",
"@types/debug": "^4.1.12",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.5",
Expand All @@ -35,9 +35,6 @@
"should": "^13.2.3",
"typescript": "^5.3.3"
},
"peerDependencies": {
"@tus/server": "workspace:^"
},
"engines": {
"node": ">=16"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/s3-store/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import sinon from 'sinon'

import {S3Store} from './'
import * as shared from '../../test/stores.test'
import {Upload} from '@tus/server'
import {Upload} from '@tus/utils'

const fixturesPath = path.resolve('../', '../', 'test', 'fixtures')
const storePath = path.resolve('../', '../', 'test', 'output', 's3-store')
Expand Down
1 change: 1 addition & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"test": "mocha --timeout 40000 --exit --extension ts --require ts-node/register"
},
"dependencies": {
"@tus/utils": "workspace:*",
"debug": "^4.3.4"
},
"devDependencies": {
Expand Down
6 changes: 2 additions & 4 deletions packages/server/src/handlers/BaseHandler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import EventEmitter from 'node:events'

import type {ServerOptions} from '../types'
import type {DataStore, CancellationContext} from '../models'
import type {DataStore, CancellationContext} from '@tus/utils'
import type http from 'node:http'
import {Upload} from '../models'
import {ERRORS} from '../constants'
import {ERRORS, Upload, StreamLimiter} from '@tus/utils'
import stream from 'node:stream/promises'
import {addAbortSignal, PassThrough} from 'stream'
import {StreamLimiter} from '../models/StreamLimiter'

const reExtractFileID = /([^/]+)\/?$/
const reForwardedHost = /host="?([^";]+)/
Expand Down
3 changes: 1 addition & 2 deletions packages/server/src/handlers/DeleteHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {BaseHandler} from './BaseHandler'
import {ERRORS, EVENTS} from '../constants'
import {CancellationContext} from '../models'
import {ERRORS, EVENTS, CancellationContext} from '@tus/utils'

import type http from 'node:http'

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/handlers/GetHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stream from 'node:stream'

import {BaseHandler} from './BaseHandler'
import {ERRORS} from '../constants'
import {ERRORS} from '@tus/utils'

import type http from 'node:http'
import type {RouteHandler} from '../types'
Expand Down
3 changes: 1 addition & 2 deletions packages/server/src/handlers/HeadHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {BaseHandler} from './BaseHandler'

import {ERRORS} from '../constants'
import {Metadata, Upload, CancellationContext} from '../models'
import {ERRORS, Metadata, Upload, CancellationContext} from '@tus/utils'

import type http from 'node:http'

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/handlers/OptionsHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {BaseHandler} from './BaseHandler'
import {ALLOWED_METHODS, MAX_AGE, HEADERS} from '../constants'
import {ALLOWED_METHODS, MAX_AGE, HEADERS} from '@tus/utils'

import type http from 'node:http'

Expand Down
3 changes: 1 addition & 2 deletions packages/server/src/handlers/PatchHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import debug from 'debug'

import {BaseHandler} from './BaseHandler'
import {ERRORS, EVENTS} from '../constants'

import type http from 'node:http'
import {CancellationContext, Upload} from '../models'
import {ERRORS, EVENTS, CancellationContext, Upload} from '@tus/utils'

const log = debug('tus-node-server:handlers:patch')

Expand Down
12 changes: 9 additions & 3 deletions packages/server/src/handlers/PostHandler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import debug from 'debug'

import {BaseHandler} from './BaseHandler'
import {Upload, Uid, Metadata} from '../models'
import {
Upload,
Uid,
Metadata,
EVENTS,
ERRORS,
DataStore,
CancellationContext,
} from '@tus/utils'
import {validateHeader} from '../validators/HeaderValidator'
import {EVENTS, ERRORS} from '../constants'

import type http from 'node:http'
import type {ServerOptions, WithRequired} from '../types'
import {DataStore, CancellationContext} from '../models'

const log = debug('tus-node-server:handlers:post')

Expand Down
4 changes: 1 addition & 3 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export {Server} from './server'
export * from './types'
export * from './models'
export * from './lockers'
export * from './constants'
export * from './kvstores'
export * from '@tus/utils'
3 changes: 1 addition & 2 deletions packages/server/src/lockers/MemoryLocker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {ERRORS} from '../constants'
import {Lock, Locker, RequestRelease} from '../models'
import {ERRORS, Lock, Locker, RequestRelease} from '@tus/utils'

/**
* MemoryLocker is an implementation of the Locker interface that manages locks in memory.
Expand Down
10 changes: 2 additions & 8 deletions packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ import {PostHandler} from './handlers/PostHandler'
import {DeleteHandler} from './handlers/DeleteHandler'
import {validateHeader} from './validators/HeaderValidator'

import {
EVENTS,
ERRORS,
EXPOSED_HEADERS,
REQUEST_METHODS,
TUS_RESUMABLE,
} from './constants'
import {EVENTS, ERRORS, EXPOSED_HEADERS, REQUEST_METHODS, TUS_RESUMABLE} from '@tus/utils'

import type stream from 'node:stream'
import type {ServerOptions, RouteHandler, WithOptional} from './types'
import type {DataStore, Upload, CancellationContext} from './models'
import type {DataStore, Upload, CancellationContext} from '@tus/utils'
import {MemoryLocker} from './lockers'

type Handlers = {
Expand Down
Loading
Loading