Skip to content

Commit

Permalink
How to export from other files (#49)
Browse files Browse the repository at this point in the history
Index Nine suggested documenting this more clearly.
  • Loading branch information
chuck-dbos authored Jan 29, 2024
1 parent 5210c5a commit 5cbabf4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/explanations/application-structure-explanation.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ All options are documented in our [configuration reference](../api-reference/con
At startup, the DBOS runtime automatically loads all classes exported from this file, serving their endpoints and registering their decorated functions.
More precisely, DBOS assumes your compiled code is exported from `dist/operations.js`, the default location to which `src/operations.ts` is compiled.
If you're writing a small application, you can write all your code directly in this file.
In a larger application, you can write your code wherever you want, but should use `src/operations.ts` as an index file, exporting code written elsewhere.
In a larger application, you can write your code wherever you want, but should use `src/operations.ts` as an index file, exporting code written elsewhere:
```typescript
// Placed in operations.ts:
export { OperationClass1, OperationClass2 } from './FileA';
export { OperationClass3 } from './operations/FileB';
```
You can also configure the entrypoint in our [configuration file](../api-reference/configuration#runtime).

As for the rest of the directory:
Expand Down
10 changes: 10 additions & 0 deletions docs/getting-started/quickstart-programming-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ This new function works similarly to `helloTransaction`.
The [`@Transaction`](../api-reference/decorators#transaction) decorator tells DBOS to run it as a database transaction.
The [`@PostApi`](../api-reference/decorators#postapi) decorator tells DBOS to serve this function from HTTP POST requests to the `/clear` endpoint.

::::tip
It is not necessary to put all DBOS functions in one `operations.ts` file; it is also possible to export them:
```typescript
// Placed in operations.ts:
export { OperationClass1, OperationClass2 } from './FileA';
export { OperationClass3 } from './operations/FileB';
```
::::


### Trying it Out

Now, let's see if this works!
Expand Down

0 comments on commit 5cbabf4

Please sign in to comment.