@dbos-inc/create 1.31.24-preview → 1.31.26-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 (142) hide show
  1. package/dist/cli.js +3 -4
  2. package/dist/cli.js.map +1 -1
  3. package/package.json +1 -1
  4. package/templates/dbos-drizzle/README.md +23 -0
  5. package/templates/dbos-drizzle/nodemon.json +7 -0
  6. package/templates/{hello-drizzle → dbos-drizzle}/package.json +1 -1
  7. package/templates/dbos-knex/README.md +23 -0
  8. package/templates/dbos-knex/nodemon.json +7 -0
  9. package/templates/{hello-contexts → dbos-knex}/package.json +3 -3
  10. package/templates/dbos-knex/src/main.ts +94 -0
  11. package/templates/dbos-prisma/README.md +23 -0
  12. package/templates/{hello-prisma → dbos-prisma}/nodemon.json +1 -1
  13. package/templates/{hello-prisma → dbos-prisma}/package.json +1 -1
  14. package/templates/{hello-express → dbos-prisma}/start_postgres_docker.js +0 -0
  15. package/templates/dbos-typeorm/README.md +23 -0
  16. package/templates/dbos-typeorm/nodemon.json +8 -0
  17. package/templates/{hello-typeorm → dbos-typeorm}/package.json +1 -1
  18. package/templates/{hello-nextjs → dbos-typeorm}/start_postgres_docker.js +0 -0
  19. package/templates/hello/.vscode/extensions.json +0 -7
  20. package/templates/hello/.vscode/launch.json +0 -21
  21. package/templates/hello/.vscode/tasks.json +0 -19
  22. package/templates/hello/README.md +0 -55
  23. package/templates/hello/dbos-config.yaml +0 -20
  24. package/templates/hello/eslint.config.js +0 -28
  25. package/templates/hello/gitignore.template +0 -144
  26. package/templates/hello/jest.config.js +0 -8
  27. package/templates/hello/knexfile.js +0 -20
  28. package/templates/hello/migrations/20240212161006_create_dbos_hello_tables.js +0 -18
  29. package/templates/hello/nodemon.json +0 -7
  30. package/templates/hello/package.json +0 -23
  31. package/templates/hello/src/operations.test.ts +0 -37
  32. package/templates/hello/src/operations.ts +0 -64
  33. package/templates/hello/start_postgres_docker.js +0 -40
  34. package/templates/hello/tsconfig.json +0 -25
  35. package/templates/hello-contexts/.vscode/extensions.json +0 -7
  36. package/templates/hello-contexts/.vscode/launch.json +0 -21
  37. package/templates/hello-contexts/.vscode/tasks.json +0 -19
  38. package/templates/hello-contexts/README.md +0 -76
  39. package/templates/hello-contexts/dbos-config.yaml +0 -20
  40. package/templates/hello-contexts/nodemon.json +0 -7
  41. package/templates/hello-contexts/src/operations.test.ts +0 -38
  42. package/templates/hello-contexts/src/operations.ts +0 -66
  43. package/templates/hello-drizzle/.vscode/extensions.json +0 -7
  44. package/templates/hello-drizzle/.vscode/launch.json +0 -21
  45. package/templates/hello-drizzle/.vscode/tasks.json +0 -19
  46. package/templates/hello-drizzle/README.md +0 -48
  47. package/templates/hello-drizzle/nodemon.json +0 -7
  48. package/templates/hello-express/README.md +0 -77
  49. package/templates/hello-express/knexfile.js +0 -20
  50. package/templates/hello-express/migrations/20240212161006_create_dbos_hello_tables.js +0 -18
  51. package/templates/hello-express/nodemon.json +0 -7
  52. package/templates/hello-express/package.json +0 -24
  53. package/templates/hello-express/src/main.ts +0 -99
  54. package/templates/hello-express/tsconfig.json +0 -25
  55. package/templates/hello-nextjs/README.md +0 -100
  56. package/templates/hello-nextjs/dbos-config.yaml +0 -18
  57. package/templates/hello-nextjs/eslint.config.mjs +0 -16
  58. package/templates/hello-nextjs/gitignore.template +0 -41
  59. package/templates/hello-nextjs/knexfile.js +0 -20
  60. package/templates/hello-nextjs/migrations/20240212161006_create_dbos_hello_tables.js +0 -18
  61. package/templates/hello-nextjs/next.config.ts +0 -18
  62. package/templates/hello-nextjs/package.json +0 -32
  63. package/templates/hello-nextjs/postcss.config.mjs +0 -8
  64. package/templates/hello-nextjs/public/file.svg +0 -1
  65. package/templates/hello-nextjs/public/globe.svg +0 -1
  66. package/templates/hello-nextjs/public/next.svg +0 -1
  67. package/templates/hello-nextjs/public/vercel.svg +0 -1
  68. package/templates/hello-nextjs/public/window.svg +0 -1
  69. package/templates/hello-nextjs/src/actions/dbosWorkflow.ts +0 -12
  70. package/templates/hello-nextjs/src/actions/hello.ts +0 -15
  71. package/templates/hello-nextjs/src/app/crash/route.ts +0 -8
  72. package/templates/hello-nextjs/src/app/favicon.ico +0 -0
  73. package/templates/hello-nextjs/src/app/globals.css +0 -21
  74. package/templates/hello-nextjs/src/app/greetings/route.ts +0 -11
  75. package/templates/hello-nextjs/src/app/layout.tsx +0 -34
  76. package/templates/hello-nextjs/src/app/page.tsx +0 -73
  77. package/templates/hello-nextjs/src/app/step/[slug]/route.ts +0 -15
  78. package/templates/hello-nextjs/src/app/tasks/[slug]/route.ts +0 -18
  79. package/templates/hello-nextjs/src/components/client/BackGroundTask.tsx +0 -179
  80. package/templates/hello-nextjs/src/components/client/callDBOSWorkflow.tsx +0 -31
  81. package/templates/hello-nextjs/src/dbos/background.ts +0 -23
  82. package/templates/hello-nextjs/src/dbos/hello.ts +0 -24
  83. package/templates/hello-nextjs/src/dbos/operations.ts +0 -9
  84. package/templates/hello-nextjs/tailwind.config.ts +0 -18
  85. package/templates/hello-nextjs/tsconfig.json +0 -29
  86. package/templates/hello-prisma/.vscode/extensions.json +0 -7
  87. package/templates/hello-prisma/.vscode/launch.json +0 -21
  88. package/templates/hello-prisma/.vscode/tasks.json +0 -19
  89. package/templates/hello-prisma/README.md +0 -51
  90. package/templates/hello-prisma/start_postgres_docker.js +0 -40
  91. package/templates/hello-typeorm/.vscode/extensions.json +0 -7
  92. package/templates/hello-typeorm/.vscode/launch.json +0 -21
  93. package/templates/hello-typeorm/.vscode/tasks.json +0 -19
  94. package/templates/hello-typeorm/README.md +0 -51
  95. package/templates/hello-typeorm/eslint.config.js +0 -28
  96. package/templates/hello-typeorm/gitignore.template +0 -144
  97. package/templates/hello-typeorm/jest.config.js +0 -8
  98. package/templates/hello-typeorm/nodemon.json +0 -8
  99. package/templates/hello-typeorm/start_postgres_docker.js +0 -40
  100. /package/templates/{hello-drizzle → dbos-drizzle}/dbos-config.yaml +0 -0
  101. /package/templates/{hello-drizzle → dbos-drizzle}/drizzle/0000_hello.sql +0 -0
  102. /package/templates/{hello-drizzle → dbos-drizzle}/drizzle/meta/0000_snapshot.json +0 -0
  103. /package/templates/{hello-drizzle → dbos-drizzle}/drizzle/meta/_journal.json +0 -0
  104. /package/templates/{hello-drizzle → dbos-drizzle}/drizzle.config.ts +0 -0
  105. /package/templates/{hello-contexts → dbos-drizzle}/eslint.config.js +0 -0
  106. /package/templates/{hello-contexts → dbos-drizzle}/gitignore.template +0 -0
  107. /package/templates/{hello-contexts → dbos-drizzle}/jest.config.js +0 -0
  108. /package/templates/{hello-drizzle → dbos-drizzle}/src/operations.test.ts +0 -0
  109. /package/templates/{hello-drizzle → dbos-drizzle}/src/operations.ts +0 -0
  110. /package/templates/{hello-drizzle → dbos-drizzle}/src/schema.ts +0 -0
  111. /package/templates/{hello-contexts → dbos-drizzle}/start_postgres_docker.js +0 -0
  112. /package/templates/{hello-contexts → dbos-drizzle}/tsconfig.json +0 -0
  113. /package/templates/{hello-express → dbos-knex}/dbos-config.yaml +0 -0
  114. /package/templates/{hello-drizzle → dbos-knex}/eslint.config.js +0 -0
  115. /package/templates/{hello-drizzle → dbos-knex}/gitignore.template +0 -0
  116. /package/templates/{hello-drizzle → dbos-knex}/jest.config.js +0 -0
  117. /package/templates/{hello-contexts → dbos-knex}/knexfile.js +0 -0
  118. /package/templates/{hello-contexts → dbos-knex}/migrations/20240212161006_create_dbos_hello_tables.js +0 -0
  119. /package/templates/{hello-express → dbos-knex}/src/main.test.ts +0 -0
  120. /package/templates/{hello-drizzle → dbos-knex}/start_postgres_docker.js +0 -0
  121. /package/templates/{hello-drizzle → dbos-knex}/tsconfig.json +0 -0
  122. /package/templates/{hello-prisma → dbos-prisma}/dbos-config.yaml +0 -0
  123. /package/templates/{hello-express → dbos-prisma}/eslint.config.js +0 -0
  124. /package/templates/{hello-prisma → dbos-prisma}/generate_env.js +0 -0
  125. /package/templates/{hello-prisma → dbos-prisma}/gitignore.template +0 -0
  126. /package/templates/{hello-express → dbos-prisma}/jest.config.js +0 -0
  127. /package/templates/{hello-prisma → dbos-prisma}/prisma/migrations/20240604184654_init/migration.sql +0 -0
  128. /package/templates/{hello-prisma → dbos-prisma}/prisma/migrations/migration_lock.toml +0 -0
  129. /package/templates/{hello-prisma → dbos-prisma}/prisma/schema.prisma +0 -0
  130. /package/templates/{hello-prisma → dbos-prisma}/src/operations.test.ts +0 -0
  131. /package/templates/{hello-prisma → dbos-prisma}/src/operations.ts +0 -0
  132. /package/templates/{hello-prisma → dbos-prisma}/tsconfig.json +0 -0
  133. /package/templates/{hello-typeorm → dbos-typeorm}/datasource.ts +0 -0
  134. /package/templates/{hello-typeorm → dbos-typeorm}/dbos-config.yaml +0 -0
  135. /package/templates/{hello-typeorm → dbos-typeorm}/entities/DBOSHello.ts +0 -0
  136. /package/templates/{hello-prisma → dbos-typeorm}/eslint.config.js +0 -0
  137. /package/templates/{hello-express → dbos-typeorm}/gitignore.template +0 -0
  138. /package/templates/{hello-prisma → dbos-typeorm}/jest.config.js +0 -0
  139. /package/templates/{hello-typeorm → dbos-typeorm}/migrations/1714934318136-DBOSHello.ts +0 -0
  140. /package/templates/{hello-typeorm → dbos-typeorm}/src/operations.test.ts +0 -0
  141. /package/templates/{hello-typeorm → dbos-typeorm}/src/operations.ts +0 -0
  142. /package/templates/{hello-typeorm → dbos-typeorm}/tsconfig.json +0 -0
