pg-codegen 5.16.0 → 5.17.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 +17 -1
- package/emit/barrel.js +4 -0
- package/emit/record.js +9 -2
- package/esm/emit/barrel.js +4 -0
- package/esm/emit/record.js +9 -2
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -106,6 +106,20 @@ await db.emailIdentities.findFirst({ select: { databaseId: false } });
|
|
|
106
106
|
|
|
107
107
|
Excluding is what a caller reaches for when a field must not be carried — a secret's id, row bookkeeping — or when this binding's table genuinely lacks it: an excluded field is absent from the type, so reading it does not compile. Naming any field `true` is a projection and wins outright; the excluded ones are simply not in it.
|
|
108
108
|
|
|
109
|
+
### Naming a filter or a write input
|
|
110
|
+
|
|
111
|
+
The client's own vocabulary is exported from the package root, keyed by a generated record, so a function that takes a filter or the values of a write says so without restating the fields:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import type { Data, Where } from './generated';
|
|
115
|
+
import type { EmailIdentities } from './generated/routing_public';
|
|
116
|
+
|
|
117
|
+
const active = (extra: Where<EmailIdentities>) => ({ isActive: true, ...extra });
|
|
118
|
+
type IdentityInput = Data<EmailIdentities>; // every field optional, camelCase
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`Where`, `Data`, `SelectShape`, `OrderBy` and `Queryable` all come from there.
|
|
122
|
+
|
|
109
123
|
### Transactions
|
|
110
124
|
|
|
111
125
|
`$with` rebinds every table client to another connection, so a transaction is the same code against a different handle:
|
|
@@ -152,7 +166,9 @@ For every table, view, materialized view and partitioned table in the schemas yo
|
|
|
152
166
|
|
|
153
167
|
Plus, per schema, a `db.ts` (the client above), an `enums.ts` — a literal union, a `readonly` value list and `as*`/`require*` checkers for every PostgreSQL enum a column references — and barrels; and one shared `client.ts` runtime at the root.
|
|
154
168
|
|
|
155
|
-
Every decoder is backed by [`@constructive-io/coerce`](../../packages/coerce): a NOT NULL column throws `CoerceError` naming the offending column, a nullable column answers `null`, and the text
|
|
169
|
+
Every decoder is backed by [`@constructive-io/coerce`](../../packages/coerce): a NOT NULL column throws `CoerceError` naming the offending column, a nullable column answers `null`, and the text form `pg` returns for `numeric` is parsed to a number. Nothing is silently coerced across types, so a malformed row cannot become a default value.
|
|
170
|
+
|
|
171
|
+
An `int8` column is a **`string`** — the canonical digits of the value, which is how `pg` returns the type, how `graphql/codegen` spells its `BigInt` scalar, and the only representation that keeps an id past 2^53 (a `number` would round `9007199254740993` to its neighbour). Its decoder accepts any of the three shapes a 64-bit value arrives in — `bigint`, integer `number`, digit string — and answers the canonical digits, so `'007'` and `7` both decode to `'7'`; a write states the string and PostgreSQL reads it as `int8`.
|
|
156
172
|
|
|
157
173
|
## 🔧 Below the client
|
|
158
174
|
|
package/emit/barrel.js
CHANGED
|
@@ -25,6 +25,10 @@ const emitSchemaIndex = (schema) => {
|
|
|
25
25
|
exports.emitSchemaIndex = emitSchemaIndex;
|
|
26
26
|
const emitRootIndex = (schemas) => {
|
|
27
27
|
const statements = schemas.map(schema => babel_1.t.exportNamedDeclaration(null, [babel_1.t.exportNamespaceSpecifier(babel_1.t.identifier((0, inflekt_1.toCamelCase)(schema.name)))], babel_1.t.stringLiteral(`./${schema.name}`)));
|
|
28
|
+
// The client's own vocabulary — `Where`, `Data`, `SelectShape`, `OrderBy` —
|
|
29
|
+
// so a consumer that names a filter or a write input states it over a
|
|
30
|
+
// generated record instead of hand-writing the field list again.
|
|
31
|
+
statements.push(babel_1.t.exportAllDeclaration(babel_1.t.stringLiteral('./client')));
|
|
28
32
|
return (0, babel_1.generateCode)(statements);
|
|
29
33
|
};
|
|
30
34
|
exports.emitRootIndex = emitRootIndex;
|
package/emit/record.js
CHANGED
|
@@ -12,7 +12,11 @@ const enums_1 = require("./enums");
|
|
|
12
12
|
const COERCERS = {
|
|
13
13
|
boolean: { require: 'requireBoolean', as: 'asBoolean', expectedArray: 'an array of booleans' },
|
|
14
14
|
integer: { require: 'requireInteger', as: 'asInteger', expectedArray: 'an array of integers' },
|
|
15
|
-
bigint: {
|
|
15
|
+
bigint: {
|
|
16
|
+
require: 'requireBigIntString',
|
|
17
|
+
as: 'asBigIntString',
|
|
18
|
+
expectedArray: 'an array of whole numbers'
|
|
19
|
+
},
|
|
16
20
|
number: { require: 'requireNumeric', as: 'asNumeric', expectedArray: 'an array of numbers' },
|
|
17
21
|
string: { require: 'requireString', as: 'asString', expectedArray: 'an array of non-empty strings' },
|
|
18
22
|
uuid: { require: 'requireUuid', as: 'asUuid', expectedArray: 'an array of UUIDs' },
|
|
@@ -24,9 +28,12 @@ const scalarTsType = (column) => {
|
|
|
24
28
|
case 'boolean':
|
|
25
29
|
return babel_1.t.tsBooleanKeyword();
|
|
26
30
|
case 'integer':
|
|
27
|
-
case 'bigint':
|
|
28
31
|
case 'number':
|
|
29
32
|
return babel_1.t.tsNumberKeyword();
|
|
33
|
+
// int8 carries values a JS number cannot hold, so it is a digit string —
|
|
34
|
+
// the same spelling graphql/codegen gives the `BigInt` scalar, and the one
|
|
35
|
+
// node-postgres already returns for the type.
|
|
36
|
+
case 'bigint':
|
|
30
37
|
case 'string':
|
|
31
38
|
case 'uuid':
|
|
32
39
|
case 'timestamp':
|
package/esm/emit/barrel.js
CHANGED
|
@@ -20,5 +20,9 @@ export const emitSchemaIndex = (schema) => {
|
|
|
20
20
|
};
|
|
21
21
|
export const emitRootIndex = (schemas) => {
|
|
22
22
|
const statements = schemas.map(schema => t.exportNamedDeclaration(null, [t.exportNamespaceSpecifier(t.identifier(toCamelCase(schema.name)))], t.stringLiteral(`./${schema.name}`)));
|
|
23
|
+
// The client's own vocabulary — `Where`, `Data`, `SelectShape`, `OrderBy` —
|
|
24
|
+
// so a consumer that names a filter or a write input states it over a
|
|
25
|
+
// generated record instead of hand-writing the field list again.
|
|
26
|
+
statements.push(t.exportAllDeclaration(t.stringLiteral('./client')));
|
|
23
27
|
return generateCode(statements);
|
|
24
28
|
};
|
package/esm/emit/record.js
CHANGED
|
@@ -9,7 +9,11 @@ import { enumAsName, enumRequireName, enumTypeName } from './enums';
|
|
|
9
9
|
const COERCERS = {
|
|
10
10
|
boolean: { require: 'requireBoolean', as: 'asBoolean', expectedArray: 'an array of booleans' },
|
|
11
11
|
integer: { require: 'requireInteger', as: 'asInteger', expectedArray: 'an array of integers' },
|
|
12
|
-
bigint: {
|
|
12
|
+
bigint: {
|
|
13
|
+
require: 'requireBigIntString',
|
|
14
|
+
as: 'asBigIntString',
|
|
15
|
+
expectedArray: 'an array of whole numbers'
|
|
16
|
+
},
|
|
13
17
|
number: { require: 'requireNumeric', as: 'asNumeric', expectedArray: 'an array of numbers' },
|
|
14
18
|
string: { require: 'requireString', as: 'asString', expectedArray: 'an array of non-empty strings' },
|
|
15
19
|
uuid: { require: 'requireUuid', as: 'asUuid', expectedArray: 'an array of UUIDs' },
|
|
@@ -21,9 +25,12 @@ const scalarTsType = (column) => {
|
|
|
21
25
|
case 'boolean':
|
|
22
26
|
return t.tsBooleanKeyword();
|
|
23
27
|
case 'integer':
|
|
24
|
-
case 'bigint':
|
|
25
28
|
case 'number':
|
|
26
29
|
return t.tsNumberKeyword();
|
|
30
|
+
// int8 carries values a JS number cannot hold, so it is a digit string —
|
|
31
|
+
// the same spelling graphql/codegen gives the `BigInt` scalar, and the one
|
|
32
|
+
// node-postgres already returns for the type.
|
|
33
|
+
case 'bigint':
|
|
27
34
|
case 'string':
|
|
28
35
|
case 'uuid':
|
|
29
36
|
case 'timestamp':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-codegen",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.17.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "Type-safe TypeScript codegen from live PostgreSQL schemas: row types, coerce-backed decoders, serializers, table metadata, and enum unions",
|
|
6
6
|
"main": "index.js",
|
|
@@ -45,18 +45,18 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/generator": "^7.29.1",
|
|
47
47
|
"@babel/types": "^7.29.0",
|
|
48
|
-
"@constructive-io/coerce": "^0.3.
|
|
49
|
-
"@constructive-io/query-builder": "^3.10.
|
|
48
|
+
"@constructive-io/coerce": "^0.3.1",
|
|
49
|
+
"@constructive-io/query-builder": "^3.10.6",
|
|
50
50
|
"inflekt": "^0.8.1",
|
|
51
|
-
"introspectron": "^5.13.
|
|
51
|
+
"introspectron": "^5.13.1",
|
|
52
52
|
"pg": "^8.21.0",
|
|
53
|
-
"pg-env": "^1.30.
|
|
53
|
+
"pg-env": "^1.30.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/babel__generator": "^7.6.8",
|
|
57
57
|
"@types/pg": "^8.20.4",
|
|
58
58
|
"makage": "^0.3.0",
|
|
59
|
-
"pgsql-test": "^5.11.
|
|
59
|
+
"pgsql-test": "^5.11.1"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "ce544846eafd96280fac2607f873960392ae2c89"
|
|
62
62
|
}
|