@contractkit/plugin-csharp 0.1.5 → 0.2.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/.turbo/turbo-build$colon$ci.log +5 -5
- package/.turbo/turbo-test$colon$ci.log +16 -15
- package/CHANGELOG.md +28 -0
- package/README.md +86 -13
- package/dist/codegen-client.d.ts +3 -0
- package/dist/codegen-client.d.ts.map +1 -1
- package/dist/codegen-models.d.ts +15 -0
- package/dist/codegen-models.d.ts.map +1 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +566 -19
- package/dist/index.js.map +1 -1
- package/dist/runtime-converters.d.ts +8 -2
- package/dist/runtime-converters.d.ts.map +1 -1
- package/dist/runtime-polyfills.d.ts +20 -0
- package/dist/runtime-polyfills.d.ts.map +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/scaffold.d.ts +18 -4
- package/dist/scaffold.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/codegen-client.ts +19 -9
- package/src/codegen-models.ts +53 -2
- package/src/index.ts +74 -5
- package/src/runtime-converters.ts +135 -4
- package/src/runtime-polyfills.ts +352 -0
- package/src/runtime.ts +24 -0
- package/src/scaffold.ts +45 -6
- package/tests/codegen-client.test.ts +38 -4
- package/tests/codegen-models.test.ts +40 -3
- package/tests/index.test.ts +43 -0
- package/tests/runtime.test.ts +83 -1
- package/tests/scaffold.test.ts +22 -0
|
@@ -5,9 +5,9 @@ $ tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly
|
|
|
5
5
|
[34mCLI[39m tsup v8.5.1
|
|
6
6
|
[34mCLI[39m Target: esnext
|
|
7
7
|
[34mESM[39m Build start
|
|
8
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
9
|
-
[32mESM[39m [1mdist/index.js.map [22m[
|
|
10
|
-
[32mESM[39m ⚡️ Build success in
|
|
8
|
+
[32mESM[39m [1mdist/index.js [22m[32m110.33 KB[39m
|
|
9
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m228.03 KB[39m
|
|
10
|
+
[32mESM[39m ⚡️ Build success in 120ms
|
|
11
11
|
[34mDTS[39m Build start
|
|
12
|
-
[32mDTS[39m ⚡️ Build success in
|
|
13
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
12
|
+
[32mDTS[39m ⚡️ Build success in 5515ms
|
|
13
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.81 KB[39m
|
|
@@ -3,32 +3,33 @@ $ vitest run --coverage
|
|
|
3
3
|
[1m[30m[46m RUN [49m[39m[22m [36mv4.1.5 [39m[90m/home/runner/work/ContractKit/ContractKit/packages/plugin-csharp[39m
|
|
4
4
|
[2mCoverage enabled with [22m[33mv8[39m
|
|
5
5
|
|
|
6
|
-
[32m✓[39m tests/
|
|
7
|
-
[32m✓[39m tests/codegen-client.test.ts [2m([22m[
|
|
8
|
-
[32m✓[39m tests/codegen-models.test.ts [2m([22m[
|
|
9
|
-
[32m✓[39m tests/index.test.ts [2m([22m[
|
|
10
|
-
[32m✓[39m tests/
|
|
11
|
-
[32m✓[39m tests/scaffold.test.ts [2m([22m[
|
|
12
|
-
[32m✓[39m tests/hoist.test.ts [2m([22m[2m10 tests[22m[2m)[22m[32m
|
|
6
|
+
[32m✓[39m tests/runtime.test.ts [2m([22m[2m24 tests[22m[2m)[22m[32m 57[2mms[22m[39m
|
|
7
|
+
[32m✓[39m tests/codegen-client.test.ts [2m([22m[2m42 tests[22m[2m)[22m[32m 224[2mms[22m[39m
|
|
8
|
+
[32m✓[39m tests/codegen-models.test.ts [2m([22m[2m70 tests[22m[2m)[22m[32m 242[2mms[22m[39m
|
|
9
|
+
[32m✓[39m tests/index.test.ts [2m([22m[2m15 tests[22m[2m)[22m[32m 188[2mms[22m[39m
|
|
10
|
+
[32m✓[39m tests/naming.test.ts [2m([22m[2m23 tests[22m[2m)[22m[32m 70[2mms[22m[39m
|
|
11
|
+
[32m✓[39m tests/scaffold.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m 18[2mms[22m[39m
|
|
12
|
+
[32m✓[39m tests/hoist.test.ts [2m([22m[2m10 tests[22m[2m)[22m[32m 31[2mms[22m[39m
|
|
13
13
|
|
|
14
14
|
[2m Test Files [22m [1m[32m7 passed[39m[22m[90m (7)[39m
|
|
15
|
-
[2m Tests [22m [1m[
|
|
16
|
-
[2m Start at [22m
|
|
17
|
-
[2m Duration [22m 9.
|
|
15
|
+
[2m Tests [22m [1m[32m192 passed[39m[22m[90m (192)[39m
|
|
16
|
+
[2m Start at [22m 18:03:12
|
|
17
|
+
[2m Duration [22m 9.97s[2m (transform 3.89s, setup 0ms, import 15.92s, tests 830ms, environment 1ms)[22m
|
|
18
18
|
|
|
19
19
|
[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
20
20
|
-------------------|---------|----------|---------|---------|-------------------
|
|
21
21
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
22
22
|
-------------------|---------|----------|---------|---------|-------------------
|
|
23
|
-
All files |
|
|
24
|
-
src |
|
|
25
|
-
...gen-client.ts |
|
|
26
|
-
...gen-models.ts | 91.
|
|
23
|
+
All files | 89.28 | 80.61 | 90.98 | 91.5 |
|
|
24
|
+
src | 89.37 | 80.46 | 91.34 | 91.57 |
|
|
25
|
+
...gen-client.ts | 97.02 | 91.83 | 98.48 | 98.35 | ...66,520,551-552
|
|
26
|
+
...gen-models.ts | 91.53 | 76.87 | 96.72 | 93.24 | ...69,971,993-996
|
|
27
27
|
codegen-sdk.ts | 100 | 100 | 100 | 100 |
|
|
28
28
|
hoist.ts | 78.66 | 61.9 | 93.1 | 79.06 | ...13-322,350-362
|
|
29
|
-
index.ts |
|
|
29
|
+
index.ts | 74.4 | 78.4 | 59.37 | 78.91 | ...94-398,419-438
|
|
30
30
|
naming.ts | 88.05 | 72.72 | 100 | 100 | ...40,187-214,227
|
|
31
31
|
...converters.ts | 100 | 100 | 100 | 100 |
|
|
32
|
+
...-polyfills.ts | 100 | 100 | 100 | 100 |
|
|
32
33
|
runtime.ts | 100 | 100 | 100 | 100 |
|
|
33
34
|
scaffold.ts | 100 | 100 | 100 | 100 |
|
|
34
35
|
tests | 86.95 | 83.78 | 88 | 89.74 |
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @contractkit/plugin-csharp
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- aab7560: The generated C# SDK can now be built for `netstandard2.0`, which is what a UWP or .NET Framework project can reference.
|
|
8
|
+
|
|
9
|
+
`targetFrameworks: ["netstandard2.0", "net10.0"]` adds a `Runtime/Polyfills.cs` to the output and, in a fresh scaffold, multi-targets the project file with a `System.Text.Json` reference on the old leg alone. The generated sources are the same either way — everything framework-specific sits behind `#if NETSTANDARD2_0` — and so is the public surface, so consuming code is portable across both.
|
|
10
|
+
|
|
11
|
+
Leaving the option out changes nothing. A single-framework scaffold is byte-for-byte what it was, with no package reference and a restore that needs no feed at all.
|
|
12
|
+
|
|
13
|
+
`dateTypes: "datetime"` is new alongside it: a contract's `date` maps to a `DateTime` at midnight with an unspecified kind instead of a `DateOnly`, for a UI stack whose date controls bind to that and nothing else, XAML's `DatePicker` among them. The mapping applies on every framework the SDK is built for, not only the old one, and the wire form stays `yyyy-MM-dd`. A `time` is `TimeOnly` in both modes.
|
|
14
|
+
|
|
15
|
+
Three smaller fixes went with it, and they apply on every framework:
|
|
16
|
+
- PATCH goes out through a verb the runtime declares itself. `HttpMethod.Patch` is the one verb the grammar allows that the framework does not spell everywhere, and no fixture had declared a PATCH operation, so no generator had golden output for it.
|
|
17
|
+
- The `bigint` converter no longer reads a JSON number through an overload of `Encoding.GetString` that only newer frameworks have.
|
|
18
|
+
- The README's `Headers` sample used `ValueTask.FromResult`, a static that arrived in .NET 5, where the constructor works everywhere.
|
|
19
|
+
|
|
20
|
+
**An existing project keeps its own `.csproj`**, which is never regenerated. Set the option, rebuild to pick up `Runtime/Polyfills.cs`, then paste the project-file snippet from the plugin's README. That README also covers what the consuming project has to set — chiefly `<LangVersion>11</LangVersion>` or higher, since a legacy UWP project defaults to C# 7.3 and cannot construct a type with `required` members.
|
|
21
|
+
|
|
22
|
+
The output tests now compile both legs with warnings as errors and round-trip every scalar through the netstandard2.0 one. No UWP or .NET Native Release build is part of that, so smoke-test one call from the app before relying on it.
|
|
23
|
+
|
|
24
|
+
## 0.1.6
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [b1bb346]
|
|
29
|
+
- @contractkit/core@0.31.1
|
|
30
|
+
|
|
3
31
|
## 0.1.5
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Generates a C#/.NET SDK client from ContractKit `.ck` files.
|
|
4
4
|
|
|
5
5
|
The output is built on `System.Text.Json` and `HttpClient` from the shared framework and takes **no
|
|
6
|
-
NuGet dependencies at all**, so a generated SDK restores and builds with no feed reachable.
|
|
6
|
+
NuGet dependencies at all**, so a generated SDK restores and builds with no feed reachable. It can
|
|
7
|
+
also be built for `netstandard2.0`, which is what a UWP or .NET Framework project can reference; see
|
|
8
|
+
[Older frameworks](#older-frameworks).
|
|
7
9
|
|
|
8
10
|
## Install
|
|
9
11
|
|
|
@@ -26,13 +28,15 @@ pnpm add -D @contractkit/plugin-csharp
|
|
|
26
28
|
}
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
| Option
|
|
30
|
-
|
|
|
31
|
-
| `baseDir`
|
|
32
|
-
| `namespace`
|
|
33
|
-
| `sdkName`
|
|
34
|
-
| `includeInternal`
|
|
35
|
-
| `scaffold`
|
|
31
|
+
| Option | Default | Meaning |
|
|
32
|
+
| ------------------ | ----------------- | ----------------------------------------------------------------------- |
|
|
33
|
+
| `baseDir` | `csharp-sdk` | Output directory, relative to the config's `rootDir`. |
|
|
34
|
+
| `namespace` | `ContractKit.Sdk` | Root namespace for the generated sources. |
|
|
35
|
+
| `sdkName` | `Sdk` | Aggregator class name, and the assembly name when scaffolding. |
|
|
36
|
+
| `includeInternal` | `false` | Emit client methods for operations marked `internal`. |
|
|
37
|
+
| `scaffold` | `false` | Write `<SdkName>.csproj` once, as a user-owned file. Never overwritten. |
|
|
38
|
+
| `targetFrameworks` | `["net10.0"]` | The frameworks the SDK is built for. Add `netstandard2.0` for UWP. |
|
|
39
|
+
| `dateTypes` | `dateonly` | Which C# type a `date` maps to: `dateonly` or `datetime`. |
|
|
36
40
|
|
|
37
41
|
Config arrives as JSON, so it is validated at run time: an invalid namespace, a namespace segment
|
|
38
42
|
that is a C# keyword, or a non-boolean flag fails the build rather than emitting C# that cannot
|
|
@@ -44,6 +48,7 @@ compile.
|
|
|
44
48
|
<baseDir>/
|
|
45
49
|
Runtime/SdkRuntime.cs SdkHttp, SdkOptions, SdkException, SdkResponse, SdkPart
|
|
46
50
|
Runtime/Converters.cs SdkJson.Options and the scalar converters
|
|
51
|
+
Runtime/Polyfills.cs only with `netstandard2.0` in `targetFrameworks`
|
|
47
52
|
Models/<File>.cs one file per contract file
|
|
48
53
|
Clients/<File>Client.cs one client per operations file
|
|
49
54
|
<SdkName>.cs the aggregator
|
|
@@ -65,7 +70,7 @@ using Acme.Sdk.Runtime;
|
|
|
65
70
|
using var sdk = new AcmeSdk(new SdkOptions
|
|
66
71
|
{
|
|
67
72
|
BaseUrl = "https://api.example.com",
|
|
68
|
-
Headers = _ => ValueTask
|
|
73
|
+
Headers = _ => new ValueTask<IReadOnlyDictionary<string, string>>(
|
|
69
74
|
new Dictionary<string, string> { ["authorization"] = $"Bearer {token}" }),
|
|
70
75
|
});
|
|
71
76
|
|
|
@@ -86,7 +91,7 @@ the converters registered there.
|
|
|
86
91
|
|
|
87
92
|
| `.ck` | C# | `.ck` | C# |
|
|
88
93
|
| ------------------------------------ | ----------------------- | --------------------------- | ---------------- |
|
|
89
|
-
| `string`, `email`, `url`, `interval` | `string` | `date` | `DateOnly
|
|
94
|
+
| `string`, `email`, `url`, `interval` | `string` | `date` | `DateOnly`¹ |
|
|
90
95
|
| `number` | `double` | `time` | `TimeOnly` |
|
|
91
96
|
| `int` | `long` | `datetime` | `DateTimeOffset` |
|
|
92
97
|
| `bigint` | `BigInteger` | `duration` | `TimeSpan` |
|
|
@@ -95,6 +100,13 @@ the converters registered there.
|
|
|
95
100
|
| `array(T)` | `List<T>` | `null` | `object?` |
|
|
96
101
|
| `record(string, V)` | `Dictionary<string, V>` | `unknown`, `json`, `object` | `JsonElement` |
|
|
97
102
|
|
|
103
|
+
¹ `dateTypes: "datetime"` maps `date` to a `DateTime` at midnight with an unspecified kind instead,
|
|
104
|
+
on every framework the SDK is built for, so the surface never differs between them. It is there for a
|
|
105
|
+
UI stack whose date controls bind to `DateTime` and nothing else, XAML's `DatePicker` among them. The
|
|
106
|
+
wire form is `yyyy-MM-dd` either way. `time` stays `TimeOnly` in both: `duration` is already a
|
|
107
|
+
`TimeSpan`, and serialization dispatches on the CLR type, so a `time` carried as one would go out as
|
|
108
|
+
`PT9H30M`.
|
|
109
|
+
|
|
98
110
|
`int` is a JavaScript safe integer in the source language, which overflows a 32-bit `int`, so it
|
|
99
111
|
maps to `long`. `decimal` travels as a quoted JSON string and refuses to read an unquoted number,
|
|
100
112
|
matching the server's own schema. `duration` travels as ISO 8601 rather than the framework's
|
|
@@ -154,9 +166,66 @@ comes back as a value; everything else throws `SdkException`, and the method doc
|
|
|
154
166
|
|
|
155
167
|
## Scaffolding
|
|
156
168
|
|
|
157
|
-
`scaffold: true` writes `<SdkName>.csproj` once, targeting `
|
|
158
|
-
|
|
159
|
-
package id, a version or an analyzer set and the
|
|
169
|
+
`scaffold: true` writes `<SdkName>.csproj` once, targeting what `targetFrameworks` names, with
|
|
170
|
+
nullable enabled. On `net10.0` alone there is no package reference at all. It is emitted `ifAbsent`,
|
|
171
|
+
so it is created once and never regenerated: add a package id, a version or an analyzer set and the
|
|
172
|
+
next build leaves them alone.
|
|
173
|
+
|
|
174
|
+
## Older frameworks
|
|
175
|
+
|
|
176
|
+
A UWP project targets .NET Standard 2.0 and the .NET Native toolchain, so it cannot reference an SDK
|
|
177
|
+
built only for `net10.0`. Name the framework and it can:
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"plugins": {
|
|
182
|
+
"@contractkit/plugin-csharp": {
|
|
183
|
+
"targetFrameworks": ["netstandard2.0", "net10.0"],
|
|
184
|
+
"scaffold": true
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
That adds `Runtime/Polyfills.cs` to the output and, in a fresh scaffold, multi-targets the project
|
|
191
|
+
file. The generated sources are the same either way: everything framework-specific is behind
|
|
192
|
+
`#if NETSTANDARD2_0`, so the same files compile on both legs and the public surface is the same on
|
|
193
|
+
both. .NET Standard 2.0 does not carry `System.Text.Json`, so that one leg takes a package reference
|
|
194
|
+
and needs a feed to restore; `net10.0` keeps its dependency-free build.
|
|
195
|
+
|
|
196
|
+
**An existing project keeps its own `.csproj`** — the file is never regenerated. Set the option,
|
|
197
|
+
rebuild to pick up `Runtime/Polyfills.cs`, then edit the project file by hand:
|
|
198
|
+
|
|
199
|
+
```xml
|
|
200
|
+
<PropertyGroup>
|
|
201
|
+
<!-- replacing <TargetFramework>net10.0</TargetFramework> -->
|
|
202
|
+
<TargetFrameworks>netstandard2.0;net10.0</TargetFrameworks>
|
|
203
|
+
</PropertyGroup>
|
|
204
|
+
|
|
205
|
+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
|
206
|
+
<LangVersion>12.0</LangVersion>
|
|
207
|
+
</PropertyGroup>
|
|
208
|
+
|
|
209
|
+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
|
210
|
+
<PackageReference Include="System.Text.Json" Version="10.0.12" />
|
|
211
|
+
</ItemGroup>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Three things to know on the consuming side:
|
|
215
|
+
|
|
216
|
+
1. **The consuming project needs `<LangVersion>11</LangVersion>` or higher.** A legacy UWP project
|
|
217
|
+
defaults to C# 7.3, which cannot construct a type with `required` members or set an `init`
|
|
218
|
+
property — and every generated model has both. The error names the language version, not the SDK.
|
|
219
|
+
2. **`DateOnly` and `TimeOnly` are the SDK's own types on this framework**, declared in
|
|
220
|
+
`<namespace>.Runtime` rather than in `System`, so they cannot collide with a package that
|
|
221
|
+
backfills `System.DateOnly` for your own code. Importing `<namespace>.Runtime` gives you the same
|
|
222
|
+
short spelling your `net10.0` code uses. Both convert to a `DateTime` or `TimeSpan` in one call,
|
|
223
|
+
for binding to a XAML picker; `dateTypes: "datetime"` skips the conversion for dates entirely.
|
|
224
|
+
3. **A .NET Native Release build may need runtime directives.** `System.Text.Json` reflects over the
|
|
225
|
+
model types unless a source generator is used, which the generated SDK does not use. If a Release
|
|
226
|
+
build loses properties that a Debug build serializes, add an `rd.xml` entry for the SDK assembly.
|
|
227
|
+
|
|
228
|
+
Minimum UWP target is 10.0.16299, which is where .NET Standard 2.0 support arrived.
|
|
160
229
|
|
|
161
230
|
## Status and known limitations
|
|
162
231
|
|
|
@@ -172,3 +241,7 @@ package id, a version or an analyzer set and the next build leaves them alone.
|
|
|
172
241
|
6. **Only the first declared request mime is used**, since a method has one signature.
|
|
173
242
|
7. **A type switch is not exhaustive.** C# has no compiler check that a union switch covers every
|
|
174
243
|
member, so each generated converter ends in a `default` that throws.
|
|
244
|
+
8. **The netstandard2.0 leg is verified by build and by serialization, not on a device.** The output
|
|
245
|
+
tests compile both legs with warnings as errors and round-trip every scalar through the old one.
|
|
246
|
+
No UWP or .NET Native Release build is part of that, so smoke-test one call from the app before
|
|
247
|
+
relying on it.
|
package/dist/codegen-client.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { ModelNode, OpOperationNode, OpRootNode, OpRouteNode, ParamSource } from '@contractkit/core';
|
|
2
2
|
import type { HoistResult } from './hoist.js';
|
|
3
|
+
import { type CSharpDateTypes } from './codegen-models.js';
|
|
3
4
|
export interface CSharpClientCodegenOptions {
|
|
4
5
|
namespace: string;
|
|
6
|
+
/** Which C# type a `date` maps to (default: `dateonly`). Applies to response headers too. */
|
|
7
|
+
dateTypes?: CSharpDateTypes;
|
|
5
8
|
modelsWithInput: ReadonlySet<string>;
|
|
6
9
|
modelIndex?: ReadonlyMap<string, ModelNode>;
|
|
7
10
|
hoisted?: HoistResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-client.d.ts","sourceRoot":"","sources":["../src/codegen-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,SAAS,EACT,eAAe,EAIf,UAAU,EACV,WAAW,EACX,WAAW,EACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"codegen-client.d.ts","sourceRoot":"","sources":["../src/codegen-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,SAAS,EACT,eAAe,EAIf,UAAU,EACV,WAAW,EACX,WAAW,EACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAqD,KAAK,eAAe,EAAsB,MAAM,qBAAqB,CAAC;AAYlI,MAAM,WAAW,0BAA0B;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,6FAA6F;IAC7F,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACrC,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5C,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAwBD,gFAAgF;AAChF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,eAAe,UAAQ,GAAG,OAAO,CAOtF;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,0BAA0B,GAAG,MAAM,CA2E/F;AA8cD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAetH;AAuGD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAIhF"}
|
package/dist/codegen-models.d.ts
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import type { ContractRootNode, ContractTypeNode, ModelNode, ScalarTypeNode } from '@contractkit/core';
|
|
2
2
|
import type { HoistResult } from './hoist.js';
|
|
3
|
+
/**
|
|
4
|
+
* Which C# type a contract's `date` maps to.
|
|
5
|
+
*
|
|
6
|
+
* `dateonly` is `DateOnly`, the type the framework added for exactly this. `datetime` is `DateTime`
|
|
7
|
+
* at midnight with an unspecified kind, for a UI stack whose date controls bind to that and nothing
|
|
8
|
+
* else — XAML's `DatePicker` among them. The choice applies to every framework the SDK is built for,
|
|
9
|
+
* so the public surface never differs between them.
|
|
10
|
+
*
|
|
11
|
+
* `time` is `TimeOnly` either way: `duration` already maps to `TimeSpan`, and serialization dispatches
|
|
12
|
+
* on the CLR type, so a `time` carried as a `TimeSpan` would go out as `PT9H30M`.
|
|
13
|
+
*/
|
|
14
|
+
export type CSharpDateTypes = 'dateonly' | 'datetime';
|
|
3
15
|
export interface CSharpModelCodegenOptions {
|
|
4
16
|
/** Root namespace the SDK is generated into. Models land in `<namespace>.Models`. */
|
|
5
17
|
namespace: string;
|
|
18
|
+
/** Which C# type a `date` maps to (default: `dateonly`). */
|
|
19
|
+
dateTypes?: CSharpDateTypes;
|
|
6
20
|
/** Model names that have a distinct `Input` variant, including ones declared in other files. */
|
|
7
21
|
modelsWithInput?: ReadonlySet<string>;
|
|
8
22
|
/**
|
|
@@ -34,6 +48,7 @@ export declare function generateCSharpModels(root: ContractRootNode, opts: CShar
|
|
|
34
48
|
export declare function resolveModelsWithInput(models: readonly ModelNode[], external?: ReadonlySet<string>): Set<string>;
|
|
35
49
|
interface RenderContext {
|
|
36
50
|
namespace: string;
|
|
51
|
+
dateTypes: CSharpDateTypes;
|
|
37
52
|
modelsWithInput: ReadonlySet<string>;
|
|
38
53
|
modelIndex: ReadonlyMap<string, ModelNode>;
|
|
39
54
|
hoisted?: HoistResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-models.d.ts","sourceRoot":"","sources":["../src/codegen-models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAA2B,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEhI,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,YAAY,CAAC;AAK3D,MAAM,WAAW,yBAAyB;IACtC,qFAAqF;IACrF,SAAS,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5C,kGAAkG;IAClG,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;
|
|
1
|
+
{"version":3,"file":"codegen-models.d.ts","sourceRoot":"","sources":["../src/codegen-models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAA2B,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEhI,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,YAAY,CAAC;AAK3D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,UAAU,CAAC;AAEtD,MAAM,WAAW,yBAAyB;IACtC,qFAAqF;IACrF,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,gGAAgG;IAChG,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5C,kGAAkG;IAClG,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAsBD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,yBAAyB,GAAG,MAAM,CAyBpG;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,QAAQ,GAAE,WAAW,CAAC,MAAM,CAAa,GAAG,GAAG,CAAC,MAAM,CAAC,CAG3H;AAID,UAAU,aAAa;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,eAAe,CAAC;IAC3B,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACrC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,oFAAoF;IACpF,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,6FAA6F;IAC7F,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,2FAA2F;AAC3F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,yBAAyB,GAAG;IAAE,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAE,GAAG,aAAa,CAU7H;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAYvI;AAID;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,UAAQ,GAAG,MAAM,CAqDrG;AAqBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,aAAa,GAAG,MAAM,CA4CrF;AAssBD,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ContractKitPlugin } from '@contractkit/core';
|
|
2
|
+
import { type CSharpDateTypes } from './codegen-models.js';
|
|
3
|
+
import { type CSharpTargetFramework } from './scaffold.js';
|
|
2
4
|
export interface CSharpSdkPluginConfig {
|
|
3
5
|
/** Output directory relative to rootDir (default: "csharp-sdk") */
|
|
4
6
|
baseDir?: string;
|
|
@@ -13,12 +15,33 @@ export interface CSharpSdkPluginConfig {
|
|
|
13
15
|
includeInternal?: boolean;
|
|
14
16
|
/** Emit `<SdkName>.csproj` once, as a user-owned file. Never overwritten. */
|
|
15
17
|
scaffold?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The frameworks the SDK is built for (default: `["net10.0"]`).
|
|
20
|
+
*
|
|
21
|
+
* Naming `netstandard2.0` is what makes the output usable from a UWP or .NET Framework project:
|
|
22
|
+
* `Runtime/Polyfills.cs` is emitted alongside the rest, and a scaffolded `.csproj` multi-targets
|
|
23
|
+
* and references `System.Text.Json` on that leg. Convention puts the oldest framework first.
|
|
24
|
+
*/
|
|
25
|
+
targetFrameworks?: CSharpTargetFramework[];
|
|
26
|
+
/**
|
|
27
|
+
* Which C# type a contract's `date` maps to (default: `"dateonly"`).
|
|
28
|
+
*
|
|
29
|
+
* `"datetime"` maps it to `DateTime` at midnight with an unspecified kind, for a UI stack whose
|
|
30
|
+
* date controls bind to that and nothing else — XAML's `DatePicker` among them. It applies to
|
|
31
|
+
* every framework the SDK is built for, so the public surface never differs between them.
|
|
32
|
+
*
|
|
33
|
+
* `time` is `TimeOnly` either way, because `duration` already maps to `TimeSpan` and a `time`
|
|
34
|
+
* carried as one would go out as `PT9H30M`.
|
|
35
|
+
*/
|
|
36
|
+
dateTypes?: CSharpDateTypes;
|
|
16
37
|
}
|
|
17
38
|
/**
|
|
18
39
|
* Bumped when the C# codegen output shape changes in a way that should invalidate every per-file
|
|
19
40
|
* fingerprint, so a plugin upgrade forces full regeneration even when no `.ck` file has changed.
|
|
20
41
|
*/
|
|
21
|
-
export declare const CSHARP_CODEGEN_VERSION = "
|
|
42
|
+
export declare const CSHARP_CODEGEN_VERSION = "2";
|
|
43
|
+
export type { CSharpTargetFramework } from './scaffold.js';
|
|
44
|
+
export type { CSharpDateTypes } from './codegen-models.js';
|
|
22
45
|
declare const plugin: ContractKitPlugin;
|
|
23
46
|
export default plugin;
|
|
24
47
|
export declare function createCSharpSdkPlugin(config: CSharpSdkPluginConfig, rootDir: string): ContractKitPlugin;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,iBAAiB,EAUpB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,iBAAiB,EAUpB,MAAM,mBAAmB,CAAC;AAW3B,OAAO,EAAgD,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAOzG,OAAO,EAA6C,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGtG,MAAM,WAAW,qBAAqB;IAClC,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6FAA6F;IAC7F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uFAAuF;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAC3C;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED;;;GAGG;AACH,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3D,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAQ3D,QAAA,MAAM,MAAM,EAAE,iBAMb,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAOvG;AAKD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CA+BrE"}
|