@dbos-inc/create 1.31.6-preview → 1.31.12-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.
Files changed (39) hide show
  1. package/package.json +1 -1
  2. package/templates/hello/README.md +9 -28
  3. package/templates/hello/package.json +1 -5
  4. package/templates/hello/src/operations.test.ts +7 -8
  5. package/templates/hello/src/operations.ts +11 -13
  6. package/templates/{hello-v2 → hello-contexts}/README.md +28 -7
  7. package/templates/{hello-v2 → hello-contexts}/package.json +5 -1
  8. package/templates/{hello-v2 → hello-contexts}/src/operations.test.ts +8 -7
  9. package/templates/{hello-v2 → hello-contexts}/src/operations.ts +13 -11
  10. package/templates/hello-drizzle/README.md +4 -4
  11. package/templates/hello-drizzle/package.json +2 -2
  12. package/templates/hello-drizzle/src/operations.test.ts +7 -8
  13. package/templates/hello-drizzle/src/operations.ts +7 -7
  14. package/templates/hello-express/README.md +3 -3
  15. package/templates/hello-nextjs/README.md +21 -12
  16. package/templates/hello-nextjs/src/actions/dbosWorkflow.tsx +24 -0
  17. package/templates/hello-nextjs/src/app/crash/route.ts +8 -0
  18. package/templates/hello-nextjs/src/app/page.tsx +10 -2
  19. package/templates/hello-nextjs/src/app/step/[slug]/route.ts +15 -0
  20. package/templates/hello-nextjs/src/app/tasks/[slug]/route.ts +18 -0
  21. package/templates/hello-nextjs/src/components/client/BackGroundTask.tsx +180 -0
  22. package/templates/hello-prisma/README.md +6 -6
  23. package/templates/hello-prisma/src/operations.test.ts +6 -6
  24. package/templates/hello-prisma/src/operations.ts +7 -7
  25. package/templates/hello-typeorm/README.md +6 -6
  26. package/templates/hello-typeorm/src/operations.test.ts +7 -6
  27. package/templates/hello-typeorm/src/operations.ts +7 -7
  28. /package/templates/{hello-v2 → hello-contexts}/.vscode/extensions.json +0 -0
  29. /package/templates/{hello-v2 → hello-contexts}/.vscode/launch.json +0 -0
  30. /package/templates/{hello-v2 → hello-contexts}/.vscode/tasks.json +0 -0
  31. /package/templates/{hello-v2 → hello-contexts}/dbos-config.yaml +0 -0
  32. /package/templates/{hello-v2 → hello-contexts}/eslint.config.js +0 -0
  33. /package/templates/{hello-v2 → hello-contexts}/gitignore.template +0 -0
  34. /package/templates/{hello-v2 → hello-contexts}/jest.config.js +0 -0
  35. /package/templates/{hello-v2 → hello-contexts}/knexfile.js +0 -0
  36. /package/templates/{hello-v2 → hello-contexts}/migrations/20240212161006_create_dbos_hello_tables.js +0 -0
  37. /package/templates/{hello-v2 → hello-contexts}/nodemon.json +0 -0
  38. /package/templates/{hello-v2 → hello-contexts}/start_postgres_docker.js +0 -0
  39. /package/templates/{hello-v2 → hello-contexts}/tsconfig.json +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbos-inc/create",
3
- "version": "1.31.6-preview",
3
+ "version": "1.31.12-preview",
4
4
  "description": "Tool for performing project initialization from template",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  # DBOS Hello
2
2
 
