create-db 1.1.2-pr44-DC-4828-json-flag-17109503084.0 → 1.1.2

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/README.md CHANGED
@@ -1,106 +1,239 @@
1
- ## **What is `create-db`?**
1
+ # create-db
2
2
 
3
- `create-db` is an open-source CLI tool that provisions [**temporary Prisma Postgres databases**](https://www.prisma.io/postgres?utm_source=create_db_npm_docs) with a single command.
3
+ `create-db` is an open-source CLI tool and library that provisions [**temporary Prisma Postgres databases**](https://www.prisma.io/postgres?utm_source=create_db_npm_docs) with a single command.
4
4
 
5
- Each database is available for **24 hours** by default. To keep the database permanently, you can **claim it for free** using the URL displayed in the CLI output.
5
+ Each database is available for **24 hours** by default. To keep the database permanently, you can **claim it for free** using the URL displayed in the output.
6
6
 
7
7
  This tool is designed for developers who need a fast way to test, prototype, or integrate Prisma Postgres without manual setup or creating an account.
8
8
 
9
- ## **Installation and usage**
9
+ ## Installation and Usage
10
10
 
11
- There is no need to install the tool globally. Simply run:
11
+ No installation required. Simply run:
12
12
 
13
13
  ```bash
14
14
  npx create-db@latest
15
15
  ```
16
16
 
17
- You can also use the following aliases:
17
+ You can also use these aliases:
18
18
 
19
19
  ```bash
20
20
  npx create-pg@latest
21
21
  npx create-postgres@latest
22
22
  ```
23
23
 
24
- ## **Examples**
24
+ ## CLI Usage
25
25
 
26
- ```bash
27
- npx create-db # Creates a database in the default region
28
- npx create-db --region eu-west-1 # Creates a database in a specific region
29
- npx create-db --i # Interactive region selection
26
+ ### Commands
30
27
 
28
+ ```bash
29
+ npx create-db [create] # Create a new database (default command)
30
+ npx create-db regions # List available regions
31
31
  ```
32
32
 
33
- ## **Available options**
33
+ ### Options
34
+
35
+ | Flag | Alias | Description |
36
+ |------|-------|-------------|
37
+ | `--region <region>` | `-r` | AWS region for the database |
38
+ | `--interactive` | `-i` | Interactive mode to select a region |
39
+ | `--json` | `-j` | Output machine-readable JSON |
40
+ | `--env <path>` | `-e` | Write DATABASE_URL and CLAIM_URL to specified .env file |
41
+ | `--help` | `-h` | Show help message |
42
+ | `--version` | | Show version |
43
+
44
+ ### Available Regions
45
+
46
+ - `ap-southeast-1` - Asia Pacific (Singapore)
47
+ - `ap-northeast-1` - Asia Pacific (Tokyo)
48
+ - `eu-central-1` - Europe (Frankfurt)
49
+ - `eu-west-3` - Europe (Paris)
50
+ - `us-east-1` - US East (N. Virginia)
51
+ - `us-west-1` - US West (N. California)
52
+
53
+ ### Examples
54
+
55
+ ```bash
56
+ # Create database in auto-detected nearest region
57
+ npx create-db
58
+
59
+ # Create database in a specific region
60
+ npx create-db --region eu-west-3
61
+ npx create-db -r us-east-1
62
+
63
+ # Interactive region selection
64
+ npx create-db --interactive
65
+ npx create-db -i
34
66
 
35
- You can run `npx create-db --help` or `npx create-db -h` to see all the available CLI options:
67
+ # Output as JSON (useful for scripting)
68
+ npx create-db --json
69
+ npx create-db -j
36
70
 
71
+ # Write connection string to .env file
72
+ npx create-db --env .env
73
+ npx create-db -e .env.local
74
+
75
+ # Combine flags
76
+ npx create-db -r eu-central-1 -j
77
+ npx create-db -i -e .env
78
+
79
+ # List available regions
80
+ npx create-db regions
37
81
  ```
38
- npx create-db [options]
39
82
 
40
- Options:
41
- --region <region>, -r <region> Specify a region
42
- Available regions:
43
- ap-southeast-1, ap-northeast-1,
44
- eu-central-1, eu-west-3,
45
- us-east-1, us-west-1
83
+ ### JSON Output
84
+
85
+ When using `--json`, the output includes:
86
+
87
+ ```json
88
+ {
89
+ "success": true,
90
+ "connectionString": "postgresql://user:pass@host:5432/postgres?sslmode=require",
91
+ "claimUrl": "https://create-db.prisma.io/claim?projectID=...",
92
+ "deletionDate": "2025-12-13T12:00:00.000Z",
93
+ "region": "us-east-1",
94
+ "name": "2025-12-12T12:00:00.000Z",
95
+ "projectId": "proj_..."
96
+ }
97
+ ```
46
98
 
47
- --interactive, -i Run in interactive mode
99
+ ### Environment File Output
48
100
 
49
- --help, -h Show this help message
101
+ When using `--env`, the following variables are appended to the specified file:
50
102
 
103
+ ```env
104
+ DATABASE_URL="postgresql://user:pass@host:5432/postgres?sslmode=require"
105
+ CLAIM_URL="https://create-db.prisma.io/claim?projectID=..."
51
106
  ```
52
107
 
53
- ## **CLI output example**
108
+ ## Programmatic API
54
109
 
110
+ You can also use `create-db` as a library in your Node.js applications:
111
+
112
+ ```bash
113
+ npm install create-db
114
+ # or
115
+ bun add create-db
55
116
  ```
56
- ┌ 🚀 Creating a Prisma Postgres database
57
-
58
- │ Provisioning a temporary database in us-east-1...
59
-
60
- │ It will be automatically deleted in 24 hours, but you can claim it.
61
-
62
- ◇ Database created successfully!
63
-
64
- ● Connect to your database →
65
-
66
- │ Prisma connection string:
67
- │ prisma+postgres://accelerate.prisma-data.net/?api_key=...
68
-
69
- │ Standard connection string:
70
- │ postgresql://<username>:<password>@db.prisma.io:5432/postgres
71
-
72
- ◆ Claim your database →
73
-
74
- │ Want to keep your database? Claim for free:
75
- │ https://create-db.prisma.io?projectID=proj_...
76
-
77
117
 
118
+ ### `create(options?)`
119
+
120
+ Create a new Prisma Postgres database programmatically.
121
+
122
+ ```typescript
123
+ import { create } from "create-db";
124
+
125
+ const result = await create({ region: "us-east-1" });
126
+
127
+ if (result.success) {
128
+ console.log(`Connection string: ${result.connectionString}`);
129
+ console.log(`Claim URL: ${result.claimUrl}`);
130
+ console.log(`Expires: ${result.deletionDate}`);
131
+ } else {
132
+ console.error(`Error: ${result.message}`);
133
+ }
78
134
  ```
79
135
 
80
- ## **Claiming a database**
136
+ #### Options
81
137
 
82
- When you create a database using `create-db`, it is temporary and will be deleted automatically after **24 hours**.
138
+ | Option | Type | Description |
139
+ |--------|------|-------------|
140
+ | `region` | `RegionId` | AWS region for the database (optional, defaults to `us-east-1`) |
141
+ | `userAgent` | `string` | Custom user agent string for tracking (optional) |
83
142
 
84
- The CLI output includes a **claim URL** that allows you to keep the database permanently for free.
143
+ ### `regions()`
85
144
 
86
- **What claiming does:**
145
+ List available Prisma Postgres regions.
146
+
147
+ ```typescript
148
+ import { regions } from "create-db";
149
+
150
+ const availableRegions = await regions();
151
+ console.log(availableRegions);
152
+ // [{ id: "us-east-1", name: "US East (N. Virginia)", status: "available" }, ...]
153
+ ```
154
+
155
+ ### Type Guards
156
+
157
+ ```typescript
158
+ import { create, isDatabaseSuccess, isDatabaseError } from "create-db";
87
159
 
88
- - Moves the database into your Prisma Data Platform account.
89
- - Prevents it from being auto-deleted.
90
- - Lets you continue using the database as a long-term instance.
160
+ const result = await create();
91
161
 
92
- Example:
162
+ if (isDatabaseSuccess(result)) {
163
+ // result is DatabaseResult
164
+ console.log(result.connectionString);
165
+ }
93
166
 
167
+ if (isDatabaseError(result)) {
168
+ // result is DatabaseError
169
+ console.error(result.message);
170
+ }
94
171
  ```
95
- ◆ Claim your database →
96
-
97
- │ Want to keep your database? Claim for free:
98
- |
99
- │ https://create-db.prisma.io?projectID=proj_...
100
-
101
- │ Your database will be deleted on 7/24/2025, 2:25:41 AM if not claimed.
172
+
173
+ ### Types
174
+
175
+ ```typescript
176
+ import type {
177
+ Region,
178
+ RegionId,
179
+ CreateDatabaseResult,
180
+ DatabaseResult,
181
+ DatabaseError,
182
+ ProgrammaticCreateOptions,
183
+ } from "create-db";
184
+
185
+ // RegionId is a union type of available regions
186
+ type RegionId = "ap-southeast-1" | "ap-northeast-1" | "eu-central-1" | "eu-west-3" | "us-east-1" | "us-west-1";
187
+
188
+ // DatabaseResult (success)
189
+ interface DatabaseResult {
190
+ success: true;
191
+ connectionString: string | null;
192
+ claimUrl: string;
193
+ deletionDate: string;
194
+ region: string;
195
+ name: string;
196
+ projectId: string;
197
+ userAgent?: string;
198
+ }
199
+
200
+ // DatabaseError (failure)
201
+ interface DatabaseError {
202
+ success: false;
203
+ error: string;
204
+ message: string;
205
+ raw?: string;
206
+ details?: unknown;
207
+ status?: number;
208
+ }
209
+
210
+ // CreateDatabaseResult is DatabaseResult | DatabaseError
102
211
  ```
103
212
 
104
- ## **Next steps**
213
+ ### Region Validation with Zod
214
+
215
+ ```typescript
216
+ import { RegionSchema } from "create-db";
217
+
218
+ // Validate region input
219
+ const result = RegionSchema.safeParse("us-east-1");
220
+ if (result.success) {
221
+ console.log("Valid region:", result.data);
222
+ }
223
+ ```
224
+
225
+ ## Claiming a Database
226
+
227
+ When you create a database, it is temporary and will be deleted after **24 hours**.
228
+
229
+ The output includes a **claim URL** that allows you to keep the database permanently for free.
230
+
231
+ **What claiming does:**
232
+
233
+ - Moves the database into your Prisma Data Platform account
234
+ - Prevents it from being auto-deleted
235
+ - Lets you continue using the database as a long-term instance
236
+
237
+ ## Next Steps
105
238
 
106
- - Refer to the section in the official [Prisma Postgres documentation](https://www.prisma.io/docs/postgres/introduction/npx-create-db).
239
+ - Refer to the [Prisma Postgres documentation](https://www.prisma.io/docs/postgres/introduction/npx-create-db) for more details.
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.mjs ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { n as createDbCli } from "./src-CIUkHOCN.mjs";
3
+
4
+ //#region src/cli.ts
5
+ createDbCli().run();
6
+
7
+ //#endregion
8
+ export { };
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env node
2
+ import * as trpc_cli0 from "trpc-cli";
3
+ import z$1 from "zod";
4
+
5
+ //#region src/types.d.ts
6
+ declare const RegionSchema: z$1.ZodEnum<{
7
+ "ap-southeast-1": "ap-southeast-1";
8
+ "ap-northeast-1": "ap-northeast-1";
9
+ "eu-central-1": "eu-central-1";
10
+ "eu-west-3": "eu-west-3";
11
+ "us-east-1": "us-east-1";
12
+ "us-west-1": "us-west-1";
13
+ }>;
14
+ type RegionId = z$1.infer<typeof RegionSchema>;
15
+ interface Region {
16
+ id: string;
17
+ name?: string;
18
+ status: string;
19
+ }
20
+ interface DatabaseResult {
21
+ success: true;
22
+ connectionString: string | null;
23
+ claimUrl: string;
24
+ deletionDate: string;
25
+ region: string;
26
+ name: string;
27
+ projectId: string;
28
+ userAgent?: string;
29
+ }
30
+ interface DatabaseError {
31
+ success: false;
32
+ error: string;
33
+ message: string;
34
+ raw?: string;
35
+ details?: unknown;
36
+ status?: number;
37
+ }
38
+ type CreateDatabaseResult = DatabaseResult | DatabaseError;
39
+ declare function isDatabaseError(result: CreateDatabaseResult): result is DatabaseError;
40
+ declare function isDatabaseSuccess(result: CreateDatabaseResult): result is DatabaseResult;
41
+ interface ProgrammaticCreateOptions {
42
+ region?: RegionId;
43
+ userAgent?: string;
44
+ }
45
+ //#endregion
46
+ //#region src/index.d.ts
47
+ declare function createDbCli(): trpc_cli0.TrpcCli;
48
+ /**
49
+ * Create a new Prisma Postgres database programmatically.
50
+ *
51
+ * @param options - Options for creating the database
52
+ * @param options.region - The AWS region for the database (optional)
53
+ * @param options.userAgent - Custom user agent string (optional)
54
+ * @returns A promise that resolves to either a {@link DatabaseResult} or {@link DatabaseError}
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * import { create } from "create-db";
59
+ *
60
+ * const result = await create({ region: "us-east-1" });
61
+ *
62
+ * if (result.success) {
63
+ * console.log(`Connection string: ${result.connectionString}`);
64
+ * console.log(`Claim URL: ${result.claimUrl}`);
65
+ * } else {
66
+ * console.error(`Error: ${result.message}`);
67
+ * }
68
+ * ```
69
+ */
70
+ declare function create(options?: ProgrammaticCreateOptions): Promise<CreateDatabaseResult>;
71
+ /**
72
+ * List available Prisma Postgres regions programmatically.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * import { regions } from "create-db";
77
+ *
78
+ * const availableRegions = await regions();
79
+ * console.log(availableRegions);
80
+ * ```
81
+ */
82
+ declare function regions(): Promise<Region[]>;
83
+ //#endregion
84
+ export { type CreateDatabaseResult, type DatabaseError, type DatabaseResult, type ProgrammaticCreateOptions, type Region, type RegionId, RegionSchema, create, createDbCli, isDatabaseError, isDatabaseSuccess, regions };
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { a as isDatabaseError, i as RegionSchema, n as createDbCli, o as isDatabaseSuccess, r as regions, t as create } from "./src-CIUkHOCN.mjs";
3
+
4
+ export { RegionSchema, create, createDbCli, isDatabaseError, isDatabaseSuccess, regions };