@contractkit/plugin-csharp 0.1.2 → 0.1.3

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.
@@ -5,9 +5,9 @@ $ tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly
5
5
  CLI tsup v8.5.1
6
6
  CLI Target: esnext
7
7
  ESM Build start
8
- ESM dist/index.js 86.93 KB
9
- ESM dist/index.js.map 187.54 KB
10
- ESM ⚡️ Build success in 141ms
8
+ ESM dist/index.js 87.30 KB
9
+ ESM dist/index.js.map 188.87 KB
10
+ ESM ⚡️ Build success in 180ms
11
11
  DTS Build start
12
- DTS ⚡️ Build success in 6474ms
12
+ DTS ⚡️ Build success in 7420ms
13
13
  DTS dist/index.d.ts 1.50 KB
@@ -3,27 +3,27 @@ $ vitest run --coverage
3
3
   RUN  v4.1.5 /home/runner/work/ContractKit/ContractKit/packages/plugin-csharp
4
4
  Coverage enabled with v8
5
5
 
6
- ✓ tests/codegen-client.test.ts (26 tests) 231ms
7
- ✓ tests/codegen-models.test.ts (63 tests) 272ms
8
- ✓ tests/index.test.ts (10 tests) 212ms
9
- ✓ tests/runtime.test.ts (14 tests) 67ms
10
- ✓ tests/naming.test.ts (19 tests) 76ms
11
- ✓ tests/scaffold.test.ts (5 tests) 28ms
12
- ✓ tests/hoist.test.ts (10 tests) 61ms
6
+ ✓ tests/codegen-client.test.ts (26 tests) 252ms
7
+ ✓ tests/codegen-models.test.ts (65 tests) 282ms
8
+ ✓ tests/index.test.ts (10 tests) 207ms
9
+ ✓ tests/naming.test.ts (19 tests) 88ms
10
+ ✓ tests/runtime.test.ts (14 tests) 51ms
11
+ ✓ tests/scaffold.test.ts (5 tests) 14ms
12
+ ✓ tests/hoist.test.ts (10 tests) 67ms
13
13
 
14
14
   Test Files  7 passed (7)
15
-  Tests  147 passed (147)
16
-  Start at  13:40:51
17
-  Duration  12.55s (transform 6.16s, setup 0ms, import 20.87s, tests 948ms, environment 18ms)
15
+  Tests  149 passed (149)
16
+  Start at  15:17:08
17
+  Duration  13.50s (transform 5.27s, setup 0ms, import 22.08s, tests 962ms, environment 10ms)
18
18
 
19
19
   % Coverage report from v8
20
20
  -------------------|---------|----------|---------|---------|-------------------
21
21
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
22
22
  -------------------|---------|----------|---------|---------|-------------------
23
- All files | 87.99 | 76.98 | 89.44 | 90.79 |
24
- src | 88.03 | 77.05 | 89.63 | 90.83 |
23
+ All files | 88.04 | 77.07 | 89.59 | 90.82 |
24
+ src | 88.08 | 77.15 | 89.79 | 90.86 |
25
25
  ...gen-client.ts | 94.61 | 87.12 | 94.91 | 97.59 | ...94-496,513-514
26
- ...gen-models.ts | 91.19 | 75 | 96.42 | 92.97 | ...79,881,903-906
26
+ ...gen-models.ts | 91.29 | 75.25 | 96.61 | 93.02 | ...05,907,929-932
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
29
  index.ts | 70.74 | 71.21 | 58.06 | 75.59 | ...25-329,350-369
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @contractkit/plugin-csharp
2
2
 
3
+ ## 0.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - ad6b72e: A default on a field whose property shares its enum's name now compiles. `rating?: Rating = neutral`
8
+ generated `public Rating? Rating { get; init; } = Rating.Neutral;`, and inside the record `Rating`
9
+ resolved to the property rather than the type, so the build failed with CS0236. C#'s rule that lets a
10
+ member share its type's name only applies when the member's type is exactly that type, and `Rating?`
11
+ is `Nullable<Rating>`. The initializer is now written from the global namespace whenever a property of
12
+ the same record would shadow the enum.
13
+
3
14
  ## 0.1.2
4
15
 
