@constructive-io/cli 5.1.24 → 5.2.1

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,96 +1,20 @@
1
1
  # Constructive CLI
2
2
 
3
- > Build secure, role-aware GraphQL backends powered by PostgreSQL with database-first development
3
+ > API Server and Development Tools for PostgreSQL
4
4
 
5
- Constructive CLI is a comprehensive command-line tool that transforms your PostgreSQL database into a powerful GraphQL API. With automated schema generation, sophisticated migration management, and robust deployment capabilities, you can focus on building great applications instead of boilerplate code.
5
+ Constructive CLI provides GraphQL server capabilities and code generation tools for PostgreSQL databases. For database migrations, packages, and deployment operations, use [pgpm](https://pgpm.io).
6
6
 
7
- ## ✨ Features
8
-
9
- - 🚀 **Database-First Development** - Design your database, get your GraphQL API automatically
10
- - 🔐 **Built-in Security** - Role-based access control and security policies
11
- - 📦 **Module System** - Reusable database modules with dependency management
12
- - 🛠️ **Developer Experience** - Hot-reload development server with GraphiQL explorer
13
- - 🏗️ **Production Ready** - Deployment plans, versioning, and rollback support
14
-
15
- ## 🚀 Quick Start
16
-
17
- ### Installation
7
+ ## Installation
18
8
 
19
9
  ```bash
20
10
  npm install -g @constructive-io/cli
21
11
  ```
22
12
 
23
- ### Create Your First Project
24
-
25
- ```bash
26
- # Initialize a new workspace
27
- cnc init workspace
28
- cd my-project
29
-
30
- # Create your first module
31
- cnc init
32
-
33
- # Deploy to your database
34
- cnc deploy --createdb
35
-
36
- # Start the development server
37
- cnc server
38
- ```
39
-
40
- Visit `http://localhost:5555` to explore your GraphQL API!
41
-
42
- ## 📖 Core Concepts
43
-
44
- ### Workspaces and Modules
45
-
46
- - **Workspace**: A collection of related database modules
47
- - **Module**: A self-contained database package with migrations, functions, and types
48
- - **Dependencies**: Modules can depend on other modules, creating reusable building blocks
49
-
50
- ### Database-First Workflow
51
-
52
- 1. **Design** your database schema using SQL migrations
53
- 2. **Deploy** changes with `cnc deploy`
54
- 3. **Develop** against the auto-generated GraphQL API
55
- 4. **Version** and **package** your modules for distribution
56
-
57
- ## 🛠️ Commands
58
-
59
- ### Getting Started
60
-
61
- #### `cnc init`
62
-
63
- Initialize a new Constructive workspace or module.
64
-
65
- ```bash
66
- # Create a new workspace
67
- cnc init workspace
68
-
69
- # Create a new module (run inside workspace)
70
- cnc init
71
-
72
- # Use templates from GitHub repository (defaults to constructive-io/pgpm-boilerplates.git)
73
- cnc init workspace --repo owner/repo
74
- cnc init --repo owner/repo --from-branch develop
75
-
76
- # Use templates from custom paths
77
- cnc init workspace --template-path ./custom-templates
78
- cnc init --template-path ./custom-templates/module
79
- ```
80
-
81
- **Options:**
82
-
83
- - `--repo <repo>` - Template repo (default: `https://github.com/constructive-io/pgpm-boilerplates.git`)
84
- - `--template-path <path>` - Template sub-path (defaults to `workspace`/`module`) or local path override
85
- - `--from-branch <branch>` - Branch/tag when cloning the template repo
86
-
87
- Templates are cached for one week under the `pgpm` tool namespace. Run `cnc cache clean` if you need to refresh the boilerplates.
13
+ ## Commands
88
14
 
89
- ### Development
15
+ ### `cnc server`
90
16
 
91
- #### `cnc server`
92
-
93
- Start the GraphQL development server with hot-reload.
17
+ Start the GraphQL development server.
94
18
 
95
19
  ```bash
96
20
  # Start with defaults (port 5555)
@@ -103,7 +27,16 @@ cnc server --port 8080 --no-postgis
103
27
  cnc server --origin http://localhost:3000
104
28
  ```
105
29
 
106
- #### `cnc explorer`
30
+ **Options:**
31
+
32
+ - `--port <number>` - Server port (default: 5555)
33
+ - `--origin <url>` - CORS origin URL
34
+ - `--simpleInflection` - Use simple inflection (default: true)
35
+ - `--oppositeBaseNames` - Use opposite base names (default: false)
36
+ - `--postgis` - Enable PostGIS extension (default: true)
37
+ - `--metaApi` - Enable Meta API (default: true)
38
+
39
+ ### `cnc explorer`
107
40
 
108
41
  Launch GraphiQL explorer for your API.
109
42
 
@@ -115,419 +48,89 @@ cnc explorer
115
48
  cnc explorer --origin http://localhost:3000
116
49
  ```
117
50
 
118
- #### `cnc docker`
119
-
120
- Manage PostgreSQL Docker containers for local development.
121
-
122
- ```bash
123
- # Start PostgreSQL container
124
- cnc docker start
125
-
126
- # Stop PostgreSQL container
127
- cnc docker stop
128
- ```
129
-
130
- #### `cnc env`
131
-
132
- Display environment configuration for PostgreSQL connection.
133
-
134
- ```bash
135
- # Print environment variables for shell export
136
- cnc env
137
-
138
- # Use with eval to set environment
139
- eval "$(cnc env)"
140
-
141
- # Print Supabase local development environment
142
- cnc env --supabase
143
- ```
144
-
145
- ## 🔄 Updates
146
-
147
- The CLI performs a lightweight npm version check at most once per week (skipped in CI or when `PGPM_SKIP_UPDATE_CHECK` is set). Use `cnc update` to install the latest release (installs `pgpm` by default; pass `--package @constructive-io/cli` to target the CLI package).
148
-
149
- ### Database Operations
150
-
151
- #### `cnc deploy`
152
-
153
- Deploy your database changes and migrations.
154
-
155
- ```bash
156
- # Deploy to selected database
157
- cnc deploy
158
-
159
- # Create database if it doesn't exist
160
- cnc deploy --createdb
161
-
162
- # Deploy specific package to a tag
163
- cnc deploy --package mypackage --to @v1.0.0
164
-
165
- # Fast deployment without transactions
166
- cnc deploy --fast --no-tx
167
- ```
168
-
169
- #### `cnc verify`
170
-
171
- Verify your database state matches expected migrations.
172
-
173
- ```bash
174
- # Verify current state
175
- cnc verify
176
-
177
- # Verify specific package
178
- cnc verify --package mypackage
179
- ```
180
-
181
- #### `cnc revert`
182
-
183
- Safely revert database changes.
184
-
185
- ```bash
186
- # Revert latest changes
187
- cnc revert
188
-
189
- # Revert to specific tag
190
- cnc revert --to @v1.0.0
191
- ```
192
-
193
- ### Migration Management
194
-
195
- #### `cnc migrate`
196
-
197
- Comprehensive migration management.
198
-
199
- ```bash
200
- # Initialize migration tracking
201
- cnc migrate init
202
-
203
- # Check migration status
204
- cnc migrate status
205
-
206
- # List all changes
207
- cnc migrate list
208
-
209
- # Show change dependencies
210
- cnc migrate deps
211
- ```
212
-
213
- ### Module Management
214
-
215
- #### `cnc install`
216
-
217
- Install PGPM modules as dependencies.
218
-
219
- ```bash
220
- # Install single package
221
- cnc install @constructive-io/auth
222
-
223
- # Install multiple packages
224
- cnc install @constructive-io/auth @constructive-io/utils
225
- ```
226
-
227
- #### `cnc extension`
228
-
229
- Interactively manage module dependencies.
230
-
231
- ```bash
232
- cnc extension
233
- ```
234
-
235
- #### `cnc upgrade-modules`
236
-
237
- Upgrade installed pgpm modules to their latest versions from npm.
238
-
239
- ```bash
240
- # Interactive selection of modules to upgrade
241
- cnc upgrade-modules
242
-
243
- # Upgrade all installed modules without prompting
244
- cnc upgrade-modules --all
245
-
246
- # Preview available upgrades without making changes
247
- cnc upgrade-modules --dry-run
248
-
249
- # Upgrade specific modules
250
- cnc upgrade-modules --modules @pgpm/base32,@pgpm/faker
251
-
252
- # Upgrade modules across all packages in the workspace
253
- cnc upgrade-modules --workspace --all
254
- ```
255
-
256
51
  **Options:**
257
52
 
258
- - `--all` - Upgrade all modules without prompting
259
- - `--dry-run` - Show what would be upgraded without making changes
260
- - `--modules <names>` - Comma-separated list of specific modules to upgrade
261
- - `--workspace` - Upgrade modules across all packages in the workspace
262
- - `--cwd <directory>` - Working directory (default: current directory)
263
-
264
- #### `cnc tag`
265
-
266
- Version your changes with tags.
267
-
268
- ```bash
269
- # Tag latest change
270
- cnc tag v1.0.0
271
-
272
- # Tag with comment
273
- cnc tag v1.0.0 --comment "Initial release"
274
-
275
- # Tag specific change
276
- cnc tag v1.1.0 --package mypackage --changeName my-change
277
- ```
278
-
279
- ### Packaging and Distribution
280
-
281
- #### `cnc plan`
282
-
283
- Generate deployment plans for your modules.
284
-
285
- ```bash
286
- cnc plan
287
- ```
288
-
289
- #### `cnc package`
290
-
291
- Package your module for distribution.
292
-
293
- ```bash
294
- # Package with defaults
295
- cnc package
296
-
297
- # Package without deployment plan
298
- cnc package --no-plan
299
- ```
300
-
301
- ### Utilities
302
-
303
- #### `cnc add`
304
-
305
- Add a new database change to your module.
306
-
307
- ```bash
308
- # Add a new change
309
- cnc add my_change
310
-
311
- # Add with specific type
312
- cnc add my_function --type function
313
- ```
314
-
315
- #### `cnc export`
316
-
317
- Export migrations from existing databases.
318
-
319
- ```bash
320
- cnc export
321
- ```
322
-
323
- #### `cnc kill`
324
-
325
- Clean up database connections and optionally drop databases.
326
-
327
- ```bash
328
- # Kill connections and drop databases
329
- cnc kill
330
-
331
- # Only kill connections
332
- cnc kill --no-drop
333
- ```
334
-
335
- #### `cnc clear`
336
-
337
- Clear database state.
338
-
339
- ```bash
340
- cnc clear
341
- ```
342
-
343
- #### `cnc remove`
344
-
345
- Remove database changes.
346
-
347
- ```bash
348
- cnc remove my_change
349
- ```
350
-
351
- #### `cnc analyze`
352
-
353
- Analyze database structure.
354
-
355
- ```bash
356
- cnc analyze
357
- ```
358
-
359
- #### `cnc rename`
360
-
361
- Rename database changes.
362
-
363
- ```bash
364
- cnc rename old_name new_name
365
- ```
53
+ - `--port <number>` - Server port (default: 5555)
54
+ - `--origin <url>` - CORS origin URL (default: http://localhost:3000)
55
+ - `--simpleInflection` - Use simple inflection (default: true)
56
+ - `--oppositeBaseNames` - Use opposite base names (default: false)
57
+ - `--postgis` - Enable PostGIS extension (default: true)
366
58
 
367
- #### `cnc admin-users`
59
+ ### `cnc codegen`
368
60
 
369
- Manage admin users for your database.
61
+ Generate TypeScript types, operations, and SDK from a GraphQL schema.
370
62
 
371
63
  ```bash
372
- # Bootstrap admin users
373
- cnc admin-users bootstrap
374
-
375
- # Add an admin user
376
- cnc admin-users add
377
-
378
- # Remove an admin user
379
- cnc admin-users remove
380
- ```
381
-
382
- ### Testing
383
-
384
- #### `cnc test-packages`
385
-
386
- Run integration tests on all modules in a workspace. Creates a temporary database for each module, deploys, and optionally runs verify/revert/deploy cycles.
387
-
388
- ```bash
389
- # Test all modules in workspace (deploy only)
390
- cnc test-packages
391
-
392
- # Run full deploy/verify/revert/deploy cycle
393
- cnc test-packages --full-cycle
394
-
395
- # Continue testing all packages even after failures
396
- cnc test-packages --continue-on-fail
397
-
398
- # Exclude specific modules
399
- cnc test-packages --exclude my-module,another-module
64
+ # From SDL file
65
+ cnc codegen --schema ./schema.graphql --out ./codegen
400
66
 
401
- # Combine options
402
- cnc test-packages --full-cycle --continue-on-fail --exclude legacy-module
67
+ # From endpoint with Host override
68
+ cnc codegen --endpoint http://localhost:3000/graphql --headerHost meta8.localhost --out ./codegen
403
69
  ```
404
70
 
405
71
  **Options:**
406
72
 
407
- - `--full-cycle` - Run full deploy/verify/revert/deploy cycle (default: deploy only)
408
- - `--continue-on-fail` - Continue testing all packages even after failures (default: stop on first failure)
409
- - `--exclude <modules>` - Comma-separated module names to exclude
410
- - `--cwd <directory>` - Working directory (default: current directory)
411
-
412
- **Notes:**
413
-
414
- - Discovers modules from workspace `pgpm.json` configuration
415
- - Creates isolated test databases (`test_<module_name>`) for each module
416
- - Automatically cleans up test databases after each test
417
- - Uses internal APIs for deploy/verify/revert operations
418
-
419
- ## 💡 Common Workflows
420
-
421
- ### Starting a New Project
422
-
423
- ```bash
424
- # 1. Create workspace
425
- mkdir my-app && cd my-app
426
- cnc init workspace
427
-
428
- # 2. Create your first module
429
- cnc init
430
-
431
- # 3. Add some SQL migrations to sql/ directory
432
- # 4. Deploy to database
433
- cnc deploy --createdb
434
-
435
- # 5. Start developing
436
- cnc server
437
- ```
438
-
439
- ### Using Custom Templates
440
-
441
- You can use custom templates from GitHub repositories or local paths:
442
-
443
- ```bash
444
- # Initialize workspace with templates from GitHub
445
- cnc init workspace --repo owner/repo
446
-
447
- # Initialize workspace with templates from local path
448
- cnc init workspace --template-path ./my-custom-templates
449
-
450
- # Initialize module with custom templates
451
- cnc init --template-path ./my-custom-templates
73
+ - `--schema <path>` - Schema SDL file path
74
+ - `--endpoint <url>` - GraphQL endpoint to fetch schema via introspection
75
+ - `--headerHost <host>` - Optional Host header for endpoint requests
76
+ - `--auth <token>` - Optional Authorization header value
77
+ - `--header "Name: Value"` - Optional HTTP header (repeatable)
78
+ - `--out <dir>` - Output root directory (default: graphql/codegen/dist)
79
+ - `--format <gql|ts>` - Document format (default: gql)
80
+ - `--convention <style>` - Filename convention (dashed|underscore|camelcase|camelUpper)
81
+ - `--emitTypes <bool>` - Emit types (default: true)
82
+ - `--emitOperations <bool>` - Emit operations (default: true)
83
+ - `--emitSdk <bool>` - Emit SDK (default: true)
84
+ - `--config <path>` - Config file (JSON/YAML)
85
+
86
+ **Config file example (`codegen.json`):**
452
87
 
453
- # Use specific branch from GitHub repository
454
- cnc init workspace --repo owner/repo --from-branch develop
88
+ ```json
89
+ {
90
+ "input": {
91
+ "schema": "./schema.graphql",
92
+ "headers": { "Host": "meta8.localhost" }
93
+ },
94
+ "output": {
95
+ "root": "graphql/codegen/dist"
96
+ },
97
+ "documents": {
98
+ "format": "gql",
99
+ "convention": "dashed",
100
+ "excludePatterns": [".*Module$"]
101
+ },
102
+ "features": {
103
+ "emitTypes": true,
104
+ "emitOperations": true,
105
+ "emitSdk": true,
106
+ "emitReactQuery": true
107
+ }
108
+ }
455
109
  ```
456
110
 
457
- **Template Structure:**
458
- Custom templates should follow the same structure as the default templates:
111
+ ### `cnc get-graphql-schema`
459
112
 
460
- - For workspace: `boilerplates/workspace/` directory
461
- - For module: `boilerplates/module/` directory
462
- - Or provide direct path to `workspace/` or `module/` directory
463
-
464
- ### Working with Existing Projects
113
+ Fetch or build GraphQL schema SDL.
465
114
 
466
115
  ```bash
467
- # 1. Clone and enter project
468
- git clone <repo> && cd <project>
469
-
470
- # 2. Install dependencies
471
- cnc install
116
+ # From database schemas
117
+ cnc get-graphql-schema --database mydb --schemas myapp,public --out ./schema.graphql
472
118
 
473
- # 3. Deploy to local database
474
- cnc deploy --createdb
475
-
476
- # 4. Start development server
477
- cnc server
119
+ # From running server
120
+ cnc get-graphql-schema --endpoint http://localhost:3000/graphql --out ./schema.graphql
478
121
  ```
479
122
 
480
- ### Production Deployment
481
-
482
- ```bash
483
- # 1. Create deployment plan
484
- cnc plan
485
-
486
- # 2. Package module
487
- cnc package
488
-
489
- # 3. Deploy to production
490
- cnc deploy --package myapp --to @production
491
-
492
- # 4. Verify deployment
493
- cnc verify --package myapp
494
- ```
495
-
496
- ### Get Graphql Schema
497
-
498
- Fetch and output your GraphQL schema in SDL.
499
-
500
- - Option 1 – Programmatic builder (from database schemas):
501
- - Write to file:
502
- - `cnc get-graphql-schema --database constructive --schemas myapp,public --out ./schema.graphql`
503
- - Print to stdout:
504
- - `cnc get-graphql-schema --database constructive --schemas myapp,public`
505
-
506
- - Option 2 – Fetch from running server (via endpoint introspection):
507
- - Write to file:
508
- - `cnc get-graphql-schema --endpoint http://localhost:3000/graphql --headerHost meta8.localhost --out ./schema.graphql`
509
- - Print to stdout:
510
- - `cnc get-graphql-schema --endpoint http://localhost:3000/graphql --headerHost meta8.localhost`
511
-
512
- Options:
513
- - `--database <name>` (Option 1)
514
- - `--schemas <list>` (Option 1; comma-separated)
515
- - `--endpoint <url>` (Option 2)
516
- - `--headerHost <hostname>` (Option 2; optional custom HTTP Host header for vhost-based local setups)
517
- - `--auth <token>` (Option 2; optional; sets Authorization header)
518
- - `--header <name: value>` (Option 2; optional; repeatable; adds request headers, last value wins on duplicates)
519
- - `--out <path>` (optional; if omitted, prints to stdout)
520
-
521
- Notes:
522
- - If your local dev server routes by hostname (e.g., `meta8.localhost`), but is reachable at `http://localhost:<port>`, use:
523
- - `cnc get-graphql-schema --endpoint http://localhost:3000/graphql --headerHost meta8.localhost`
524
- - You can repeat `--header` to add multiple headers, e.g.: `--header 'X-Mode: fast' --header 'Authorization: Bearer abc123'`
525
-
526
- Tip:
527
- - For Option 1, include only the schemas you need (e.g., `myapp,public`) to avoid type naming conflicts when multiple schemas contain similarly named tables.
123
+ **Options:**
528
124
 
125
+ - `--database <name>` - Database name (for programmatic builder)
126
+ - `--schemas <list>` - Comma-separated schemas to include
127
+ - `--endpoint <url>` - GraphQL endpoint to fetch schema via introspection
128
+ - `--headerHost <host>` - Optional Host header for endpoint requests
129
+ - `--auth <token>` - Optional Authorization header value
130
+ - `--header "Name: Value"` - Optional HTTP header (repeatable)
131
+ - `--out <path>` - Output file path (prints to stdout if omitted)
529
132
 
530
- ## ⚙️ Configuration
133
+ ## Configuration
531
134
 
532
135
  ### Environment Variables
533
136
 
@@ -541,85 +144,41 @@ export PGUSER=postgres
541
144
  export PGPASSWORD=password
542
145
  ```
543
146
 
544
- ## 🆘 Getting Help
147
+ ## Database Operations
545
148
 
546
- ### Command Help
149
+ For database migrations, packages, and deployment, use **pgpm**:
547
150
 
548
151
  ```bash
549
- # Global help
550
- cnc --help
551
-
552
- # Command-specific help
553
- cnc deploy --help
554
- cnc server -h
152
+ npm install -g pgpm
555
153
  ```
556
154
 
557
- ### Common Options
155
+ Common pgpm commands:
558
156
 
559
- Most commands support these global options:
157
+ - `pgpm init workspace` - Initialize a new workspace
158
+ - `pgpm init` - Create a new module
159
+ - `pgpm add <change>` - Add a database change
160
+ - `pgpm deploy` - Deploy database changes
161
+ - `pgpm verify` - Verify database state
162
+ - `pgpm revert` - Revert database changes
560
163
 
561
- - `--help, -h` - Show help information
562
- - `--version, -v` - Show version information
563
- - `--cwd <dir>` - Set working directory
564
- ### Codegen
164
+ See the [pgpm documentation](https://pgpm.io) for more details.
565
165
 
566
- Generate types, operations, and SDK from a schema or endpoint.
166
+ ## Getting Help
567
167
 
568
168
  ```bash
569
- # From SDL file
570
- cnc codegen --schema ./schema.graphql --out ./codegen
571
-
572
- # From endpoint with Host override
573
- cnc codegen --endpoint http://localhost:3000/graphql --headerHost meta8.localhost --out ./codegen
574
- ```
575
-
576
- Options:
577
- - `--schema <path>` or `--endpoint <url>`
578
- - `--out <dir>` output root (default: `graphql/codegen/dist`)
579
- - `--format <gql|ts>` documents format
580
- - `--convention <dashed|underscore|camelcase|camelUpper>` filenames
581
- - `--headerHost <host>` optional HTTP Host header for endpoint requests
582
- - `--auth <token>` Authorization header value (e.g., `Bearer 123`)
583
- - `--header "Name: Value"` repeatable headers
584
- - `--emitTypes <bool>` `--emitOperations <bool>` `--emitSdk <bool>` `--emitReactQuery <bool>`
585
- - `--config ./config.json` Use customized config file
586
-
587
-
588
- Config file (JSON/YAML):
169
+ # Global help
170
+ cnc --help
589
171
 
590
- ```bash
591
- # Use a JSON config to override defaults
592
- cnc codegen --config ./my-options.json
172
+ # Command-specific help
173
+ cnc server --help
174
+ cnc codegen -h
593
175
  ```
594
176
 
595
- Example `my-options.json`:
177
+ ## Global Options
596
178
 
597
- ```json
598
- {
599
- "input": {
600
- "schema": "./schema.graphql",
601
- "headers": { "Host": "meta8.localhost" }
602
- },
603
- "output": {
604
- "root": "graphql/codegen/dist/codegen-config",
605
- "reactQueryFile": "react-query.ts"
606
- },
607
- "documents": {
608
- "format": "gql",
609
- "convention": "dashed",
610
- "excludePatterns": [".*Module$", ".*By.+And.+$"]
611
- },
612
- "features": {
613
- "emitTypes": true,
614
- "emitOperations": true,
615
- "emitSdk": true,
616
- "emitReactQuery": true
617
- },
618
- "reactQuery": {
619
- "fetcher": "graphql-request"
620
- }
621
- }
622
- ```
179
+ - `--help, -h` - Show help information
180
+ - `--version, -v` - Show version information
181
+ - `--cwd <dir>` - Set working directory
623
182
 
624
183
  ---
625
184