diff --git a/packages/create/templates/hello-drizzle/src/operations.ts b/packages/create/templates/hello-drizzle/src/operations.ts index acae7cf31..cc728178f 100644 --- a/packages/create/templates/hello-drizzle/src/operations.ts +++ b/packages/create/templates/hello-drizzle/src/operations.ts @@ -1,34 +1,52 @@ +// Welcome to DBOS! + +// This is the Quickstart Drizzle template app. It greets visitors, counting how many total greetings were made. +// To learn how to run this app, visit the Drizzle tutorial: https://docs.dbos.dev/tutorials/using-drizzle + import { HandlerContext, TransactionContext, Transaction, GetApi } from '@dbos-inc/dbos-sdk'; import { dbosHello } from './schema'; import { NodePgDatabase } from 'drizzle-orm/node-postgres'; -const app_notes = ` -To learn how to run this app on your computer, visit the -DBOS Quickstart.
-After that, to learn how to build apps, visit the -DBOS Programming Guide.`; - export class Hello { - @GetApi('/') // Serve a quick readme for the app - static async readme(_ctxt: HandlerContext) { - const readme = `

- Welcome to the DBOS Hello App!

- Visit the route /greeting/:name to be greeted!
- For example, visit /greeting/dbos.
- The counter increments with each page visit.

- ${app_notes} -

`; - return Promise.resolve(readme); - } - + // Serve this function from HTTP GET requests at the /greeting endpoint with 'user' as a path parameter @GetApi('/greeting/:user') @Transaction() static async helloTransaction(ctxt: TransactionContext, user: string) { const greeting = `Hello, ${user}!`; const greetings_output = await ctxt.client.insert(dbosHello).values({greeting}).returning({greet_count: dbosHello.greet_count}); const greeting_message = `${greeting} We have made ${greetings_output[0].greet_count} greetings.`; - const page = `

${greeting_message}

${app_notes}

`; + return Hello.makeHTML(greeting_message); + } + + // Serve a quick readme for the app at the / endpoint + @GetApi('/') + static async readme(_ctxt: HandlerContext) { + const message = Hello.makeHTML( + `Visit the route /greeting/{name} to be greeted!
+ For example, visit /greeting/Mike
+ The counter increments with each page visit.` + ); + return Promise.resolve(message); + } + + // A helper function to create HTML pages with some styling + static makeHTML(message: string) { + const page = ` + + + + DBOS Template App + + + +

Welcome to DBOS!

+

` + message + `

+

+ This is the Drizzle quickstart template app. Read the documentation for it here. +

+ + `; return page; } } diff --git a/packages/create/templates/hello-prisma/src/operations.ts b/packages/create/templates/hello-prisma/src/operations.ts index 56bfb96fa..5ab4f0fa8 100644 --- a/packages/create/templates/hello-prisma/src/operations.ts +++ b/packages/create/templates/hello-prisma/src/operations.ts @@ -1,26 +1,15 @@ +// Welcome to DBOS! + +// This is the Quickstart Prisma template app. It greets visitors, counting how many total greetings were made. +// To learn how to run this app, visit the Prisma tutorial: https://docs.dbos.dev/tutorials/using-prisma + import { HandlerContext, TransactionContext, Transaction, GetApi } from '@dbos-inc/dbos-sdk'; -import { PrismaClient } from "@prisma/client"; -const app_notes = ` -To learn how to run this app on your computer, visit the -DBOS Quickstart.
-After that, to learn how to build apps, visit the -DBOS Programming Guide.`; +import { PrismaClient } from "@prisma/client"; export class Hello { - @GetApi('/') // Serve a quick readme for the app - static async readme(_ctxt: HandlerContext) { - const readme = `

- Welcome to the DBOS Hello App!

- Visit the route /greeting/:name to be greeted!
- For example, visit /greeting/dbos.
- The counter increments with each page visit.

- ${app_notes} -

`; - return Promise.resolve(readme); - } - + // Serve this function from HTTP GET requests at the /greeting endpoint with 'name' as a path parameter @GetApi('/greeting/:name') @Transaction() static async helloTransaction(txnCtxt: TransactionContext, name: string) { @@ -31,7 +20,37 @@ export class Hello { }, }); const greeting_note = `Greeting ${res.greeting_id}: ${greeting}`; - const page = `

${greeting_note}

${app_notes}

`; + return Hello.makeHTML(greeting_note); + } + + // Serve a quick readme for the app at the / endpoint + @GetApi('/') + static async readme(_ctxt: HandlerContext) { + const message = Hello.makeHTML( + `Visit the route /greeting/{name} to be greeted!
+ For example, visit /greeting/Mike
+ The counter increments with each page visit.` + ); + return Promise.resolve(message); + } + + // A helper function to create HTML pages with some styling + static makeHTML(message: string) { + const page = ` + + + + DBOS Template App + + + +

Welcome to DBOS!

+

` + message + `

+

+ This is the Prisma quickstart template app. Read the documentation for it here. +

+ + `; return page; } } diff --git a/packages/create/templates/hello-typeorm/src/operations.ts b/packages/create/templates/hello-typeorm/src/operations.ts index a2e0d2176..ee455c82d 100644 --- a/packages/create/templates/hello-typeorm/src/operations.ts +++ b/packages/create/templates/hello-typeorm/src/operations.ts @@ -1,28 +1,15 @@ +// Welcome to DBOS! + +// This is the Quickstart TypeORM template app. It greets visitors, counting how many total greetings were made. +// To learn how to run this app, visit the TypeORM tutorial: https://docs.dbos.dev/tutorials/using-typeorm + import { HandlerContext, TransactionContext, Transaction, GetApi, OrmEntities } from '@dbos-inc/dbos-sdk'; import { EntityManager } from "typeorm"; import { DBOSHello } from '../entities/DBOSHello'; -const app_notes = ` -To learn how to run this app on your computer, visit the -DBOS Quickstart.
-After that, to learn how to build apps, visit the -DBOS Programming Guide.`; - @OrmEntities([DBOSHello]) export class Hello { - @GetApi('/') // Serve a quick readme for the app - static async readme(_ctxt: HandlerContext) { - const readme = `