5
16
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"codegen-models.d.ts","sourceRoot":"","sources":["../src/codegen-models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,g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M,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,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,CAS7H;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,CA2CrF;AA8pBD,YAAY,EAAE,aAAa,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -329,7 +329,8 @@ function literalCSharpType(value, ctx) {
329
329
  if (typeof value === "boolean") return qualify("bool", "System.Boolean", ctx);
330
330
  return Number.isInteger(value) ? qualify("long", "System.Int64", ctx) : qualify("double", "System.Double", ctx);
331
331
  }
332
- function renderDefault(value, type, ctx) {
332
+ function renderDefault(value, type, ctx, memberNames = /* @__PURE__ */ new Set()) {
333
+ const enumType = (name) => memberNames.has(name) ? `global::${ctx.namespace}.Models.${name}` : name;
333
334
  const inner = type.kind === "lazy" ? type.inner : type;
334
335
  if (typeof value === "boolean") return String(value);
335
336
  if (typeof value === "number") {
@@ -350,13 +351,13 @@ function renderDefault(value, type, ctx) {
350
351
  if (inner.kind === "enum") {
351
352
  const decl = ctx.hoisted?.byNode.get(inner);
352
353
  if (!decl || !inner.values.includes(value)) return void 0;
353
- return `${decl.name}.${enumMemberNames(inner.values).get(value)}`;
354
+ return `${enumType(decl.name)}.${enumMemberNames(inner.values).get(value)}`;
354
355
  }
355
356
  if (inner.kind === "ref") {
356
357
  const target = ctx.modelIndex.get(inner.name);
357
358
  const targetType = target?.type?.kind === "lazy" ? target.type.inner : target?.type;
358
359
  if (targetType?.kind !== "enum" || !targetType.values.includes(value)) return void 0;
359
- return `${inner.name}.${enumMemberNames(targetType.values).get(value)}`;
360
+ return `${enumType(inner.name)}.${enumMemberNames(targetType.values).get(value)}`;
360
361
  }
361
362
  if (inner.kind === "scalar") {
362
363
  switch (inner.name) {
@@ -555,24 +556,28 @@ function renderRecord(name, fields, ctx, forInput, supertypes, description, depr
555
556
  lines.push(`public sealed record ${name}${implementsClause};`);
556
557
  return lines;
557
558
  }
559
+ const memberNames = new Set(fields.map((field) => memberName(field, name)));
558
560
  lines.push(`public sealed record ${name}${implementsClause}`);
559
561
  lines.push("{");
560
562
  fields.forEach((field, index) => {
561
563
  if (index > 0) lines.push("");
562
- lines.push(...renderField(field, ctx, forInput, name, wireCase));
564
+ lines.push(...renderField(field, ctx, forInput, name, memberNames, wireCase));
563
565
  });
564
566
  lines.push("}");
565
567
  return lines;
566
568
  }
567
- function renderField(field, ctx, forInput, ownerTypeName, wireCase) {
568
- const propName = safeMemberName(toCSharpPropertyName(field.name), ownerTypeName);
569
+ function memberName(field, ownerTypeName) {
570
+ return safeMemberName(toCSharpPropertyName(field.name), ownerTypeName);
571
+ }
572
+ function renderField(field, ctx, forInput, ownerTypeName, memberNames, wireCase) {
573
+ const propName = memberName(field, ownerTypeName);
569
574
  const wireName = applyWireCase(field.name, wireCase);
570
575
  let typeStr = renderCSharpType(field.type, ctx, forInput);
571
576
  if ((field.optional || field.nullable) && !typeStr.endsWith("?")) typeStr += "?";
572
- let initializer = field.default !== void 0 ? renderDefault(field.default, field.type, ctx) : void 0;
577
+ let initializer = field.default !== void 0 ? renderDefault(field.default, field.type, ctx, memberNames) : void 0;
573
578
  if (initializer === void 0 && !field.optional && !field.nullable) {
574
579
  const inner = field.type.kind === "lazy" ? field.type.inner : field.type;
575
- if (inner.kind === "literal") initializer = renderDefault(inner.value, inner, ctx);
580
+ if (inner.kind === "literal") initializer = renderDefault(inner.value, inner, ctx, memberNames);
576
581
  }
577
582
  const isRequired = !field.optional && initializer === void 0;
578
583
  const lines = [];