@dbos-inc/create 1.31.4-preview → 1.31.6-preview
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/hello/README.md +2 -2
- package/templates/hello-drizzle/README.md +2 -2
- package/templates/hello-express/README.md +7 -5
- package/templates/hello-express/dbos-config.yaml +1 -1
- package/templates/hello-express/src/main.test.ts +1 -1
- package/templates/hello-express/src/main.ts +86 -3
- package/templates/hello-prisma/README.md +2 -2
- package/templates/hello-typeorm/README.md +2 -2
- package/templates/hello-v2/README.md +2 -2
- package/templates/hello-express/src/operations.ts +0 -81
package/package.json
CHANGED
|
@@ -37,7 +37,7 @@ npm run build
|
|
|
37
37
|
Then, run a schema migration to create some tables:
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
|
-
npx dbos
|
|
40
|
+
npx dbos migrate
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
If successful, the migration should print `Migration successful!`.
|
|
@@ -45,7 +45,7 @@ If successful, the migration should print `Migration successful!`.
|
|
|
45
45
|
Finally, run the app:
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
|
-
npx dbos
|
|
48
|
+
npx dbos start
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
## The application
|
|
@@ -23,7 +23,7 @@ npm run build
|
|
|
23
23
|
Then, run a schema migration to create some tables:
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
npx dbos
|
|
26
|
+
npx dbos migrate
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
If successful, the migration should print `Migration successful!`.
|
|
@@ -31,7 +31,7 @@ If successful, the migration should print `Migration successful!`.
|
|
|
31
31
|
Finally, run the app:
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
npx dbos
|
|
34
|
+
npx dbos start
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
To see that it's working, visit this URL in your browser: [`http://localhost:3000/greeting/dbos`](http://localhost:3000/greeting/dbos).
|
|
@@ -37,7 +37,7 @@ npm run build
|
|
|
37
37
|
Then, run a schema migration to create some tables:
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
|
-
npx dbos
|
|
40
|
+
npx dbos migrate
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
If successful, the migration should print `Migration successful!`.
|
|
@@ -45,15 +45,17 @@ If successful, the migration should print `Migration successful!`.
|
|
|
45
45
|
Finally, run the app:
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
|
-
npx dbos
|
|
48
|
+
npx dbos start
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
## The application
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
- `src/main.ts` declares the code to start a DBOS instance and an Express application. When you pass the Express app object as parameter to `DBOS.launch()`, DBOS will wrap all routes with an [OpenTelemetry](https://opentelemetry.io/) tracing middleware and tie HTTP traces to DBOS workflow traces.
|
|
53
|
+
In `src/main.ts`, the Express app object is created and configured to serve an "hello world" DBOS workflow on `/greetings/:user`. This file also hosts the code of said DBOS workflow: an `Hello` class with a single `helloTransaction` method.
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
|
|
56
|
+
Then the `main()` function declares the code to start a DBOS instance and an Express application. When you pass the Express app object as parameter to `DBOS.launch()`, DBOS will wrap all routes with an [OpenTelemetry](https://opentelemetry.io/) tracing middleware and tie HTTP traces to DBOS workflow traces.
|
|
57
|
+
|
|
58
|
+
To add more functionality to this application, modify `src/main.ts`. If you used `npm run dev`, it will automatically rebuild and restart.
|
|
57
59
|
|
|
58
60
|
## Running in DBOS Cloud
|
|
59
61
|
|
|
@@ -1,6 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
import { DBOS } from '@dbos-inc/dbos-sdk';
|
|
1
|
+
// Welcome to DBOS!
|
|
3
2
|
|
|
3
|
+
// This is a sample "Hello" app built with DBOS, Express.js, and Knex.
|
|
4
|
+
// It greets visitors and keeps track of how many times each visitor has been greeted.
|
|
5
|
+
|
|
6
|
+
// First let's import express and DBOS
|
|
7
|
+
import express from "express";
|
|
8
|
+
import { DBOS } from "@dbos-inc/dbos-sdk";
|
|
9
|
+
|
|
10
|
+
// Then, let's declare a type representing the "dbos_hello" database table
|
|
11
|
+
export interface dbos_hello {
|
|
12
|
+
name: string;
|
|
13
|
+
greet_count: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Now let's define a class with some static functions.
|
|
17
|
+
// DBOS uses TypeScript decorators to automatically make your functions reliable, so they need to be static.
|
|
18
|
+
export class Hello {
|
|
19
|
+
// This function greets a user and increments the greet count in the database.
|
|
20
|
+
// The @DBOS.transaction() decorator ensures that this function runs as a database transaction.
|
|
21
|
+
@DBOS.transaction()
|
|
22
|
+
static async helloTransaction(user: string) {
|
|
23
|
+
const query = "INSERT INTO dbos_hello (name, greet_count) VALUES (?, 1) ON CONFLICT (name) DO UPDATE SET greet_count = dbos_hello.greet_count + 1 RETURNING greet_count;";
|
|
24
|
+
const { rows } = (await DBOS.knexClient.raw(query, [user])) as { rows: dbos_hello[] };
|
|
25
|
+
const greet_count = rows[0].greet_count;
|
|
26
|
+
const greeting = `Hello, ${user}! You have been greeted ${greet_count} times.`;
|
|
27
|
+
return Hello.makeHTML(greeting);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Finally, we will declare helper functions to serve static HTML to user.s
|
|
31
|
+
|
|
32
|
+
static async readme() {
|
|
33
|
+
const message = Hello.makeHTML(
|
|
34
|
+
`Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br>
|
|
35
|
+
For example, visit <code class="bg-gray-100 px-1 rounded"><a href="/greeting/Mike" class="text-blue-600 hover:underline">/greeting/Mike</a></code><br>
|
|
36
|
+
The counter increments with each page visit.`
|
|
37
|
+
);
|
|
38
|
+
return Promise.resolve(message);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// A helper function to create HTML pages with some styling
|
|
42
|
+
static makeHTML(message: string) {
|
|
43
|
+
const page = `
|
|
44
|
+
<!DOCTYPE html>
|
|
45
|
+
<html lang="en">
|
|
46
|
+
<head>
|
|
47
|
+
<title>DBOS Template App</title>
|
|
48
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
49
|
+
</head>
|
|
50
|
+
<body class="font-sans text-gray-800 p-6 max-w-2xl mx-auto">
|
|
51
|
+
<h1 class="text-3xl font-semibold mb-4">Welcome to DBOS!</h1>
|
|
52
|
+
<p class="mt-8 mb-8">` + message + `</p>
|
|
53
|
+
<p class="mb-2">
|
|
54
|
+
To learn how to run this app yourself, visit our
|
|
55
|
+
<a href="https://docs.dbos.dev/quickstart?language=typescript" class="text-blue-600 hover:underline">Quickstart</a>.
|
|
56
|
+
</p><p class="mb-2">
|
|
57
|
+
Then, to learn how to build crashproof apps, continue to our
|
|
58
|
+
<a href="https://docs.dbos.dev/typescript/programming-guide" class="text-blue-600 hover:underline">Programming Guide</a>.<br>
|
|
59
|
+
</p>
|
|
60
|
+
</body>
|
|
61
|
+
</html>`;
|
|
62
|
+
return page;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Now, let's create an Express app and define some routes.
|
|
67
|
+
export const app = express();
|
|
68
|
+
// Parse JSON payloads and make it available to req.body
|
|
69
|
+
app.use(express.json());
|
|
70
|
+
|
|
71
|
+
// We'll serve the README at the root of the app
|
|
72
|
+
app.get("/", async (_, res) => {
|
|
73
|
+
res.send(await Hello.readme());
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Serve this function from HTTP GET requests at the /greeting endpoint with 'user' as a path parameter
|
|
77
|
+
// The handler will in turn call a reliable DBOS operation (helloTransaction) to greet the user
|
|
78
|
+
app.get("/greeting/:user", async (req, res) => {
|
|
79
|
+
const { user } = req.params;
|
|
80
|
+
res.send(await Hello.helloTransaction(user));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Finally, let's start the server
|
|
4
84
|
async function main() {
|
|
5
85
|
await DBOS.launch({expressApp: app});
|
|
6
86
|
|
|
@@ -13,4 +93,7 @@ async function main() {
|
|
|
13
93
|
});
|
|
14
94
|
}
|
|
15
95
|
|
|
16
|
-
|
|
96
|
+
// Only start the server when this file is run directly from Node
|
|
97
|
+
if (require.main === module) {
|
|
98
|
+
main().catch(console.log);
|
|
99
|
+
}
|
|
@@ -25,7 +25,7 @@ Prisma provides rich support for [schema migrations](https://www.prisma.io/docs/
|
|
|
25
25
|
Fore more information, see [our docs](https://docs.dbos.dev/tutorials/using-prisma).
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
npx dbos
|
|
28
|
+
npx dbos migrate
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
If successful, the migration should print `Migration successful!`.
|
|
@@ -33,7 +33,7 @@ If successful, the migration should print `Migration successful!`.
|
|
|
33
33
|
Finally, run the app:
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
npx dbos
|
|
36
|
+
npx dbos start
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
To see that it's working, visit this URL in your browser: [`http://localhost:3000/greeting/dbos`](http://localhost:3000/greeting/dbos).
|
|
@@ -25,7 +25,7 @@ TypeORM provides rich support for [schema migrations](https://typeorm.io/migrati
|
|
|
25
25
|
Fore more information, see [our docs](https://docs.dbos.dev/tutorials/using-typeorm).
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
npx dbos
|
|
28
|
+
npx dbos migrate
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
If successful, the migration should print `Migration successful!`.
|
|
@@ -33,7 +33,7 @@ If successful, the migration should print `Migration successful!`.
|
|
|
33
33
|
Finally, run the app:
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
npx dbos
|
|
36
|
+
npx dbos start
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
To see that it's working, visit this URL in your browser: [`http://localhost:3000/greeting/dbos`](http://localhost:3000/greeting/dbos).
|
|
@@ -36,7 +36,7 @@ npm run build
|
|
|
36
36
|
Then, run a schema migration to create some tables:
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
npx dbos
|
|
39
|
+
npx dbos migrate
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
If successful, the migration should print `Migration successful!`.
|
|
@@ -44,7 +44,7 @@ If successful, the migration should print `Migration successful!`.
|
|
|
44
44
|
Finally, run the app:
|
|
45
45
|
|
|
46
46
|
```bash
|
|
47
|
-
npx dbos
|
|
47
|
+
npx dbos start
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
## Next Steps
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// Welcome to DBOS!
|
|
2
|
-
|
|
3
|
-
// This is a sample "Hello" app built with DBOS, Express.js, and Knex.
|
|
4
|
-
// It greets visitors and keeps track of how many times each visitor has been greeted.
|
|
5
|
-
|
|
6
|
-
// First let's import express and DBOS
|
|
7
|
-
import express from "express";
|
|
8
|
-
import { DBOS } from "@dbos-inc/dbos-sdk";
|
|
9
|
-
|
|
10
|
-
// Then, let's declare a type representing the "dbos_hello" database table
|
|
11
|
-
export interface dbos_hello {
|
|
12
|
-
name: string;
|
|
13
|
-
greet_count: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Now let's define a class with some static functions.
|
|
17
|
-
// DBOS uses TypeScript decorators to automatically make your functions reliable, so they need to be static.
|
|
18
|
-
export class Hello {
|
|
19
|
-
// This function greets a user and increments the greet count in the database.
|
|
20
|
-
// The @DBOS.transaction() decorator ensures that this function runs as a database transaction.
|
|
21
|
-
@DBOS.transaction()
|
|
22
|
-
static async helloTransaction(user: string) {
|
|
23
|
-
const query = "INSERT INTO dbos_hello (name, greet_count) VALUES (?, 1) ON CONFLICT (name) DO UPDATE SET greet_count = dbos_hello.greet_count + 1 RETURNING greet_count;";
|
|
24
|
-
const { rows } = (await DBOS.knexClient.raw(query, [user])) as { rows: dbos_hello[] };
|
|
25
|
-
const greet_count = rows[0].greet_count;
|
|
26
|
-
const greeting = `Hello, ${user}! You have been greeted ${greet_count} times.`;
|
|
27
|
-
return Hello.makeHTML(greeting);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Finally, we will declare helper functions to serve static HTML to user.s
|
|
31
|
-
|
|
32
|
-
static async readme() {
|
|
33
|
-
const message = Hello.makeHTML(
|
|
34
|
-
`Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br>
|
|
35
|
-
For example, visit <code class="bg-gray-100 px-1 rounded"><a href="/greeting/Mike" class="text-blue-600 hover:underline">/greeting/Mike</a></code><br>
|
|
36
|
-
The counter increments with each page visit.`
|
|
37
|
-
);
|
|
38
|
-
return Promise.resolve(message);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// A helper function to create HTML pages with some styling
|
|
42
|
-
static makeHTML(message: string) {
|
|
43
|
-
const page = `
|
|
44
|
-
<!DOCTYPE html>
|
|
45
|
-
<html lang="en">
|
|
46
|
-
<head>
|
|
47
|
-
<title>DBOS Template App</title>
|
|
48
|
-
<script src="https://cdn.tailwindcss.com"></script>
|
|
49
|
-
</head>
|
|
50
|
-
<body class="font-sans text-gray-800 p-6 max-w-2xl mx-auto">
|
|
51
|
-
<h1 class="text-3xl font-semibold mb-4">Welcome to DBOS!</h1>
|
|
52
|
-
<p class="mt-8 mb-8">` + message + `</p>
|
|
53
|
-
<p class="mb-2">
|
|
54
|
-
To learn how to run this app yourself, visit our
|
|
55
|
-
<a href="https://docs.dbos.dev/quickstart?language=typescript" class="text-blue-600 hover:underline">Quickstart</a>.
|
|
56
|
-
</p><p class="mb-2">
|
|
57
|
-
Then, to learn how to build crashproof apps, continue to our
|
|
58
|
-
<a href="https://docs.dbos.dev/typescript/programming-guide" class="text-blue-600 hover:underline">Programming Guide</a>.<br>
|
|
59
|
-
</p>
|
|
60
|
-
</body>
|
|
61
|
-
</html>`;
|
|
62
|
-
return page;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Now, let's create an Express app and define some routes.
|
|
67
|
-
export const app = express();
|
|
68
|
-
// Parse JSON payloads and make it available to req.body
|
|
69
|
-
app.use(express.json());
|
|
70
|
-
|
|
71
|
-
// We'll serve the README at the root of the app
|
|
72
|
-
app.get("/", async (_, res) => {
|
|
73
|
-
res.send(await Hello.readme());
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// Serve this function from HTTP GET requests at the /greeting endpoint with 'user' as a path parameter
|
|
77
|
-
// The handler will in turn call a reliable DBOS operation (helloTransaction) to greet the user
|
|
78
|
-
app.get("/greeting/:user", async (req, res) => {
|
|
79
|
-
const { user } = req.params;
|
|
80
|
-
res.send(await Hello.helloTransaction(user));
|
|
81
|
-
});
|