You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(tsclient): ExportTypes option to emit importable export interfaces
Adds NpgsqlRest.TsClient ExportTypes option (default false). When true,
request/response/composite interfaces are emitted as `export interface`.
With CreateSeparateTypeFile=true the separate type file becomes an
importable module {name}Types.ts (instead of ambient {name}Types.d.ts)
and the client file imports the named types from it; inline mode exports
them in the same file. No effect when SkipTypes=true. Default keeps
existing output byte-for-byte unchanged.
Wired through the client config (appsettings, defaults, template, schema)
and covered by a separate-module generation test.
Copy file name to clipboardExpand all lines: NpgsqlRestClient/ConfigSchemaGenerator.cs
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -463,6 +463,7 @@ public static partial class ConfigSchemaGenerator
463
463
["NpgsqlRest:ClientCodeGen:BySchema"]="Create files by PostgreSQL schema. File name will use formatted FilePath where {0} is the schema name in pascal case.",
464
464
["NpgsqlRest:ClientCodeGen:IncludeStatusCode"]="Set to true to include status code in response: {status: response.status, response: model}",
465
465
["NpgsqlRest:ClientCodeGen:CreateSeparateTypeFile"]="Create separate file with global types {name}Types.d.ts",
466
+
["NpgsqlRest:ClientCodeGen:ExportTypes"]="Emit interfaces with the `export` keyword so they can be imported by other modules. When true and CreateSeparateTypeFile is true, the separate type file becomes an importable module ({name}Types.ts) instead of an ambient {name}Types.d.ts, and the client file imports the named types from it. No effect when SkipTypes is true.",
466
467
["NpgsqlRest:ClientCodeGen:ImportBaseUrlFrom"]="Module name to import \"baseUrl\" constant, instead of defining it in a module.",
467
468
["NpgsqlRest:ClientCodeGen:ImportParseQueryFrom"]="Module name to import \"parseQuery\" function, instead of defining it in a module.",
468
469
["NpgsqlRest:ClientCodeGen:IncludeParseUrlParam"]="Include optional parameter `parseUrl: (url: string) => string = url=>url` that will parse the constructed URL.",
Copy file name to clipboardExpand all lines: NpgsqlRestClient/ConfigTemplate.cs
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2679,6 +2679,10 @@ public static partial class ConfigSchemaGenerator
2679
2679
//
2680
2680
"CreateSeparateTypeFile": true,
2681
2681
//
2682
+
// Emit interfaces with the `export` keyword so they can be imported by other modules. When true and CreateSeparateTypeFile is true, the separate type file becomes an importable module ({name}Types.ts) instead of an ambient {name}Types.d.ts, and the client file imports the named types from it. No effect when SkipTypes is true.
2683
+
//
2684
+
"ExportTypes": false,
2685
+
//
2682
2686
// Module name to import "baseUrl" constant, instead of defining it in a module.
Copy file name to clipboardExpand all lines: NpgsqlRestClient/appsettings.json
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2670,6 +2670,10 @@
2670
2670
//
2671
2671
"CreateSeparateTypeFile": true,
2672
2672
//
2673
+
// Emit interfaces with the `export` keyword so they can be imported by other modules. When true and CreateSeparateTypeFile is true, the separate type file becomes an importable module ({name}Types.ts) instead of an ambient {name}Types.d.ts, and the client file imports the named types from it. No effect when SkipTypes is true.
2674
+
//
2675
+
"ExportTypes": false,
2676
+
//
2673
2677
// Module name to import "baseUrl" constant, instead of defining it in a module.
- Resolved **once at startup**, matched **case-insensitively**, injected as the **raw** value. A **routine parameter of the same name takes precedence**.
71
71
-**Security:** a value substituted into a *response* header is sent to the client — reserve secrets for outbound HTTP-type calls / custom parameters, and use response headers only for non-secret values (e.g. server/environment name).
72
72
73
+
### TsClient: `ExportTypes` — emit request/response interfaces with the `export` keyword
74
+
75
+
The TypeScript client generator (`NpgsqlRest.TsClient`) previously emitted its request/response (and composite) interfaces as plain `interface` declarations: module-private when inlined into the client file (`CreateSeparateTypeFile: false`), or ambient/global in the separate `{name}Types.d.ts` file (the default). Neither form could be imported by other modules. The new **`ExportTypes`** option (config `NpgsqlRest:ClientCodeGen:ExportTypes`, default `false`) emits them as `export interface` so they can be imported:
76
+
77
+
-**Inline** (`CreateSeparateTypeFile: false`) — interfaces are emitted as `export interface` in the same file as the functions.
78
+
-**Separate file** (`CreateSeparateTypeFile: true`) — the type file becomes an importable module **`{name}Types.ts`** (`export interface …`) instead of an ambient **`{name}Types.d.ts`**, and the generated client file gets an `import type { … } from "./{name}Types";` referencing the named types.
79
+
80
+
Has no effect when `SkipTypes` is `true`. Defaulting to `false` keeps existing output byte-for-byte unchanged.
Copy file name to clipboardExpand all lines: plugins/NpgsqlRest.TsClient/TsClientOptions.cs
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,14 @@ public class TsClientOptions
50
50
/// </summary>
51
51
publicboolCreateSeparateTypeFile{get;set;}=true;
52
52
53
+
/// <summary>
54
+
/// Emit request/response (and composite) interfaces with the `export` keyword so they can be imported by other modules.
55
+
/// When false (default), interfaces are emitted as plain `interface` declarations (module-private when inline, ambient/global in the separate `.d.ts` file).
56
+
/// When true and CreateSeparateTypeFile is true, the separate type file becomes an importable module (`{name}Types.ts` with `export interface`) instead of an ambient `{name}Types.d.ts`, and the generated client file imports the named types from it.
57
+
/// Has no effect when SkipTypes is true.
58
+
/// </summary>
59
+
publicboolExportTypes{get;set;}=false;
60
+
53
61
/// <summary>
54
62
/// Lines to add to each header. {0} format placeholder is current timestamp
0 commit comments