Skip to content

Commit 5f537c4

Browse files
vbilopavclaude
andcommitted
refactor!: drop CrudSource from the standalone client app
Auto-generated CRUD over arbitrary tables and views is a different product shape from the rest of NpgsqlRest. The project's core promise is "your PostgreSQL routines become REST endpoints" — explicit, version-controlled, comment-annotated procedures and functions where the developer chose what to expose. Auto-CRUD inverts that, so it no longer belongs in the standalone client's configuration surface. The plugin itself still ships as a NuGet package and remains fully functional for embedded use: using NpgsqlRest.CrudSource; ... sources.Add(new CrudSource()) Library consumers see zero change. Only NpgsqlRestClient's JSON-driven path is affected. Removed from NpgsqlRestClient: - ProjectReference to NpgsqlRest.CrudSource - using NpgsqlRest.CrudSource imports + version listing in --version and --version --json output - App.cs config-driven CrudSource registration block - The entire NpgsqlRest:CrudSource block in appsettings.json, ConfigTemplate.cs, ConfigDefaults.cs, and the description / enum-values entries in ConfigSchemaGenerator.cs Migration for users who had `"CrudSource": { "Enabled": true }`: 1. (recommended) Rewrite as PostgreSQL functions/procedures with HTTP annotations — explicit per-endpoint auth, validation, caching, rate limiting. 2. Embed the library in a custom host and register CrudSource programmatically. 1949/1949 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6c7ab45 commit 5f537c4

9 files changed

Lines changed: 19 additions & 226 deletions

File tree

NpgsqlRestClient/App.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using NpgsqlRest.HttpFiles;
55
using NpgsqlRest.TsClient;
66
using Serilog;
7-
using NpgsqlRest.CrudSource;
87
using NpgsqlRest.SqlFileSource;
98
using Microsoft.AspNetCore.Antiforgery;
109
using Microsoft.AspNetCore.DataProtection;
@@ -583,31 +582,6 @@ public List<IEndpointSource> CreateEndpointSources()
583582
_builder.ClientLogger?.LogDebug("Using {name} PostrgeSQL Source", nameof(RoutineSource));
584583
}
585584

586-
var crudSourceCfg = _config.NpgsqlRestCfg.GetSection("CrudSource");
587-
if (crudSourceCfg.Exists() is true && _config.GetConfigBool("Enabled", crudSourceCfg, true) is true)
588-
{
589-
sources.Add(new CrudSource()
590-
{
591-
SchemaSimilarTo = _config.GetConfigStr("SchemaSimilarTo", crudSourceCfg),
592-
SchemaNotSimilarTo = _config.GetConfigStr("SchemaNotSimilarTo", crudSourceCfg),
593-
IncludeSchemas = _config.GetConfigEnumerable("IncludeSchemas", crudSourceCfg)?.ToArray(),
594-
ExcludeSchemas = _config.GetConfigEnumerable("ExcludeSchemas", crudSourceCfg)?.ToArray(),
595-
NameSimilarTo = _config.GetConfigStr("NameSimilarTo", crudSourceCfg),
596-
NameNotSimilarTo = _config.GetConfigStr("NameNotSimilarTo", crudSourceCfg),
597-
IncludeNames = _config.GetConfigEnumerable("IncludeNames", crudSourceCfg)?.ToArray(),
598-
ExcludeNames = _config.GetConfigEnumerable("ExcludeNames", crudSourceCfg)?.ToArray(),
599-
CommentsMode = _config.GetConfigEnum<CommentsMode?>("CommentsMode", crudSourceCfg),
600-
CrudTypes = _config.GetConfigFlag<CrudCommandType>("CrudTypes", crudSourceCfg),
601-
602-
ReturningUrlPattern = _config.GetConfigStr("ReturningUrlPattern", crudSourceCfg) ?? "{0}/returning",
603-
OnConflictDoNothingUrlPattern = _config.GetConfigStr("OnConflictDoNothingUrlPattern", crudSourceCfg) ?? "{0}/on-conflict-do-nothing",
604-
OnConflictDoNothingReturningUrlPattern = _config.GetConfigStr("OnConflictDoNothingReturningUrlPattern", crudSourceCfg) ?? "{0}/on-conflict-do-nothing/returning",
605-
OnConflictDoUpdateUrlPattern = _config.GetConfigStr("OnConflictDoUpdateUrlPattern", crudSourceCfg) ?? "{0}/on-conflict-do-update",
606-
OnConflictDoUpdateReturningUrlPattern = _config.GetConfigStr("OnConflictDoUpdateReturningUrlPattern", crudSourceCfg) ?? "{0}/on-conflict-do-update/returning",
607-
});
608-
_builder.ClientLogger?.LogDebug("Using {name} PostrgeSQL Source", nameof(CrudSource));
609-
}
610-
611585
var sqlFileSourceCfg = _config.NpgsqlRestCfg.GetSection("SqlFileSource");
612586
if (sqlFileSourceCfg.Exists() is true && _config.GetConfigBool("Enabled", sqlFileSourceCfg, true) is true)
613587
{

NpgsqlRestClient/CliJson.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Text.Json.Nodes;
33
using Npgsql;
44
using NpgsqlRest;
5-
using NpgsqlRest.CrudSource;
65
using NpgsqlRest.HttpFiles;
76
using NpgsqlRest.TsClient;
87

@@ -37,7 +36,6 @@ public static JsonObject GetVersionJson()
3736
["NpgsqlRestClient"] = GetVersion<Program>(),
3837
["NpgsqlRest.HttpFiles"] = GetVersion<HttpFileOptions>(),
3938
["NpgsqlRest.TsClient"] = GetVersion<TsClientOptions>(),
40-
["NpgsqlRest.CrudSource"] = GetVersion<CrudSource>(),
4139
["NpgsqlRest.SqlFileSource"] = GetVersion<NpgsqlRest.SqlFileSource.SqlFileSource>(),
4240
["NpgsqlRest.OpenApi"] = GetVersion<NpgsqlRest.OpenAPI.OpenApiOptions>(),
4341
["Npgsql"] = GetVersion<NpgsqlConnection>(),

NpgsqlRestClient/ConfigDefaults.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,6 @@ private static JsonObject GetNpgsqlRestDefaults()
797797
["ClientCodeGen"] = GetClientCodeGenDefaults(),
798798
["HttpClientOptions"] = GetHttpClientOptionsDefaults(),
799799
["ProxyOptions"] = GetProxyOptionsDefaults(),
800-
["CrudSource"] = GetCrudSourceDefaults(),
801800
["SqlFileSource"] = GetSqlFileSourceDefaults()
802801
};
803802
}
@@ -1011,29 +1010,6 @@ private static JsonObject GetProxyOptionsDefaults()
10111010
};
10121011
}
10131012