- Welcome to the DBOS Hello App!

- Visit the route /greeting/:name to be greeted!
- For example, visit /greeting/dbos.
- The counter increments with each page visit.

- ${app_notes} -

`; - return Promise.resolve(readme); - } - @GetApi('/greeting/:name') @Transaction() static async helloTransaction(txnCtxt: TransactionContext, name: string) { @@ -31,7 +18,37 @@ export class Hello { entity.greeting = greeting; entity = await txnCtxt.client.save(entity); const greeting_note = `Greeting ${entity.greeting_id}: ${greeting}`; - const page = `

${greeting_note}

${app_notes}

`; + return Hello.makeHTML(greeting_note); + } + + // Serve a quick readme for the app at the / endpoint + @GetApi('/') + static async readme(_ctxt: HandlerContext) { + const message = Hello.makeHTML( + `Visit the route /greeting/{name} to be greeted!
+ For example, visit /greeting/Mike
+ The counter increments with each page visit.` + ); + return Promise.resolve(message); + } + + // A helper function to create HTML pages with some styling + static makeHTML(message: string) { + const page = ` + + + + DBOS Template App + + + +

Welcome to DBOS!

+

` + message + `

+

+ This is the TypeORM quickstart template app. Read the documentation for it here. +

+ + `; return page; } } diff --git a/packages/create/templates/hello/src/operations.ts b/packages/create/templates/hello/src/operations.ts index 279c5b6b7..eedd1375f 100644 --- a/packages/create/templates/hello/src/operations.ts +++ b/packages/create/templates/hello/src/operations.ts @@ -1,12 +1,12 @@ +// Welcome to DBOS! + +// This is a sample "Hello" app built with DBOS. +// It greets visitors and keeps track of how many times each visitor has been greeted. +// To run this app, visit our Quickstart: https://docs.dbos.dev/getting-started/quickstart + import { HandlerContext, TransactionContext, Transaction, GetApi, ArgSource, ArgSources } from '@dbos-inc/dbos-sdk'; import { Knex } from 'knex'; -const app_notes = ` -To learn how to run this app on your computer, visit the -DBOS Quickstart.
-After that, to learn how to build apps, visit the -DBOS Programming Guide.`; - // The schema of the database table used in this example. export interface dbos_hello { name: string; @@ -15,20 +15,8 @@ export interface dbos_hello { export class Hello { - @GetApi('/') // Serve a quick readme for the app - static async readme(_ctxt: HandlerContext) { - const readme = `

- Welcome to the DBOS Hello App!

- Visit the route /greeting/:name to be greeted!
- For example, visit /greeting/dbos.
- The counter increments with each page visit.
- If you visit a new name like /greeting/alice, the counter starts at 1.

- ${app_notes} -

`; - return Promise.resolve(readme); - } - - @GetApi('/greeting/:user') // Serve this function from HTTP GET requests to the /greeting endpoint with 'user' as a path parameter + // Serve this function from HTTP GET requests at the /greeting endpoint with 'user' as a path parameter + @GetApi('/greeting/:user') @Transaction() // Run this function as a database transaction static async helloTransaction(ctxt: TransactionContext, @ArgSource(ArgSources.URL) user: string) { // Retrieve and increment the number of times this user has been greeted. @@ -36,7 +24,41 @@ export class Hello { const { rows } = await ctxt.client.raw(query, [user]) as { rows: dbos_hello[] }; const greet_count = rows[0].greet_count; const greeting = `Hello, ${user}! You have been greeted ${greet_count} times.`; - const page = `

${greeting}

${app_notes}

`; + return Hello.makeHTML(greeting); + } + + // Serve a quick readme for the app at the / endpoint + @GetApi('/') + static async readme(_ctxt: HandlerContext) { + const message = Hello.makeHTML( + `Visit the route /greeting/{name} to be greeted!
+ For example, visit /greeting/Mike
+ The counter increments with each page visit.` + ); + return Promise.resolve(message); + } + + // A helper function to create HTML pages with some styling + static makeHTML(message: string) { + const page = ` + + + + DBOS Template App + + + +

Welcome to DBOS!

+

` + message + `

+

+ To learn how to run this app yourself, visit our + Quickstart. +

+ Then, to learn how to build crashproof apps, continue to our + Programming Guide.
+

+ + `; return page; } } diff --git a/packages/dbos-openapi/tests/openapi.test.ts b/packages/dbos-openapi/tests/openapi.test.ts index f73f4f440..9dfa3ac5f 100644 --- a/packages/dbos-openapi/tests/openapi.test.ts +++ b/packages/dbos-openapi/tests/openapi.test.ts @@ -20,9 +20,11 @@ describe("TypeParser", () => { const [$class] = classes!; expect($class.name).toBe("Hello"); expect($class.decorators.length).toBe(0); - expect($class.methods.length).toBe(2); + expect($class.methods.length).toBe(3); - const method = $class.methods[0].name === "helloTransaction" ? $class.methods[0] : $class.methods[1]; + const method = $class.methods[0].name === "helloTransaction" ? $class.methods[0] : + $class.methods[1].name === "helloTransaction" ? $class.methods[1] : + $class.methods[2]; expect(method.name).toBe("helloTransaction"); expect(method.decorators.length).toBe(2);