3
- This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Knex](https://docs.dbos.dev/tutorials/using-knex).
3
+ This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Knex](https://docs.dbos.dev/typescript/tutorials/orms/using-knex).
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -14,11 +14,11 @@ node start_postgres_docker.js
14
14
 
15
15
  If successful, the script should print `Database started successfully!`.
16
16
 
17
- Next, you can build and run the app in one step under `nodemon`:
18
-
17
+ To build the app, set up the database, and run, in one step:
19
18
  ```bash
20
19
  npm run dev
21
20
  ```
21
+ This uses `nodemon`, so if you change your app it will automatically restart with changes.
22
22
 
23
23
  To see that it's working, visit this URL in your browser: [`http://localhost:3000/greeting/dbos`](http://localhost:3000/greeting/dbos).
24
24
  You should get this message: `Hello, dbos! You have been greeted 1 times.`
@@ -26,10 +26,9 @@ Each time you refresh the page, the counter should go up by one!
26
26
 
27
27
  Congratulations! You just launched a DBOS application.
28
28
 
29
- ## Production build
30
-
31
- In production, instead of using `nodemon`, the following separate steps should be used to build, run database setup, and start the app.
29
+ ### Separate Build and Run Steps
32
30
 
31
+ To build the app:
33
32
  ```bash
34
33
  npm run build
35
34
  ```
@@ -48,27 +47,9 @@ Finally, run the app:
48
47
  npx dbos start
49
48
  ```
50
49
 
51
- ## The application
52
-
53
- The core of the application resides in `src/operations.ts`. It declares an "hello world" DBOS workflow served at `/greetings/:user`. To add more functionality, modify `src/operations.ts`. If you used `npm run dev`, it will automatically rebuild and restart.
54
-
55
- ## Running in DBOS Cloud
56
-
57
- To deploy this app to DBOS Cloud, first install the DBOS Cloud CLI (example with [npm](https://www.npmjs.com/)):
58
-
59
- ```shell
60
- npm i -g @dbos-inc/dbos-cloud
61
- ```
62
-
63
- Then, run this command to deploy your app:
64
-
65
- ```shell
66
- dbos-cloud app deploy
67
- ```
68
-
69
- functionality to this application, modify `src/operations.ts`. If you used `npm run dev`, it will automatically rebuild and restart.
70
-
71
50
  ## Next Steps
72
51
 
73
- - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/getting-started/quickstart-programming).
74
- - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc/dbos-transact).
52
+ - To add more functionality to this application, modify `src/operations.ts`, and save it. If you are using, `npm run dev`, `nodemon` will rebuild and restart the app automatically.
53
+ - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/typescript/programming-guide).
54
+ - To learn how to deploy your application to DBOS Cloud, visit our [cloud quickstart](https://docs.dbos.dev/quickstart)
55
+ - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc).
@@ -1,19 +1,15 @@
1
1
  {
2
- "name": "dbos-hello",
2
+ "name": "dbos-hello-v2",
3
3
  "version": "0.0.1",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "test": "npx dbos rollback && npx dbos migrate && jest",
7
- "lint": "eslint src",
8
- "lint-fix": "eslint --fix src",
9
7
  "dev": "nodemon",
10
8
  "start": "npx dbos start"
11
9
  },
12
10
  "devDependencies": {
13
- "@dbos-inc/eslint-plugin": "^3.3.4",
14
11
  "@types/jest": "^29.5.12",
15
12
  "@types/supertest": "^2.0.16",
16
- "eslint": "^8.57.0",
17
13
  "jest": "^29.7.0",
18
14
  "nodemon": "^3.1.0",
19
15
  "supertest": "^7.0.0",
@@ -1,27 +1,26 @@
1
- import { TestingRuntime, createTestingRuntime } from "@dbos-inc/dbos-sdk";
1
+ import { DBOS } from "@dbos-inc/dbos-sdk";
2
2
  import { Hello, dbos_hello } from "./operations";
3
3
  import request from "supertest";
4
4
 
5
5
  describe("operations-test", () => {
6
- let testRuntime: TestingRuntime;
7
-
8
6
  beforeAll(async () => {
9
- testRuntime = await createTestingRuntime();
7
+ await DBOS.launch();
8
+ await DBOS.launchAppHTTPServer();
10
9
  });
11
10
 
12
11
  afterAll(async () => {
13
- await testRuntime.destroy();
12
+ await DBOS.shutdown();
14
13
  });
15
14
 
16
15
  /**
17
16
  * Test the transaction.
18
17
  */
19
18
  test("test-transaction", async () => {
20
- const res = await testRuntime.invoke(Hello).helloTransaction("dbos");
19
+ const res = await Hello.helloTransaction("dbos");
21
20
  expect(res).toMatch("Hello, dbos! You have been greeted");
22
21
 
23
22
  // Check the greet count.
24
- const rows = await testRuntime.queryUserDB<dbos_hello>("SELECT * FROM dbos_hello WHERE name=$1", "dbos");
23
+ const rows = await DBOS.executor.queryUserDB("SELECT * FROM dbos_hello WHERE name=$1", ["dbos"]) as dbos_hello[];
25
24
  expect(rows[0].greet_count).toBe(1);
26
25
  });
27
26
 
@@ -29,7 +28,7 @@ describe("operations-test", () => {
29
28
  * Test the HTTP endpoint.
30
29
  */
31
30
  test("test-endpoint", async () => {
32
- const res = await request(testRuntime.getHandlersCallback()).get(
31
+ const res = await request(DBOS.getHTTPHandlersCallback()).get(
33
32
  "/greeting/dbos"
34
33
  );
35
34
  expect(res.statusCode).toBe(200);
@@ -2,36 +2,34 @@
2
2
 
3
3
  // This is a sample "Hello" app built with DBOS.
4
4
  // It greets visitors and keeps track of how many times each visitor has been greeted.
5
- // To run this app, visit our Quickstart: https://docs.dbos.dev/getting-started/quickstart
6
5
 
7
- import { HandlerContext, TransactionContext, Transaction, GetApi, ArgSource, ArgSources } from "@dbos-inc/dbos-sdk";
8
- import { Knex } from "knex";
6
+ // First, let's import DBOS
7
+ import { DBOS } from "@dbos-inc/dbos-sdk";
9
8
 
10
- // The schema of the database table used in this example.
9
+ // Then, let's declare a type representing the "dbos_hello" database table
11
10
  export interface dbos_hello {
12
11
  name: string;
13
12
  greet_count: number;
14
13
  }
15
14
 
15
+ // Now let's define a class with some static functions.
16
+ // DBOS uses TypeScript decorators to automatically make your functions reliable, so they need to be static.
16
17
  export class Hello {
17
18
  // Serve this function from HTTP GET requests at the /greeting endpoint with 'user' as a path parameter
18
- // The @Transaction() decorator ensures that this function runs as a database transaction.
19
- @GetApi("/greeting/:user")
20
- @Transaction() // Run this function as a database transaction
21
- static async helloTransaction(ctxt: TransactionContext<Knex>, @ArgSource(ArgSources.URL) user: string) {
19
+ @DBOS.getApi("/greeting/:user")
20
+ @DBOS.transaction() // Run this function as a database transaction
21
+ static async helloTransaction(user: string) {
22
22
  // Retrieve and increment the number of times this user has been greeted.
23
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 ctxt.client.raw(query, [user]) as { rows: dbos_hello[] };
24
+ const { rows } = (await DBOS.knexClient.raw(query, [user])) as { rows: dbos_hello[] };
25
25
  const greet_count = rows[0].greet_count;
26
26
  const greeting = `Hello, ${user}! You have been greeted ${greet_count} times.`;
27
27
  return Hello.makeHTML(greeting);
28
28
  }
29
29
 
30
- // Let's declare helper functions to serve static HTML
31
-
32
30
  // Serve a quick readme for the app at the / endpoint
33
- @GetApi('/')
34
- static async readme(_ctxt: HandlerContext) {
31
+ @DBOS.getApi("/")
32
+ static async readme() {
35
33
  const message = Hello.makeHTML(
36
34
  `Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br>
37
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>
@@ -1,6 +1,8 @@
1
1
  # DBOS Hello
2
2
 
3
- This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Knex](https://docs.dbos.dev/tutorials/using-knex).
3
+ *NOTE:* This is an older version of the DBOS `hello` app that uses a previous API based on passing [DBOS contexts](https://docs.dbos.dev/typescript/reference/transactapi/oldapi/contexts) around as function arguments.
4
+
5
+ This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Knex](https://docs.dbos.dev/typescript/tutorials/orms/using-knex).
4
6
 
5
7
  ## Getting Started
6
8
 
@@ -14,11 +16,11 @@ node start_postgres_docker.js
14
16
 
15
17
  If successful, the script should print `Database started successfully!`.
16
18
 
17
- To build the app, set up the database, and run, in one step:
19
+ Next, you can build and run the app in one step under `nodemon`:
20
+
18
21
  ```bash
19
22
  npm run dev
20
23
  ```
21
- This uses `nodemon`, so if you change your app it will automatically restart with changes.
22
24
 
23
25
  To see that it's working, visit this URL in your browser: [`http://localhost:3000/greeting/dbos`](http://localhost:3000/greeting/dbos).
24
26
  You should get this message: `Hello, dbos! You have been greeted 1 times.`
@@ -26,9 +28,10 @@ Each time you refresh the page, the counter should go up by one!
26
28
 
27
29
  Congratulations! You just launched a DBOS application.
28
30
 
29
- ### Separate Build and Run Steps
31
+ ## Production build
32
+
33
+ In production, instead of using `nodemon`, the following separate steps should be used to build, run database setup, and start the app.
30
34
 
31
- To build the app:
32
35
  ```bash
33
36
  npm run build
34
37
  ```
@@ -47,9 +50,27 @@ Finally, run the app:
47
50
  npx dbos start
48
51
  ```
49
52
 
53
+ ## The application
54
+
55
+ The core of the application resides in `src/operations.ts`. It declares an "hello world" DBOS workflow served at `/greetings/:user`. To add more functionality, modify `src/operations.ts`. If you used `npm run dev`, it will automatically rebuild and restart.
56
+
57
+ ## Running in DBOS Cloud
58
+
59
+ To deploy this app to DBOS Cloud, first install the DBOS Cloud CLI (example with [npm](https://www.npmjs.com/)):
60
+
61
+ ```shell
62
+ npm i -g @dbos-inc/dbos-cloud
63
+ ```
64
+
65
+ Then, run this command to deploy your app:
66
+
67
+ ```shell
68
+ dbos-cloud app deploy
69
+ ```
70
+
71
+ functionality to this application, modify `src/operations.ts`. If you used `npm run dev`, it will automatically rebuild and restart.
72
+
50
73
  ## Next Steps
51
74
 
52
- - To add more functionality to this application, modify `src/operations.ts`, and save it. If you are using, `npm run dev`, `nodemon` will rebuild and restart the app automatically.
53
75
  - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/getting-started/quickstart-programming).
54
- - To learn how to deploy your application to DBOS Cloud, visit our [cloud quickstart](https://docs.dbos.dev/getting-started/quickstart-cloud/)
55
76
  - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc/dbos-transact).
@@ -1,15 +1,19 @@
1
1
  {
2
- "name": "dbos-hello-v2",
2
+ "name": "dbos-hello",
3
3
  "version": "0.0.1",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "test": "npx dbos rollback && npx dbos migrate && jest",
7
+ "lint": "eslint src",
8
+ "lint-fix": "eslint --fix src",
7
9
  "dev": "nodemon",
8
10
  "start": "npx dbos start"
9
11
  },
10
12
  "devDependencies": {
13
+ "@dbos-inc/eslint-plugin": "^3.3.4",
11
14
  "@types/jest": "^29.5.12",
12
15
  "@types/supertest": "^2.0.16",
16
+ "eslint": "^8.57.0",
13
17
  "jest": "^29.7.0",
14
18
  "nodemon": "^3.1.0",
15
19
  "supertest": "^7.0.0",
@@ -1,26 +1,27 @@
1
- import { DBOS } from "@dbos-inc/dbos-sdk";
1
+ import { TestingRuntime, createTestingRuntime } from "@dbos-inc/dbos-sdk";
2
2
  import { Hello, dbos_hello } from "./operations";
3
3
  import request from "supertest";
4
4
 
5
5
  describe("operations-test", () => {
6
+ let testRuntime: TestingRuntime;
7
+
6
8
  beforeAll(async () => {
7
- await DBOS.launch();
8
- await DBOS.launchAppHTTPServer();
9
+ testRuntime = await createTestingRuntime();
9
10
  });
10
11
 
11
12
  afterAll(async () => {
12
- await DBOS.shutdown();
13
+ await testRuntime.destroy();
13
14
  });
14
15
 
15
16
  /**
16
17
  * Test the transaction.
17
18
  */
18
19
  test("test-transaction", async () => {
19
- const res = await Hello.helloTransaction("dbos");
20
+ const res = await testRuntime.invoke(Hello).helloTransaction("dbos");
20
21
  expect(res).toMatch("Hello, dbos! You have been greeted");
21
22
 
22
23
  // Check the greet count.
23
- const rows = await DBOS.executor.queryUserDB("SELECT * FROM dbos_hello WHERE name=$1", ["dbos"]) as dbos_hello[];
24
+ const rows = await testRuntime.queryUserDB<dbos_hello>("SELECT * FROM dbos_hello WHERE name=$1", "dbos");
24
25
  expect(rows[0].greet_count).toBe(1);
25
26
  });
26
27
 
@@ -28,7 +29,7 @@ describe("operations-test", () => {
28
29
  * Test the HTTP endpoint.
29
30
  */
30
31
  test("test-endpoint", async () => {
31
- const res = await request(DBOS.getHTTPHandlersCallback()).get(
32
+ const res = await request(testRuntime.getHandlersCallback()).get(
32
33
  "/greeting/dbos"
33
34
  );
34
35
  expect(res.statusCode).toBe(200);
@@ -2,34 +2,36 @@
2
2
 
3
3
  // This is a sample "Hello" app built with DBOS.
4
4
  // It greets visitors and keeps track of how many times each visitor has been greeted.
5
+ // To run this app, visit our Quickstart: https://docs.dbos.dev/getting-started/quickstart
5
6
 
6
- // First, let's import DBOS
7
- import { DBOS } from "@dbos-inc/dbos-sdk";
7
+ import { HandlerContext, TransactionContext, Transaction, GetApi, ArgSource, ArgSources } from "@dbos-inc/dbos-sdk";
8
+ import { Knex } from "knex";
8
9
 
9
- // Then, let's declare a type representing the "dbos_hello" database table
10
+ // The schema of the database table used in this example.
10
11
  export interface dbos_hello {
11
12
  name: string;
12
13
  greet_count: number;
13
14
  }
14
15
 
15
- // Now let's define a class with some static functions.
16
- // DBOS uses TypeScript decorators to automatically make your functions reliable, so they need to be static.
17
16
  export class Hello {
18
17
  // Serve this function from HTTP GET requests at the /greeting endpoint with 'user' as a path parameter
19
- @DBOS.getApi("/greeting/:user")
20
- @DBOS.transaction() // Run this function as a database transaction
21
- static async helloTransaction(user: string) {
18
+ // The @Transaction() decorator ensures that this function runs as a database transaction.
19
+ @GetApi("/greeting/:user")
20
+ @Transaction() // Run this function as a database transaction
21
+ static async helloTransaction(ctxt: TransactionContext<Knex>, @ArgSource(ArgSources.URL) user: string) {
22
22
  // Retrieve and increment the number of times this user has been greeted.
23
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[] };
24
+ const { rows } = await ctxt.client.raw(query, [user]) as { rows: dbos_hello[] };
25
25
  const greet_count = rows[0].greet_count;
26
26
  const greeting = `Hello, ${user}! You have been greeted ${greet_count} times.`;
27
27
  return Hello.makeHTML(greeting);
28
28
  }
29
29
 
30
+ // Let's declare helper functions to serve static HTML
31
+
30
32
  // Serve a quick readme for the app at the / endpoint
31
- @DBOS.getApi("/")
32
- static async readme() {
33
+ @GetApi('/')
34
+ static async readme(_ctxt: HandlerContext) {
33
35
  const message = Hello.makeHTML(
34
36
  `Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br>
35
37
  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>
@@ -1,6 +1,6 @@
1
1
  # DBOS Hello with Drizzle
2
2
 
3
- This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Drizzle](https://docs.dbos.dev/tutorials/using-drizzle).
3
+ This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Drizzle](https://docs.dbos.dev/typescript/tutorials/orms/using-drizzle).
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -43,6 +43,6 @@ Congratulations! You just launched a DBOS application.
43
43
  ## Next Steps
44
44
 
45
45
  - To add more functionality to this application, modify `src/operations.ts`, then rebuild and restart it. Alternatively, `npm run dev` uses `nodemon` to automatically rebuild and restart the app when source files change, using instructions specified in `nodemon.json`.
46
- - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/getting-started/quickstart-programming).
47
- - To learn how to deploy your application to DBOS Cloud, visit our [cloud quickstart](https://docs.dbos.dev/getting-started/quickstart-cloud/)
48
- - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc/dbos-transact).
46
+ - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/typescript/programming-guide).
47
+ - To learn how to deploy your application to DBOS Cloud, visit our [cloud quickstart](https://docs.dbos.dev/quickstart)
48
+ - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc).
@@ -13,7 +13,7 @@
13
13
  "@dbos-inc/eslint-plugin": "^3.3.4",