1014-
private static JsonObject GetCrudSourceDefaults()
1015-
{
1016-
return new JsonObject
1017-
{
1018-
["Enabled"] = false,
1019-
["SchemaSimilarTo"] = null,
1020-
["SchemaNotSimilarTo"] = null,
1021-
["IncludeSchemas"] = null,
1022-
["ExcludeSchemas"] = null,
1023-
["NameSimilarTo"] = null,
1024-
["NameNotSimilarTo"] = null,
1025-
["IncludeNames"] = null,
1026-
["ExcludeNames"] = null,
1027-
["CommentsMode"] = "OnlyWithHttpTag",
1028-
["ReturningUrlPattern"] = "{0}/returning",
1029-
["OnConflictDoNothingUrlPattern"] = "{0}/on-conflict-do-nothing",
1030-
["OnConflictDoNothingReturningUrlPattern"] = "{0}/on-conflict-do-nothing/returning",
1031-
["OnConflictDoUpdateUrlPattern"] = "{0}/on-conflict-do-update",
1032-
["OnConflictDoUpdateReturningUrlPattern"] = "{0}/on-conflict-do-update/returning",
1033-
["CrudTypes"] = CreateStringArray("All")
1034-
};
1035-
}
1036-
10371013
private static JsonObject GetSqlFileSourceDefaults()
10381014
{
10391015
return new JsonObject

NpgsqlRestClient/ConfigSchemaGenerator.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -476,23 +476,6 @@ public static partial class ConfigSchemaGenerator
476476
["NpgsqlRest:ProxyOptions:ResponseSuccessParameter"] = "Default name for the proxy response success parameter.",
477477
["NpgsqlRest:ProxyOptions:ResponseErrorMessageParameter"] = "Default name for the proxy response error message parameter.",
478478
["NpgsqlRest:ProxyOptions:ForwardUploadContent"] = "When true, for upload endpoints marked as proxy, the raw multipart/form-data content is forwarded directly to the upstream proxy instead of being processed locally. This allows the upstream service to handle file uploads. When false (default), upload endpoints with proxy annotation will process uploads locally and upload metadata will not be available to the proxy.",
479-
["NpgsqlRest:CrudSource"] = "CRUD endpoints for the PostgreSQL tables and views.",
480-
["NpgsqlRest:CrudSource:Enabled"] = "Enable or disable the creation of the endpoints for the PostgreSQL tables and views.",
481-
["NpgsqlRest:CrudSource:SchemaSimilarTo"] = "Filter schema names similar to this parameter or `null` to ignore this parameter.",
482-
["NpgsqlRest:CrudSource:SchemaNotSimilarTo"] = "Filter schema names NOT similar to this parameter or `null` to ignore this parameter.",
483-
["NpgsqlRest:CrudSource:IncludeSchemas"] = "List of schema names to be included or `null` to ignore this parameter.",
484-
["NpgsqlRest:CrudSource:ExcludeSchemas"] = "List of schema names to be excluded or `null` to ignore this parameter.",
485-
["NpgsqlRest:CrudSource:NameSimilarTo"] = "Filter names similar to this parameter or `null` to ignore this parameter.",
486-
["NpgsqlRest:CrudSource:NameNotSimilarTo"] = "Filter names NOT similar to this parameter or `null` to ignore this parameter.",
487-
["NpgsqlRest:CrudSource:IncludeNames"] = "List of names to be included or `null` to ignore this parameter.",
488-
["NpgsqlRest:CrudSource:ExcludeNames"] = "List of names to be excluded or `null` to ignore this parameter.",
489-
["NpgsqlRest:CrudSource:CommentsMode"] = "Configure how the comment annotations will behave. `Ignore` will create all endpoints and ignore comment annotations. `ParseAll` will create all endpoints and parse comment annotations to alter the endpoint. `OnlyWithHttpTag` (default) will only create endpoints that contain the `HTTP` tag in the comments and then parse comment annotations.",
490-
["NpgsqlRest:CrudSource:ReturningUrlPattern"] = "URL pattern for all \"returning\" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.",
491-
["NpgsqlRest:CrudSource:OnConflictDoNothingUrlPattern"] = "URL pattern for all \"do nothing\" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.",
492-
["NpgsqlRest:CrudSource:OnConflictDoNothingReturningUrlPattern"] = "URL pattern for all \"do nothing returning \" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.",
493-
["NpgsqlRest:CrudSource:OnConflictDoUpdateUrlPattern"] = "URL pattern for all \"do update\" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.",
494-
["NpgsqlRest:CrudSource:OnConflictDoUpdateReturningUrlPattern"] = "URL pattern for all \"do update returning\" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.",
495-
["NpgsqlRest:CrudSource:CrudTypes"] = "Set of flags to enable or disable the creation of the CRUD endpoints for the specific types of the PostgreSQL tables and views.\n\nPossible values are:\nSelect, Update, UpdateReturning, Insert, InsertReturning, InsertOnConflictDoNothing, InsertOnConflictDoUpdate, InsertOnConflictDoNothingReturning,\nInsertOnConflictDoUpdateReturning, Delete, DeleteReturning, All",
496479
["NpgsqlRest:SqlFileSource"] = "SQL file source for generating REST API endpoints from .sql files.",
497480
["NpgsqlRest:SqlFileSource:Enabled"] = "Enable or disable SQL file source endpoints. Default is false.",
498481
["NpgsqlRest:SqlFileSource:FilePattern"] = "Glob pattern for SQL files, e.g. \"sql/**/*.sql\", \"queries/*.sql\".\nSupports * (any chars), ** (recursive, any including /), ? (single char).\nEmpty string disables the feature.",
@@ -556,7 +539,6 @@ public static partial class ConfigSchemaGenerator
556539
["NpgsqlRest:HttpFileOptions:CommentHeader"] = ["None", "Simple", "Full"],
557540
["NpgsqlRest:HttpFileOptions:FileMode"] = ["Database", "Schema"],
558541
["NpgsqlRest:ClientCodeGen:CommentHeader"] = ["None", "Simple", "Full"],
559-
["NpgsqlRest:CrudSource:CommentsMode"] = ["Ignore", "ParseAll", "OnlyWithHttpTag"],
560542

561543
// ConnectionSettings
562544
["ConnectionSettings:MultiHostConnectionTargets:Default"] = ["Any", "Primary", "Standby", "PreferPrimary", "PreferStandby", "ReadWrite", "ReadOnly"],

NpgsqlRestClient/ConfigTemplate.cs

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,82 +2694,6 @@ public static partial class ConfigSchemaGenerator
26942694
"ForwardUploadContent": false
26952695
},
26962696
2697-
//
2698-
// CRUD endpoints for the PostgreSQL tables and views.
2699-
//
2700-
"CrudSource": {
2701-
//
2702-
// Enable or disable the creation of the endpoints for the PostgreSQL tables and views.
2703-
//
2704-
"Enabled": false,
2705-
//
2706-
// Filter schema names similar to this parameter or `null` to ignore this parameter.
2707-
//
2708-
"SchemaSimilarTo": null,
2709-
//
2710-
// Filter schema names NOT similar to this parameter or `null` to ignore this parameter.
2711-
//
2712-
"SchemaNotSimilarTo": null,
2713-
//
2714-
// List of schema names to be included or `null` to ignore this parameter.
2715-
//
2716-
"IncludeSchemas": null,
2717-
//
2718-
// List of schema names to be excluded or `null` to ignore this parameter.
2719-
//
2720-
"ExcludeSchemas": null,
2721-
//
2722-
// Filter names similar to this parameter or `null` to ignore this parameter.
2723-
//
2724-
"NameSimilarTo": null,
2725-
//
2726-
// Filter names NOT similar to this parameter or `null` to ignore this parameter.
2727-
//
2728-
"NameNotSimilarTo": null,
2729-
//
2730-
// List of names to be included or `null` to ignore this parameter.
2731-
//
2732-
"IncludeNames": null,
2733-
//
2734-
// List of names to be excluded or `null` to ignore this parameter.
2735-
//
2736-
"ExcludeNames": null,
2737-
//
2738-
// Configure how the comment annotations will behave. `Ignore` will create all endpoints and ignore comment annotations. `ParseAll` will create all endpoints and parse comment annotations to alter the endpoint. `OnlyWithHttpTag` (default) will only create endpoints that contain the `HTTP` tag in the comments and then parse comment annotations.
2739-
//
2740-
"CommentsMode": "OnlyWithHttpTag",
2741-
//
2742-
// URL pattern for all "returning" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2743-
//
2744-
"ReturningUrlPattern": "{0}/returning",
2745-
//
2746-
// URL pattern for all "do nothing" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2747-
//
2748-
"OnConflictDoNothingUrlPattern": "{0}/on-conflict-do-nothing",
2749-
//
2750-
// URL pattern for all "do nothing returning " endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2751-
//
2752-
"OnConflictDoNothingReturningUrlPattern": "{0}/on-conflict-do-nothing/returning",
2753-
//
2754-
// URL pattern for all "do update" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2755-
//
2756-
"OnConflictDoUpdateUrlPattern": "{0}/on-conflict-do-update",
2757-
//
2758-
// URL pattern for all "do update returning" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2759-
//
2760-
"OnConflictDoUpdateReturningUrlPattern": "{0}/on-conflict-do-update/returning",
2761-
//
2762-
// Set of flags to enable or disable the creation of the CRUD endpoints for the specific types of the PostgreSQL tables and views.
2763-
//
2764-
// Possible values are:
2765-
// Select, Update, UpdateReturning, Insert, InsertReturning, InsertOnConflictDoNothing, InsertOnConflictDoUpdate, InsertOnConflictDoNothingReturning,
2766-
// InsertOnConflictDoUpdateReturning, Delete, DeleteReturning, All
2767-
//
2768-
"CrudTypes": [
2769-
"All"
2770-
]
2771-
},
2772-
27732697
//
27742698
// SQL file source for generating REST API endpoints from .sql files.
27752699
// Each SQL file must contain exactly one statement.

