Skip to content

Commit 89bc5a2

Browse files
authored
Use import instead of require in all code examples (#739)
1 parent 1abc100 commit 89bc5a2

File tree

6 files changed

+119
-126
lines changed

6 files changed

+119
-126
lines changed

README.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,47 +52,49 @@ A standalone server which stores files on disk.
5252
> Try it yourself in [StackBlitz](https://stackblitz.com/edit/stackblitz-starters-zg6mgnuf?file=index.js)
5353
5454
```js
55-
const {Server} = require('@tus/server')
56-
const {FileStore} = require('@tus/file-store')
55+
import { Server } from "@tus/server";
56+
import { FileStore } from "@tus/file-store";
5757

58-
const host = '127.0.0.1'
59-
const port = 1080
58+
const host = "127.0.0.1";
59+
const port = 1080;
6060
const server = new Server({
61-
path: '/files',
62-
datastore: new FileStore({directory: './files'}),
63-
})
61+
path: "/files",
62+
datastore: new FileStore({ directory: "./files" }),
63+
});
6464

65-
server.listen({host, port})
65+
server.listen({ host, port });
6666
```
6767

6868
A tus server integrated into your existing Node.js server. `@tus/server` has no
6969
dependencies so it can be integrated in any server-side framework. More examples can be
7070
found in [`@tus/server`][].
7171

7272
```js
73-
const fastify = require('fastify')({ logger: true });
74-
const {Server} = require('@tus/server');
75-
const {FileStore} = require('@tus/file-store');
73+
import fastify from "fastify";
74+
import { Server } from "@tus/server";
75+
import { FileStore } from "@tus/file-store";
7676

77+
const app = fastify({ logger: true });
7778
const tusServer = new Server({
78-
path: '/files',
79-
datastore: new FileStore({ directory: './files' })
80-
})
79+
path: "/files",
80+
datastore: new FileStore({ directory: "./files" }),
81+
});
8182

82-
fastify.addContentTypeParser(
83-
'application/offset+octet-stream', (request, payload, done) => done(null);
83+
app.addContentTypeParser(
84+
"application/offset+octet-stream",
85+
(request, payload, done) => done(null)
8486
);
85-
fastify.all('/files', (req, res) => {
86-
tusServer.handle(req.raw, res.raw);
87+
app.all("/files", (req, res) => {
88+
tusServer.handle(req.raw, res.raw);
8789
});
88-
fastify.all('/files/*', (req, res) => {
89-
tusServer.handle(req.raw, res.raw);
90+
app.all("/files/*", (req, res) => {
91+
tusServer.handle(req.raw, res.raw);
9092
});
91-
fastify.listen(3000, (err) => {
92-
if (err) {
93-
fastify.log.error(err);
94-
process.exit(1);
95-
}
93+
app.listen(3000, (err) => {
94+
if (err) {
95+
app.log.error(err);
96+
process.exit(1);
97+
}
9698
});
9799
```
98100

@@ -144,8 +146,7 @@ See
144146
[`@tus/azure-store`]: https://github.com/tus/tus-node-server/tree/main/packages/azure-store
145147
[extensions]: https://tus.io/protocols/resumable-upload.html#protocol-extensions
146148
[creation]: https://tus.io/protocols/resumable-upload.html#creation
147-
[creation with upload]:
148-
https://tus.io/protocols/resumable-upload.html#creation-with-upload
149+
[creation with upload]: https://tus.io/protocols/resumable-upload.html#creation-with-upload
149150
[expiration]: https://tus.io/protocols/resumable-upload.html#expiration
150151
[checksum]: https://tus.io/protocols/resumable-upload.html#checksum
151152
[termination]: https://tus.io/protocols/resumable-upload.html#termination

packages/azure-store/README.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ npm install @tus/azure-store
2525
## Use
2626

2727
```js
28-
const {Server} = require('@tus/server')
29-
const {AzureStore} = require('@tus/azure-store')
28+
import { Server } from "@tus/server";
29+
import { AzureStore } from "@tus/azure-store";
3030

3131
const server = new Server({
32-
path: '/files',
32+
path: "/files",
3333
datastore: new AzureStore({
34-
account: process.env.AZURE_ACCOUNT_ID,
35-
accountKey: process.env.AZURE_ACCOUNT_KEY,
36-
containerName: process.env.AZURE_CONTAINER_NAME,
34+
account: process.env.AZURE_ACCOUNT_ID,
35+
accountKey: process.env.AZURE_ACCOUNT_KEY,
36+
containerName: process.env.AZURE_CONTAINER_NAME,
3737
}),
38-
})
38+
});
3939
// ...
4040
```
4141

@@ -98,17 +98,12 @@ See
9898

9999
[extensions]: https://tus.io/protocols/resumable-upload.html#protocol-extensions
100100
[creation]: https://tus.io/protocols/resumable-upload.html#creation
101-
[creation with upload]:
102-
https://tus.io/protocols/resumable-upload.html#creation-with-upload
101+
[creation with upload]: https://tus.io/protocols/resumable-upload.html#creation-with-upload
103102
[expiration]: https://tus.io/protocols/resumable-upload.html#expiration
104103
[checksum]: https://tus.io/protocols/resumable-upload.html#checksum
105104
[termination]: https://tus.io/protocols/resumable-upload.html#termination
106105
[concatenation]: https://tus.io/protocols/resumable-upload.html#concatenation
107-
[`cleanUpExpiredUploads`]:
108-
https://github.com/tus/tus-node-server/tree/main/packages/server#cleanupexpireduploads
106+
[`cleanUpExpiredUploads`]: https://github.com/tus/tus-node-server/tree/main/packages/server#cleanupexpireduploads
109107
[kvstores]: https://github.com/tus/tus-node-server/tree/main/packages/server#kvstores
110-
[`KvStore`]:
111-
https://github.com/tus/tus-node-server/blob/main/packages/utils/src/kvstores/Types.ts
112-
113-
[`MemoryKvStore`]:
114-
https://github.com/tus/tus-node-server/blob/main/packages/utils/src/kvstores/MemoryKvStore.ts
108+
[`KvStore`]: https://github.com/tus/tus-node-server/blob/main/packages/utils/src/kvstores/Types.ts
109+
[`MemoryKvStore`]: https://github.com/tus/tus-node-server/blob/main/packages/utils/src/kvstores/MemoryKvStore.ts

packages/file-store/README.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ npm install @tus/file-store
2929
## Use
3030

3131
```js
32-
const {Server} = require('@tus/server')
33-
const {FileStore} = require('@tus/file-store')
32+
import { Server } from "@tus/server";
33+
import { FileStore } from "@tus/file-store";
3434

3535
const server = new Server({
36-
path: '/files',
37-
datastore: new FileStore({directory: './some/path'}),
38-
})
36+
path: "/files",
37+
datastore: new FileStore({ directory: "./some/path" }),
38+
});
3939
// ...
4040
```
4141

@@ -87,25 +87,25 @@ For demonstration purposes we will create a memory config store, but that's not
8787
idea. It's written in TypeScript.
8888

8989
```ts
90-
import type {Upload} from '@tus/server'
90+
import type { Upload } from "@tus/server";
9191

9292
export class MemoryConfigstore {
93-
data: Map<string, Upload> = new Map()
93+
data: Map<string, Upload> = new Map();
9494

9595
get(key: string): Upload | undefined {
96-
return this.data.get(key)
96+
return this.data.get(key);
9797
}
9898

9999
set(key: string, value: Upload) {
100-
this.data.set(key, value)
100+
this.data.set(key, value);
101101
}
102102

103103
delete(key: string) {
104-
return this.data.delete(key)
104+
return this.data.delete(key);
105105
}
106106

107107
get list(): Record<string, Upload> {
108-
return Object.fromEntries(this.data.entries())
108+
return Object.fromEntries(this.data.entries());
109109
}
110110
}
111111
```
@@ -138,14 +138,11 @@ See
138138

139139
[extensions]: https://tus.io/protocols/resumable-upload.html#protocol-extensions
140140
[creation]: https://tus.io/protocols/resumable-upload.html#creation
141-
[creation with upload]:
142-
https://tus.io/protocols/resumable-upload.html#creation-with-upload
141+
[creation with upload]: https://tus.io/protocols/resumable-upload.html#creation-with-upload
143142
[expiration]: https://tus.io/protocols/resumable-upload.html#expiration
144143
[checksum]: https://tus.io/protocols/resumable-upload.html#checksum
145144
[termination]: https://tus.io/protocols/resumable-upload.html#termination
146145
[concatenation]: https://tus.io/protocols/resumable-upload.html#concatenation
147-
[`cleanUpExpiredUploads`]:
148-
https://github.com/tus/tus-node-server/tree/main/packages/server#cleanupexpireduploads
146+
[`cleanUpExpiredUploads`]: https://github.com/tus/tus-node-server/tree/main/packages/server#cleanupexpireduploads
149147
[kvstores]: https://github.com/tus/tus-node-server/tree/main/packages/server#kvstores
150-
[`KvStore`]:
151-
https://github.com/tus/tus-node-server/blob/main/packages/utils/src/kvstores/Types.ts
148+
[`KvStore`]: https://github.com/tus/tus-node-server/blob/main/packages/utils/src/kvstores/Types.ts

packages/gcs-store/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@ npm install @tus/gcs-store
2626
## Use
2727

2828
```js
29-
const {Server} = require('@tus/server')
30-
const {GCSStore} = require('@tus/gcs-store')
29+
import { Server } from "@tus/server";
30+
import { GCSStore } from "@tus/gcs-store";
31+
import { Storage } from "@google-cloud/storage";
3132

32-
const {Storage} = require('@google-cloud/storage')
33-
34-
const storage = new Storage({keyFilename: 'key.json'})
33+
const storage = new Storage({ keyFilename: "key.json" });
3534

3635
const server = new Server({
37-
path: '/files',
36+
path: "/files",
3837
datastore: new GCSStore({
39-
bucket: storage.bucket('tus-node-server-ci'),
38+
bucket: storage.bucket("tus-node-server-ci"),
4039
}),
41-
})
40+
});
4241
// ...
4342
```
4443

@@ -88,8 +87,7 @@ See
8887

8988
[extensions]: https://tus.io/protocols/resumable-upload.html#protocol-extensions
9089
[creation]: https://tus.io/protocols/resumable-upload.html#creation
91-
[creation with upload]:
92-
https://tus.io/protocols/resumable-upload.html#creation-with-upload
90+
[creation with upload]: https://tus.io/protocols/resumable-upload.html#creation-with-upload
9391
[expiration]: https://tus.io/protocols/resumable-upload.html#expiration
9492
[checksum]: https://tus.io/protocols/resumable-upload.html#checksum
9593
[termination]: https://tus.io/protocols/resumable-upload.html#termination

packages/s3-store/README.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ npm install @tus/s3-store
3131
## Use
3232

3333
```js
34-
const {Server} = require('@tus/server')
35-
const {S3Store} = require('@tus/s3-store')
34+
import { Server } from "@tus/server";
35+
import { S3Store } from "@tus/s3-store";
3636

3737
const s3Store = new S3Store({
3838
partSize: 8 * 1024 * 1024, // Each uploaded part will have ~8MiB,
@@ -44,8 +44,8 @@ const s3Store = new S3Store({
4444
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
4545
},
4646
},
47-
})
48-
const server = new Server({path: '/files', datastore: s3Store})
47+
});
48+
const server = new Server({ path: "/files", datastore: s3Store });
4949
// ...
5050
```
5151

@@ -199,22 +199,22 @@ docs for the supported values of
199199
[credentials](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html#constructor-property)
200200

201201
```js
202-
const aws = require('aws-sdk')
203-
const {Server} = require('@tus/server')
204-
const {S3Store} = require('@tus/s3-store')
202+
import aws from "aws-sdk";
203+
import { Server } from "@tus/server";
204+
import { S3Store } from "@tus/s3-store";
205205

206206
const s3Store = new S3Store({
207207
partSize: 8 * 1024 * 1024,
208208
s3ClientConfig: {
209209
bucket: process.env.AWS_BUCKET,
210210
region: process.env.AWS_REGION,
211211
credentials: new aws.ECSCredentials({
212-
httpOptions: {timeout: 5000},
212+
httpOptions: { timeout: 5000 },
213213
maxRetries: 10,
214214
}),
215215
},
216-
})
217-
const server = new Server({path: '/files', datastore: s3Store})
216+
});
217+
const server = new Server({ path: "/files", datastore: s3Store });
218218
// ...
219219
```
220220

@@ -231,7 +231,7 @@ const s3Store = new S3Store({
231231
partSize: 8 * 1024 * 1024,
232232
minPartSize: 8 * 1024 * 1024,
233233
// ...
234-
})
234+
});
235235
```
236236

237237
### Example: use with Scaleway Object Storage
@@ -242,7 +242,7 @@ const s3Store = new S3Store({
242242
const s3Store = new S3Store({
243243
maxMultipartParts: 1000,
244244
// ...
245-
})
245+
});
246246
```
247247

248248
## Types
@@ -265,16 +265,12 @@ See
265265

266266
[extensions]: https://tus.io/protocols/resumable-upload.html#protocol-extensions
267267
[creation]: https://tus.io/protocols/resumable-upload.html#creation
268-
[creation with upload]:
269-
https://tus.io/protocols/resumable-upload.html#creation-with-upload
268+
[creation with upload]: https://tus.io/protocols/resumable-upload.html#creation-with-upload
270269
[expiration]: https://tus.io/protocols/resumable-upload.html#expiration
271270
[checksum]: https://tus.io/protocols/resumable-upload.html#checksum
272271
[termination]: https://tus.io/protocols/resumable-upload.html#termination
273272
[concatenation]: https://tus.io/protocols/resumable-upload.html#concatenation
274-
[cleanExpiredUploads]:
275-
https://github.com/tus/tus-node-server/tree/main/packages/server#servercleanupexpireduploads
276-
[lifecyle]:
277-
https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html
273+
[cleanExpiredUploads]: https://github.com/tus/tus-node-server/tree/main/packages/server#servercleanupexpireduploads
274+
[lifecyle]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html
278275
[kvstores]: https://github.com/tus/tus-node-server/tree/main/packages/server#kvstores
279-
[`KvStore`]:
280-
https://github.com/tus/tus-node-server/blob/main/packages/utils/src/kvstores/Types.ts
276+
[`KvStore`]: https://github.com/tus/tus-node-server/blob/main/packages/utils/src/kvstores/Types.ts

0 commit comments

Comments
 (0)