true-pg 0.1.1 → 0.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
@@ -51,12 +51,13 @@ Example config file:
51
51
 
52
52
  ## Configuration Options
53
53
 
54
- | Option | Description | Default |
55
- | --------------- | -------------------------------------------------------- | ---------- |
56
- | `uri` | PostgreSQL connection URI | Required |
57
- | `out` | Output directory for generated files | `"models"` |
58
- | `adapters` | Adapters to use (e.g. `kysely`, `zod`) | `"kysely"` |
59
- | `defaultSchema` | Default schema to use (Kysely schema will be unprefixed) | `"public"` |
54
+ | Option | Description | Default |
55
+ | ------------------ | -------------------------------------------------------- | ----------------------------- |
56
+ | `uri` | PostgreSQL connection URI | Required, or connectionConfig |
57
+ | `connectionConfig` | PostgreSQL connection config object | Required, or uri |
58
+ | `out` | Output directory for generated files | `"models"` |
59
+ | `adapters` | Adapters to use (e.g. `kysely`, `zod`) | `"kysely"` |
60
+ | `defaultSchema` | Default schema to use (Kysely schema will be unprefixed) | `"public"` |
60
61
 
61
62
  ## Customising Code Generation
62
63
 
package/lib/bin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import mri from "mri";
3
- import { existsSync } from "fs";
3
+ import { existsSync, readFileSync } from "fs";
4
4
  import { generate, adapters } from "./index.js";
5
5
  const args = process.argv.slice(2);
6
6
  const opts = mri(args, {
@@ -49,7 +49,7 @@ if (!configfile) {
49
49
  }
50
50
  }
51
51
  }
52
- const config = configfile ? await Bun.file(configfile).json() : {};
52
+ const config = configfile ? JSON.parse(readFileSync(configfile, "utf-8")) : {};
53
53
  if (opts["all-adapters"]) {
54
54
  opts.adapter = Object.keys(adapters);
55
55
  console.log("Enabling all built-in adapters:", opts.adapter);
package/lib/index.js CHANGED
@@ -135,7 +135,10 @@ const multifile = async (generators, schemas, opts) => {
135
135
  };
136
136
  export async function generate(opts, generators) {
137
137
  const out = opts.out || "./models";
138
- const extractor = new Extractor(opts.uri);
138
+ const conn = opts.uri ?? opts.connectionConfig;
139
+ if (!conn)
140
+ throw new Error("Either uri or connectionConfig is required. Add either option to your .truepgrc.json.");
141
+ const extractor = new Extractor(conn);
139
142
  const schemas = await extractor.extractSchemas();
140
143
  generators ??= opts.adapters.map(adapter => {
141
144
  const selected = adapters[adapter];
package/lib/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CanonicalType, CompositeTypeDetails, EnumDetails, FunctionDetails, TableDetails, SchemaType, Schema } from "pg-extract";
1
+ import type { CanonicalType, CompositeTypeDetails, EnumDetails, FunctionDetails, TableDetails, SchemaType, Schema, Extractor } from "pg-extract";
2
2
  export declare const allowed_kind_names: readonly ["tables", "enums", "composites", "functions"];
3
3
  export type allowed_kind_names = (typeof allowed_kind_names)[number];
4
4
  export interface FolderStructure {
@@ -64,8 +64,10 @@ export declare namespace Nodes {
64
64
  star: boolean;
65
65
  }
66
66
  }
67
+ export type ConnectionConfig = Exclude<ConstructorParameters<typeof Extractor>[0], string | undefined>;
67
68
  export interface TruePGOpts {
68
- uri: string;
69
+ uri?: string;
70
+ connectionConfig?: ConnectionConfig;
69
71
  out: string;
70
72
  adapters: string[];
71
73
  defaultSchema?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "true-pg",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "module": "lib/index.js",
6
6
  "main": "lib/index.js",
@@ -10,6 +10,11 @@
10
10
  "files": [
11
11
  "lib"
12
12
  ],
13
+ "homepage": "https://github.com/feathers-studio/true-pg",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/feathers-studio/true-pg.git"
17
+ },
13
18
  "scripts": {
14
19
  "check": "tsc --noEmit",
15
20
  "build": "tsc",