14
14
  "@types/jest": "^29.5.12",
15
15
  "@types/supertest": "^2.0.16",
16
- "drizzle-kit": "^0.23.2",
16
+ "drizzle-kit": "^0.30.1",
17
17
  "eslint": "^8.57.0",
18
18
  "jest": "^29.7.0",
19
19
  "nodemon": "^3.1.0",
@@ -23,6 +23,6 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@dbos-inc/dbos-sdk": "file:../../../..",
26
- "drizzle-orm": "^0.32.2"
26
+ "drizzle-orm": "^0.38.3"
27
27
  }
28
28
  }
@@ -1,27 +1,26 @@
1
- import { TestingRuntime, createTestingRuntime } from "@dbos-inc/dbos-sdk";
1
+ import { DBOS } from "@dbos-inc/dbos-sdk";
2
2
  import { Hello } from "./operations";
3
3
  import request from "supertest";
4
4
 
5
5
  describe("operations-test", () => {
6
- let testRuntime: TestingRuntime;
7
-
8
6
  beforeAll(async () => {
9
- testRuntime = await createTestingRuntime();
7
+ await DBOS.launch();
8
+ await DBOS.launchAppHTTPServer();
10
9
  });
11
10
 
12
11
  afterAll(async () => {
13
- await testRuntime.destroy();
12
+ await DBOS.shutdown();
14
13
  });
15
14
 
16
15
  /**
17
16
  * Test the transaction.
18
17
  */
19
18
  test("test-transaction", async () => {
20
- const res = await testRuntime.invoke(Hello).helloTransaction("dbos");
19
+ const res = await Hello.helloTransaction("dbos");
21
20
  expect(res).toMatch("Hello, dbos! We have made");
22
21
 
23
22
  // Check the greet count.
24
- const rows = await testRuntime.queryUserDB("SELECT * FROM dbos_hello WHERE greet_count=1");
23
+ const rows = await DBOS.executor.queryUserDB("SELECT * FROM dbos_hello WHERE greet_count=1");
25
24
  expect(rows.length).toEqual(1);
26
25
  });
27
26
 
@@ -29,7 +28,7 @@ describe("operations-test", () => {
29
28
  * Test the HTTP endpoint.
30
29
  */
31
30
  test("test-endpoint", async () => {
32
- const res = await request(testRuntime.getHandlersCallback()).get(
31
+ const res = await request(DBOS.getHTTPHandlersCallback()).get(
33
32
  "/greeting/dbos"
34
33
  );
35
34
  expect(res.statusCode).toBe(200);
@@ -3,25 +3,25 @@
3
3
  // This is the Quickstart Drizzle template app. It greets visitors, counting how many total greetings were made.
4
4
  // To learn how to run this app, visit the Drizzle tutorial: https://docs.dbos.dev/tutorials/using-drizzle
5
5
 
6
- import { HandlerContext, TransactionContext, Transaction, GetApi } from '@dbos-inc/dbos-sdk';
6
+ import { DBOS } from '@dbos-inc/dbos-sdk';
7
7
  import { dbosHello } from './schema';
8
8
  import { NodePgDatabase } from 'drizzle-orm/node-postgres';
9
9
 
10
10
  export class Hello {
11
11
 
12
12
  // Serve this function from HTTP GET requests at the /greeting endpoint with 'user' as a path parameter
13
- @GetApi('/greeting/:user')
14
- @Transaction()
15
- static async helloTransaction(ctxt: TransactionContext<NodePgDatabase>, user: string) {
13
+ @DBOS.getApi('/greeting/:user')
14
+ @DBOS.transaction()
15
+ static async helloTransaction(user: string) {
16
16
  const greeting = `Hello, ${user}!`;
17
- const greetings_output = await ctxt.client.insert(dbosHello).values({greeting}).returning({greet_count: dbosHello.greet_count});
17
+ const greetings_output = await (DBOS.drizzleClient as NodePgDatabase).insert(dbosHello).values({greeting}).returning({greet_count: dbosHello.greet_count});
18
18
  const greeting_message = `${greeting} We have made ${greetings_output[0].greet_count} greetings.`;
19
19
  return Hello.makeHTML(greeting_message);
20
20
  }
21
21
 
22
22
  // Serve a quick readme for the app at the / endpoint
23
- @GetApi('/')
24
- static async readme(_ctxt: HandlerContext) {
23
+ @DBOS.getApi('/')
24
+ static async readme() {
25
25
  const message = Hello.makeHTML(
26
26
  `Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br>
27
27
  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>
@@ -1,6 +1,6 @@
1
1
  # DBOS Hello
2
2
 
3
- This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create`, using [Express.js](https://expressjs.com/) and [Knex](https://docs.dbos.dev/tutorials/using-knex) to interact with postgres.
3
+ This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create`, using [Express.js](https://expressjs.com/) and [Knex](https://docs.dbos.dev/typescript/tutorials/orms/using-knex) to interact with postgres.
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -73,5 +73,5 @@ dbos-cloud app deploy
73
73
 
74
74
  ## Next Steps
75
75
 
76
- - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/getting-started/quickstart-programming).
77
- - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc/dbos-transact).
76
+ - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/typescript/programming-guide).
77
+ - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc).
@@ -1,6 +1,6 @@
1
- # DBOS Hello
1
+ # DBOS Background Job
2
2
 
3
- This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create`, using [Express.js](https://expressjs.com/) and [Knex](https://docs.dbos.dev/tutorials/using-knex) to interact with postgres.
3
+ This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create`, using [Express.js](https://expressjs.com/) and [Knex](https://docs.dbos.dev/typescript/tutorials/orms/using-knex) to interact with postgres.
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -40,12 +40,22 @@ npm run start
40
40
 
41
41
  To see that it's working, visit this URL in your browser: [`http://localhost:3000/`](http://localhost:3000/).
42
42
 
43
- Click on the "Run DBOS Workflow" button.
43
+ Click on the "Start Background Job" button.
44
44
 
45
- You should get this message: `Hello, dbos! You have been greeted 1 times.`
46
- Each time you refresh the page, the counter should go up by one!
45
+ You should this message: `Your background task has completed step 0 of 9.`
46
+ As the background job completes steps, the step counter should go up by one!
47
47
 
48
- Congratulations! You just launched a DBOS application.
48
+ Click on "Crash the application" button.
49
+
50
+ The step counter stops increasing.
51
+ On the command line, you will see that the application has stopped.
52
+ Start the application again.
53
+ ```bash
54
+ npm run start
55
+ ```
56
+ In the browser, you will see that the execution of steps resumes where it left off and eventually completes.
57
+
58
+ Congratulations! You just run a DBOS application.
49
59
 
50
60
  ## The application
51
61
 
@@ -57,9 +67,9 @@ if (process.env.NEXT_PHASE !== "phase-production-build") {
57
67
  await DBOS.launch();
58
68
  }
59
69
  ```
60
- - The workflow is called by the POST method in app/greetings/route.ts.
70
+ - The workflow for the background job is called by the called the GET method in app/tasks/route.ts.
61
71
 
62
- - The POST is called by the component in src/components/callDBOSWorkflow.tsx. It calls the route /greetings.
72
+ - The GET is called by the component in src/components/BackGroundTask.tsx. It calls the route /tasks.
63
73
 
64
74
  - The component is called from the main UI page.tsx.
65
75
 
@@ -72,7 +82,7 @@ To add more functionality to this application, modify `src/operations.ts`. If yo
72
82
 
73
83
  ## Running in DBOS Cloud
74
84
 
75
- To deploy this app to DBOS Cloud, first install the DBOS Cloud CLI (example with [npm](https://www.npmjs.com/)):
85
+ To deploy this app to DBOS Cloud, first install the DBOS Cloud CLI (example with [npm](https://www.npmjs.com/)):
76
86
 
77
87
  ```shell
78
88
  npm i -g @dbos-inc/dbos-cloud
@@ -86,6 +96,5 @@ dbos-cloud app deploy
86
96
 
87
97
  ## Next Steps
88
98
 
89
- - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/getting-started/quickstart-programming).
90
- - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc/dbos-transact).
91
-
99
+ - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/typescript/programming-guide).
100
+ - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc).
@@ -20,6 +20,25 @@ class dbosWorkflowClass {
20
20
  const greeting = `Hello! You have been greeted ${greet_count} times.`;
21
21
  return greeting;
22
22
  }
23
+
24
+ @DBOS.transaction()
25
+ static async backgroundTaskStep(i : number) {
26
+ DBOS.logger.info(`Completed step ${i}`);
27
+ }
28
+
29
+ @DBOS.workflow()
30
+ static async backgroundTask(i: number) {
31
+ DBOS.logger.info("Hello from background task!");
32
+ for (let j = 1; j <= i; j++) {
33
+ await dbosWorkflowClass.backgroundTaskStep(j);
34
+ DBOS.logger.info("Sleeping for 2 seconds");
35
+ await DBOS.sleepSeconds(2);
36
+ await DBOS.setEvent("steps_event", j)
37
+ }
38
+ DBOS.logger.info("Background task complete!");
39
+ }
40
+
41
+
23
42
  }
24
43
 
25
44
  // Launch the DBOS runtime
@@ -34,4 +53,9 @@ if (process.env.NEXT_PHASE !== "phase-production-build") {
34
53
  export async function dbosWorkflow(userName: string) {
35
54
  DBOS.logger.info("Hello from DBOS!");
36
55
  return await dbosWorkflowClass.helloDBOS(userName);
56
+ }
57
+
58
+ export async function dbosBackgroundTask(workflowID: string) {
59
+ DBOS.logger.info("Hello from DBOS!");
60
+ return DBOS.startWorkflow(dbosWorkflowClass, {workflowID: workflowID}).backgroundTask(10);
37
61
  }
@@ -0,0 +1,8 @@
1
+
2
+ export async function GET(request: Request) {
3
+
4
+ console.log("Received request Crashing the app");
5
+
6
+ process.exit(1);
7
+
8
+ }
@@ -1,12 +1,20 @@
1
1
  import Image from "next/image";
2
- import CallDBOSWorkflow from "../components/client/callDBOSWorkflow";
2
+ import BackGroundTask from "@/components/client/BackGroundTask";
3
3
 
4
4
  export default function Home() {
5
5
  return (
6
6
  <div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
7
7
  <main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">
8
+
9
+
10
+ <h1 className="text-xl font-semibold mb-4">Welcome to DBOS!</h1>
11
+
12
+
13
+ <p className="mb-4">
14
+ DBOS helps you build applications that are <strong>resilient to any failure</strong>&mdash;no matter how many times you crash this app, your background task will always recover from its last completed step in about ten seconds.
15
+ </p>
8
16
  <div>
9
- <CallDBOSWorkflow wfResult=""/>
17
+ <BackGroundTask />
10
18
  </div>
11
19
  </main>
12
20
  <footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
@@ -0,0 +1,15 @@
1
+ import { NextResponse } from "next/server";
2
+ import { DBOS } from "@dbos-inc/dbos-sdk";
3
+
4
+ export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
5
+
6
+ const taskId = (await params).slug;
7
+ DBOS.logger.info(`Received request to check on taskId: ${taskId}`);
8
+
9
+ let step = await DBOS.getEvent(taskId, "steps_event");
10
+
11
+ DBOS.logger.info(`For taskId: ${taskId} we are done with ${step} steps`);
12
+
13
+ return NextResponse.json({ "stepsCompleted": step});
14
+
15
+ }
@@ -0,0 +1,18 @@
1
+ import { NextResponse } from "next/server";
2
+ import { DBOS } from "@dbos-inc/dbos-sdk";
3
+ import { dbosBackgroundTask } from "@/actions/dbosWorkflow";
4
+
5
+ export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
6
+
7
+ const taskId = (await params).slug;
8
+
9
+ DBOS.logger.info(`Received request to start background task taskId: ${taskId}`);
10
+
11
+ DBOS.logger.info(`Started background task taskId: ${taskId}`);
12
+
13
+ await dbosBackgroundTask(taskId)
14
+
15
+ return NextResponse.json({ message: "Background task started" });
16
+
17
+ }
18
+
@@ -0,0 +1,180 @@
1
+ "use client";
2
+
3
+ import { useState, useEffect } from "react";
4
+ import { useRouter, useSearchParams } from "next/navigation";
5
+ import { dbosBackgroundTask } from "@/actions/dbosWorkflow";
6
+ import { Suspense } from 'react'
7
+
8
+ let intervalInitialized = false;
9
+
10
+ function generateRandomString(): string {
11
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
12
+ const array = new Uint8Array(6);
13
+ crypto.getRandomValues(array); // Fills the array with cryptographically random values
14
+
15
+ return Array.from(array)
16
+ .map(x => chars[x % chars.length])
17
+ .join('');
18
+ }
19
+
20
+ function BackGroundTask() {
21
+ const [isRunning, setIsRunning] = useState(false);
22
+ const [currentStep, setCurrentStep] = useState(0);
23
+ const [taskId, setTaskid] = useState("");
24
+ const [isReconnecting, setIsReconnecting] = useState(false);
25
+
26
+ const router = useRouter();
27
+ const searchParams = useSearchParams();
28
+
29
+ const startBackgroundJob = async () => {
30
+ setIsRunning(true);
31
+
32
+ setCurrentStep(0);
33
+
34
+ let task = taskId
35
+ if (taskId === "") {
36
+ task = generateRandomString();
37
+ setTaskid(task);
38
+ updateQueryParam("id", task);
39
+ }
40
+
41
+ // start the background job
42
+ try {
43
+ await fetch(`/tasks/${task}`, { method: "GET" });
44
+ } catch (error) {
45
+ console.error("Failed to start job", error);
46
+ setIsRunning(false);
47
+ }
48
+ };
49
+
50
+ const crashApp = async () => {
51
+
52
+ if(!isRunning) {
53
+ console.log("Not running, nothing to crash");
54
+ return;
55
+ }
56
+
57
+ setIsRunning(false);
58
+
59
+ console.log("Crashing the application");
60
+
61
+ // stop the background job
62
+ try {
63
+ await fetch("/crash", { method: "GET" });
64
+ } catch (error) {
65
+ console.error("Failed to start job", error);
66
+
67
+ }
68
+
69
+ };
70
+
71
+ // Update the URL query parameter
72
+ const updateQueryParam = (key: string, value: string) => {
73
+ const params = new URLSearchParams(searchParams.toString());
74
+ params.set(key, value);
75
+ const newUrl = `${window.location.pathname}?${params.toString()}`;
76
+ router.replace(newUrl);
77
+ };
78
+
79
+ // Remove the `id` query parameter from the URL
80
+ const clearQueryParam = (key: string) => {
81
+ const params = new URLSearchParams(searchParams.toString());
82
+ params.delete(key);
83
+ const newUrl = `${window.location.pathname}?${params.toString()}`;
84
+ router.replace(newUrl);
85
+ };
86
+
87
+ // fetch the current progress
88
+ const fetchProgress = async () => {
89
+ try {
90
+
91
+ if (taskId === "") {
92
+ console.log("No task to monitor");
93
+ return;
94
+ }
95
+
96
+ const response = await fetch(`/step/${taskId}`, { method: "GET" });
97
+ if (!response.ok) {
98
+ console.error("Failed to fetch job progress", response.statusText);
99
+ setIsReconnecting(true);
100
+ return;
101
+ }
102
+ setIsReconnecting(false);
103
+
104
+ const data = await response.json();
105
+
106
+ console.log("Step completed", data.stepsCompleted);
107
+
108
+ if (data.stepsCompleted) {
109
+ setIsRunning(true);
110
+ setCurrentStep(data.stepsCompleted);
111
+
112
+
113
+ if (data.stepsCompleted === 10) {
114
+ clearQueryParam("id");
115
+ setIsRunning(false);
116
+ setTaskid("");
117
+ setCurrentStep(0);
118
+
119
+ }
120
+ }
121
+ } catch (error) {
122
+ console.error("Failed to fetch job progress", error);
123
+ setIsRunning(false);
124
+ setTaskid("");
125
+ setIsReconnecting(true);
126
+ }
127
+ };
128
+
129
+ // Polling the progress every 2 seconds while the job is running
130
+ useEffect(() => {
131
+ const idFromUrl = searchParams.get("id");
132
+ if (idFromUrl) {
133
+ setTaskid(idFromUrl);
134
+ setIsRunning(true); // Assume the job is already running if there's an ID
135
+ }
136
+
137
+ if (!intervalInitialized) {
138
+ const interval = setInterval(fetchProgress, 2000);
139
+ intervalInitialized = true;
140
+ return () => {
141
+ clearInterval(interval);
142
+ intervalInitialized = false;
143
+ };
144
+ }
145
+ }, [searchParams]);
146
+
147
+
148
+ return (
149
+ <div>
150
+ <div className="flex flex-row gap-2">
151
+ <button onClick={startBackgroundJob} disabled={isRunning} className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
152
+ {isRunning ? "Job in Progress..." : "Start Background Job"}
153
+ </button>
154
+ <button onClick={crashApp} disabled={!isRunning} className="px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600">
155
+ { isRunning ? "Crash the application" : "Not Running"}
156
+ </button>
157
+ </div>
158
+
159
+ <p>
160
+ {currentStep < 10
161
+ ? `Your background task has completed step ${currentStep} of 10.`
162
+ : "Background task completed successfully!"}
163
+ </p>
164
+ <p>
165
+ {isReconnecting ? "Reconnecting..." : ""}
166
+ </p>
167
+
168
+
169
+ </div>
170
+ );
171
+
172
+ }
173
+
174
+ const WrappedBackgroundJobComponent = () => (
175
+ <Suspense fallback={<p>Loading...</p>}>
176
+ <BackGroundTask />
177
+ </Suspense>
178
+ );
179
+
180
+ export default WrappedBackgroundJobComponent;
@@ -1,6 +1,6 @@
1
1
  # DBOS Hello with Prisma
2
2
 
3
- This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Prisma](https://docs.dbos.dev/tutorials/using-prisma).
3
+ This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Prisma](https://docs.dbos.dev/typescript/tutorials/orms/using-prisma).
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -22,7 +22,7 @@ npm run build
22
22
 
23
23
  Then, run a schema migration to create some tables.
24
24
  Prisma provides rich support for [schema migrations](https://www.prisma.io/docs/orm/prisma-migrate), including automatic generation of migration files from Prisma schema.
25
- Fore more information, see [our docs](https://docs.dbos.dev/tutorials/using-prisma).
25
+ Fore more information, see [our docs](https://docs.dbos.dev/typescript/tutorials/orms/using-prisma).
26
26
 
27
27
  ```bash
28
28
  npx dbos migrate
@@ -44,8 +44,8 @@ Congratulations! You just launched a DBOS application.
44
44
 
45
45
  ## Next Steps
46
46
 
47
- - For more information on using Prisma with DBOS, check out [our docs](https://docs.dbos.dev/tutorials/using-prisma).
47
+ - For more information on using Prisma with DBOS, check out [our docs](https://docs.dbos.dev/typescript/tutorials/orms/using-prisma).
48
48
  - To add more functionality to this application, modify `src/operations.ts`, then rebuild and restart it. Alternatively, `npm run dev` uses `nodemon` to automatically rebuild and restart the app when source files change, using instructions specified in `nodemon.json`.
49
- - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/getting-started/quickstart-programming).
50
- - To learn how to deploy your application to DBOS Cloud, visit our [cloud quickstart](https://docs.dbos.dev/getting-started/quickstart-cloud/)
51
- - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc/dbos-transact).
49
+ - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/typescript/programming-guide).
50
+ - To learn how to deploy your application to DBOS Cloud, visit our [cloud quickstart](https://docs.dbos.dev/quickstart/)
51
+ - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc).
@@ -1,26 +1,26 @@
1
- import { TestingRuntime, createTestingRuntime } from "@dbos-inc/dbos-sdk";
1
+ import { DBOS } from "@dbos-inc/dbos-sdk";
2
2
  import { Hello } from "./operations";
3
3
  import request from "supertest";
4
4
 
5
5
  describe("operations-test", () => {
6
- let testRuntime: TestingRuntime;
7
-
8
6
  beforeAll(async () => {
9
- testRuntime = await createTestingRuntime([Hello]);
7
+ await DBOS.launch();
8
+ await DBOS.launchAppHTTPServer();
10
9
  });
11
10
 
12
11
  afterAll(async () => {
13
- await testRuntime.destroy();
12
+ await DBOS.shutdown();
14
13
  });
15
14
 
16
15
  /**
17
16
  * Test the HTTP endpoint.
18
17
  */
19
18
  test("test-greet", async () => {
20
- const res = await request(testRuntime.getHandlersCallback()).get(
19
+ const res = await request(DBOS.getHTTPHandlersCallback()!).get(
21
20
  "/greeting/dbos"
22
21
  );
23
22
  expect(res.statusCode).toBe(200);
24
23
  expect(res.text).toMatch("Greeting 1: Hello, dbos!");
24
+ expect (await Hello.helloTransaction('bob')).toMatch("Greeting 2: Hello, bob!");
25
25
  });
26
26
  });
@@ -3,18 +3,18 @@
3
3
  // This is the Quickstart Prisma template app. It greets visitors, counting how many total greetings were made.
4
4
  // To learn how to run this app, visit the Prisma tutorial: https://docs.dbos.dev/tutorials/using-prisma
5
5
 
6
- import { HandlerContext, TransactionContext, Transaction, GetApi } from '@dbos-inc/dbos-sdk';
6
+ import { DBOS } from '@dbos-inc/dbos-sdk';
7
7
 
8
8
  import { PrismaClient } from "@prisma/client";
9
9
 
10
10
  export class Hello {
11
11
 
12
12
  // Serve this function from HTTP GET requests at the /greeting endpoint with 'name' as a path parameter
13
- @GetApi('/greeting/:name')
14
- @Transaction()
15
- static async helloTransaction(txnCtxt: TransactionContext<PrismaClient>, name: string) {
13
+ @DBOS.getApi('/greeting/:name')
14
+ @DBOS.transaction()
15
+ static async helloTransaction(name: string) {
16
16
  const greeting = `Hello, ${name}!`;
17
- const res = await txnCtxt.client.dbosHello.create({
17
+ const res = await (DBOS.prismaClient as PrismaClient).dbosHello.create({
18
18
  data: {
19
19
  greeting: greeting,
20
20
  },
@@ -24,8 +24,8 @@ export class Hello {
24
24
  }
25
25
 
26
26
  // Serve a quick readme for the app at the / endpoint
27
- @GetApi('/')
28
- static async readme(_ctxt: HandlerContext) {
27
+ @DBOS.getApi('/')
28
+ static async readme() {
29
29
  const message = Hello.makeHTML(
30
30
  `Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br>
31
31
  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>
@@ -1,6 +1,6 @@
1
1
  # DBOS Hello with TypeORM
2
2
 
3
- This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [TypeORM](https://docs.dbos.dev/tutorials/using-typeorm).
3
+ This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [TypeORM](https://docs.dbos.dev/typescript/tutorials/orms/using-typeorm).
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -22,7 +22,7 @@ npm run build
22
22
 
23
23
  Then, run a schema migration to create some tables.
24
24
  TypeORM provides rich support for [schema migrations](https://typeorm.io/migrations), including automatic generation of migration files from entity files.
25
- Fore more information, see [our docs](https://docs.dbos.dev/tutorials/using-typeorm).
25
+ Fore more information, see [our docs](https://docs.dbos.dev/typescript/tutorials/orms/using-typeorm).
26
26
 
27
27
  ```bash
28
28
  npx dbos migrate
@@ -44,8 +44,8 @@ Congratulations! You just launched a DBOS application.
44
44
 
45
45
  ## Next Steps
46
46
 
47
- - For more information on using TypeORM with DBOS, check out [our docs](https://docs.dbos.dev/tutorials/using-typeorm).
47
+ - For more information on using TypeORM with DBOS, check out [our docs](https://docs.dbos.dev/typescript/tutorials/orms/using-typeorm).
48
48
  - To add more functionality to this application, modify `src/operations.ts`, then rebuild and restart it. Alternatively, `npm run dev` uses `nodemon` to automatically rebuild and restart the app when source files change, using instructions specified in `nodemon.json`.
49
- - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/getting-started/quickstart-programming).
50
- - To learn how to deploy your application to DBOS Cloud, visit our [cloud quickstart](https://docs.dbos.dev/getting-started/quickstart-cloud/)
51
- - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc/dbos-transact).
49
+ - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/typescript/programming-guide).
50
+ - To learn how to deploy your application to DBOS Cloud, visit our [cloud quickstart](https://docs.dbos.dev/quickstart)
51
+ - To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc).
@@ -1,26 +1,27 @@
1
- import { TestingRuntime, createTestingRuntime } from "@dbos-inc/dbos-sdk";
1
+ import { DBOS } from "@dbos-inc/dbos-sdk";
2
2
  import { Hello } from "./operations";
3
3
  import request from "supertest";
4
4
 
5
5
  describe("operations-test", () => {
6
- let testRuntime: TestingRuntime;
7
-
8
6
  beforeAll(async () => {
9
- testRuntime = await createTestingRuntime([Hello]);
7
+ await DBOS.launch();
8
+ await DBOS.launchAppHTTPServer();
10
9
  });
11
10
 
12
11
  afterAll(async () => {
13
- await testRuntime.destroy();
12
+ await DBOS.shutdown();
14
13
  });
15
14
 
16
15
  /**
17
16
  * Test the HTTP endpoint.
18
17
  */
19
18
  test("test-greet", async () => {
20
- const res = await request(testRuntime.getHandlersCallback()).get(
19
+ const res = await request(DBOS.getHTTPHandlersCallback()!).get(
21
20
  "/greeting/dbos"
22
21
  );
23
22
  expect(res.statusCode).toBe(200);
24
23
  expect(res.text).toMatch("Greeting 1: Hello, dbos!");
24
+
25
+ expect(await Hello.helloTransaction('bob')).toMatch("Greeting 2: Hello, bob!");
25
26
  });
26
27
  });
@@ -3,27 +3,27 @@
3
3
  // This is the Quickstart TypeORM template app. It greets visitors, counting how many total greetings were made.
4
4
  // To learn how to run this app, visit the TypeORM tutorial: https://docs.dbos.dev/tutorials/using-typeorm
5
5
 
6
- import { HandlerContext, TransactionContext, Transaction, GetApi, OrmEntities } from '@dbos-inc/dbos-sdk';
6
+ import { DBOS, OrmEntities } from '@dbos-inc/dbos-sdk';
7
7
  import { EntityManager } from "typeorm";
8
8
  import { DBOSHello } from '../entities/DBOSHello';
9
9
 
10
10
  @OrmEntities([DBOSHello])
11
11
  export class Hello {
12
12
 
13
- @GetApi('/greeting/:name')
14
- @Transaction()
15
- static async helloTransaction(txnCtxt: TransactionContext<EntityManager>, name: string) {
13
+ @DBOS.getApi('/greeting/:name')
14
+ @DBOS.transaction()
15
+ static async helloTransaction(name: string) {
16
16
  const greeting = `Hello, ${name}!`;
17
17
  let entity = new DBOSHello();
18
18
  entity.greeting = greeting;
19
- entity = await txnCtxt.client.save(entity);
19
+ entity = await (DBOS.typeORMClient as EntityManager).save(entity);
20
20
  const greeting_note = `Greeting ${entity.greeting_id}: ${greeting}`;
21
21
  return Hello.makeHTML(greeting_note);
22
22
  }
23
23
 
24
24
  // Serve a quick readme for the app at the / endpoint
25
- @GetApi('/')
26
- static async readme(_ctxt: HandlerContext) {
25
+ @DBOS.getApi('/')
26
+ static async readme() {
27
27
  const message = Hello.makeHTML(
28
28
  `Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br>
29
29
  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>