@dbos-inc/create 1.19.21 → 1.20.3-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbos-inc/create",
3
- "version": "1.19.21",
3
+ "version": "1.20.3-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/dbos-sdk init`.
3
+ This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create`.
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,21 @@
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
+ }
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,48 @@
1
+ # DBOS Hello with Drizzle
2
+
3
+ This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create`.
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-sdk migrate
27
+ ```
28
+
29
+ If successful, the migration should print `Migration successful!`.
30
+
31
+ Finally, run the app:
32
+
33
+ ```bash
34
+ npx dbos-sdk 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/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).
@@ -0,0 +1,19 @@
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
+ app_db_name: hello_drizzle
13
+ connectionTimeoutMillis: 3000
14
+ app_db_client: drizzle
15
+ migrate:
16
+ - npx drizzle-kit migrate
17
+ runtimeConfig:
18
+ entrypoints:
19
+ - dist/operations.js
@@ -0,0 +1,4 @@
1
+ CREATE TABLE IF NOT EXISTS "dbos_hello" (
2
+ "name" text PRIMARY KEY NOT NULL,
3
+ "greet_count" integer DEFAULT 0
4
+ );
@@ -0,0 +1,39 @@
1
+ {
2
+ "id": "a4d3c46e-f0ff-439d-8265-f04a053fc603",
3
+ "prevId": "00000000-0000-0000-0000-000000000000",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.dbos_hello": {
8
+ "name": "dbos_hello",
9
+ "schema": "",
10
+ "columns": {
11
+ "name": {
12
+ "name": "name",
13
+ "type": "text",
14
+ "primaryKey": true,
15
+ "notNull": true
16
+ },
17
+ "greet_count": {
18
+ "name": "greet_count",
19
+ "type": "integer",
20
+ "primaryKey": false,
21
+ "notNull": false,
22
+ "default": 0
23
+ }
24
+ },
25
+ "indexes": {},
26
+ "foreignKeys": {},
27
+ "compositePrimaryKeys": {},
28
+ "uniqueConstraints": {}
29
+ }
30
+ },
31
+ "enums": {},
32
+ "schemas": {},
33
+ "sequences": {},
34
+ "_meta": {
35
+ "columns": {},
36
+ "schemas": {},
37
+ "tables": {}
38
+ }
39
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "postgresql",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "7",
8
+ "when": 1722903584204,
9
+ "tag": "0000_hello",
10
+ "breakpoints": true
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,19 @@
1
+ import { defineConfig } from 'drizzle-kit';
2
+
3
+ const { parseConfigFile } = require('@dbos-inc/dbos-sdk');
4
+
5
+ const [dbosConfig, ] = parseConfigFile();
6
+
7
+ export default defineConfig({
8
+ schema: './src/schema.ts',
9
+ out: './drizzle',
10
+ dialect: 'postgresql',
11
+ dbCredentials: {
12
+ host: dbosConfig.poolConfig.host,
13
+ port: dbosConfig.poolConfig.port,
14
+ user: dbosConfig.poolConfig.user,
15
+ password: dbosConfig.poolConfig.password,
16
+ database: dbosConfig.poolConfig.database,
17
+ ssl: dbosConfig.poolConfig.ssl,
18
+ },
19
+ });
@@ -0,0 +1,26 @@
1
+ const { FlatCompat } = require("@eslint/eslintrc");
2
+ const dbosIncEslintPlugin = require("@dbos-inc/eslint-plugin");
3
+ const typescriptEslint = require("typescript-eslint");
4
+ const typescriptEslintParser = require("@typescript-eslint/parser");
5
+ const globals = require("globals");
6
+ const js = require("@eslint/js");
7
+
8
+ const compat = new FlatCompat({
9
+ baseDirectory: __dirname,
10
+ recommendedConfig: js.configs.recommended
11
+ });
12
+
13
+ module.exports = typescriptEslint.config({
14
+ extends: compat.extends("plugin:@dbos-inc/dbosRecommendedConfig"),
15
+ plugins: { "@dbos-inc": dbosIncEslintPlugin },
16
+
17
+ languageOptions: {
18
+ parser: typescriptEslintParser,
19
+ parserOptions: { project: "./tsconfig.json" },
20
+ globals: { ...globals.node, ...globals.es6 }
21
+ },
22
+
23
+ rules: {},
24
+
25
+ ignores: ["**/*.test.ts"]
26
+ });
@@ -0,0 +1,144 @@
1
+ # DBOS-specific
2
+ .dbos
3
+
4
+ # Logs
5
+ **/.DS_Store
6
+ **/prisma/migrations/*
7
+
8
+ logs
9
+ *.log
10
+ npm-debug.log*
11
+ yarn-debug.log*
12
+ yarn-error.log*
13
+ lerna-debug.log*
14
+ .pnpm-debug.log*
15
+ dbos_deploy/
16
+
17
+ # Diagnostic reports (https://nodejs.org/api/report.html)
18
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
19
+
20
+ # Runtime data
21
+ pids
22
+ *.pid
23
+ *.seed
24
+ *.pid.lock
25
+
26
+ # Directory for instrumented libs generated by jscoverage/JSCover
27
+ lib-cov
28
+
29
+ # Coverage directory used by tools like istanbul
30
+ coverage
31
+ *.lcov
32
+
33
+ # nyc test coverage
34
+ .nyc_output
35
+
36
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
37
+ .grunt
38
+
39
+ # Bower dependency directory (https://bower.io/)
40
+ bower_components
41
+
42
+ # node-waf configuration
43
+ .lock-wscript
44
+
45
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
46
+ build/Release
47
+
48
+ # Dependency directories
49
+ node_modules/
50
+ jspm_packages/
51
+
52
+ # Snowpack dependency directory (https://snowpack.dev/)
53
+ web_modules/
54
+
55
+ # TypeScript cache
56
+ *.tsbuildinfo
57
+
58
+ # Optional npm cache directory
59
+ .npm
60
+
61
+ # Optional eslint cache
62
+ .eslintcache
63
+
64
+ # Optional stylelint cache
65
+ .stylelintcache
66
+
67
+ # Microbundle cache
68
+ .rpt2_cache/
69
+ .rts2_cache_cjs/
70
+ .rts2_cache_es/
71
+ .rts2_cache_umd/
72
+
73
+ # Optional REPL history
74
+ .node_repl_history
75
+
76
+ # Output of 'npm pack'
77
+ *.tgz
78
+
79
+ # Yarn Integrity file
80
+ .yarn-integrity
81
+
82
+ # dotenv environment variable files
83
+ .env
84
+ .env.development.local
85
+ .env.test.local
86
+ .env.production.local
87
+ .env.local
88
+
89
+ # parcel-bundler cache (https://parceljs.org/)
90
+ .cache
91
+ .parcel-cache
92
+
93
+ # Next.js build output
94
+ .next
95
+ out
96
+
97
+ # Nuxt.js build / generate output
98
+ .nuxt
99
+ dist
100
+
101
+ # Gatsby files
102
+ .cache/
103
+ # Comment in the public line in if your project uses Gatsby and not Next.js
104
+ # https://nextjs.org/blog/next-9-1#public-directory-support
105
+ # public
106
+
107
+ # vuepress build output
108
+ .vuepress/dist
109
+
110
+ # vuepress v2.x temp and cache directory
111
+ .temp
112
+ .cache
113
+
114
+ # Docusaurus cache and generated files
115
+ .docusaurus
116
+
117
+ # Serverless directories
118
+ .serverless/
119
+
120
+ # FuseBox cache
121
+ .fusebox/
122
+
123
+ # DynamoDB Local files
124
+ .dynamodb/
125
+
126
+ # TernJS port file
127
+ .tern-port
128
+
129
+ # Stores VSCode versions used for testing VSCode extensions
130
+ .vscode-test
131
+
132
+ # VSCode settings
133
+ .vscode/settings.json
134
+
135
+ # yarn v2
136
+ .yarn/cache
137
+ .yarn/unplugged
138
+ .yarn/build-state.yml
139
+ .yarn/install-state.gz
140
+ .pnp.*
141
+
142
+ # Editor temp/recovery files
143
+ *.swp
144
+ *.swo
@@ -0,0 +1,8 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ testRegex: '((\\.|/)(test|spec))\\.ts?$',
6
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7
+ modulePaths: ["./"],
8
+ };
@@ -0,0 +1,7 @@
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
+
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "dbos-hello-drizzle",
3
+ "version": "0.0.1",
4
+ "scripts": {
5
+ "build": "tsc",
6
+ "test": "npx dbos migrate && jest",
7
+ "lint": "eslint src",
8
+ "lint-fix": "eslint --fix src",
9
+ "dev": "nodemon",
10
+ "start": "npx dbos start"
11
+ },
12
+ "devDependencies": {
13
+ "@dbos-inc/eslint-plugin": "^3.1.0",
14
+ "@types/jest": "^29.5.12",
15
+ "@types/supertest": "^2.0.16",
16
+ "drizzle-kit": "^0.23.2",
17
+ "eslint": "^8.57.0",
18
+ "jest": "^29.7.0",
19
+ "nodemon": "^3.1.0",
20
+ "supertest": "^7.0.0",
21
+ "ts-jest": "^29.1.2",
22
+ "typescript": "^5.4.5"
23
+ },
24
+ "dependencies": {
25
+ "@dbos-inc/dbos-sdk": "file:../../../..",
26
+ "drizzle-orm": "^0.32.2"
27
+ }
28
+ }
@@ -0,0 +1,38 @@
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();
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("SELECT * FROM dbos_hello WHERE name=$1", "dbos") as {greet_count: number}[];
25
+ expect(rows[0].greet_count).toBeGreaterThanOrEqual(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
+ });
@@ -0,0 +1,33 @@
1
+ import { HandlerContext, TransactionContext, Transaction, GetApi, ArgSource, ArgSources } from '@dbos-inc/dbos-sdk';
2
+ import { DBOSHello } from './schema';
3
+ import { sql } from 'drizzle-orm';
4
+ import { NodePgDatabase } from 'drizzle-orm/node-postgres';
5
+
6
+ export class Hello {
7
+
8
+ @GetApi('/') // Serve a quick readme for the app
9
+ static async readme(_ctxt: HandlerContext) {
10
+ const readme = '<html><body><p>' +
11
+ 'Welcome to the DBOS Hello App!<br><br>' +
12
+ 'Visit the route /greeting/:name to be greeted!<br>' +
13
+ 'For example, visit <a href="/greeting/dbos">/greeting/dbos</a>.<br>' +
14
+ 'The counter increments with each page visit.<br>' +
15
+ 'If you visit a new name like <a href="/greeting/alice">/greeting/alice</a>, the counter starts at 1.' +
16
+ '</p></body></html>';
17
+ return Promise.resolve(readme);
18
+ }
19
+
20
+ @GetApi('/greeting/:user') // Serve this function from HTTP GET requests to the /greeting endpoint with 'user' as a path parameter
21
+ @Transaction() // Run this function as a database transaction
22
+ static async helloTransaction(ctxt: TransactionContext<NodePgDatabase>, @ArgSource(ArgSources.URL) user: string) {
23
+ const output = await ctxt.client.execute(sql`
24
+ INSERT INTO ${DBOSHello} (name, greet_count)
25
+ VALUES (${user}, 1)
26
+ ON CONFLICT (name) DO UPDATE
27
+ SET greet_count = ${DBOSHello.greet_count} + 1
28
+ RETURNING greet_count
29
+ `);
30
+ const greet_count = output.rows[0].greet_count as number;
31
+ return `Hello, ${user}! You have been greeted ${greet_count} times.\n`;
32
+ }
33
+ }
@@ -0,0 +1,7 @@
1
+ import { integer } from "drizzle-orm/pg-core";
2
+ import { pgTable, text } from "drizzle-orm/pg-core";
3
+
4
+ export const DBOSHello = pgTable('dbos_hello', {
5
+ name: text('name').primaryKey(),
6
+ greet_count: integer('greet_count').default(0)
7
+ });
@@ -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 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
+ }
@@ -0,0 +1,25 @@
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,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/dbos-sdk init` 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/tutorials/using-prisma).
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -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/dbos-sdk init` 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/tutorials/using-typeorm).
4
4
 
5
5
  ## Getting Started
6
6