@supabase/postgrest-typegen 0.2.5 → 0.3.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
@@ -113,19 +113,27 @@ breaks at read time.
113
113
 
114
114
  ```ts
115
115
  import {
116
- generateTypescript, // async (uses prettier)
116
+ generateTypescript, // async (formats its output)
117
117
  generateGo,
118
118
  generatePython,
119
119
  generateSwift,
120
120
  } from "@supabase/postgrest-typegen/generation";
121
121
  ```
122
122
 
123
- | Function | Options |
124
- | -------------------- | ----------------------------------------------------------------------- |
125
- | `generateTypescript` | `{ detectOneToOneRelationships?, postgrestVersion?, defaultSchema? }` |
126
- | `generateGo` | — |
127
- | `generatePython` | — |
128
- | `generateSwift` | `{ accessControl?: 'internal' \| 'public' \| 'private' \| 'package' }` |
123
+ | Function | Options |
124
+ | -------------------- | ------------------------------------------------------------------------------ |
125
+ | `generateTypescript` | `{ detectOneToOneRelationships?, postgrestVersion?, defaultSchema?, format? }` |
126
+ | `generateGo` | — |
127
+ | `generatePython` | — |
128
+ | `generateSwift` | `{ accessControl?: 'internal' \| 'public' \| 'private' \| 'package' }` |
129
+
130
+ `generateTypescript` formats its output with `oxfmt` unless `format` is
131
+ supplied. `oxfmt` is an optional peer dependency, imported only when that
132
+ default runs: install it to use the default formatter, or pass your own
133
+ `format` (an identity function, for byte-identical unformatted output, or a
134
+ worker-pool-backed formatter) and it is never loaded or needed. Calling
135
+ `generateTypescript` without `format` when `oxfmt` is missing throws an error
136
+ saying so.
129
137
 
130
138
  ## Installation
131
139
 
@@ -134,6 +142,8 @@ Not yet published; consumed in-repo for now (`packages/postgrest-typegen`).
134
142
  ```bash
135
143
  # pg is a peer of your application, not bundled here
136
144
  npm install pg
145
+ # only if you rely on generateTypescript's default formatter
146
+ npm install oxfmt@0.66.0
137
147
  ```
138
148
 
139
149
  ## Releasing
