postgresdk 0.1.2-alpha.3 → 0.2.0

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
@@ -35,7 +35,7 @@ CREATE TABLE book_tags (
35
35
  Run one command:
36
36
 
37
37
  ```bash
38
- npx postgresdk
38
+ npx postgresdk generate
39
39
  ```
40
40
 
41
41
  Get a complete, type-safe SDK with:
@@ -140,36 +140,43 @@ All from your existing database schema. No manual coding required.
140
140
  - 🔐 **Built-in Auth** - API key and JWT authentication with zero configuration
141
141
  - 🎯 **Zero Config** - Works out of the box with sensible defaults
142
142
  - 🏗️ **Framework Ready** - Server routes built for Hono, client SDK works anywhere
143
- - 📦 **Lightweight** - Minimal dependencies, optimized for production
143
+ - 📦 **Lightweight** - Minimal dependencies, optimized bundle size with shared BaseClient
144
+ - 🔄 **SDK Distribution** - Built-in SDK bundling and pull mechanism for easy client distribution
144
145
 
145
146
  ## Installation
146
147
 
147
148
  ```bash
148
149
  npm install -g postgresdk
149
150
  # or
150
- npx postgresdk
151
+ npx postgresdk generate
151
152
  ```
152
153
 
153
154
  ## Quick Start
154
155
 
155
- 1. Create a configuration file `postgresdk.config.ts`:
156
+ 1. Initialize your project:
157
+
158
+ ```bash
159
+ npx postgresdk init
160
+ ```
161
+
162
+ This creates a `postgresdk.config.ts` file with all available options documented.
163
+
164
+ 2. Edit the configuration file with your database connection:
156
165
 
157
166
  ```typescript
158
167
  export default {
159
- connectionString: "postgres://user:pass@localhost:5432/mydb",
160
- schema: "public",
161
- outServer: "./generated/server",
162
- outClient: "./generated/client",
168
+ connectionString: process.env.DATABASE_URL || "postgres://user:pass@localhost:5432/mydb",
169
+ // Uncomment and customize other options as needed
163
170
  };
164
171
  ```
165
172
 
166
- 2. Run the generator:
173
+ 3. Run the generator:
167
174
 
168
175
  ```bash
169
- postgresdk
176
+ postgresdk generate
170
177
  ```
171
178
 
172
- 3. Use the generated SDK:
179
+ 4. Use the generated SDK:
173
180
 
174
181
  ```typescript
175
182
  // Server (Hono)
@@ -212,19 +219,19 @@ export default {
212
219
  includeDepthLimit: 3, // Max depth for nested includes
213
220
  dateType: "date", // "date" | "string" - How to handle timestamps
214
221
 
215
- // Authentication (optional)
222
+ // Authentication (optional) - simplified syntax
216
223
  auth: {
224
+ apiKey: process.env.API_KEY, // Simple API key auth
225
+ // OR
226
+ jwt: process.env.JWT_SECRET, // Simple JWT auth
227
+ // OR full syntax for advanced options:
217
228
  strategy: "none" | "api-key" | "jwt-hs256", // Default: "none"
218
-
219
- // For API key auth
220
- apiKeyHeader: "x-api-key", // Header name for API key
221
- apiKeys: ["key1", "key2"], // Array of valid keys
222
-
223
- // For JWT auth (HS256)
229
+ apiKeyHeader: "x-api-key", // Custom header name
230
+ apiKeys: ["key1", "key2"], // Multiple valid keys
224
231
  jwt: {
225
- sharedSecret: "your-secret", // Shared secret for HS256
226
- issuer: "your-app", // Optional: validate issuer claim
227
- audience: "your-audience" // Optional: validate audience claim
232
+ sharedSecret: "your-secret", // Shared secret for HS256
233
+ issuer: "your-app", // Optional: validate issuer claim
234
+ audience: "your-audience" // Optional: validate audience claim
228
235
  }
229
236
  }
230
237
  };
@@ -348,11 +355,11 @@ export default {
348
355
  ### API Key Authentication
349
356
 
350
357
  ```typescript
351
- // postgresdk.config.ts - Simplified syntax
358
+ // postgresdk.config.ts - Simple syntax (recommended)
352
359
  export default {
353
360
  connectionString: "...",
354
361
  auth: {
355
- apiKey: "your-api-key" // Single key shorthand
362
+ apiKey: process.env.API_KEY // Single key shorthand
356
363
  }
357
364
  };
358
365
 
@@ -360,50 +367,45 @@ export default {
360
367
  export default {
361
368
  connectionString: "...",
362
369
  auth: {
363
- apiKeys: ["key1", "key2", "key3"]
370
+ apiKeys: [process.env.API_KEY_1, process.env.API_KEY_2]
364
371
  }
365
372
  };
366
373
 
367
- // Or full syntax with custom header
374
+ // Full syntax with custom header (optional)
368
375
  export default {
369
376
  connectionString: "...",
370
377
  auth: {
371
378
  strategy: "api-key",
372
- apiKeyHeader: "x-api-key", // Optional, defaults to "x-api-key"
373
- apiKeys: [
374
- "your-api-key-1",
375
- "your-api-key-2",
376
- // Can also use environment variables
377
- "env:API_KEYS" // Reads comma-separated keys from process.env.API_KEYS
378
- ]
379
+ apiKeyHeader: "x-custom-key", // Default: "x-api-key"
380
+ apiKeys: ["key1", "key2"]
379
381
  }
380
382
  };
381
383
 
382
384
  // Client SDK usage
383
385
  const sdk = new SDK({
384
386
  baseUrl: "http://localhost:3000",
385
- auth: { apiKey: "your-api-key-1" }
387
+ auth: { apiKey: process.env.API_KEY }
386
388
  });
387
389
  ```
388
390
 
389
391
  ### JWT Authentication (HS256)
390
392
 
391
393
  ```typescript
392
- // postgresdk.config.ts - Simplified syntax
394
+ // postgresdk.config.ts - Simple syntax (recommended)
393
395
  export default {
394
396
  connectionString: "...",
395
397
  auth: {
396
- jwt: "your-secret-key" // Shared secret shorthand
398
+ jwt: process.env.JWT_SECRET // Shared secret shorthand
397
399
  }
398
400
  };
399
401
 
400
- // Or full syntax with issuer/audience validation
402
+ // Full syntax with issuer/audience validation (optional)
401
403
  export default {
402
404
  connectionString: "...",
403
405
  auth: {
404
406
  strategy: "jwt-hs256",
405
407
  jwt: {
406
- sharedSecret: process.env.JWT_SECRET || "your-secret-key",
408
+ sharedSecret: process.env.JWT_SECRET,
407
409
  issuer: "my-app", // Optional: validates 'iss' claim
408
410
  audience: "my-users" // Optional: validates 'aud' claim
409
411
  }
@@ -772,15 +774,114 @@ process.on("SIGTERM", async () => {
772
774
  });
773
775
  ```
774
776
 
775
- ## CLI Options
777
+ ## SDK Distribution
778
+
779
+ postgresdk makes it easy to distribute your generated SDK to client applications. When you generate your SDK, it's automatically bundled and served through your API, allowing client apps to pull the latest SDK directly.
780
+
781
+ ### Publishing Your SDK
782
+
783
+ When you run `postgresdk generate`, the SDK is automatically:
784
+ 1. Generated as TypeScript files for both server and client
785
+ 2. Bundled and made available through API endpoints
786
+ 3. Ready to be pulled by client applications
787
+
788
+ Your API automatically serves the SDK at these endpoints:
789
+ - `GET /sdk/manifest` - SDK metadata and file list
790
+ - `GET /sdk/download` - Download all SDK files as JSON
791
+ - `GET /sdk/files/:path` - Download individual SDK files
792
+
793
+ ### Pulling the SDK in Client Apps
794
+
795
+ Client applications can pull your SDK using the `postgresdk pull` command:
796
+
797
+ ```bash
798
+ # Install postgresdk in your client app
799
+ npm install -D postgresdk
800
+
801
+ # Pull the SDK from your API
802
+ postgresdk pull --from=https://api.myapp.com --output=./src/sdk
803
+
804
+ # Or with authentication
805
+ postgresdk pull --from=https://api.myapp.com --output=./src/sdk --token=your-token
806
+ ```
807
+
808
+ ### Configuration-based Pull
809
+
810
+ Create a `postgresdk.config.ts` in your client app:
811
+
812
+ ```typescript
813
+ export default {
814
+ pull: {
815
+ from: "https://api.myapp.com",
816
+ output: "./src/sdk",
817
+ token: process.env.API_TOKEN // Optional auth
818
+ }
819
+ };
820
+ ```
821
+
822
+ Then simply run:
823
+ ```bash
824
+ postgresdk pull
825
+ ```
826
+
827
+ ### Automated SDK Updates
828
+
829
+ You can automate SDK updates in your client app's build process:
830
+
831
+ ```json
832
+ // package.json
833
+ {
834
+ "scripts": {
835
+ "prebuild": "postgresdk pull",
836
+ "build": "tsc"
837
+ }
838
+ }
839
+ ```
840
+
841
+ ### SDK Versioning
842
+
843
+ The pulled SDK includes metadata about when it was generated and from where:
844
+
845
+ ```typescript
846
+ // .postgresdk.json (auto-generated)
847
+ {
848
+ "version": "1.0.0",
849
+ "generated": "2024-01-15T10:30:00Z",
850
+ "pulledFrom": "https://api.myapp.com",
851
+ "pulledAt": "2024-01-15T11:00:00Z"
852
+ }
853
+ ```
854
+
855
+ ## CLI Commands
776
856
 
777
857
  ```bash
778
- postgresdk [options]
858
+ postgresdk <command> [options]
859
+
860
+ Commands:
861
+ init Create a postgresdk.config.ts file with all options
862
+ generate Generate SDK from database
863
+ pull Pull SDK from API endpoint
864
+ version Show version
865
+ help Show help
779
866
 
780
- Options:
867
+ Init Options:
868
+ (no options) Creates postgresdk.config.ts in current directory
869
+
870
+ Generate Options:
781
871
  -c, --config <path> Path to config file (default: postgresdk.config.ts)
782
- -v, --version Show version
783
- -h, --help Show help
872
+
873
+ Pull Options:
874
+ --from <url> API URL to pull SDK from
875
+ --output <path> Output directory (default: ./src/sdk)
876
+ --token <token> Authentication token
877
+ -c, --config <path> Path to config file with pull settings
878
+
879
+ Examples:
880
+ postgresdk init # Create config file
881
+ postgresdk generate # Generate using default config
882
+ postgresdk generate -c custom.config.ts
883
+ postgresdk pull --from=https://api.com --output=./src/sdk
884
+ postgresdk pull -c client.config.ts # Pull using config file
784
885
  ```
785
886
 
786
887
  ## How It Works
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function initCommand(args: string[]): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function pullCommand(args: string[]): Promise<void>;