From 4206370218bbf51f1819b9fff80b0f1b870c9f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedran=20Bilopavlovi=C4=87?= Date: Sat, 21 Nov 2026 10:35:33 +0100 Subject: [PATCH 01/11] feat: 4.1.0 - what did not become an endpoint and why (--inspect), --parse, RequireAtPrefix, Npgsql 11 For editors and other tools: - npgsqlrest --inspect: the endpoints, everything that was looked at and is not an endpoint with a reason code and a message (no_comment, no_http_annotation, unprefixed_annotations, disabled, tag_mismatch, excluded_by_filter, sql_error, empty_file), and the files generated for each endpoint with the generated name and its line (TsClient and its hooks, DartClient, HttpFiles, OpenAPI). EndpointReport is the API. - npgsqlrest --parse= and --parse-comment=: how a comment is read, line by line, by the parsers the server runs, without a database. - NpgsqlRest:RequireAtPrefix (default false): only a line that begins with @ is an annotation; everything else is text. Applies to endpoint comments, to the SQL file source's own lines and to HTTP Custom Type directives. A comment in the short form creates no endpoint under it, and says so. Npgsql 10.0.3 -> 11.0.0. Measured against 4.0.1 as JIT and native AOT: equal, rows responses about 3% less server CPU. The load test harness is kept in BenchmarkTests/LoadTest. Fixes: - A tab separates the words of an annotation ("@authorizeadmin" gave the endpoint no authorization). - "@Name: value" response headers no longer keep the @ in the header name. - SQL files: quoted identifiers, E'' escape strings, and "$1$2" is two parameters, not a dollar quote. - Logout without a valid token in an application whose only scheme is JWT no longer answers 500. - NpgsqlRest.Mcp produces a NuGet package (it was never published). Version 4.1.0; plugins TsClient 1.39.0, DartClient 1.2.0, OpenAPI 1.4.0, HttpFiles 1.6.0, SqlFileSource 1.3.0, CrudSource 1.5.1, Mcp 1.2.1. changelog/v4.1.0.md; skill files updated. --- .claude/skills/npgsqlrest/SKILL.md | 6 + .../npgsqlrest/configuration-reference.jsonc | 10 +- .../Baselines/LoadTest-4.1.0-npgsql11.tsv | 128 +++++++ BenchmarkTests/LoadTest/LoadGen.cs.txt | 92 +++++ BenchmarkTests/LoadTest/README.md | 23 ++ BenchmarkTests/LoadTest/loadgen.csproj.txt | 1 + BenchmarkTests/LoadTest/run.sh | 27 ++ BenchmarkTests/LoadTest/setup.sql | 50 +++ NpgsqlRest.Common/CommentPrimitives.cs | 5 +- NpgsqlRest/Auth/LogoutHandler.cs | 6 + NpgsqlRest/Defaults/DefaultCommentParser.cs | 75 +++- NpgsqlRest/Defaults/DefaultEndpoint.cs | 29 +- NpgsqlRest/EndpointReport.cs | 188 ++++++++++ NpgsqlRest/HttpClientType/HttpClientTypes.cs | 15 + NpgsqlRest/NpgsqlRest.csproj | 2 +- NpgsqlRest/NpgsqlRestBuilder.cs | 14 + NpgsqlRest/Options/NpgsqlRestOptions.cs | 12 + NpgsqlRest/RequestContextBatch.cs | 2 +- NpgsqlRest/RoutineSource.cs | 97 +++++ NpgsqlRestClient/App.cs | 2 +- NpgsqlRestClient/Builder.cs | 2 +- NpgsqlRestClient/CommentInspector.cs | 268 ++++++++++++++ NpgsqlRestClient/Config.cs | 2 +- NpgsqlRestClient/ConfigDefaults.cs | 1 + NpgsqlRestClient/ConfigSchemaGenerator.cs | 1 + NpgsqlRestClient/ConfigTemplate.cs | 8 + NpgsqlRestClient/EndpointCapture.cs | 62 ++++ NpgsqlRestClient/Program.cs | 64 +++- NpgsqlRestClient/appsettings.json | 8 + .../AuthTests/JwtOnlyLogoutTests.cs | 135 +++++++ NpgsqlRestTests/CliTests/CliCommandTests.cs | 143 ++++++++ .../CliTests/CommentInspectorTests.cs | 157 +++++++++ .../CommentTests/EndpointReportTests.cs | 330 ++++++++++++++++++ .../CommentTests/RequireAtPrefixTests.cs | 231 ++++++++++++ .../ParserTests/LexerAndPrefixTests.cs | 124 +++++++ changelog/v4.1.0.md | 285 +++++++++++++++ npm/package.json | 2 +- .../NpgsqlRest.CrudSource.csproj | 8 +- plugins/NpgsqlRest.DartClient/DartClient.cs | 9 +- .../NpgsqlRest.DartClient.csproj | 8 +- plugins/NpgsqlRest.HttpFiles/HttpFile.cs | 9 + .../NpgsqlRest.HttpFiles.csproj | 8 +- plugins/NpgsqlRest.Mcp/McpToolSchemas.cs | 1 + plugins/NpgsqlRest.Mcp/NpgsqlRest.Mcp.csproj | 15 +- .../NpgsqlRest.OpenApi.csproj | 8 +- plugins/NpgsqlRest.OpenApi/OpenApi.cs | 5 + .../NpgsqlRest.SqlFileSource.csproj | 8 +- .../NpgsqlRest.SqlFileSource/SqlFileParser.cs | 61 +++- .../NpgsqlRest.SqlFileSource/SqlFileSource.cs | 64 +++- .../NpgsqlRest.TsClient.csproj | 8 +- plugins/NpgsqlRest.TsClient/TsClient.cs | 21 +- version.txt | 2 +- 52 files changed, 2775 insertions(+), 67 deletions(-) create mode 100644 BenchmarkTests/Baselines/LoadTest-4.1.0-npgsql11.tsv create mode 100644 BenchmarkTests/LoadTest/LoadGen.cs.txt create mode 100644 BenchmarkTests/LoadTest/README.md create mode 100644 BenchmarkTests/LoadTest/loadgen.csproj.txt create mode 100755 BenchmarkTests/LoadTest/run.sh create mode 100644 BenchmarkTests/LoadTest/setup.sql create mode 100644 NpgsqlRest/EndpointReport.cs create mode 100644 NpgsqlRestClient/CommentInspector.cs create mode 100644 NpgsqlRestTests/AuthTests/JwtOnlyLogoutTests.cs create mode 100644 NpgsqlRestTests/CliTests/CommentInspectorTests.cs create mode 100644 NpgsqlRestTests/CommentTests/EndpointReportTests.cs create mode 100644 NpgsqlRestTests/CommentTests/RequireAtPrefixTests.cs create mode 100644 NpgsqlRestTests/SqlFileSourceTests/ParserTests/LexerAndPrefixTests.cs create mode 100644 changelog/v4.1.0.md diff --git a/.claude/skills/npgsqlrest/SKILL.md b/.claude/skills/npgsqlrest/SKILL.md index 28a2dab..3802da0 100644 --- a/.claude/skills/npgsqlrest/SKILL.md +++ b/.claude/skills/npgsqlrest/SKILL.md @@ -27,6 +27,8 @@ The annotation/config surface is large and version-dependent. In order of prefer npgsqlrest --annotations # every supported annotation, as JSON npgsqlrest --config # full default appsettings.json (every option, commented) npgsqlrest --validate # test DB connectivity + that endpoints build (incl. .sql Describe) + npgsqlrest --inspect # 4.1.0+: endpoints + everything that did NOT become an endpoint, with the reason + generated files + npgsqlrest --parse=x.sql # 4.1.0+: no database: how a SQL file's comments are read, line by line (--parse-comment=file for a routine comment) npgsqlrest --version ``` 3. **Online:** docs at (e.g. `/guide/annotations`, `/guide/sql-files`, `/annotations/`, `/config/
`); source & issues at . @@ -102,6 +104,10 @@ Everything below (annotations, HTTP types, proxy, caching, auth, SSE, MCP) works Same annotations apply to functions and `.sql` files. Confirm exact syntax/aliases with `npgsqlrest --annotations`. +**The `@` prefix.** By default it is optional: `HTTP GET` and `@http get` are the same line. With `"NpgsqlRest": { "RequireAtPrefix": true }` (4.1.0+) only a line that begins with `@` is an annotation, and everything else is description text, whatever word it begins with. Prefer writing the `@` always: it is read in both settings and can never be mistaken for a sentence. In strict mode this includes `@http`, `key = value` lines (`@timeout = 30s`), response headers (`@Content-Type: text/plain`), the SQL-file lines (`@returns`, `@result`, `@single`, `@skip`, `@param`, `@define_param`) and HTTP Custom Type directives (`@timeout`); the request line and headers of an HTTP Custom Type take no prefix. + +**"Why is there no endpoint?"** Run `npgsqlrest --inspect` and look at `notExposed`: each routine or `.sql` file that was looked at and is not an endpoint is listed with a `reason` (`no_comment`, `no_http_annotation`, `unprefixed_annotations`, `disabled`, `tag_mismatch`, `excluded_by_filter`, `sql_error`, `empty_file`) and a `message` that says what to change. A `.sql` file that is not in the list at all is not matched by `SqlFileSource.FilePattern`. + **Routing / exposure** - `HTTP [GET|POST|PUT|DELETE|QUERY] [/path]` — expose (`QUERY` = the standardized safe method with a body; its params default to the JSON body). `@path /x` — override path. `@disabled`/`@enabled`. `@internal` — exists but no public route (reachable via proxy / HTTP-type self-call). `@tags a,b`, `@openapi …`. diff --git a/.claude/skills/npgsqlrest/configuration-reference.jsonc b/.claude/skills/npgsqlrest/configuration-reference.jsonc index c92d7af..70bf2c6 100644 --- a/.claude/skills/npgsqlrest/configuration-reference.jsonc +++ b/.claude/skills/npgsqlrest/configuration-reference.jsonc @@ -1,5 +1,5 @@ // NpgsqlRest — FULL configuration reference (every option, with inline comments). -// Generated verbatim from: npgsqlrest --config (NpgsqlRest v4.0.1) +// Generated verbatim from: npgsqlrest --config (NpgsqlRest v4.1.0) // This is the source of truth for configuration. Regenerate with: npgsqlrest --config { @@ -2087,6 +2087,14 @@ // "CommentsMode": "OnlyAnnotated", // + // Require the @ prefix on annotations. When false (default), the prefix is optional: `HTTP GET` and `@http get` are both read. + // When true, a comment line is an annotation only if it begins with @ (`@http get`, `@authorize admin`, `@timeout = 30s`, `@Content-Type: text/plain`); every other line is text, the endpoint's description, whatever word it begins with. + // That makes a comment unambiguous for people and for tools: a sentence such as "Disabled until Friday" or "Note: see the docs" can never be taken for an annotation. + // It applies to routine comments, to the comments of SQL files (also `@returns`, `@result`, `@single`, `@skip`, `@param`, `@define_param`) and to the directives in HTTP Custom Type comments (`@timeout`, `@retry_delay`, `@cache`). + // Lines without the prefix that look like an access restriction (`authorize`, `disabled`, `login` ...) are logged as a warning when this is on. + // + "RequireAtPrefix": false, + // // The URL prefix string for every URL created by the default URL builder or `null` to ignore the URL prefix. // "UrlPathPrefix": "/api", diff --git a/BenchmarkTests/Baselines/LoadTest-4.1.0-npgsql11.tsv b/BenchmarkTests/Baselines/LoadTest-4.1.0-npgsql11.tsv new file mode 100644 index 0000000..f4bc80e --- /dev/null +++ b/BenchmarkTests/Baselines/LoadTest-4.1.0-npgsql11.tsv @@ -0,0 +1,128 @@ +jit401-r1 text 13 194.7 38798 141.7 37.5 +jit401-r1 plpgsql 23 263.7 31844 151.8 113.4 +jit401-r1 post4 33 211.6 36238 149.3 57.5 +jit401-r1 rows100 15217 428.2 19130 286.7 248.2 +jit401-r1 json119k 169548 2207.9 4259 555.7 1824.8 +jit401-r1 ctx_text 17 216.0 36921 148.0 58.2 +jit401-r1 ctx_rows100 15125 435.5 18887 287.0 254.9 +jit401-r1 RSS_MB 117 +jit402-r1 text 13 191.4 39267 143.7 36.8 +jit402-r1 plpgsql 23 260.2 30383 154.3 111.8 +jit402-r1 post4 33 213.9 37373 150.8 57.6 +jit402-r1 rows100 15217 413.6 19378 275.3 241.0 +jit402-r1 json119k 169548 2230.2 4460 545.3 1785.9 +jit402-r1 ctx_text 17 211.0 35541 152.1 58.4 +jit402-r1 ctx_rows100 15125 441.9 18787 283.8 251.3 +jit402-r1 RSS_MB 113 +aot401-r1 text 13 187.0 37656 145.3 37.0 +aot401-r1 plpgsql 23 266.2 31151 156.7 115.6 +aot401-r1 post4 33 212.0 35957 155.1 57.7 +aot401-r1 rows100 15217 449.3 17916 317.2 245.9 +aot401-r1 json119k 169548 2217.2 4535 540.7 1783.8 +aot401-r1 ctx_text 17 215.1 36487 152.9 57.9 +aot401-r1 ctx_rows100 15125 479.1 18024 318.2 257.3 +aot401-r1 RSS_MB 81 +aot402-r1 text 13 192.9 38494 145.4 37.0 +aot402-r1 plpgsql 23 264.4 30565 156.0 115.6 +aot402-r1 post4 33 214.1 35992 154.8 57.2 +aot402-r1 rows100 15217 429.7 18886 304.6 245.2 +aot402-r1 json119k 169548 2215.5 4516 540.1 1767.4 +aot402-r1 ctx_text 17 214.2 36946 150.8 58.9 +aot402-r1 ctx_rows100 15125 457.4 18703 310.3 256.1 +aot402-r1 RSS_MB 81 +jit402-r2 text 13 187.8 38532 142.5 37.3 +jit402-r2 plpgsql 23 261.8 31855 154.7 113.4 +jit402-r2 post4 33 209.3 36982 151.3 57.7 +jit402-r2 rows100 15217 414.0 19587 278.2 237.8 +jit402-r2 json119k 169548 2268.4 4560 545.6 1829.6 +jit402-r2 ctx_text 17 215.1 35786 151.5 57.8 +jit402-r2 ctx_rows100 15125 443.7 18991 278.6 252.2 +jit402-r2 RSS_MB 113 +aot401-r2 text 13 188.3 38604 149.0 36.8 +aot401-r2 plpgsql 23 263.9 32421 158.4 116.8 +aot401-r2 post4 33 212.1 36115 155.6 57.6 +aot401-r2 rows100 15217 449.7 18402 316.0 245.1 +aot401-r2 json119k 169548 2193.8 4561 545.9 1770.2 +aot401-r2 ctx_text 17 216.5 36760 152.1 58.9 +aot401-r2 ctx_rows100 15125 470.2 18400 316.5 256.6 +aot401-r2 RSS_MB 85 +aot402-r2 text 13 190.4 38167 139.3 38.2 +aot402-r2 plpgsql 23 289.5 28207 158.5 119.1 +aot402-r2 post4 33 216.3 35963 158.3 60.1 +aot402-r2 rows100 15217 445.4 18120 307.2 244.9 +aot402-r2 json119k 169548 2463.2 4415 546.0 1770.3 +aot402-r2 ctx_text 17 216.2 37047 155.1 59.5 +aot402-r2 ctx_rows100 15125 486.3 17952 305.9 258.5 +aot402-r2 RSS_MB 84 +jit401-r2 text 13 188.9 39020 143.5 37.5 +jit401-r2 plpgsql 23 265.9 32469 154.5 115.8 +jit401-r2 post4 33 213.9 37112 150.8 58.6 +jit401-r2 rows100 15217 416.6 18760 283.4 243.0 +jit401-r2 json119k 169548 2496.5 4344 536.4 1799.1 +jit401-r2 ctx_text 17 212.3 35864 149.4 58.3 +jit401-r2 ctx_rows100 15125 458.9 18954 287.8 255.3 +jit401-r2 RSS_MB 117 +aot401-r3 text 13 188.8 38861 141.3 37.2 +aot401-r3 plpgsql 23 268.3 32091 157.8 116.0 +aot401-r3 post4 33 214.5 35321 156.7 58.4 +aot401-r3 rows100 15217 478.1 17509 316.1 246.5 +aot401-r3 json119k 169548 2491.4 4383 543.3 1772.0 +aot401-r3 ctx_text 17 220.8 36297 153.3 58.5 +aot401-r3 ctx_rows100 15125 489.3 17472 317.5 258.4 +aot401-r3 RSS_MB 84 +aot402-r3 text 13 186.3 38916 140.5 36.8 +aot402-r3 plpgsql 23 261.1 31381 157.2 115.1 +aot402-r3 post4 33 220.1 35912 155.7 58.3 +aot402-r3 rows100 15217 431.6 18770 307.0 244.3 +aot402-r3 json119k 169548 2384.8 4522 553.3 1772.2 +aot402-r3 ctx_text 17 212.5 35845 154.5 59.1 +aot402-r3 ctx_rows100 15125 498.7 18501 307.7 256.9 +aot402-r3 RSS_MB 81 +jit401-r3 text 13 184.7 39277 144.3 37.0 +jit401-r3 plpgsql 23 261.4 30740 154.8 114.1 +jit401-r3 post4 33 207.7 37238 152.3 57.8 +jit401-r3 rows100 15217 428.4 19460 282.7 238.7 +jit401-r3 json119k 169548 2184.7 4500 544.0 1765.0 +jit401-r3 ctx_text 17 211.6 36441 148.5 58.4 +jit401-r3 ctx_rows100 15125 440.6 19725 285.5 253.9 +jit401-r3 RSS_MB 112 +jit402-r3 text 13 196.1 39522 141.1 35.9 +jit402-r3 plpgsql 23 257.2 31746 154.9 114.8 +jit402-r3 post4 33 209.1 38086 148.8 56.9 +jit402-r3 rows100 15217 412.2 19383 272.3 239.2 +jit402-r3 json119k 169548 1942.8 4523 536.2 1748.9 +jit402-r3 ctx_text 17 210.2 36923 148.4 58.4 +jit402-r3 ctx_rows100 15125 448.5 19117 278.2 250.6 +jit402-r3 RSS_MB 116 +aot402-r4 text 13 188.2 38914 145.5 37.2 +aot402-r4 plpgsql 23 265.7 30545 155.0 114.0 +aot402-r4 post4 33 210.3 37359 154.6 57.2 +aot402-r4 rows100 15217 427.0 18364 305.4 239.9 +aot402-r4 json119k 169548 1967.1 4696 547.9 1768.9 +aot402-r4 ctx_text 17 211.5 35774 154.2 58.4 +aot402-r4 ctx_rows100 15125 484.8 18345 308.5 254.9 +aot402-r4 RSS_MB 85 +jit401-r4 text 13 187.1 38554 143.9 36.4 +jit401-r4 plpgsql 23 256.3 32671 152.0 113.3 +jit401-r4 post4 33 208.1 36680 150.3 56.5 +jit401-r4 rows100 15217 418.8 19800 283.9 236.8 +jit401-r4 json119k 169548 2225.1 4524 542.2 1740.4 +jit401-r4 ctx_text 17 211.8 36983 146.8 57.3 +jit401-r4 ctx_rows100 15125 441.0 18832 282.2 250.4 +jit401-r4 RSS_MB 117 +jit402-r4 text 13 190.9 40056 143.5 36.5 +jit402-r4 plpgsql 23 258.0 31845 153.3 113.9 +jit402-r4 post4 33 209.6 37955 150.5 57.6 +jit402-r4 rows100 15217 411.3 19257 275.6 238.2 +jit402-r4 json119k 169548 2241.9 4464 544.4 1762.7 +jit402-r4 ctx_text 17 208.2 37431 147.6 57.5 +jit402-r4 ctx_rows100 15125 446.0 19637 276.4 252.6 +jit402-r4 RSS_MB 119 +aot401-r4 text 13 185.9 36845 140.8 36.2 +aot401-r4 plpgsql 23 262.9 31832 154.7 117.2 +aot401-r4 post4 33 210.0 37187 153.2 57.3 +aot401-r4 rows100 15217 445.5 19027 313.2 244.3 +aot401-r4 json119k 169548 2251.2 4507 539.1 1792.9 +aot401-r4 ctx_text 17 211.1 35826 152.3 57.8 +aot401-r4 ctx_rows100 15125 496.5 18318 316.4 258.4 +aot401-r4 RSS_MB 79 diff --git a/BenchmarkTests/LoadTest/LoadGen.cs.txt b/BenchmarkTests/LoadTest/LoadGen.cs.txt new file mode 100644 index 0000000..91ffa02 --- /dev/null +++ b/BenchmarkTests/LoadTest/LoadGen.cs.txt @@ -0,0 +1,92 @@ +// HTTP/1.1 keep-alive load generator. Usage: loadgen