@@ -17,9 +17,11 @@ export interface GenerateTypescriptOptions {
17
17
  */
18
18
  defaultSchema?: string;
19
19
  /**
20
- * Formatter used on the generated output. Defaults to `oxfmt`, called
21
- * inline. Callers on a latency-sensitive request path (e.g. postgres-meta's
22
- * hosted `/generators/typescript` route) can substitute a worker-pool-backed
20
+ * Formatter used on the generated output. Defaults to `oxfmt`, an optional
21
+ * peer dependency that is imported only when this default runs, so callers
22
+ * that always pass their own formatter need not install it. Callers on a
23
+ * latency-sensitive request path (e.g. postgres-meta's hosted
24
+ * `/generators/typescript` route) can substitute a worker-pool-backed
23
25
  * formatter here instead of blocking the event loop on every call.
24
26
  */
25
27
  format?: (code: string) => Promise<string>;
@@ -1,13 +1,16 @@
1
- // oxlint-disable typescript/restrict-template-expressions -- this is a verbatim port of
2
- // postgres-meta's template, which intentionally interpolates arrays/values into template
3
- // literals (relying on Array#toString) to build the output. Preserving that is required for
4
- // byte-parity, and the offending expressions sit inside template literals where a targeted
5
- // disable comment would corrupt the emitted string.
6
- import { format as oxfmtFormat } from "oxfmt";
7
1
  import { VALID_FUNCTION_ARGS_MODE, VALID_UNNAMED_FUNCTION_ARG_TYPES, } from "./constants.js";
8
2
  import { compareStrings } from "../collation.js";
3
+ const loadOxfmt = async () => {
4
+ try {
5
+ return await import("oxfmt");
6
+ }
7
+ catch (error) {
8
+ throw new Error("oxfmt is not installed. It is an optional peer dependency that only the default formatter needs: install it, or pass a `format` option to generateTypescript.", { cause: error });
9
+ }
10
+ };
9
11
  const defaultFormat = async (code) => {
10
- const { code: formatted, errors } = await oxfmtFormat("output.ts", code, {
12
+ const { format } = await loadOxfmt();
13
+ const { code: formatted, errors } = await format("output.ts", code, {
11
14
  semi: false,
12
15
  printWidth: 80,
13
16
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supabase/postgrest-typegen",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "description": "Type generation for PostgREST from PostgreSQL schemas",
5
5
  "keywords": [
6
6
  "codegen",
@@ -62,8 +62,7 @@
62
62
  "test": "bun scripts/run-tests.ts test/"
63
63
  },
64
64
  "dependencies": {
65
- "arktype": "2.2.3",
66
- "oxfmt": "0.66.0"
65
+ "arktype": "2.2.3"
67
66
  },
68
67
  "devDependencies": {
69
68
  "@testcontainers/postgresql": "^12.1.0",
@@ -74,12 +73,21 @@
74
73
  "@types/node": "^26.3.0",
75
74
  "@types/pg": "^8.23.1",
76
75
  "knip": "^6.32.3",
76
+ "oxfmt": "0.66.0",
77
77
  "oxlint": "1.83.0",
78
78
  "oxlint-tsgolint": "7.0.2002",
79
79
  "pg": "^8.23.0",
80
80
  "testcontainers": "^12.1.0",
81
81
  "typescript": "7.0.2"
82
82
  },
83
+ "peerDependencies": {
84
+ "oxfmt": "0.66.0"
85
+ },
86
+ "peerDependenciesMeta": {
87
+ "oxfmt": {
88
+ "optional": true
89
+ }
90
+ },
83
91
  "engines": {
84
92
  "node": ">=22.12.0"
85
93
  }
@@ -3,7 +3,6 @@
3
3
  // literals (relying on Array#toString) to build the output. Preserving that is required for
4
4
  // byte-parity, and the offending expressions sit inside template literals where a targeted
5
5
  // disable comment would corrupt the emitted string.
6
- import { format as oxfmtFormat } from "oxfmt";
7
6
  import type {
8
7
  GeneratorMetadata,
9
8
  PostgresColumn,
@@ -39,16 +38,30 @@ export interface GenerateTypescriptOptions {
39
38
  */
40
39
  defaultSchema?: string;
41
40
  /**
42
- * Formatter used on the generated output. Defaults to `oxfmt`, called
43
- * inline. Callers on a latency-sensitive request path (e.g. postgres-meta's
44
- * hosted `/generators/typescript` route) can substitute a worker-pool-backed
41
+ * Formatter used on the generated output. Defaults to `oxfmt`, an optional
42
+ * peer dependency that is imported only when this default runs, so callers
43
+ * that always pass their own formatter need not install it. Callers on a
44
+ * latency-sensitive request path (e.g. postgres-meta's hosted
45
+ * `/generators/typescript` route) can substitute a worker-pool-backed
45
46
  * formatter here instead of blocking the event loop on every call.
46
47
  */
47
48
  format?: (code: string) => Promise<string>;
48
49
  }
49
50
 
51
+ const loadOxfmt = async () => {
52
+ try {
53
+ return await import("oxfmt");
54
+ } catch (error) {
55
+ throw new Error(
56
+ "oxfmt is not installed. It is an optional peer dependency that only the default formatter needs: install it, or pass a `format` option to generateTypescript.",
57
+ { cause: error },
58
+ );
59
+ }
60
+ };
61
+
50
62
  const defaultFormat = async (code: string): Promise<string> => {
51
- const { code: formatted, errors } = await oxfmtFormat("output.ts", code, {
63
+ const { format } = await loadOxfmt();
64
+ const { code: formatted, errors } = await format("output.ts", code, {
52
65
  semi: false,
53
66
  printWidth: 80,
54
67
  });