@dbos-inc/create 1.31.14-preview.g31029d25df → 1.31.16-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 +11 -30
- package/templates/hello/package.json +1 -5
- package/templates/hello/src/operations.test.ts +7 -8
- package/templates/hello/src/operations.ts +11 -13
- package/templates/{hello-v2 → hello-contexts}/README.md +30 -9
- package/templates/{hello-v2 → hello-contexts}/package.json +5 -1
- package/templates/{hello-v2 → hello-contexts}/src/operations.test.ts +8 -7
- package/templates/{hello-v2 → hello-contexts}/src/operations.ts +13 -11
- package/templates/hello-drizzle/README.md +6 -6
- package/templates/hello-drizzle/package.json +2 -2
- package/templates/hello-drizzle/src/operations.test.ts +7 -8
- package/templates/hello-drizzle/src/operations.ts +7 -7
- package/templates/hello-express/README.md +10 -8
- 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-nextjs/README.md +21 -12
- package/templates/hello-nextjs/src/actions/dbosWorkflow.tsx +24 -0
- package/templates/hello-nextjs/src/app/crash/route.ts +8 -0
- package/templates/hello-nextjs/src/app/page.tsx +10 -2
- package/templates/hello-nextjs/src/app/step/[slug]/route.ts +15 -0
- package/templates/hello-nextjs/src/app/tasks/[slug]/route.ts +18 -0
- package/templates/hello-nextjs/src/components/client/BackGroundTask.tsx +180 -0
- package/templates/hello-prisma/README.md +8 -8
- package/templates/hello-prisma/src/operations.test.ts +6 -6
- package/templates/hello-prisma/src/operations.ts +7 -7
- package/templates/hello-typeorm/README.md +8 -8
- package/templates/hello-typeorm/src/operations.test.ts +7 -6
- package/templates/hello-typeorm/src/operations.ts +7 -7
- package/templates/hello-express/src/operations.ts +0 -81
- /package/templates/{hello-v2 → hello-contexts}/.vscode/extensions.json +0 -0
- /package/templates/{hello-v2 → hello-contexts}/.vscode/launch.json +0 -0
- /package/templates/{hello-v2 → hello-contexts}/.vscode/tasks.json +0 -0
- /package/templates/{hello-v2 → hello-contexts}/dbos-config.yaml +0 -0
- /package/templates/{hello-v2 → hello-contexts}/eslint.config.js +0 -0
- /package/templates/{hello-v2 → hello-contexts}/gitignore.template +0 -0
- /package/templates/{hello-v2 → hello-contexts}/jest.config.js +0 -0
- /package/templates/{hello-v2 → hello-contexts}/knexfile.js +0 -0
- /package/templates/{hello-v2 → hello-contexts}/migrations/20240212161006_create_dbos_hello_tables.js +0 -0
- /package/templates/{hello-v2 → hello-contexts}/nodemon.json +0 -0
- /package/templates/{hello-v2 → hello-contexts}/start_postgres_docker.js +0 -0
- /package/templates/{hello-v2 → hello-contexts}/tsconfig.json +0 -0
|
@@ -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 {
|
|
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
|
-
@
|
|
14
|
-
@
|
|
15
|
-
static async helloTransaction(
|
|
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
|
|
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
|
-
@
|
|
26
|
-
static async readme(
|
|
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>
|
|
@@ -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
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/templates/{hello-v2 → hello-contexts}/migrations/20240212161006_create_dbos_hello_tables.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|