quicktype 18.0.6 → 19.0.5

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.
Files changed (174) hide show
  1. package/README.md +1 -1
  2. package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
  3. package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
  4. package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
  5. package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
  6. package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
  7. package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
  8. package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
  9. package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
  10. package/dist/{cli/index.d.ts → index.d.ts} +2 -1
  11. package/dist/{cli/index.js → index.js} +4 -4
  12. package/package.json +61 -77
  13. package/dist/quicktype-core/Annotation.d.ts +0 -8
  14. package/dist/quicktype-core/Annotation.js +0 -16
  15. package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
  16. package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
  17. package/dist/quicktype-core/DateTime.d.ts +0 -10
  18. package/dist/quicktype-core/DateTime.js +0 -57
  19. package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
  20. package/dist/quicktype-core/DeclarationIR.js +0 -167
  21. package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
  22. package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
  23. package/dist/quicktype-core/GatherNames.d.ts +0 -2
  24. package/dist/quicktype-core/GatherNames.js +0 -333
  25. package/dist/quicktype-core/Graph.d.ts +0 -12
  26. package/dist/quicktype-core/Graph.js +0 -220
  27. package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
  28. package/dist/quicktype-core/GraphRewriting.js +0 -421
  29. package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
  30. package/dist/quicktype-core/MakeTransformations.js +0 -193
  31. package/dist/quicktype-core/MarkovChain.d.ts +0 -15
  32. package/dist/quicktype-core/MarkovChain.js +0 -154
  33. package/dist/quicktype-core/Messages.d.ts +0 -294
  34. package/dist/quicktype-core/Messages.js +0 -105
  35. package/dist/quicktype-core/Naming.d.ts +0 -64
  36. package/dist/quicktype-core/Naming.js +0 -356
  37. package/dist/quicktype-core/Renderer.d.ts +0 -50
  38. package/dist/quicktype-core/Renderer.js +0 -274
  39. package/dist/quicktype-core/RendererOptions.d.ts +0 -71
  40. package/dist/quicktype-core/RendererOptions.js +0 -141
  41. package/dist/quicktype-core/Run.d.ts +0 -174
  42. package/dist/quicktype-core/Run.js +0 -393
  43. package/dist/quicktype-core/Source.d.ts +0 -65
  44. package/dist/quicktype-core/Source.js +0 -204
  45. package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
  46. package/dist/quicktype-core/TargetLanguage.js +0 -66
  47. package/dist/quicktype-core/Transformers.d.ts +0 -209
  48. package/dist/quicktype-core/Transformers.js +0 -836
  49. package/dist/quicktype-core/Type.d.ts +0 -206
  50. package/dist/quicktype-core/Type.js +0 -716
  51. package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
  52. package/dist/quicktype-core/TypeBuilder.js +0 -324
  53. package/dist/quicktype-core/TypeGraph.d.ts +0 -75
  54. package/dist/quicktype-core/TypeGraph.js +0 -420
  55. package/dist/quicktype-core/TypeUtils.d.ts +0 -33
  56. package/dist/quicktype-core/TypeUtils.js +0 -230
  57. package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
  58. package/dist/quicktype-core/UnifyClasses.js +0 -159
  59. package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
  60. package/dist/quicktype-core/UnionBuilder.js +0 -282
  61. package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
  62. package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
  63. package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
  64. package/dist/quicktype-core/attributes/Constraints.js +0 -172
  65. package/dist/quicktype-core/attributes/Description.d.ts +0 -9
  66. package/dist/quicktype-core/attributes/Description.js +0 -97
  67. package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
  68. package/dist/quicktype-core/attributes/EnumValues.js +0 -31
  69. package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
  70. package/dist/quicktype-core/attributes/StringTypes.js +0 -189
  71. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
  72. package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
  73. package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
  74. package/dist/quicktype-core/attributes/TypeNames.js +0 -274
  75. package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
  76. package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
  77. package/dist/quicktype-core/index.d.ts +0 -48
  78. package/dist/quicktype-core/index.js +0 -180
  79. package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
  80. package/dist/quicktype-core/input/CompressedJSON.js +0 -276
  81. package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
  82. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
  83. package/dist/quicktype-core/input/Inference.d.ts +0 -22
  84. package/dist/quicktype-core/input/Inference.js +0 -240
  85. package/dist/quicktype-core/input/Inputs.d.ts +0 -48
  86. package/dist/quicktype-core/input/Inputs.js +0 -145
  87. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
  88. package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
  89. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
  90. package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
  91. package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
  92. package/dist/quicktype-core/input/PostmanCollection.js +0 -60
  93. package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
  94. package/dist/quicktype-core/input/io/NodeIO.js +0 -87
  95. package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
  96. package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
  97. package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
  98. package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
  99. package/dist/quicktype-core/language/All.d.ts +0 -3
  100. package/dist/quicktype-core/language/All.js +0 -57
  101. package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
  102. package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
  103. package/dist/quicktype-core/language/CSharp.d.ts +0 -201
  104. package/dist/quicktype-core/language/CSharp.js +0 -1850
  105. package/dist/quicktype-core/language/Crystal.d.ts +0 -37
  106. package/dist/quicktype-core/language/Crystal.js +0 -337
  107. package/dist/quicktype-core/language/Dart.d.ts +0 -66
  108. package/dist/quicktype-core/language/Dart.js +0 -576
  109. package/dist/quicktype-core/language/Elm.d.ts +0 -58
  110. package/dist/quicktype-core/language/Elm.js +0 -522
  111. package/dist/quicktype-core/language/Golang.d.ts +0 -51
  112. package/dist/quicktype-core/language/Golang.js +0 -460
  113. package/dist/quicktype-core/language/Haskell.d.ts +0 -56
  114. package/dist/quicktype-core/language/Haskell.js +0 -411
  115. package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
  116. package/dist/quicktype-core/language/JSONSchema.js +0 -169
  117. package/dist/quicktype-core/language/Java.d.ts +0 -125
  118. package/dist/quicktype-core/language/Java.js +0 -1081
  119. package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
  120. package/dist/quicktype-core/language/JavaScript.js +0 -435
  121. package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
  122. package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
  123. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
  124. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
  125. package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
  126. package/dist/quicktype-core/language/Kotlin.js +0 -832
  127. package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
  128. package/dist/quicktype-core/language/Objective-C.js +0 -777
  129. package/dist/quicktype-core/language/Php.d.ts +0 -80
  130. package/dist/quicktype-core/language/Php.js +0 -702
  131. package/dist/quicktype-core/language/Pike.d.ts +0 -37
  132. package/dist/quicktype-core/language/Pike.js +0 -276
  133. package/dist/quicktype-core/language/Python.d.ts +0 -107
  134. package/dist/quicktype-core/language/Python.js +0 -969
  135. package/dist/quicktype-core/language/Rust.d.ts +0 -56
  136. package/dist/quicktype-core/language/Rust.js +0 -309
  137. package/dist/quicktype-core/language/Swift.d.ts +0 -96
  138. package/dist/quicktype-core/language/Swift.js +0 -1211
  139. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
  140. package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
  141. package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
  142. package/dist/quicktype-core/language/ruby/index.js +0 -557
  143. package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
  144. package/dist/quicktype-core/language/ruby/keywords.js +0 -358
  145. package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
  146. package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
  147. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
  148. package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
  149. package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
  150. package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
  151. package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
  152. package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
  153. package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
  154. package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
  155. package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
  156. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
  157. package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
  158. package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
  159. package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
  160. package/dist/quicktype-core/support/Acronyms.js +0 -1128
  161. package/dist/quicktype-core/support/Chance.d.ts +0 -38
  162. package/dist/quicktype-core/support/Chance.js +0 -2146
  163. package/dist/quicktype-core/support/Converters.d.ts +0 -6
  164. package/dist/quicktype-core/support/Converters.js +0 -16
  165. package/dist/quicktype-core/support/Strings.d.ts +0 -44
  166. package/dist/quicktype-core/support/Strings.js +0 -525
  167. package/dist/quicktype-core/support/Support.d.ts +0 -29
  168. package/dist/quicktype-core/support/Support.js +0 -162
  169. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
  170. package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
  171. package/dist/quicktype-graphql-input/index.d.ts +0 -17
  172. package/dist/quicktype-graphql-input/index.js +0 -407
  173. package/dist/quicktype-typescript-input/index.d.ts +0 -2
  174. package/dist/quicktype-typescript-input/index.js +0 -98
