@dbos-inc/create 1.12.6-preview → 1.12.8-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.
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "dbos-hello-prisma",
3
+ "version": "0.0.1",
4
+ "scripts": {
5
+ "build": "node generate_env.js && npx prisma generate && tsc",
6
+ "test": "npx prisma migrate reset --force && jest",
7
+ "lint": "eslint src",
8
+ "lint-fix": "eslint --fix src",
9
+ "dev": "nodemon",
10
+ "start": "npx dbos start"
11
+ },
12
+ "author": "",
13
+ "license": "ISC",
14
+ "devDependencies": {
15
+ "@dbos-inc/eslint-plugin": "^0.0.6",
16
+ "@types/jest": "^29.5.12",
17
+ "@types/supertest": "^6.0.2",
18
+ "eslint": "^8.57.0",
19
+ "jest": "^29.7.0",
20
+ "nodemon": "^3.1.0",
21
+ "prisma": "^5.15.0",
22
+ "supertest": "^7.0.0",
23
+ "ts-jest": "^29.1.2",
24
+ "typescript": "^5.4.5"
25
+ },
26
+ "dependencies": {
27
+ "@dbos-inc/dbos-sdk": "file:../../../..",
28
+ "@prisma/client": "^5.15.0"
29
+ }
30
+ }
@@ -0,0 +1,7 @@
1
+ -- CreateTable
2
+ CREATE TABLE "dbos_hello" (
3
+ "greeting_id" SERIAL NOT NULL,
4
+ "greeting" TEXT NOT NULL,
5
+
6
+ CONSTRAINT "dbos_hello_pkey" PRIMARY KEY ("greeting_id")
7
+ );
@@ -0,0 +1,3 @@
1
+ # Please do not edit this file manually
2
+ # It should be added in your version-control system (i.e. Git)
3
+ provider = "postgresql"
@@ -0,0 +1,17 @@
1
+ // This is your Prisma schema file,
2
+ // learn more about it in the docs: https://pris.ly/d/prisma-schema
3
+
4
+ generator client {
5
+ provider = "prisma-client-js"
6
+ }
7
+
8
+ datasource db {
9
+ provider = "postgresql"
10
+ url = env("DATABASE_URL")
11
+ }
12
+
13
+ model DbosHello {
14
+ @@map("dbos_hello")
15
+ greeting_id Int @id @default(autoincrement())
16
+ greeting String
17
+ }
@@ -0,0 +1,26 @@
1
+ import { TestingRuntime, createTestingRuntime } from "@dbos-inc/dbos-sdk";
2
+ import { 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([Hello]);
10
+ });
11
+
12
+ afterAll(async () => {
13
+ await testRuntime.destroy();
14
+ });
15
+
16
+ /**
17
+ * Test the HTTP endpoint.
18
+ */
19
+ test("test-greet", async () => {
20
+ const res = await request(testRuntime.getHandlersCallback()).get(
21
+ "/greeting/dbos"
22
+ );
23
+ expect(res.statusCode).toBe(200);
24
+ expect(res.text).toMatch("Greeting 1: Hello, dbos!");
25
+ });
26
+ });
@@ -0,0 +1,18 @@
1
+ import { TransactionContext, Transaction, GetApi } from '@dbos-inc/dbos-sdk';
2
+ import { PrismaClient } from "@prisma/client";
3
+
4
+ export class Hello {
5
+
6
+ @GetApi('/greeting/:name')
7
+ @Transaction()
8
+ static async helloTransaction(txnCtxt: TransactionContext<PrismaClient>, name: string) {
9
+ const greeting = `Hello, ${name}!`;
10
+ const p: PrismaClient = txnCtxt.client as PrismaClient;
11
+ const res = await p.dbosHello.create({
12
+ data: {
13
+ greeting: greeting,
14
+ },
15
+ });
16
+ return `Greeting ${res.greeting_id}: ${greeting}`;
17
+ }
18
+ }
@@ -0,0 +1,40 @@
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 postgres:16.1`);
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
+ }
@@ -0,0 +1,24 @@
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
+ ]
24
+ }