NpgsqlRestClient/NpgsqlRestClient.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
<ItemGroup>
2929
<ProjectReference Include="..\NpgsqlRest\NpgsqlRest.csproj" />
30-
<ProjectReference Include="..\plugins\NpgsqlRest.CrudSource\NpgsqlRest.CrudSource.csproj" />
3130
<ProjectReference Include="..\plugins\NpgsqlRest.HttpFiles\NpgsqlRest.HttpFiles.csproj" />
3231
<ProjectReference Include="..\plugins\NpgsqlRest.OpenApi\NpgsqlRest.OpenApi.csproj" />
3332
<ProjectReference Include="..\plugins\NpgsqlRest.TsClient\NpgsqlRest.TsClient.csproj" />

NpgsqlRestClient/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using NpgsqlRestClient.Fido2;
88

99
using Npgsql;
10-
using NpgsqlRest.CrudSource;
1110
using NpgsqlRest.HttpFiles;
1211
using NpgsqlRest.TsClient;
1312

@@ -78,7 +77,6 @@
7877
("NpgsqlRestClient", System.Reflection.Assembly.GetAssembly(typeof(Program))?.GetName().Version?.ToString() ?? "-"),
7978
("NpgsqlRest.HttpFiles", System.Reflection.Assembly.GetAssembly(typeof(HttpFileOptions))?.GetName().Version?.ToString() ?? "-"),
8079
("NpgsqlRest.TsClient", System.Reflection.Assembly.GetAssembly(typeof(TsClientOptions))?.GetName().Version?.ToString() ?? "-"),
81-
("NpgsqlRest.CrudSource", System.Reflection.Assembly.GetAssembly(typeof(CrudSource))?.GetName().Version?.ToString() ?? "-"),
8280
("NpgsqlRest.SqlFileSource", System.Reflection.Assembly.GetAssembly(typeof(NpgsqlRest.SqlFileSource.SqlFileSource))?.GetName().Version?.ToString() ?? "-"),
8381
("NpgsqlRest.OpenApi", System.Reflection.Assembly.GetAssembly(typeof(NpgsqlRest.OpenAPI.OpenApiOptions))?.GetName().Version?.ToString() ?? "-"),
8482
(" ", " "),