@@ -1,411 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HaskellRenderer = exports.HaskellTargetLanguage = exports.haskellOptions = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const TargetLanguage_1 = require("../TargetLanguage");
6
- const RendererOptions_1 = require("../RendererOptions");
7
- const TypeUtils_1 = require("../TypeUtils");
8
- const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
9
- const Naming_1 = require("../Naming");
10
- const Strings_1 = require("../support/Strings");
11
- const Source_1 = require("../Source");
12
- exports.haskellOptions = {
13
- justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
14
- useList: new RendererOptions_1.EnumOption("array-type", "Use Array or List", [
15
- ["array", false],
16
- ["list", true]
17
- ]),
18
- moduleName: new RendererOptions_1.StringOption("module", "Generated module name", "NAME", "QuickType")
19
- };
20
- class HaskellTargetLanguage extends TargetLanguage_1.TargetLanguage {
21
- constructor() {
22
- super("Haskell", ["haskell"], "haskell");
23
- }
24
- getOptions() {
25
- return [exports.haskellOptions.justTypes, exports.haskellOptions.moduleName, exports.haskellOptions.useList];
26
- }
27
- get supportsOptionalClassProperties() {
28
- return true;
29
- }
30
- get supportsUnionsWithBothNumberTypes() {
31
- return true;
32
- }
33
- makeRenderer(renderContext, untypedOptionValues) {
34
- return new HaskellRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.haskellOptions, untypedOptionValues));
35
- }
36
- }
37
- exports.HaskellTargetLanguage = HaskellTargetLanguage;
38
- const forbiddenNames = [
39
- // reserved keywords
40
- "as",
41
- "case",
42
- "class",
43
- "data",
44
- "default",
45
- "deriving",
46
- "do",
47
- "else",
48
- "family",
49
- "forall",
50
- "foreign",
51
- "hiding",
52
- "if",
53
- "import",
54
- "in",
55
- "infix",
56
- "infixl",
57
- "infixr",
58
- "instance",
59
- "let",
60
- "of",
61
- "mdo",
62
- "module",
63
- "newtype",
64
- "proc",
65
- "qualified",
66
- "rec",
67
- "then",
68
- "type",
69
- "where",
70
- // in Prelude keywords ...
71
- "id",
72
- "Array",
73
- "HashMap",
74
- "Map",
75
- "Maybe",
76
- "Bool",
77
- "Int",
78
- "True",
79
- "False",
80
- "Enum",
81
- // Aeson types
82
- "encode",
83
- "decode",
84
- "text",
85
- "Text",
86
- "Value",
87
- "Object",
88
- "Result",
89
- "Series",
90
- "Error"
91
- ];
92
- const legalizeName = (0, Strings_1.legalizeCharacters)(cp => (0, Strings_1.isAscii)(cp) && (0, Strings_1.isLetterOrUnderscoreOrDigit)(cp));
93
- function haskellNameStyle(original, upper) {
94
- const words = (0, Strings_1.splitIntoWords)(original);
95
- return (0, Strings_1.combineWords)(words, legalizeName, upper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, upper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.allUpperWordStyle, "", Strings_1.isLetterOrUnderscore);
96
- }
97
- const upperNamingFunction = (0, Naming_1.funPrefixNamer)("upper", n => haskellNameStyle(n, true));
98
- const lowerNamingFunction = (0, Naming_1.funPrefixNamer)("lower", n => haskellNameStyle(n, false));
99
- class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
100
- _options;
101
- constructor(targetLanguage, renderContext, _options) {
102
- super(targetLanguage, renderContext);
103
- this._options = _options;
104
- }
105
- forbiddenNamesForGlobalNamespace() {
106
- return forbiddenNames;
107
- }
108
- makeNamedTypeNamer() {
109
- return upperNamingFunction;
110
- }
111
- namerForObjectProperty() {
112
- return lowerNamingFunction;
113
- }
114
- forbiddenForObjectProperties(_c, _className) {
115
- return { names: [], includeGlobalForbidden: true };
116
- }
117
- makeUnionMemberNamer() {
118
- return upperNamingFunction;
119
- }
120
- get unionMembersInGlobalNamespace() {
121
- return true;
122
- }
123
- makeEnumCaseNamer() {
124
- return upperNamingFunction;
125
- }
126
- get enumCasesInGlobalNamespace() {
127
- return true;
128
- }
129
- proposeUnionMemberName(u, unionName, fieldType, lookup) {
130
- const fieldName = super.proposeUnionMemberName(u, unionName, fieldType, lookup);
131
- return `${fieldName}_in_${lookup(unionName)}`;
132
- }
133
- get commentLineStart() {
134
- return "-- ";
135
- }
136
- emitDescriptionBlock(lines) {
137
- if (lines.length === 1) {
138
- this.emitLine("{-| ", lines[0], " -}");
139
- }
140
- else {
141
- this.emitCommentLines(lines, "", undefined, "-}", "{-| ");
142
- }
143
- }
144
- haskellType(t, noOptional = false) {
145
- return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.multiWord)(" ", "Maybe", "Text"), _nullType => (0, Source_1.multiWord)(" ", "Maybe", "Text"), _boolType => (0, Source_1.singleWord)("Bool"), _integerType => (0, Source_1.singleWord)("Int"), _doubleType => (0, Source_1.singleWord)("Float"), _stringType => (0, Source_1.singleWord)("Text"), arrayType => {
146
- if (this._options.useList) {
147
- return (0, Source_1.multiWord)("", "[", (0, Source_1.parenIfNeeded)(this.haskellType(arrayType.items)), "]");
148
- }
149
- return (0, Source_1.multiWord)(" ", "Vector", (0, Source_1.parenIfNeeded)(this.haskellType(arrayType.items)));
150
- }, classType => (0, Source_1.singleWord)(this.nameForNamedType(classType)), mapType => (0, Source_1.multiWord)(" ", "HashMap Text", (0, Source_1.parenIfNeeded)(this.haskellType(mapType.values))), enumType => (0, Source_1.singleWord)(this.nameForNamedType(enumType)), unionType => {
151
- const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
152
- if (nullable !== null) {
153
- const nullableType = this.haskellType(nullable);
154
- if (noOptional)
155
- return nullableType;
156
- return (0, Source_1.multiWord)(" ", "Maybe", (0, Source_1.parenIfNeeded)(nullableType));
157
- }
158
- return (0, Source_1.singleWord)(this.nameForNamedType(unionType));
159
- });
160
- }
161
- haskellProperty(p) {
162
- if (p.isOptional) {
163
- return (0, Source_1.multiWord)(" ", "Maybe", (0, Source_1.parenIfNeeded)(this.haskellType(p.type, true))).source;
164
- }
165
- else {
166
- return this.haskellType(p.type).source;
167
- }
168
- }
169
- encoderNameForType(t) {
170
- return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.singleWord)("String"), _nullType => (0, Source_1.singleWord)("Null"), _boolType => (0, Source_1.singleWord)("Bool"), _integerType => (0, Source_1.singleWord)("Number"), _doubleType => (0, Source_1.singleWord)("Number"), _stringType => (0, Source_1.singleWord)("String"), _arrayType => (0, Source_1.singleWord)("Array"), _classType => (0, Source_1.singleWord)("Object"), _mapType => (0, Source_1.singleWord)("Object"), _enumType => (0, Source_1.singleWord)("Object"), _unionType => (0, Source_1.singleWord)("Object"));
171
- }
172
- emitTopLevelDefinition(t, topLevelName) {
173
- this.emitLine("type ", topLevelName, " = ", this.haskellType(t).source);
174
- }
175
- emitClassDefinition(c, className) {
176
- let description = this.descriptionForType(c);
177
- this.forEachClassProperty(c, "none", (name, jsonName) => {
178
- const propertyDescription = this.descriptionForClassProperty(c, jsonName);
179
- if (propertyDescription === undefined)
180
- return;
181
- if (description === undefined) {
182
- description = [];
183
- }
184
- else {
185
- description.push("");
186
- }
187
- description.push(`${this.sourcelikeToString(name)}:`);
188
- description.push(...propertyDescription);
189
- });
190
- this.emitDescription(description);
191
- this.emitLine("data ", className, " = ", className);
192
- this.indent(() => {
193
- let onFirst = true;
194
- this.forEachClassProperty(c, "none", (name, _jsonName, p) => {
195
- this.emitLine(onFirst ? "{ " : ", ", name, className, " :: ", this.haskellProperty(p));
196
- onFirst = false;
197
- });
198
- if (onFirst) {
199
- this.emitLine("{");
200
- }
201
- this.emitLine("} deriving (Show)");
202
- });
203
- }
204
- emitEnumDefinition(e, enumName) {
205
- this.emitDescription(this.descriptionForType(e));
206
- this.emitLine("data ", enumName);
207
- this.indent(() => {
208
- let onFirst = true;
209
- this.forEachEnumCase(e, "none", name => {
210
- const equalsOrPipe = onFirst ? "=" : "|";
211
- this.emitLine(equalsOrPipe, " ", name, enumName);
212
- onFirst = false;
213
- });
214
- this.emitLine("deriving (Show)");
215
- });
216
- }
217
- emitUnionDefinition(u, unionName) {
218
- this.emitDescription(this.descriptionForType(u));
219
- this.emitLine("data ", unionName);
220
- this.indent(() => {
221
- let onFirst = true;
222
- this.forEachUnionMember(u, null, "none", null, (constructor, t) => {
223
- const equalsOrPipe = onFirst ? "=" : "|";
224
- if (t.kind === "null") {
225
- this.emitLine(equalsOrPipe, " ", constructor);
226
- }
227
- else {
228
- this.emitLine(equalsOrPipe, " ", constructor, " ", (0, Source_1.parenIfNeeded)(this.haskellType(t)));
229
- }
230
- onFirst = false;
231
- });
232
- this.emitLine("deriving (Show)");
233
- });
234
- }
235
- emitTopLevelFunctions(topLevelName) {
236
- this.emitLine("decodeTopLevel :: ByteString -> Maybe ", topLevelName);
237
- this.emitLine("decodeTopLevel = decode");
238
- }
239
- classPropertyLength(c) {
240
- let counter = 0;
241
- this.forEachClassProperty(c, "none", () => {
242
- counter += 1;
243
- });
244
- return counter;
245
- }
246
- emitClassEncoderInstance(c, className) {
247
- let classProperties = [];
248
- this.forEachClassProperty(c, "none", name => {
249
- classProperties.push(" ");
250
- classProperties.push(name);
251
- classProperties.push(className);
252
- });
253
- this.emitLine("instance ToJSON ", className, " where");
254
- this.indent(() => {
255
- if (classProperties.length === 0) {
256
- this.emitLine("toJSON = \\_ -> emptyObject");
257
- }
258
- else {
259
- this.emitLine("toJSON (", className, ...classProperties, ") =");
260
- this.indent(() => {
261
- this.emitLine("object");
262
- let onFirst = true;
263
- this.forEachClassProperty(c, "none", (name, jsonName) => {
264
- this.emitLine(onFirst ? "[ " : ", ", '"', (0, Strings_1.stringEscape)(jsonName), '" .= ', name, className);
265
- onFirst = false;
266
- });
267
- if (onFirst) {
268
- this.emitLine("[");
269
- }
270
- this.emitLine("]");
271
- });
272
- }
273
- });
274
- }
275
- emitClassDecoderInstance(c, className) {
276
- this.emitLine("instance FromJSON ", className, " where");
277
- this.indent(() => {
278
- if (this.classPropertyLength(c) === 0) {
279
- this.emitLine("parseJSON emptyObject = return ", className);
280
- }
281
- else {
282
- this.emitLine("parseJSON (Object v) = ", className);
283
- this.indent(() => {
284
- let onFirst = true;
285
- this.forEachClassProperty(c, "none", (_, jsonName, p) => {
286
- const operator = p.isOptional ? ".:?" : ".:";
287
- this.emitLine(onFirst ? "<$> " : "<*> ", "v ", operator, ' "', (0, Strings_1.stringEscape)(jsonName), '"');
288
- onFirst = false;
289
- });
290
- });
291
- }
292
- });
293
- }
294
- emitClassFunctions(c, className) {
295
- this.emitClassEncoderInstance(c, className);
296
- this.ensureBlankLine();
297
- this.emitClassDecoderInstance(c, className);
298
- }
299
- emitEnumEncoderInstance(e, enumName) {
300
- this.emitLine("instance ToJSON ", enumName, " where");
301
- this.indent(() => {
302
- this.forEachEnumCase(e, "none", (name, jsonName) => {
303
- this.emitLine("toJSON ", name, enumName, ' = "', (0, Strings_1.stringEscape)(jsonName), '"');
304
- });
305
- });
306
- }
307
- emitEnumDecoderInstance(e, enumName) {
308
- this.emitLine("instance FromJSON ", enumName, " where");
309
- this.indent(() => {
310
- this.emitLine('parseJSON = withText "', enumName, '" parseText');
311
- this.indent(() => {
312
- this.emitLine("where");
313
- this.indent(() => {
314
- this.forEachEnumCase(e, "none", (name, jsonName) => {
315
- this.emitLine('parseText "', (0, Strings_1.stringEscape)(jsonName), '" = return ', name, enumName);
316
- });
317
- });
318
- });
319
- });
320
- }
321
- emitEnumFunctions(e, enumName) {
322
- this.emitEnumEncoderInstance(e, enumName);
323
- this.ensureBlankLine();
324
- this.emitEnumDecoderInstance(e, enumName);
325
- }
326
- emitUnionEncoderInstance(u, unionName) {
327
- this.emitLine("instance ToJSON ", unionName, " where");
328
- this.indent(() => {
329
- this.forEachUnionMember(u, null, "none", null, (constructor, t) => {
330
- if (t.kind === "null") {
331
- this.emitLine("toJSON ", constructor, " = Null");
332
- }
333
- else {
334
- this.emitLine("toJSON (", constructor, " x) = toJSON x");
335
- }
336
- });
337
- });
338
- }
339
- emitUnionDecoderInstance(u, unionName) {
340
- this.emitLine("instance FromJSON ", unionName, " where");
341
- this.indent(() => {
342
- this.forEachUnionMember(u, null, "none", null, (constructor, t) => {
343
- if (t.kind === "null") {
344
- this.emitLine("parseJSON Null = return ", constructor);
345
- }
346
- else {
347
- this.emitLine("parseJSON xs@(", this.encoderNameForType(t).source, " _) = (fmap ", constructor, " . parseJSON) xs");
348
- }
349
- });
350
- });
351
- }
352
- emitUnionFunctions(u, unionName) {
353
- this.emitUnionEncoderInstance(u, unionName);
354
- this.ensureBlankLine();
355
- this.emitUnionDecoderInstance(u, unionName);
356
- }
357
- emitLanguageExtensions(ext) {
358
- this.emitLine(`{-# LANGUAGE ${ext} #-}`);
359
- }
360
- emitSourceStructure() {
361
- const exports = [];
362
- this.forEachTopLevel("none", (_, name) => {
363
- exports.push([name, " (..)"]);
364
- });
365
- this.forEachObject("none", (t, name) => {
366
- if (!(0, collection_utils_1.mapContains)(this.topLevels, t))
367
- exports.push([name, " (..)"]);
368
- });
369
- this.forEachEnum("none", (t, name) => {
370
- if (!(0, collection_utils_1.mapContains)(this.topLevels, t))
371
- exports.push([name, " (..)"]);
372
- });
373
- this.forEachUnion("none", (t, name) => {
374
- if (!(0, collection_utils_1.mapContains)(this.topLevels, t))
375
- exports.push([name, " (..)"]);
376
- });
377
- this.emitLanguageExtensions("StrictData");
378
- this.emitLanguageExtensions("OverloadedStrings");
379
- if (!this._options.justTypes) {
380
- this.ensureBlankLine();
381
- this.emitLine("module ", this._options.moduleName);
382
- this.indent(() => {
383
- for (let i = 0; i < exports.length; i++) {
384
- this.emitLine(i === 0 ? "(" : ",", " ", exports[i]);
385
- }
386
- this.emitLine(", decodeTopLevel");
387
- this.emitLine(") where");
388
- });
389
- this.ensureBlankLine();
390
- this.emitMultiline(`import Data.Aeson
391
- import Data.Aeson.Types (emptyObject)
392
- import Data.ByteString.Lazy (ByteString)
393
- import Data.HashMap.Strict (HashMap)
394
- import Data.Text (Text)`);
395
- if (this._options.useList) {
396
- // this.emitLine("import List (map)");
397
- }
398
- else {
399
- this.emitLine("import Data.Vector (Vector)");
400
- }
401
- }
402
- this.forEachTopLevel("leading-and-interposing", (t, topLevelName) => this.emitTopLevelDefinition(t, topLevelName), t => this.namedTypeToNameForTopLevel(t) === undefined);
403
- this.forEachNamedType("leading-and-interposing", (c, className) => this.emitClassDefinition(c, className), (e, enumName) => this.emitEnumDefinition(e, enumName), (u, unionName) => this.emitUnionDefinition(u, unionName));
404
- this.forEachTopLevel("leading-and-interposing", (_, topLevelName) => this.emitTopLevelFunctions(topLevelName));
405
- this.forEachNamedType("leading-and-interposing", (c, className) => this.emitClassFunctions(c, className), (e, enumName) => this.emitEnumFunctions(e, enumName), (u, unionName) => this.emitUnionFunctions(u, unionName));
406
- if (this._options.justTypes)
407
- return;
408
- this.ensureBlankLine();
409
- }
410
- }
411
- exports.HaskellRenderer = HaskellRenderer;
@@ -1,31 +0,0 @@
1
- import { TargetLanguage } from "../TargetLanguage";
2
- import { ConvenienceRenderer } from "../ConvenienceRenderer";
3
- import { Namer } from "../Naming";
4
- import { StringTypeMapping } from "../TypeBuilder";
5
- import { Option } from "../RendererOptions";
6
- import { RenderContext } from "../Renderer";
7
- export declare class JSONSchemaTargetLanguage extends TargetLanguage {
8
- constructor();
9
- protected getOptions(): Option<any>[];
10
- get stringTypeMapping(): StringTypeMapping;
11
- get supportsOptionalClassProperties(): boolean;
12
- get supportsFullObjectType(): boolean;
13
- protected makeRenderer(renderContext: RenderContext, _untypedOptionValues: {
14
- [name: string]: any;
15
- }): JSONSchemaRenderer;
16
- }
17
- export declare class JSONSchemaRenderer extends ConvenienceRenderer {
18
- protected makeNamedTypeNamer(): Namer;
19
- protected namerForObjectProperty(): null;
20
- protected makeUnionMemberNamer(): null;
21
- protected makeEnumCaseNamer(): null;
22
- private nameForType;
23
- private makeOneOf;
24
- private makeRef;
25
- private addAttributesToSchema;
26
- private schemaForType;
27
- private definitionForObject;
28
- private definitionForUnion;
29
- private definitionForEnum;
30
- protected emitSourceStructure(): void;
31
- }
@@ -1,169 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JSONSchemaRenderer = exports.JSONSchemaTargetLanguage = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const TargetLanguage_1 = require("../TargetLanguage");
6
- const Type_1 = require("../Type");
7
- const TypeUtils_1 = require("../TypeUtils");
8
- const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
9
- const Naming_1 = require("../Naming");
10
- const Strings_1 = require("../support/Strings");
11
- const Support_1 = require("../support/Support");
12
- const TypeBuilder_1 = require("../TypeBuilder");
13
- const Description_1 = require("../attributes/Description");
14
- class JSONSchemaTargetLanguage extends TargetLanguage_1.TargetLanguage {
15
- constructor() {
16
- super("JSON Schema", ["schema", "json-schema"], "schema");
17
- }
18
- getOptions() {
19
- return [];
20
- }
21
- get stringTypeMapping() {
22
- return (0, TypeBuilder_1.getNoStringTypeMapping)();
23
- }
24
- get supportsOptionalClassProperties() {
25
- return true;
26
- }
27
- get supportsFullObjectType() {
28
- return true;
29
- }
30
- makeRenderer(renderContext, _untypedOptionValues) {
31
- return new JSONSchemaRenderer(this, renderContext);
32
- }
33
- }
34
- exports.JSONSchemaTargetLanguage = JSONSchemaTargetLanguage;
35
- const namingFunction = (0, Naming_1.funPrefixNamer)("namer", jsonNameStyle);
36
- const legalizeName = (0, Strings_1.legalizeCharacters)(cp => cp >= 32 && cp < 128 && cp !== 0x2f /* slash */);
37
- function jsonNameStyle(original) {
38
- const words = (0, Strings_1.splitIntoWords)(original);
39
- return (0, Strings_1.combineWords)(words, legalizeName, Strings_1.firstUpperWordStyle, Strings_1.firstUpperWordStyle, Strings_1.allUpperWordStyle, Strings_1.allUpperWordStyle, "", _ => true);
40
- }
41
- class JSONSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
42
- makeNamedTypeNamer() {
43
- return namingFunction;
44
- }
45
- namerForObjectProperty() {
46
- return null;
47
- }
48
- makeUnionMemberNamer() {
49
- return null;
50
- }
51
- makeEnumCaseNamer() {
52
- return null;
53
- }
54
- nameForType(t) {
55
- return (0, Support_1.defined)(this.names.get(this.nameForNamedType(t)));
56
- }
57
- makeOneOf(types) {
58
- const first = (0, collection_utils_1.iterableFirst)(types);
59
- if (first === undefined) {
60
- return (0, Support_1.panic)("Must have at least one type for oneOf");
61
- }
62
- if (types.size === 1) {
63
- return this.schemaForType(first);
64
- }
65
- return { anyOf: Array.from(types).map((t) => this.schemaForType(t)) };
66
- }
67
- makeRef(t) {
68
- return { $ref: `#/definitions/${this.nameForType(t)}` };
69
- }
70
- addAttributesToSchema(t, schema) {
71
- const attributes = this.typeGraph.attributeStore.attributesForType(t);
72
- for (const [kind, attr] of attributes) {
73
- kind.addToSchema(schema, t, attr);
74
- }
75
- }
76
- schemaForType(t) {
77
- const schema = (0, TypeUtils_1.matchTypeExhaustive)(t, _noneType => {
78
- return (0, Support_1.panic)("none type should have been replaced");
79
- }, _anyType => ({}), _nullType => ({ type: "null" }), _boolType => ({ type: "boolean" }), _integerType => ({ type: "integer" }), _doubleType => ({ type: "number" }), _stringType => ({ type: "string" }), arrayType => ({ type: "array", items: this.schemaForType(arrayType.items) }), classType => this.makeRef(classType), mapType => this.definitionForObject(mapType, undefined), objectType => this.makeRef(objectType), enumType => this.makeRef(enumType), unionType => {
80
- if (this.unionNeedsName(unionType)) {
81
- return this.makeRef(unionType);
82
- }
83
- else {
84
- return this.definitionForUnion(unionType);
85
- }
86
- }, transformedStringType => {
87
- const target = Type_1.transformedStringTypeTargetTypeKindsMap.get(transformedStringType.kind);
88
- if (target === undefined) {
89
- return (0, Support_1.panic)(`Unknown transformed string type ${transformedStringType.kind}`);
90
- }
91
- return { type: "string", format: target.jsonSchema };
92
- });
93
- if (schema.$ref === undefined) {
94
- this.addAttributesToSchema(t, schema);
95
- }
96
- return schema;
97
- }
98
- definitionForObject(o, title) {
99
- let properties;
100
- let required;
101
- if (o.getProperties().size === 0) {
102
- properties = undefined;
103
- required = undefined;
104
- }
105
- else {
106
- const props = {};
107
- const req = [];
108
- for (const [name, p] of o.getProperties()) {
109
- const prop = this.schemaForType(p.type);
110
- if (prop.description === undefined) {
111
- (0, Description_1.addDescriptionToSchema)(prop, this.descriptionForClassProperty(o, name));
112
- }
113
- props[name] = prop;
114
- if (!p.isOptional) {
115
- req.push(name);
116
- }
117
- }
118
- properties = props;
119
- required = req.sort();
120
- }
121
- const additional = o.getAdditionalProperties();
122
- const additionalProperties = additional !== undefined ? this.schemaForType(additional) : false;
123
- const schema = {
124
- type: "object",
125
- additionalProperties,
126
- properties,
127
- required,
128
- title
129
- };
130
- this.addAttributesToSchema(o, schema);
131
- return schema;
132
- }
133
- definitionForUnion(u, title) {
134
- const oneOf = this.makeOneOf(u.sortedMembers);
135
- if (title !== undefined) {
136
- oneOf.title = title;
137
- }
138
- this.addAttributesToSchema(u, oneOf);
139
- return oneOf;
140
- }
141
- definitionForEnum(e, title) {
142
- const schema = { type: "string", enum: Array.from(e.cases), title };
143
- this.addAttributesToSchema(e, schema);
144
- return schema;
145
- }
146
- emitSourceStructure() {
147
- // FIXME: Find a good way to do multiple top-levels. Maybe multiple files?
148
- const topLevelType = this.topLevels.size === 1 ? this.schemaForType((0, Support_1.defined)((0, collection_utils_1.mapFirst)(this.topLevels))) : {};
149
- const schema = Object.assign({ $schema: "http://json-schema.org/draft-06/schema#" }, topLevelType);
150
- const definitions = {};
151
- this.forEachObject("none", (o, name) => {
152
- const title = (0, Support_1.defined)(this.names.get(name));
153
- definitions[title] = this.definitionForObject(o, title);
154
- });
155
- this.forEachUnion("none", (u, name) => {
156
- if (!this.unionNeedsName(u))
157
- return;
158
- const title = (0, Support_1.defined)(this.names.get(name));
159
- definitions[title] = this.definitionForUnion(u, title);
160
- });
161
- this.forEachEnum("none", (e, name) => {
162
- const title = (0, Support_1.defined)(this.names.get(name));
163
- definitions[title] = this.definitionForEnum(e, title);
164
- });
165
- schema.definitions = definitions;
166
- this.emitMultiline(JSON.stringify(schema, undefined, " "));
167
- }
168
- }
169
- exports.JSONSchemaRenderer = JSONSchemaRenderer;