@@ -1,18 +0,0 @@
1
- const { Knex } = require("knex");
2
-
3
- exports.up = async function(knex) {
4
- await knex.schema.createTable('dbos_hello', table => {
5
- table.text('name').primary();
6
- table.integer('greet_count').defaultTo(0);
7
- });
8
-
9
- return knex.schema.createTable('dbos_greetings', table => {
10
- table.text('greeting_name');
11
- table.text('greeting_note_content');
12
- });
13
- };
14
-
15
- exports.down = async function(knex) {
16
- await knex.schema.dropTable('dbos_greetings');
17
- return knex.schema.dropTable('dbos_hello');
18
- };
@@ -1,7 +0,0 @@
1
- {
2
- "watch": ["src/","migrations/"],
3
- "ext": "ts,json",
4
- "ignore": ["src/**/*.test.ts"],
5
- "exec": "npm run build && npx dbos migrate && npm run start"
6
- }
7
-
@@ -1,23 +0,0 @@
1
- {
2
- "name": "dbos-hello-v2",
3
- "version": "0.0.1",
4
- "scripts": {
5
- "build": "tsc",
6
- "test": "npx dbos rollback && npx dbos migrate && jest",
7
- "dev": "nodemon",
8
- "start": "npx dbos start"
9
- },
10
- "devDependencies": {
11
- "@types/jest": "^29.5.12",
12
- "@types/supertest": "^2.0.16",
13
- "jest": "^29.7.0",
14
- "nodemon": "^3.1.0",
15
- "supertest": "^7.0.0",
16
- "ts-jest": "^29.1.2",
17
- "typescript": "^5.4.5"
18
- },
19
- "dependencies": {
20
- "@dbos-inc/dbos-sdk": "file:../../../..",
21
- "knex": "3.1.0"
22
- }
23
- }
@@ -1,37 +0,0 @@
1
- import { DBOS } from "@dbos-inc/dbos-sdk";
2
- import { Hello, dbos_hello } from "./operations";
3
- import request from "supertest";
4
-
5
- describe("operations-test", () => {
6
- beforeAll(async () => {
7
- await DBOS.launch();
8
- await DBOS.launchAppHTTPServer();
9
- });
10
-
11
- afterAll(async () => {
12
- await DBOS.shutdown();
13
- });
14
-
15
- /**
16
- * Test the transaction.
17
- */
18
- test("test-transaction", async () => {
19
- const res = await Hello.helloTransaction("dbos");
20
- expect(res).toMatch("Hello, dbos! You have been greeted");
21
-
22
- // Check the greet count.
23
- const rows = await DBOS.executor.queryUserDB("SELECT * FROM dbos_hello WHERE name=$1", ["dbos"]) as dbos_hello[];
24
- expect(rows[0].greet_count).toBe(1);
25
- });
26
-
27
- /**
28
- * Test the HTTP endpoint.
29
- */
30
- test("test-endpoint", async () => {
31
- const res = await request(DBOS.getHTTPHandlersCallback()).get(
32
- "/greeting/dbos"
33
- );
34
- expect(res.statusCode).toBe(200);
35
- expect(res.text).toMatch("Hello, dbos! You have been greeted");
36
- });
37
- });
@@ -1,64 +0,0 @@
1
- // Welcome to DBOS!
2
-
3
- // This is a sample "Hello" app built with DBOS.
4
- // It greets visitors and keeps track of how many times each visitor has been greeted.
5
-
6
- // First, let's import DBOS
7
- import { DBOS } from "@dbos-inc/dbos-sdk";
8
-
9
- // Then, let's declare a type representing the "dbos_hello" database table
10
- export interface dbos_hello {
11
- name: string;
12
- greet_count: number;
13
- }
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.
17
- export class Hello {
18
- // 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) {
22
- // Retrieve and increment the number of times this user has been greeted.
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
- // Serve a quick readme for the app at the / endpoint
31
- @DBOS.getApi("/")
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
- }
@@ -1,40 +0,0 @@
1
- const { execSync } = require('child_process');
2
-
3
- // Default PostgreSQL port
4
- let port = '5432';
5
-
6
- // Set the host PostgreSQL port with the -p/--port flag.
7
- process.argv.forEach((val, index) => {
8
- if (val === '-p' || val === '--port') {
9
- if (process.argv[index + 1]) {
10
- port = process.argv[index + 1];
11
- }
12
- }
13
- });
14
-
15
- if (!process.env.PGPASSWORD) {
16
- console.error("Error: PGPASSWORD is not set.");
17
- process.exit(1);
18
- }
19
-
20
- try {
21
- execSync(`docker run --rm --name=dbos-db --env=POSTGRES_PASSWORD="${process.env.PGPASSWORD}" --env=PGDATA=/var/lib/postgresql/data --volume=/var/lib/postgresql/data -p ${port}:5432 -d sibedge/postgres-plv8`);
22
- console.log("Waiting for PostgreSQL to start...");
23
-
24
- let attempts = 30;
25
- const checkDatabase = setInterval(() => {
26
- try {
27
- execSync('docker exec dbos-db psql -U postgres -c "SELECT 1;"', { stdio: 'ignore' });
28
- console.log("PostgreSQL started!");
29
- clearInterval(checkDatabase);
30
- console.log("Database started successfully!");
31
- } catch (error) {
32
- if (--attempts === 0) {
33
- clearInterval(checkDatabase);
34
- console.error("Failed to start PostgreSQL.");
35
- }
36
- }
37
- }, 1000);
38
- } catch (error) {
39
- console.error("Error starting PostgreSQL in Docker:", error.message);
40
- }
@@ -1,25 +0,0 @@
1
- /* Visit https://aka.ms/tsconfig to read more about this file */
2
- {
3
- "compilerOptions": {
4
- "target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
5
- "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
6
- "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
7
- "module": "Node16", /* Specify what module code is generated. */
8
- "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
9
- "declarationMap": true, /* Create sourcemaps for d.ts files. */
10
- "sourceMap": true, /* Create source map files for emitted JavaScript files. */
11
- "outDir": "./dist", /* Specify an output folder for all emitted files. */
12
- "newLine": "lf", /* Set the newline character for emitting files. */
13
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
14
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
15
- "strict": true, /* Enable all strict type-checking options. */
16
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
17
- },
18
- "include": [ /* Specifies an array of filenames or patterns to include in the program. */
19
- "src"
20
- ],
21
- "exclude": [
22
- "**/*.test.ts",
23
- "dist"
24
- ]
25
- }
@@ -1,7 +0,0 @@
1
- {
2
- // Automatically recommend the DBOS extension to VSCode users.
3
- // Documentation on extensions.json: http://go.microsoft.com/fwlink/?LinkId=827846
4
- "recommendations": [
5
- "dbos-inc.dbos-ttdbg"
6
- ]
7
- }
@@ -1,21 +0,0 @@
1
- {
2
- // Automatically configure the VSCode debugger for DBOS projects.
3
- // Documentation on launch.json: https://go.microsoft.com/fwlink/?linkid=830387
4
- "version": "0.2.0",
5
- "configurations": [
6
- {
7
- "type": "node-terminal",
8
- "request": "launch",
9
- "name": "Local Debug",
10
- "command": "npx dbos start",
11
- "preLaunchTask": "npm: build",
12
- },
13
- {
14
- "type": "node-terminal",
15
- "request": "launch",
16
- "name": "Time Travel Debug",
17
- "command": "npx dbos debug -x ${command:dbos-ttdbg.get-proxy-url} -u ${command:dbos-ttdbg.pick-workflow-id}",
18
- "preLaunchTask": "npm: build"
19
- }
20
- ]
21
- }
@@ -1,19 +0,0 @@
1
- {
2
- // Configure the build command for DBOS projects using VSCode.
3
- // Documentation on tasks.json: https://code.visualstudio.com/docs/editor/tasks
4
- "version": "2.0.0",
5
- "tasks": [
6
- {
7
- "label": "npm: build",
8
- "type": "npm",
9
- "script": "build",
10
- "group": {
11
- "kind": "build",
12
- "isDefault": true
13
- },
14
- "problemMatcher": [
15
- "$tsc"
16
- ]
17
- }
18
- ]
19
- }
@@ -1,76 +0,0 @@
1
- # DBOS Hello
2
-
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).
6
-
7
- ## Getting Started
8
-
9
- Before you can launch your app, you need a database.
10
- DBOS works with any Postgres database, but to make things easier, we've provided a script that starts a Docker Postgres container and creates a database.
11
- Run:
12
-
13
- ```bash
14
- node start_postgres_docker.js
15
- ```
16
-
17
- If successful, the script should print `Database started successfully!`.
18
-
19
- Next, you can build and run the app in one step under `nodemon`:
20
-
21
- ```bash
22
- npm run dev
23
- ```
24
-
25
- To see that it's working, visit this URL in your browser: [`http://localhost:3000/greeting/dbos`](http://localhost:3000/greeting/dbos).
26
- You should get this message: `Hello, dbos! You have been greeted 1 times.`
27
- Each time you refresh the page, the counter should go up by one!
28
-
29
- Congratulations! You just launched a DBOS application.
30
-
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.
34
-
35
- ```bash
36
- npm run build
37
- ```
38
-
39
- Then, run a schema migration to create some tables:
40
-
41
- ```bash
42
- npx dbos migrate
43
- ```
44
-
45
- If successful, the migration should print `Migration successful!`.
46
-
47
- Finally, run the app:
48
-
49
- ```bash
50
- npx dbos start
51
- ```
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
-
73
- ## Next Steps
74
-
75
- - For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/getting-started/quickstart-programming).
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,20 +0,0 @@
1
- # To enable auto-completion and validation for this file in VSCode, install the RedHat YAML extension
2
- # https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml
3
-
4
- # yaml-language-server: $schema=https://raw.githubusercontent.com/dbos-inc/dbos-transact/main/dbos-config.schema.json
5
-
6
- language: node
7
- database:
8
- hostname: localhost
9
- port: 5432
10
- username: postgres
11
- password: ${PGPASSWORD}
12
- connectionTimeoutMillis: 3000
13
- app_db_client: knex
14
- migrate:
15
- - npx knex migrate:latest
16
- rollback:
17
- - npx knex migrate:rollback
18
- runtimeConfig:
19
- entrypoints:
20
- - dist/operations.js
@@ -1,7 +0,0 @@
1
- {
2
- "watch": ["src/","migrations/"],
3
- "ext": "ts,json",
4
- "ignore": ["src/**/*.test.ts"],
5
- "exec": "npm run build && npx dbos migrate && npm run start"
6
- }
7
-
@@ -1,38 +0,0 @@
1
- import { TestingRuntime, createTestingRuntime } from "@dbos-inc/dbos-sdk";
2
- import { Hello, dbos_hello } from "./operations";
3
- import request from "supertest";
4
-
5
- describe("operations-test", () => {
6
- let testRuntime: TestingRuntime;
7
-
8
- beforeAll(async () => {
9
- testRuntime = await createTestingRuntime();
10
- });
11
-
12
- afterAll(async () => {
13
- await testRuntime.destroy();
14
- });
15
-
16
- /**
17
- * Test the transaction.
18
- */
19
- test("test-transaction", async () => {
20
- const res = await testRuntime.invoke(Hello).helloTransaction("dbos");
21
- expect(res).toMatch("Hello, dbos! You have been greeted");
22
-
23
- // Check the greet count.
24
- const rows = await testRuntime.queryUserDB<dbos_hello>("SELECT * FROM dbos_hello WHERE name=$1", "dbos");
25
- expect(rows[0].greet_count).toBe(1);
26
- });
27
-
28
- /**
29
- * Test the HTTP endpoint.
30
- */
31
- test("test-endpoint", async () => {
32
- const res = await request(testRuntime.getHandlersCallback()).get(
33
- "/greeting/dbos"
34
- );
35
- expect(res.statusCode).toBe(200);
36
- expect(res.text).toMatch("Hello, dbos! You have been greeted");
37
- });
38
- });
@@ -1,66 +0,0 @@
1
- // Welcome to DBOS!
2
-
3
- // This is a sample "Hello" app built with DBOS.
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
-
7
- import { HandlerContext, TransactionContext, Transaction, GetApi, ArgSource, ArgSources } from "@dbos-inc/dbos-sdk";
8
- import { Knex } from "knex";
9
-
10
- // The schema of the database table used in this example.
11
- export interface dbos_hello {
12
- name: string;
13
- greet_count: number;
14
- }
15
-
16
- export class Hello {
17
- // 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) {
22
- // Retrieve and increment the number of times this user has been greeted.
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[] };
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
- // Let's declare helper functions to serve static HTML
31
-
32
- // Serve a quick readme for the app at the / endpoint
33
- @GetApi('/')
34
- static async readme(_ctxt: HandlerContext) {
35
- const message = Hello.makeHTML(
36
- `Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br>
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>
38
- The counter increments with each page visit.`
39
- );
40
- return Promise.resolve(message);
41
- }
42
-
43
- // A helper function to create HTML pages with some styling
44
- static makeHTML(message: string) {
45
- const page = `
46
- <!DOCTYPE html>
47
- <html lang="en">
48
- <head>
49
- <title>DBOS Template App</title>
50
- <script src="https://cdn.tailwindcss.com"></script>
51
- </head>
52
- <body class="font-sans text-gray-800 p-6 max-w-2xl mx-auto">
53
- <h1 class="text-3xl font-semibold mb-4">Welcome to DBOS!</h1>
54
- <p class="mt-8 mb-8">` + message + `</p>
55
- <p class="mb-2">
56
- To learn how to run this app yourself, visit our
57
- <a href="https://docs.dbos.dev/quickstart?language=typescript" class="text-blue-600 hover:underline">Quickstart</a>.
58
- </p><p class="mb-2">
59
- Then, to learn how to build crashproof apps, continue to our
60
- <a href="https://docs.dbos.dev/typescript/programming-guide" class="text-blue-600 hover:underline">Programming Guide</a>.<br>
61
- </p>
62
- </body>
63
- </html>`;
64
- return page;
65
- }
66
- }
@@ -1,7 +0,0 @@
1
- {
2
- // Automatically recommend the DBOS extension to VSCode users.
3
- // Documentation on extensions.json: http://go.microsoft.com/fwlink/?LinkId=827846
4
- "recommendations": [
5
- "dbos-inc.dbos-ttdbg"
6
- ]
7
- }
@@ -1,21 +0,0 @@
1
- {
2
- // Automatically configure the VSCode debugger for DBOS projects.
3
- // Documentation on launch.json: https://go.microsoft.com/fwlink/?linkid=830387
4
- "version": "0.2.0",
5
- "configurations": [
6
- {
7
- "type": "node-terminal",
8
- "request": "launch",
9
- "name": "Local Debug",
10
- "command": "npx dbos start",
11
- "preLaunchTask": "npm: build",
12
- },
13
- {
14
- "type": "node-terminal",
15
- "request": "launch",
16
- "name": "Time Travel Debug",
17
- "command": "npx dbos debug -x ${command:dbos-ttdbg.get-proxy-url} -u ${command:dbos-ttdbg.pick-workflow-id}",
18
- "preLaunchTask": "npm: build"
19
- }
20
- ]
21
- }
@@ -1,19 +0,0 @@
1
- {
2
- // Configure the build command for DBOS projects using VSCode.
3
- // Documentation on tasks.json: https://code.visualstudio.com/docs/editor/tasks
4
- "version": "2.0.0",
5
- "tasks": [
6
- {
7
- "label": "npm: build",
8
- "type": "npm",
9
- "script": "build",
10
- "group": {
11
- "kind": "build",
12
- "isDefault": true
13
- },
14
- "problemMatcher": [
15
- "$tsc"
16
- ]
17
- }
18
- ]
19
- }
@@ -1,48 +0,0 @@
1
- # DBOS Hello with Drizzle
2
-
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
-
5
- ## Getting Started
6
-
7
- Before you can launch your app, you need a database.
8
- DBOS works with any Postgres database, but to make things easier, we've provided a script that starts a Docker Postgres container and creates a database.
9
- Run:
10
-
11
- ```bash
12
- node start_postgres_docker.js
13
- ```
14
-
15
- If successful, the script should print `Database started successfully!`.
16
-
17
- Next, build the app:
18
-
19
- ```bash
20
- npm run build
21
- ```
22
-
23
- Then, run a schema migration to create some tables:
24
-
25
- ```bash
26
- npx dbos migrate
27
- ```
28
-
29
- If successful, the migration should print `Migration successful!`.
30
-
31
- Finally, run the app:
32
-
33
- ```bash
34
- npx dbos start
35
- ```
36
-
37
- To see that it's working, visit this URL in your browser: [`http://localhost:3000/greeting/dbos`](http://localhost:3000/greeting/dbos).
38
- You should get this message: `Hello, dbos! You have been greeted 1 times.`
39
- Each time you refresh the page, the counter should go up by one!
40
-
41
- Congratulations! You just launched a DBOS application.
42
-
43
- ## Next Steps
44
-
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/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).
@@ -1,7 +0,0 @@
1
- {
2
- "watch": ["src/","migrations/"],
3
- "ext": "ts,json",
4
- "ignore": ["src/**/*.test.ts"],
5
- "exec": "npm run build && npx dbos migrate && npm run start"
6
- }
7
-