quicktype-core 23.0.39 → 23.0.40

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.
@@ -22,6 +22,7 @@ export declare const swiftOptions: {
22
22
  objcSupport: BooleanOption;
23
23
  optionalEnums: BooleanOption;
24
24
  swift5Support: BooleanOption;
25
+ sendable: BooleanOption;
25
26
  multiFileOutput: BooleanOption;
26
27
  accessLevel: EnumOption<string>;
27
28
  protocol: EnumOption<{
@@ -72,7 +73,7 @@ export declare class SwiftRenderer extends ConvenienceRenderer {
72
73
  private renderSingleFileHeaderComments;
73
74
  private renderHeader;
74
75
  private renderTopLevelAlias;
75
- protected getProtocolsArray(_t: Type, isClass: boolean): string[];
76
+ protected getProtocolsArray(kind: "struct" | "class" | "enum"): string[];
76
77
  private getProtocolString;
77
78
  private getEnumPropertyGroups;
78
79
  private get accessLevel();
@@ -36,6 +36,7 @@ exports.swiftOptions = {
36
36
  objcSupport: new RendererOptions_1.BooleanOption("objective-c-support", "Objects inherit from NSObject and @objcMembers is added to classes", false),
37
37
  optionalEnums: new RendererOptions_1.BooleanOption("optional-enums", "If no matching case is found enum value is set to null", false),
38
38
  swift5Support: new RendererOptions_1.BooleanOption("swift-5-support", "Renders output in a Swift 5 compatible mode", false),
39
+ sendable: new RendererOptions_1.BooleanOption("sendable", "Mark generated models as Sendable", false),
39
40
  multiFileOutput: new RendererOptions_1.BooleanOption("multi-file-output", "Renders each top-level object in its own Swift file", false),
40
41
  accessLevel: new RendererOptions_1.EnumOption("access-level", "Access level", [
41
42
  ["internal", "internal"],
@@ -82,6 +83,7 @@ class SwiftTargetLanguage extends TargetLanguage_1.TargetLanguage {
82
83
  exports.swiftOptions.acronymStyle,
83
84
  exports.swiftOptions.objcSupport,
84
85
  exports.swiftOptions.optionalEnums,
86
+ exports.swiftOptions.sendable,
85
87
  exports.swiftOptions.swift5Support,
86
88
  exports.swiftOptions.multiFileOutput,
87
89
  exports.swiftOptions.mutableProperties
@@ -671,9 +673,10 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
671
673
  renderTopLevelAlias(t, name) {
672
674
  this.emitLine(this.accessLevel, "typealias ", name, " = ", this.swiftType(t, true));
673
675
  }
674
- getProtocolsArray(_t, isClass) {
676
+ getProtocolsArray(kind) {
675
677
  const protocols = [];
676
678
  // [Michael Fey (@MrRooni), 2019-4-24] Technically NSObject isn't a "protocol" in this instance, but this felt like the best place to slot in this superclass declaration.
679
+ const isClass = kind === "class";
677
680
  if (isClass && this._options.objcSupport) {
678
681
  protocols.push("NSObject");
679
682
  }
@@ -686,10 +689,16 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
686
689
  if (this._options.protocol.equatable) {
687
690
  protocols.push("Equatable");
688
691
  }
692
+ if (this._options.sendable && !this._options.mutableProperties && !this._options.objcSupport) {
693
+ protocols.push("Sendable");
694
+ }
689
695
  return protocols;
690
696
  }
691
- getProtocolString(_t, isClass) {
692
- const protocols = this.getProtocolsArray(_t, isClass);
697
+ getProtocolString(kind, baseClass = undefined) {
698
+ let protocols = this.getProtocolsArray(kind);
699
+ if (baseClass) {
700
+ protocols.unshift(baseClass);
701
+ }
693
702
  return protocols.length > 0 ? ": " + protocols.join(", ") : "";
694
703
  }
695
704
  getEnumPropertyGroups(c) {
@@ -765,7 +774,7 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
765
774
  // [Michael Fey (@MrRooni), 2019-4-24] Swift 5 or greater, must come before the access declaration for the class.
766
775
  this.emitItem(this.objcMembersDeclaration);
767
776
  }
768
- this.emitBlockWithAccess([structOrClass, " ", className, this.getProtocolString(c, isClass)], () => {
777
+ this.emitBlockWithAccess([structOrClass, " ", className, this.getProtocolString(structOrClass)], () => {
769
778
  if (this._options.dense) {
770
779
  let lastProperty = undefined;
771
780
  let lastNames = [];
@@ -995,18 +1004,7 @@ encoder.dateEncodingStrategy = .formatted(formatter)`);
995
1004
  this.emitLineOnce("import Foundation");
996
1005
  this.ensureBlankLine();
997
1006
  this.emitDescription(this.descriptionForType(e));
998
- const protocols = [];
999
- if (!this._options.justTypes) {
1000
- protocols.push("String"); // Not a protocol
1001
- protocols.push("Codable");
1002
- }
1003
- if (this._options.protocol.hashable) {
1004
- protocols.push("Hashable");
1005
- }
1006
- if (this._options.protocol.equatable) {
1007
- protocols.push("Equatable");
1008
- }
1009
- const protocolString = protocols.length > 0 ? ": " + protocols.join(", ") : "";
1007
+ const protocolString = this.getProtocolString("enum", "String");
1010
1008
  if (this._options.justTypes) {
1011
1009
  this.emitBlockWithAccess(["enum ", enumName, protocolString], () => {
1012
1010
  this.forEachEnumCase(e, "none", name => {
@@ -1042,7 +1040,7 @@ encoder.dateEncodingStrategy = .formatted(formatter)`);
1042
1040
  this.emitDescription(this.descriptionForType(u));
1043
1041
  const indirect = this.isCycleBreakerType(u) ? "indirect " : "";
1044
1042
  const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u, sortBy);
1045
- this.emitBlockWithAccess([indirect, "enum ", unionName, this.getProtocolString(u, false)], () => {
1043
+ this.emitBlockWithAccess([indirect, "enum ", unionName, this.getProtocolString("enum")], () => {
1046
1044
  this.forEachUnionMember(u, nonNulls, "none", null, (name, t) => {
1047
1045
  this.emitLine("case ", name, "(", this.swiftType(t), ")");
1048
1046
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.39",
3
+ "version": "23.0.40",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",