fastify-auto-sqlapi 0.4.1 → 0.5.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/BREAKING_CHANGES.md +22 -0
- package/CHANGELOG.md +30 -1
- package/README.md +1 -1
- package/dist/lib/engine/search/fields.js +1 -1
- package/dist/lib/engine/search/search.d.ts.map +1 -1
- package/dist/lib/engine/search/search.js +4 -2
- package/dist/lib/read-access.d.ts +9 -6
- package/dist/lib/read-access.d.ts.map +1 -1
- package/dist/lib/read-access.js +9 -6
- package/package.json +6 -3
package/BREAKING_CHANGES.md
CHANGED
|
@@ -873,3 +873,25 @@ some main rows have no children:
|
|
|
873
873
|
- Conditions are ANDed, so "below 5 **or** no children" is no longer one request: run the
|
|
874
874
|
`isNull` search separately, or compare against a `count` instead where that expresses the
|
|
875
875
|
same thing.
|
|
876
|
+
|
|
877
|
+
# Breaking Change — Node.js 22 or newer is required
|
|
878
|
+
|
|
879
|
+
*Landed in **0.5.0**.*
|
|
880
|
+
|
|
881
|
+
## Why this changed
|
|
882
|
+
|
|
883
|
+
`engines.node` said `>=18`, but no Node version other than 24 was tested, and the promise
|
|
884
|
+
was already wrong: Fastify 5, a required peer dependency, supports Node 20 and later only.
|
|
885
|
+
Node 18 and Node 20 are both end-of-life, so the floor now starts at the oldest maintained
|
|
886
|
+
LTS line, and CI runs the full gate on Node 22, 24 and 26 to keep that promise checked.
|
|
887
|
+
|
|
888
|
+
## Who is affected
|
|
889
|
+
|
|
890
|
+
Deployments still running Node 18 or 20. Nothing in the API, the request/response shapes
|
|
891
|
+
or the table configuration changes.
|
|
892
|
+
|
|
893
|
+
## Migration
|
|
894
|
+
|
|
895
|
+
Upgrade the runtime to Node 22 or newer. npm only warns on an `engines` mismatch (it fails
|
|
896
|
+
with `engine-strict=true`), so a deployment on an older Node may keep installing, but it is
|
|
897
|
+
no longer supported or tested.
|
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,34 @@ Migration instructions for breaking changes live in **[BREAKING_CHANGES.md](./BR
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **A search with `selectComputed` and a JOIN on the main query returned the joined table's
|
|
15
|
+
columns in the main rows.** A filtered or ordered `joinLeft`, or a tenant scope with
|
|
16
|
+
`through`, adds a JOIN to the main statement; the `selectComputed` path built its
|
|
17
|
+
projection as a bare `*, <expr> AS "x"`, which bypassed the qualification `db.select`
|
|
18
|
+
applies to a plain `*`. On a column name shared with the joined table (`id`, `name`,
|
|
19
|
+
`createdAt`…) the driver keeps the last value read, so every main row carried the parent's
|
|
20
|
+
id and its extra columns. The main projection is now always `"table".*` or the table's
|
|
21
|
+
readable columns, qualified, whatever else is projected. Searches without `selectComputed`
|
|
22
|
+
were not affected.
|
|
23
|
+
|
|
24
|
+
## [0.5.0]
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- **BREAKING: Node.js 22 or newer is required** (`engines.node` is now `>=22`, was `>=18`).
|
|
29
|
+
Node 18 and 20 are end-of-life, and Fastify 5 never supported Node 18. CI now runs the
|
|
30
|
+
full gate on Node 22, 24 and 26. See
|
|
31
|
+
[BREAKING_CHANGES.md](./BREAKING_CHANGES.md#breaking-change--nodejs-22-or-newer-is-required).
|
|
32
|
+
|
|
33
|
+
### Security
|
|
34
|
+
|
|
35
|
+
- Development dependencies only, nothing shipped in the package: `fastify` 5.12.8
|
|
36
|
+
(GHSA-4mh8-r7rc-xpvc, GHSA-389g-gv7q-r4x8) and `minimatch` forced to `^11.0.5` through
|
|
37
|
+
`overrides` (GHSA-g3hv-75wg-m249) until eslint, typescript-eslint, eslint-plugin-sonarjs
|
|
38
|
+
and ts-morph move off minimatch 10.
|
|
39
|
+
|
|
12
40
|
## [0.4.1]
|
|
13
41
|
|
|
14
42
|
### Changed
|
|
@@ -768,7 +796,8 @@ the join API redesign (documented in [BREAKING_CHANGES.md](./BREAKING_CHANGES.md
|
|
|
768
796
|
primary key support in updates, transactional insert/update with secondaries, the hook matrix,
|
|
769
797
|
and bulk operations.
|
|
770
798
|
|
|
771
|
-
[Unreleased]: https://github.com/LucaRainone/fastify-auto-sqlapi/compare/v0.
|
|
799
|
+
[Unreleased]: https://github.com/LucaRainone/fastify-auto-sqlapi/compare/v0.5.0...HEAD
|
|
800
|
+
[0.5.0]: https://github.com/LucaRainone/fastify-auto-sqlapi/releases/tag/v0.5.0
|
|
772
801
|
[0.4.1]: https://github.com/LucaRainone/fastify-auto-sqlapi/releases/tag/v0.4.1
|
|
773
802
|
[0.4.0]: https://github.com/LucaRainone/fastify-auto-sqlapi/releases/tag/v0.4.0
|
|
774
803
|
[0.3.0]: https://github.com/LucaRainone/fastify-auto-sqlapi/releases/tag/v0.3.0
|
package/README.md
CHANGED
|
@@ -325,7 +325,7 @@ request says exactly what to fix.
|
|
|
325
325
|
|
|
326
326
|
## Requirements
|
|
327
327
|
|
|
328
|
-
- Node.js >=
|
|
328
|
+
- Node.js >= 22, Fastify >= 5 (peer dependency)
|
|
329
329
|
- **PostgreSQL** + `pg` + `@fastify/postgres`, or **MySQL** / **MariaDB** + `mysql2`
|
|
330
330
|
- Optional: `@fastify/swagger` + `@fastify/swagger-ui` for Swagger UI
|
|
331
331
|
|
|
@@ -132,7 +132,7 @@ export function buildSelectionColumns(selection, joinSchema, db, joinTableConf,
|
|
|
132
132
|
if (selection === '*') {
|
|
133
133
|
if (restricted)
|
|
134
134
|
return explicitSelectColumns(joinTableConf, joinSchema, db);
|
|
135
|
-
return readableSelectColumns(joinTableConf, joinSchema, db)
|
|
135
|
+
return readableSelectColumns(joinTableConf, joinSchema, db);
|
|
136
136
|
}
|
|
137
137
|
const table = db.qi(joinSchema.tableName);
|
|
138
138
|
return selection
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../src/lib/engine/search/search.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EAGb,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../src/lib/engine/search/search.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EAGb,MAAM,mBAAmB,CAAC;AA2P3B,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,YAAY,CAAC,CA4FvB"}
|
|
@@ -48,13 +48,15 @@ async function executeMainQuery(db, tableConf, where, values, orderBy, paginator
|
|
|
48
48
|
const limit = paginator
|
|
49
49
|
? `${paginator.itemsPerPage} OFFSET ${(paginator.page - 1) * paginator.itemsPerPage}`
|
|
50
50
|
: (maxRows != null ? String(maxRows) : null);
|
|
51
|
-
// Base projection: '
|
|
51
|
+
// Base projection: the main table's own columns, qualified ("hour".* or the readable list).
|
|
52
|
+
// Never a bare `*`: the statement may carry a LEFT JOIN (filtered/ordered joinLeft) or the
|
|
53
|
+
// tenant's INNER JOIN, and a bare `*` would hand the joined table's columns to the row.
|
|
52
54
|
const readableColumns = readableSelectColumns(tableConf, tableConf.Schema, db);
|
|
53
55
|
// Optional computed projections — bound values, if any, are NOT yet supported
|
|
54
56
|
// here (would require placeholder-aware composition with WHERE values).
|
|
55
57
|
let columns = readableColumns;
|
|
56
58
|
if (selectComputed?.length) {
|
|
57
|
-
const projections = [readableColumns
|
|
59
|
+
const projections = [readableColumns];
|
|
58
60
|
for (const name of selectComputed) {
|
|
59
61
|
const fn = ownField(tableConf.computedFields, name);
|
|
60
62
|
if (!fn)
|
|
@@ -51,14 +51,17 @@ export declare function assertKnownFilterKeys(filters: Record<string, unknown> |
|
|
|
51
51
|
/** Schema field names that may be read, in schema declaration order. */
|
|
52
52
|
export declare function readableFieldNames(tableConf: ITable | undefined, schema: SchemaDefinition): string[];
|
|
53
53
|
/**
|
|
54
|
-
* SELECT
|
|
55
|
-
* table has
|
|
54
|
+
* The SELECT projection of a table's own rows: its readable columns spelled out when the
|
|
55
|
+
* table has `readExclude`, `"table".*` otherwise.
|
|
56
56
|
*
|
|
57
|
-
*
|
|
58
|
-
* `through` INNER JOIN
|
|
59
|
-
*
|
|
57
|
+
* Always qualified with the table name, never a bare `*`. A read query may carry a JOIN — a
|
|
58
|
+
* filtered or ordered `joinLeft`, a tenant `through` INNER JOIN — and a bare `*` would
|
|
59
|
+
* project the joined table's columns into the row too; on a name clash (`id`, `name`,
|
|
60
|
+
* `createdAt`…) the driver keeps the LAST value read, the joined one, so every main row
|
|
61
|
+
* would carry the parent's id. Callers compose this string further (computed projections),
|
|
62
|
+
* which is why the qualification has to be in the string itself and not only in `db.select`.
|
|
60
63
|
*/
|
|
61
|
-
export declare function readableSelectColumns(tableConf: ITable | undefined, schema: SchemaDefinition, db: QueryClient): string
|
|
64
|
+
export declare function readableSelectColumns(tableConf: ITable | undefined, schema: SchemaDefinition, db: QueryClient): string;
|
|
62
65
|
/**
|
|
63
66
|
* The same list, always spelled out. Used where `*` is not an acceptable fallback: a
|
|
64
67
|
* relation narrowed by a `fields` allowlist must project the allowlist, not the table.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-access.d.ts","sourceRoot":"","sources":["../../src/lib/read-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG5D;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACxC,GAAG,EAAE,MAAM,GACV,OAAO,CAET;AAED,sEAAsE;AACtE,wBAAgB,QAAQ,CAAC,CAAC,EACxB,GAAG,EAAE,MAAM,CAAC,MAAM,E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AG,SAAS,CAEf;AAMD,+DAA+D;AAC/D,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIjF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC5C,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B,IAAI,CAKN;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC5C,MAAM,EAAE,gBAAgB,EACxB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,iBAAiB,UAAO,GACvB,IAAI,CAkBN;AAED,wEAAwE;AACxE,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,gBAAgB,GACvB,MAAM,EAAE,CAIV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,gBAAgB,EACxB,EAAE,EAAE,WAAW,GACd,MAAM,CAGR;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,gBAAgB,EACxB,EAAE,EAAE,WAAW,GACd,MAAM,CAKR"}
|
package/dist/lib/read-access.js
CHANGED
|
@@ -92,16 +92,19 @@ export function readableFieldNames(tableConf, schema) {
|
|
|
92
92
|
return fields.filter((f) => !isReadExcluded(tableConf, f));
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
* SELECT
|
|
96
|
-
* table has
|
|
95
|
+
* The SELECT projection of a table's own rows: its readable columns spelled out when the
|
|
96
|
+
* table has `readExclude`, `"table".*` otherwise.
|
|
97
97
|
*
|
|
98
|
-
*
|
|
99
|
-
* `through` INNER JOIN
|
|
100
|
-
*
|
|
98
|
+
* Always qualified with the table name, never a bare `*`. A read query may carry a JOIN — a
|
|
99
|
+
* filtered or ordered `joinLeft`, a tenant `through` INNER JOIN — and a bare `*` would
|
|
100
|
+
* project the joined table's columns into the row too; on a name clash (`id`, `name`,
|
|
101
|
+
* `createdAt`…) the driver keeps the LAST value read, the joined one, so every main row
|
|
102
|
+
* would carry the parent's id. Callers compose this string further (computed projections),
|
|
103
|
+
* which is why the qualification has to be in the string itself and not only in `db.select`.
|
|
101
104
|
*/
|
|
102
105
|
export function readableSelectColumns(tableConf, schema, db) {
|
|
103
106
|
if (!tableConf?.readExclude?.length)
|
|
104
|
-
return
|
|
107
|
+
return `${db.qi(schema.tableName)}.*`;
|
|
105
108
|
return explicitSelectColumns(tableConf, schema, db);
|
|
106
109
|
}
|
|
107
110
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastify-auto-sqlapi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Fastify plugin for automatic CRUD API generation from PostgreSQL, MySQL and MariaDB tables",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"typebox"
|
|
70
70
|
],
|
|
71
71
|
"engines": {
|
|
72
|
-
"node": ">=
|
|
72
|
+
"node": ">=22"
|
|
73
73
|
},
|
|
74
74
|
"author": "Luca Rainone",
|
|
75
75
|
"license": "MIT",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"dependency-cruiser": "^18.1.0",
|
|
97
97
|
"eslint": "^10.8.0",
|
|
98
98
|
"eslint-plugin-sonarjs": "^4.2.0",
|
|
99
|
-
"fastify": "5.12.
|
|
99
|
+
"fastify": "5.12.8",
|
|
100
100
|
"fuse.js": "^7.5.0",
|
|
101
101
|
"jscpd": "^5.0.14",
|
|
102
102
|
"knip": "^6.31.0",
|
|
@@ -135,5 +135,8 @@
|
|
|
135
135
|
"@fastify/swagger-ui": {
|
|
136
136
|
"optional": true
|
|
137
137
|
}
|
|
138
|
+
},
|
|
139
|
+
"overrides": {
|
|
140
|
+
"minimatch": "^11.0.5"
|
|
138
141
|
}
|
|
139
142
|
}
|