quicktype-core 23.0.39 → 23.0.41

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
@@ -666,14 +668,18 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
666
668
  if (!this._options.justTypes && this._options.alamofire) {
667
669
  this.emitLineOnce("import Alamofire");
668
670
  }
671
+ if (this._options.optionalEnums) {
672
+ this.emitLineOnce("import OptionallyDecodable // https://github.com/idrougge/OptionallyDecodable");
673
+ }
669
674
  this.ensureBlankLine();
670
675
  }
671
676
  renderTopLevelAlias(t, name) {
672
677
  this.emitLine(this.accessLevel, "typealias ", name, " = ", this.swiftType(t, true));
673
678
  }
674
- getProtocolsArray(_t, isClass) {
679
+ getProtocolsArray(kind) {
675
680
  const protocols = [];
676
681
  // [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.
682
+ const isClass = kind === "class";
677
683
  if (isClass && this._options.objcSupport) {
678
684
  protocols.push("NSObject");
679
685
  }
@@ -686,10 +692,16 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
686
692
  if (this._options.protocol.equatable) {
687
693
  protocols.push("Equatable");
688
694
  }
695
+ if (this._options.sendable && !this._options.mutableProperties && !this._options.objcSupport) {
696
+ protocols.push("Sendable");
697
+ }
689
698
  return protocols;
690
699
  }
691
- getProtocolString(_t, isClass) {
692
- const protocols = this.getProtocolsArray(_t, isClass);
700
+ getProtocolString(kind, baseClass = undefined) {
701
+ let protocols = this.getProtocolsArray(kind);
702
+ if (baseClass) {
703
+ protocols.unshift(baseClass);
704
+ }
693
705
  return protocols.length > 0 ? ": " + protocols.join(", ") : "";
694
706
  }
695
707
  getEnumPropertyGroups(c) {
@@ -765,7 +777,7 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
765
777
  // [Michael Fey (@MrRooni), 2019-4-24] Swift 5 or greater, must come before the access declaration for the class.
766
778
  this.emitItem(this.objcMembersDeclaration);
767
779
  }
768
- this.emitBlockWithAccess([structOrClass, " ", className, this.getProtocolString(c, isClass)], () => {
780
+ this.emitBlockWithAccess([structOrClass, " ", className, this.getProtocolString(structOrClass)], () => {
769
781
  if (this._options.dense) {
770
782
  let lastProperty = undefined;
771
783
  let lastNames = [];
@@ -776,7 +788,7 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
776
788
  let sources = [
777
789
  [
778
790
  this._options.optionalEnums && lastProperty.type.kind === "enum"
779
- ? `@NilOnFail${this._options.namedTypePrefix} `
791
+ ? `@OptionallyDecodable `
780
792
  : "",
781
793
  this.accessLevel,
782
794
  useMutableProperties || (this._options.optionalEnums && lastProperty.type.kind === "enum")
@@ -995,18 +1007,7 @@ encoder.dateEncodingStrategy = .formatted(formatter)`);
995
1007
  this.emitLineOnce("import Foundation");
996
1008
  this.ensureBlankLine();
997
1009
  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(", ") : "";
1010
+ const protocolString = this.getProtocolString("enum", "String");
1010
1011
  if (this._options.justTypes) {
1011
1012
  this.emitBlockWithAccess(["enum ", enumName, protocolString], () => {
1012
1013
  this.forEachEnumCase(e, "none", name => {
@@ -1042,7 +1043,7 @@ encoder.dateEncodingStrategy = .formatted(formatter)`);
1042
1043
  this.emitDescription(this.descriptionForType(u));
1043
1044
  const indirect = this.isCycleBreakerType(u) ? "indirect " : "";
1044
1045
  const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u, sortBy);
1045
- this.emitBlockWithAccess([indirect, "enum ", unionName, this.getProtocolString(u, false)], () => {
1046
+ this.emitBlockWithAccess([indirect, "enum ", unionName, this.getProtocolString("enum")], () => {
1046
1047
  this.forEachUnionMember(u, nonNulls, "none", null, (name, t) => {
1047
1048
  this.emitLine("case ", name, "(", this.swiftType(t), ")");
1048
1049
  });
@@ -1157,18 +1158,6 @@ encoder.dateEncodingStrategy = .formatted(formatter)`);
1157
1158
  if (!this._options.justTypes) {
1158
1159
  this.emitSupportFunctions4();
1159
1160
  }
1160
- if (this._options.optionalEnums) {
1161
- this.emitBlockWithAccess(`@propertyWrapper public struct NilOnFail${this._options.namedTypePrefix}<T: Codable>: Codable`, () => {
1162
- this.emitMultiline(`
1163
- public let wrappedValue: T?
1164
- public init(from decoder: Decoder) throws {
1165
- wrappedValue = try? T(from: decoder)
1166
- }
1167
- public init(_ wrappedValue: T?) {
1168
- self.wrappedValue = wrappedValue
1169
- }`);
1170
- });
1171
- }
1172
1161
  }
1173
1162
  emitAlamofireExtension() {
1174
1163
  this.ensureBlankLine();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.39",
3
+ "version": "23.0.41",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",