NpgsqlRestClient/appsettings.json

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,82 +2685,6 @@
26852685
"ForwardUploadContent": false
26862686
},
26872687

2688-
//
2689-
// CRUD endpoints for the PostgreSQL tables and views.
2690-
//
2691-
"CrudSource": {
2692-
//
2693-
// Enable or disable the creation of the endpoints for the PostgreSQL tables and views.
2694-
//
2695-
"Enabled": false,
2696-
//
2697-
// Filter schema names similar to this parameter or `null` to ignore this parameter.
2698-
//
2699-
"SchemaSimilarTo": null,
2700-
//
2701-
// Filter schema names NOT similar to this parameter or `null` to ignore this parameter.
2702-
//
2703-
"SchemaNotSimilarTo": null,
2704-
//
2705-
// List of schema names to be included or `null` to ignore this parameter.
2706-
//
2707-
"IncludeSchemas": null,
2708-
//
2709-
// List of schema names to be excluded or `null` to ignore this parameter.
2710-
//
2711-
"ExcludeSchemas": null,
2712-
//
2713-
// Filter names similar to this parameter or `null` to ignore this parameter.
2714-
//
2715-
"NameSimilarTo": null,
2716-
//
2717-
// Filter names NOT similar to this parameter or `null` to ignore this parameter.
2718-
//
2719-
"NameNotSimilarTo": null,
2720-
//
2721-
// List of names to be included or `null` to ignore this parameter.
2722-
//
2723-
"IncludeNames": null,
2724-
//
2725-
// List of names to be excluded or `null` to ignore this parameter.
2726-
//
2727-
"ExcludeNames": null,
2728-
//
2729-
// Configure how the comment annotations will behave. `Ignore` will create all endpoints and ignore comment annotations. `ParseAll` will create all endpoints and parse comment annotations to alter the endpoint. `OnlyWithHttpTag` (default) will only create endpoints that contain the `HTTP` tag in the comments and then parse comment annotations.
2730-
//
2731-
"CommentsMode": "OnlyWithHttpTag",
2732-
//
2733-
// URL pattern for all "returning" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2734-
//
2735-
"ReturningUrlPattern": "{0}/returning",
2736-
//
2737-
// URL pattern for all "do nothing" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2738-
//
2739-
"OnConflictDoNothingUrlPattern": "{0}/on-conflict-do-nothing",
2740-
//
2741-
// URL pattern for all "do nothing returning " endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2742-
//
2743-
"OnConflictDoNothingReturningUrlPattern": "{0}/on-conflict-do-nothing/returning",
2744-
//
2745-
// URL pattern for all "do update" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2746-
//
2747-
"OnConflictDoUpdateUrlPattern": "{0}/on-conflict-do-update",
2748-
//
2749-
// URL pattern for all "do update returning" endpoints. Parameter is the original URL. Parameter placeholder {0} is default URL.
2750-
//
2751-
"OnConflictDoUpdateReturningUrlPattern": "{0}/on-conflict-do-update/returning",
2752-
//
2753-
// Set of flags to enable or disable the creation of the CRUD endpoints for the specific types of the PostgreSQL tables and views.
2754-
//
2755-
// Possible values are:
2756-
// Select, Update, UpdateReturning, Insert, InsertReturning, InsertOnConflictDoNothing, InsertOnConflictDoUpdate, InsertOnConflictDoNothingReturning,
2757-
// InsertOnConflictDoUpdateReturning, Delete, DeleteReturning, All
2758-
//
2759-
"CrudTypes": [
2760-
"All"
2761-
]
2762-
},
2763-
27642688
//
27652689
// SQL file source for generating REST API endpoints from .sql files.
27662690
// Each SQL file must contain exactly one statement.

0 commit comments

Comments
 (0)