Skip to content

Commit

Permalink
refactor: change export structure
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-kolja committed Feb 8, 2024
1 parent 20e57c1 commit 526f219
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 44 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ The handler has the following configuration:
| contentType (optional) | `string \| readonly string[]` | The content type/s of the file to handle. |
| size (optional) | `{ min?: number, max?: number }` | The min and max size that needs to match. One must be provided. <br/> An error is thrown when neither is provided or they are conflicting (negative or max is smaller then min) |

You can import the `createFileHandler` function from the `v1` or `v2` folder depending on which cloud function version you're using. The default entry point is `v2`.
You can get the `createFileHandler` function from the exported `v1` or `v2`.

### V1

```typescript
import { createFileHandler } from 'firebase-storage-func-helper/v1'
import { createFileHandler } from 'firebase-storage-func-helper/dist/v1'
import { v1 } from 'firebase-storage-func-helper'
```

```typescript
// declare your handler
const onChatAttachmentHandler = createFileHandler({
const onChatAttachmentHandler = v1.createFileHandler({
path: 'chats/:chatId/attachments/:attachmentId',
contentType: ['video/mp4', 'video/quicktime'],
size: {
Expand Down Expand Up @@ -66,14 +65,12 @@ const onMultipleFile = firebaseFunctions
### V2

```typescript
import { createFileHandler } from 'firebase-storage-func-helper'
import { createFileHandler } from 'firebase-storage-func-helper/v2'
import { createFileHandler } from 'firebase-storage-func-helper/dist/v2'
import { v2 } from 'firebase-storage-func-helper'
```

```typescript
// declare your handler
const onChatAttachmentHandler = createFileHandler({
const onChatAttachmentHandler = v2.createFileHandler({
path: 'chats/:chatId/attachments/:attachmentId',
contentType: ['video/mp4', 'video/quicktime'],
size: {
Expand Down
32 changes: 0 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,6 @@
"files": [
"dist"
],
"exports": {
".": {
"import": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"require": {
"default": "./dist/index.cjs",
"types": "./dist/index.d.cts"
}
},
"./v1": {
"import": {
"default": "./dist/v1.js",
"types": "./dist/v1.d.ts"
},
"require": {
"default": "./dist/v1.cjs",
"types": "./dist/v1.d.cts"
}
},
"./v2": {
"import": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"require": {
"default": "./dist/index.cjs",
"types": "./dist/index.d.cts"
}
}
},
"scripts": {
"build": "tsup",
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
export { createFileHandler } from './v2/file_handler.js'
import v1 from './v1/index.js'
import v2 from './v2/index.js'

export { v1, v2 }
export default {
v1,
v2,
}
7 changes: 6 additions & 1 deletion src/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export { createFileHandler } from './file_handler.js'
import { createFileHandler } from './file_handler.js'

export { createFileHandler }
export default {
createFileHandler,
}
7 changes: 6 additions & 1 deletion src/v2/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export { createFileHandler } from './file_handler.js'
import { createFileHandler } from './file_handler.js'

export { createFileHandler }
export default {
createFileHandler,
}
1 change: 0 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { defineConfig } from 'tsup'
export default defineConfig({
entry: {
index: 'src/index.ts',
v1: 'src/v1/index.ts',
},
format: ['cjs', 'esm'], // Build for commonJS and ESmodules
dts: true, // Generate declaration file (.d.ts)
Expand Down

0 comments on commit 526f219

Please sign in to comment.