quicktype-core 23.0.94 → 23.0.96

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,6 +5,7 @@ import { Sourcelike } from "./Source";
5
5
  import { Declaration } from "./DeclarationIR";
6
6
  import { Transformation } from "./Transformers";
7
7
  import { TargetLanguage } from "./TargetLanguage";
8
+ import { type Comment, type CommentOptions } from "./support/Comments";
8
9
  export declare const topLevelNameOrder = 1;
9
10
  export declare const inferredNameOrder = 30;
10
11
  export type ForbiddenWordsInfo = {
@@ -128,7 +129,8 @@ export declare abstract class ConvenienceRenderer extends Renderer {
128
129
  protected forEachNamedType(blankLocations: BlankLineConfig, objectFunc: ((c: ClassType, className: Name, position: ForEachPosition) => void) | ((o: ObjectType, objectName: Name, position: ForEachPosition) => void), enumFunc: (e: EnumType, enumName: Name, position: ForEachPosition) => void, unionFunc: (u: UnionType, unionName: Name, position: ForEachPosition) => void): void;
129
130
  protected sourcelikeToString(src: Sourcelike): string;
130
131
  protected get commentLineStart(): string;
131
- protected emitCommentLines(lines: Sourcelike[], lineStart?: string, beforeLine?: string, afterLine?: string, firstLineStart?: string): void;
132
+ protected emitComments(comments: Comment[]): void;
133
+ protected emitCommentLines(lines: Sourcelike[], { lineStart, firstLineStart, lineEnd, beforeComment, afterComment }?: CommentOptions): void;
132
134
  protected emitDescription(description: Sourcelike[] | undefined): void;
133
135
  protected emitDescriptionBlock(lines: Sourcelike[]): void;
134
136
  protected emitPropertyTable(c: ClassType, makePropertyRow: (name: Name, jsonName: string, p: ClassProperty) => Sourcelike[]): void;
@@ -15,6 +15,7 @@ const TypeAttributes_1 = require("./attributes/TypeAttributes");
15
15
  const Description_1 = require("./attributes/Description");
16
16
  const AccessorNames_1 = require("./attributes/AccessorNames");
17
17
  const Transformers_1 = require("./Transformers");
18
+ const Comments_1 = require("./support/Comments");
18
19
  const wordWrap = require("wordwrap")(90);
19
20
  exports.topLevelNameOrder = 1;
20
21
  const givenNameOrder = 10;
@@ -548,27 +549,43 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
548
549
  get commentLineStart() {
549
550
  return "// ";
550
551
  }
551
- emitCommentLines(lines, lineStart, beforeLine, afterLine, firstLineStart) {
552
- if (lineStart === undefined) {
553
- lineStart = this.commentLineStart;
554
- }
555
- if (firstLineStart === undefined) {
556
- firstLineStart = lineStart;
557
- }
558
- if (beforeLine !== undefined) {
559
- this.emitLine(beforeLine);
552
+ emitComments(comments) {
553
+ comments.forEach(comment => {
554
+ if ((0, Comments_1.isStringComment)(comment)) {
555
+ this.emitCommentLines([comment]);
556
+ }
557
+ else if ("lines" in comment) {
558
+ this.emitCommentLines(comment.lines);
559
+ }
560
+ else if ("descriptionBlock" in comment) {
561
+ this.emitDescriptionBlock(comment.descriptionBlock);
562
+ }
563
+ else {
564
+ this.emitCommentLines(comment.customLines, comment);
565
+ }
566
+ this.ensureBlankLine();
567
+ });
568
+ }
569
+ emitCommentLines(lines, { lineStart = this.commentLineStart, firstLineStart = lineStart, lineEnd, beforeComment, afterComment } = {}) {
570
+ if (beforeComment !== undefined) {
571
+ this.emitLine(beforeComment);
560
572
  }
561
573
  let first = true;
562
574
  for (const line of lines) {
563
575
  let start = first ? firstLineStart : lineStart;
576
+ first = false;
564
577
  if (this.sourcelikeToString(line) === "") {
565
578
  start = (0, Strings_1.trimEnd)(start);
566
579
  }
567
- this.emitLine(start, line);
568
- first = false;
580
+ if (lineEnd) {
581
+ this.emitLine(start, line, lineEnd);
582
+ }
583
+ else {
584
+ this.emitLine(start, line);
585
+ }
569
586
  }
570
- if (afterLine !== undefined) {
571
- this.emitLine(afterLine);
587
+ if (afterComment !== undefined) {
588
+ this.emitLine(afterComment);
572
589
  }
573
590
  }
574
591
  emitDescription(description) {
@@ -3,6 +3,7 @@ import { Name, Namespace } from "./Naming";
3
3
  import { Source, Sourcelike } from "./Source";
4
4
  import { AnnotationData } from "./Annotation";
5
5
  import { TargetLanguage } from "./TargetLanguage";
6
+ import { type Comment } from "./support/Comments";
6
7
  export type RenderResult = {
7
8
  sources: ReadonlyMap<string, Source>;
8
9
  names: ReadonlyMap<Name, string>;
@@ -11,13 +12,13 @@ export type BlankLinePosition = "none" | "interposing" | "leading" | "leading-an
11
12
  export type BlankLineConfig = BlankLinePosition | [BlankLinePosition, number];
12
13
  export type RenderContext = {
13
14
  typeGraph: TypeGraph;
14
- leadingComments: string[] | undefined;
15
+ leadingComments?: Comment[];
15
16
  };
16
17
  export type ForEachPosition = "first" | "last" | "middle" | "only";
17
18
  export declare abstract class Renderer {
18
19
  protected readonly targetLanguage: TargetLanguage;
19
20
  protected readonly typeGraph: TypeGraph;
20
- protected readonly leadingComments: string[] | undefined;
21
+ protected readonly leadingComments: Comment[] | undefined;
21
22
  private _names;
22
23
  private _finishedFiles;
23
24
  private _finishedEmitContexts;
package/dist/Run.d.ts CHANGED
@@ -3,6 +3,7 @@ import { SerializedRenderResult } from "./Source";
3
3
  import { StringTypeMapping } from "./TypeBuilder";
4
4
  import { InputData } from "./input/Inputs";
5
5
  import { TransformedStringTypeKind } from "./Type";
6
+ import { type Comment } from "./support/Comments";
6
7
  export declare function getTargetLanguage(nameOrInstance: string | TargetLanguage): TargetLanguage;
7
8
  export type RendererOptions = {
8
9
  [name: string]: string | boolean;
@@ -109,7 +110,7 @@ export type NonInferenceOptions = {
109
110
  /** Don't render output. This is mainly useful for benchmarking. */
110
111
  noRender: boolean;
111
112
  /** If given, output these comments at the beginning of the main output file */
112
- leadingComments: string[] | undefined;
113
+ leadingComments?: Comment[];
113
114
  /** Options for the target language's renderer */
114
115
  rendererOptions: RendererOptions;
115
116
  /** String to use for one indentation level. If not given, use the target language's default. */
@@ -5,6 +5,7 @@ import { SerializedRenderResult } from "./Source";
5
5
  import { StringTypeMapping } from "./TypeBuilder";
6
6
  import { Type } from "./Type";
7
7
  import { DateTimeRecognizer } from "./DateTime";
8
+ import { type Comment } from "./support/Comments";
8
9
  export type MultiFileRenderResult = ReadonlyMap<string, SerializedRenderResult>;
9
10
  export declare abstract class TargetLanguage {
10
11
  readonly displayName: string;
@@ -21,7 +22,7 @@ export declare abstract class TargetLanguage {
21
22
  protected abstract makeRenderer(renderContext: RenderContext, optionValues: {
22
23
  [name: string]: any;
23
24
  }): Renderer;
24
- renderGraphAndSerialize(typeGraph: TypeGraph, givenOutputFilename: string, alphabetizeProperties: boolean, leadingComments: string[] | undefined, rendererOptions: {
25
+ renderGraphAndSerialize(typeGraph: TypeGraph, givenOutputFilename: string, alphabetizeProperties: boolean, leadingComments: Comment[] | undefined, rendererOptions: {
25
26
  [name: string]: any;
26
27
  }, indentation?: string): MultiFileRenderResult;
27
28
  protected get defaultIndentation(): string;
@@ -2390,7 +2390,7 @@ class CJSONRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
2390
2390
  * @param lines: description block lines
2391
2391
  */
2392
2392
  emitDescriptionBlock(lines) {
2393
- this.emitCommentLines(lines, " * ", "/**", " */");
2393
+ this.emitCommentLines(lines, { lineStart: " * ", beforeComment: "/**", afterComment: " */" });
2394
2394
  }
2395
2395
  /**
2396
2396
  * Emit code block
@@ -667,7 +667,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
667
667
  this._currentFilename = this.sourcelikeToString(basename);
668
668
  }
669
669
  if (this.leadingComments !== undefined) {
670
- this.emitCommentLines(this.leadingComments);
670
+ this.emitComments(this.leadingComments);
671
671
  }
672
672
  else if (!this._options.justTypes) {
673
673
  this.emitCommentLines([" To parse this JSON data, first install", ""]);
@@ -741,7 +741,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
741
741
  return kind === "class";
742
742
  }
743
743
  emitDescriptionBlock(lines) {
744
- this.emitCommentLines(lines, " * ", "/**", " */");
744
+ this.emitCommentLines(lines, { lineStart: " * ", beforeComment: "/**", afterComment: " */" });
745
745
  }
746
746
  emitBlock(line, withSemicolon, f, withIndent = true) {
747
747
  this.emitLine(line, " {");
@@ -419,7 +419,7 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
419
419
  this.emitLine(start, lines.join("; "), "</summary>");
420
420
  }
421
421
  else {
422
- this.emitCommentLines(lines, "/// ", start, "/// </summary>");
422
+ this.emitCommentLines(lines, { lineStart: "/// ", beforeComment: start, afterComment: "/// </summary>" });
423
423
  }
424
424
  }
425
425
  blankLinesBetweenAttributes() {
@@ -562,7 +562,7 @@ class CSharpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
562
562
  }
563
563
  emitSourceStructure() {
564
564
  if (this.leadingComments !== undefined) {
565
- this.emitCommentLines(this.leadingComments);
565
+ this.emitComments(this.leadingComments);
566
566
  }
567
567
  else {
568
568
  this.emitDefaultLeadingComments();
@@ -297,7 +297,7 @@ class CrystalRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
297
297
  }
298
298
  emitLeadingComments() {
299
299
  if (this.leadingComments !== undefined) {
300
- this.emitCommentLines(this.leadingComments);
300
+ this.emitComments(this.leadingComments);
301
301
  return;
302
302
  }
303
303
  }
@@ -226,7 +226,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
226
226
  }
227
227
  emitFileHeader() {
228
228
  if (this.leadingComments !== undefined) {
229
- this.emitCommentLines(this.leadingComments);
229
+ this.emitComments(this.leadingComments);
230
230
  }
231
231
  if (this._options.justTypes)
232
232
  return;
@@ -267,7 +267,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
267
267
  }
268
268
  }
269
269
  emitDescriptionBlock(lines) {
270
- this.emitCommentLines(lines, "///", "");
270
+ this.emitCommentLines(lines, { lineStart: "///", beforeComment: "" });
271
271
  }
272
272
  emitBlock(line, f) {
273
273
  this.emitLine(line, " {");
@@ -157,10 +157,10 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
157
157
  }
158
158
  emitDescriptionBlock(lines) {
159
159
  if (lines.length === 1) {
160
- this.emitLine("{-| ", lines[0], " -}");
160
+ this.emitComments([{ customLines: lines, lineStart: "{-| ", lineEnd: " -}" }]);
161
161
  }
162
162
  else {
163
- this.emitCommentLines(lines, "", undefined, "-}", "{-| ");
163
+ this.emitCommentLines(lines, { firstLineStart: "{-| ", lineStart: "", afterComment: "-}" });
164
164
  }
165
165
  }
166
166
  get arrayType() {
@@ -445,7 +445,7 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
445
445
  exports.push([name, "(..)"]);
446
446
  });
447
447
  if (this.leadingComments !== undefined) {
448
- this.emitCommentLines(this.leadingComments);
448
+ this.emitComments(this.leadingComments);
449
449
  }
450
450
  else if (!this._options.justTypes) {
451
451
  this.emitCommentLines([
@@ -134,10 +134,14 @@ class HaskellRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
134
134
  }
135
135
  emitDescriptionBlock(lines) {
136
136
  if (lines.length === 1) {
137
- this.emitLine("{-| ", lines[0], " -}");
137
+ this.emitComments([{ customLines: lines, lineStart: "{-| ", lineEnd: " -}" }]);
138
138
  }
139
139
  else {
140
- this.emitCommentLines(lines, "", undefined, "-}", "{-| ");
140
+ this.emitCommentLines(lines, {
141
+ firstLineStart: "{-| ",
142
+ lineStart: "",
143
+ afterComment: "-}"
144
+ });
141
145
  }
142
146
  }
143
147
  haskellType(t, noOptional = false) {
@@ -418,7 +418,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
418
418
  // FIXME: Why is this necessary?
419
419
  this.ensureBlankLine();
420
420
  if (!this._haveEmittedLeadingComments && this.leadingComments !== undefined) {
421
- this.emitCommentLines(this.leadingComments);
421
+ this.emitComments(this.leadingComments);
422
422
  this.ensureBlankLine();
423
423
  this._haveEmittedLeadingComments = true;
424
424
  }
@@ -440,7 +440,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
440
440
  this.ensureBlankLine();
441
441
  }
442
442
  emitDescriptionBlock(lines) {
443
- this.emitCommentLines(lines, " * ", "/**", " */");
443
+ this.emitCommentLines(lines, { lineStart: " * ", beforeComment: "/**", afterComment: " */" });
444
444
  }
445
445
  emitBlock(line, f) {
446
446
  this.emitLine(line, " {");
@@ -86,7 +86,7 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
86
86
  return super.makeNameForProperty(c, className, p, jsonName, undefined);
87
87
  }
88
88
  emitDescriptionBlock(lines) {
89
- this.emitCommentLines(lines, " * ", "/**", " */");
89
+ this.emitCommentLines(lines, { lineStart: " * ", beforeComment: "/**", afterComment: " */" });
90
90
  }
91
91
  typeMapTypeFor(t) {
92
92
  if (["class", "object", "enum"].indexOf(t.kind) >= 0) {
@@ -420,7 +420,7 @@ function r(name${stringAnnotation}) {
420
420
  }
421
421
  emitSourceStructure() {
422
422
  if (this.leadingComments !== undefined) {
423
- this.emitCommentLines(this.leadingComments);
423
+ this.emitComments(this.leadingComments);
424
424
  }
425
425
  else {
426
426
  this.emitUsageComments();
@@ -104,7 +104,7 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
104
104
  "MyComponent.propTypes = {",
105
105
  " input: MyShape",
106
106
  "};"
107
- ], "// ");
107
+ ], { lineStart: "// " });
108
108
  }
109
109
  emitBlock(source, end, emit) {
110
110
  this.emitLine(source, "{");
@@ -200,7 +200,7 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
200
200
  }
201
201
  emitSourceStructure() {
202
202
  if (this.leadingComments !== undefined) {
203
- this.emitCommentLines(this.leadingComments);
203
+ this.emitComments(this.leadingComments);
204
204
  }
205
205
  else {
206
206
  this.emitUsageComments();
@@ -163,7 +163,7 @@ class KotlinRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
163
163
  return (0, Naming_1.funPrefixNamer)("upper", s => kotlinNameStyle(true, s, (0, Acronyms_1.acronymStyle)(this._kotlinOptions.acronymStyle)));
164
164
  }
165
165
  emitDescriptionBlock(lines) {
166
- this.emitCommentLines(lines, " * ", "/**", " */");
166
+ this.emitCommentLines(lines, { lineStart: " * ", beforeComment: "/**", afterComment: " */" });
167
167
  }
168
168
  emitBlock(line, f, delimiter = "curly") {
169
169
  const [open, close] = delimiter === "curly" ? ["{", "}"] : delimiter === "paren" ? ["(", ")"] : ["{", "})"];
@@ -200,7 +200,7 @@ class KotlinRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
200
200
  }
201
201
  emitHeader() {
202
202
  if (this.leadingComments !== undefined) {
203
- this.emitCommentLines(this.leadingComments);
203
+ this.emitComments(this.leadingComments);
204
204
  }
205
205
  else {
206
206
  this.emitUsageHeader();
@@ -224,7 +224,7 @@ class ObjectiveCRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
224
224
  return type;
225
225
  }
226
226
  emitDescriptionBlock(lines) {
227
- this.emitCommentLines(lines, "/// ");
227
+ this.emitCommentLines(lines, { lineStart: "/// " });
228
228
  }
229
229
  emitBlock(line, f) {
230
230
  this.emitLine(line, " {");
@@ -665,7 +665,7 @@ class ObjectiveCRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
665
665
  if (this._options.features.interface) {
666
666
  this.startFile(filename, "h");
667
667
  if (this.leadingComments !== undefined) {
668
- this.emitCommentLines(this.leadingComments);
668
+ this.emitComments(this.leadingComments);
669
669
  }
670
670
  else if (!this._options.justTypes) {
671
671
  this.emitCommentLines(["To parse this JSON:", ""]);
@@ -150,7 +150,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
150
150
  startFile(_basename) {
151
151
  this.ensureBlankLine();
152
152
  if (!this._haveEmittedLeadingComments && this.leadingComments !== undefined) {
153
- this.emitCommentLines(this.leadingComments);
153
+ this.emitComments(this.leadingComments);
154
154
  this.ensureBlankLine();
155
155
  this._haveEmittedLeadingComments = true;
156
156
  }
@@ -164,7 +164,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
164
164
  this.ensureBlankLine();
165
165
  }
166
166
  emitDescriptionBlock(lines) {
167
- this.emitCommentLines(lines, " * ", "/**", " */");
167
+ this.emitCommentLines(lines, { lineStart: " * ", beforeComment: "/**", afterComment: " */" });
168
168
  }
169
169
  emitBlock(line, f) {
170
170
  this.emitLine(line, " {");
@@ -219,7 +219,7 @@ class PikeRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
219
219
  "Bear in mind that these functions have unexpected behavior,",
220
220
  "and will likely throw an error, if the JSON string does not",
221
221
  "match the expected interface, even if the JSON itself is valid."
222
- ], "// ");
222
+ ], { lineStart: "// " });
223
223
  }
224
224
  emitTopLevelTypedef(t, name) {
225
225
  this.emitLine("typedef ", this.sourceFor(t).source, " ", name, ";");
@@ -206,10 +206,14 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
206
206
  }
207
207
  return content;
208
208
  }, lines[0]);
209
- this.emitLine('"""', docstring, '"""');
209
+ this.emitComments([{ customLines: [docstring], lineStart: '"""', lineEnd: '"""' }]);
210
210
  }
211
211
  else {
212
- this.emitCommentLines(lines, "", undefined, '"""', '"""');
212
+ this.emitCommentLines(lines, {
213
+ firstLineStart: '"""',
214
+ lineStart: "",
215
+ afterComment: '"""'
216
+ });
213
217
  }
214
218
  }
215
219
  get needsTypeDeclarationBeforeUse() {
@@ -389,7 +393,7 @@ class PythonRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
389
393
  const closingLines = this.gatherSource(() => this.emitClosingCode());
390
394
  const supportLines = this.gatherSource(() => this.emitSupportCode());
391
395
  if (this.leadingComments !== undefined) {
392
- this.emitCommentLines(this.leadingComments);
396
+ this.emitComments(this.leadingComments);
393
397
  }
394
398
  this.ensureBlankLine();
395
399
  this.emitImports();
@@ -356,7 +356,7 @@ class RustRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
356
356
  }
357
357
  emitLeadingComments() {
358
358
  if (this.leadingComments !== undefined) {
359
- this.emitCommentLines(this.leadingComments);
359
+ this.emitComments(this.leadingComments);
360
360
  return;
361
361
  }
362
362
  const topLevelName = (0, Support_1.defined)((0, collection_utils_1.mapFirst)(this.topLevels)).getCombinedName();
@@ -21,7 +21,7 @@ exports.scala3Options = {
21
21
  framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [
22
22
  ["just-types", Framework.None],
23
23
  ["circe", Framework.Circe],
24
- ["upickle", Framework.Upickle],
24
+ ["upickle", Framework.Upickle]
25
25
  ], undefined),
26
26
  packageName: new RendererOptions_1.StringOption("package", "Package", "PACKAGE", "quicktype")
27
27
  };
@@ -116,7 +116,10 @@ const keywords = [
116
116
  * @param paramName
117
117
  */
118
118
  const shouldAddBacktick = (paramName) => {
119
- return keywords.some(s => paramName === s) || invalidSymbols.some(s => paramName.includes(s)) || !isNaN(+parseFloat(paramName)) || !isNaN(parseInt(paramName.charAt(0)));
119
+ return (keywords.some(s => paramName === s) ||
120
+ invalidSymbols.some(s => paramName.includes(s)) ||
121
+ !isNaN(+parseFloat(paramName)) ||
122
+ !isNaN(parseInt(paramName.charAt(0))));
120
123
  };
121
124
  const wrapOption = (s, optional) => {
122
125
  if (optional) {
@@ -180,7 +183,7 @@ class Scala3Renderer extends ConvenienceRenderer_1.ConvenienceRenderer {
180
183
  return (0, Naming_1.funPrefixNamer)("upper", s => s.replace(" ", "")); // TODO - add backticks where appropriate
181
184
  }
182
185
  emitDescriptionBlock(lines) {
183
- this.emitCommentLines(lines, " * ", "/**", " */");
186
+ this.emitCommentLines(lines, { lineStart: " * ", beforeComment: "/**", afterComment: " */" });
184
187
  }
185
188
  emitBlock(line, f, delimiter = "curly") {
186
189
  const [open, close] = delimiter === "curly"
@@ -229,7 +232,7 @@ class Scala3Renderer extends ConvenienceRenderer_1.ConvenienceRenderer {
229
232
  }
230
233
  emitHeader() {
231
234
  if (this.leadingComments !== undefined) {
232
- this.emitCommentLines(this.leadingComments);
235
+ this.emitComments(this.leadingComments);
233
236
  }
234
237
  else {
235
238
  this.emitUsageHeader();
@@ -304,7 +307,6 @@ class Scala3Renderer extends ConvenienceRenderer_1.ConvenienceRenderer {
304
307
  if (count > 0) {
305
308
  this.emitItem("\t case ");
306
309
  }
307
- ;
308
310
  this.forEachEnumCase(e, "none", (name, jsonName) => {
309
311
  if (!(jsonName == "")) {
310
312
  const backticks = shouldAddBacktick(jsonName) ||
@@ -377,7 +379,7 @@ exports.UpickleRenderer = UpickleRenderer;
377
379
  class Smithy4sRenderer extends Scala3Renderer {
378
380
  emitHeader() {
379
381
  if (this.leadingComments !== undefined) {
380
- this.emitCommentLines(this.leadingComments);
382
+ this.emitComments(this.leadingComments);
381
383
  }
382
384
  else {
383
385
  this.emitUsageHeader();
@@ -404,20 +406,20 @@ class Smithy4sRenderer extends Scala3Renderer {
404
406
  this.emitItem(["enum ", enumName, " { "]);
405
407
  let count = e.cases.size;
406
408
  this.forEachEnumCase(e, "none", (name, jsonName) => {
407
- // if (!(jsonName == "")) {
409
+ // if (!(jsonName == "")) {
408
410
  /* const backticks =
409
411
  shouldAddBacktick(jsonName) ||
410
412
  jsonName.includes(" ") ||
411
413
  !isNaN(parseInt(jsonName.charAt(0)))
412
414
  if (backticks) {this.emitItem("`")} else */
413
415
  this.emitLine();
414
- this.emitItem([name, " = \"", jsonName, "\""]);
416
+ this.emitItem([name, ' = "', jsonName, '"']);
415
417
  // if (backticks) {this.emitItem("`")}
416
418
  if (--count > 0)
417
419
  this.emitItem([","]);
418
420
  //} else {
419
421
  //--count
420
- //}
422
+ //}
421
423
  });
422
424
  this.ensureBlankLine();
423
425
  this.emitItem(["}"]);
@@ -466,13 +468,13 @@ class CirceRenderer extends Scala3Renderer {
466
468
  jsonName.includes(" ") ||
467
469
  !isNaN(parseInt(jsonName.charAt(0)))
468
470
  if (backticks) {this.emitItem("`")} else */
469
- this.emitItem(["\"", jsonName, "\""]);
471
+ this.emitItem(['"', jsonName, '"']);
470
472
  // if (backticks) {this.emitItem("`")}
471
473
  if (--count > 0)
472
474
  this.emitItem([" | "]);
473
475
  //} else {
474
476
  //--count
475
- //}
477
+ //}
476
478
  });
477
479
  this.ensureBlankLine();
478
480
  }
@@ -493,13 +495,29 @@ class CirceRenderer extends Scala3Renderer {
493
495
  emitTopLevelArray(t, name) {
494
496
  super.emitTopLevelArray(t, name);
495
497
  const elementType = this.scalaType(t.items);
496
- this.emitLine(["given (using ev : ", elementType, "): Encoder[Map[String,", elementType, "]] = Encoder.encodeMap[String, ", elementType, "]"]);
498
+ this.emitLine([
499
+ "given (using ev : ",
500
+ elementType,
501
+ "): Encoder[Map[String,",
502
+ elementType,
503
+ "]] = Encoder.encodeMap[String, ",
504
+ elementType,
505
+ "]"
506
+ ]);
497
507
  }
498
508
  emitTopLevelMap(t, name) {
499
509
  super.emitTopLevelMap(t, name);
500
510
  const elementType = this.scalaType(t.values);
501
511
  this.ensureBlankLine();
502
- this.emitLine(["given (using ev : ", elementType, "): Encoder[Map[String, ", elementType, "]] = Encoder.encodeMap[String, ", elementType, "]"]);
512
+ this.emitLine([
513
+ "given (using ev : ",
514
+ elementType,
515
+ "): Encoder[Map[String, ",
516
+ elementType,
517
+ "]] = Encoder.encodeMap[String, ",
518
+ elementType,
519
+ "]"
520
+ ]);
503
521
  }
504
522
  emitUnionDefinition(u, unionName) {
505
523
  function sortBy(t) {
@@ -536,7 +554,7 @@ class CirceRenderer extends Scala3Renderer {
536
554
  this.indent(() => {
537
555
  this.emitLine(["List[Decoder[", unionName, "]]("]);
538
556
  this.indent(() => {
539
- sourceLikeTypes.forEach((t) => {
557
+ sourceLikeTypes.forEach(t => {
540
558
  this.emitLine(["Decoder[", t[0], "].widen,"]);
541
559
  });
542
560
  });
@@ -548,7 +566,14 @@ class CirceRenderer extends Scala3Renderer {
548
566
  this.indent(() => {
549
567
  sourceLikeTypes.forEach((t, i) => {
550
568
  const paramTemp = `enc${i.toString()}`;
551
- this.emitLine(["case ", paramTemp, " : ", t[0], " => ", this.circeEncoderForType(t[1], false, false, paramTemp)]);
569
+ this.emitLine([
570
+ "case ",
571
+ paramTemp,
572
+ " : ",
573
+ t[0],
574
+ " => ",
575
+ this.circeEncoderForType(t[1], false, false, paramTemp)
576
+ ]);
552
577
  });
553
578
  });
554
579
  this.emitLine("}");
@@ -16,9 +16,7 @@ var Framework;
16
16
  Framework[Framework["None"] = 0] = "None";
17
17
  })(Framework = exports.Framework || (exports.Framework = {}));
18
18
  exports.SmithyOptions = {
19
- framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [
20
- ["just-types", Framework.None]
21
- ], undefined),
19
+ framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [["just-types", Framework.None]], undefined),
22
20
  packageName: new RendererOptions_1.StringOption("package", "Package", "PACKAGE", "quicktype")
23
21
  };
24
22
  // Use backticks for param names with symbols
@@ -102,7 +100,10 @@ const keywords = [
102
100
  * @param paramName
103
101
  */
104
102
  const shouldAddBacktick = (paramName) => {
105
- return keywords.some(s => paramName === s) || invalidSymbols.some(s => paramName.includes(s)) || !isNaN(parseFloat(paramName)) || !isNaN(parseInt(paramName.charAt(0)));
103
+ return (keywords.some(s => paramName === s) ||
104
+ invalidSymbols.some(s => paramName.includes(s)) ||
105
+ !isNaN(parseFloat(paramName)) ||
106
+ !isNaN(parseInt(paramName.charAt(0))));
106
107
  };
107
108
  function isPartCharacter(codePoint) {
108
109
  return (0, Strings_1.isLetterOrUnderscore)(codePoint) || (0, Strings_1.isNumeric)(codePoint);
@@ -150,7 +151,7 @@ class Smithy4sRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
150
151
  return (0, Naming_1.funPrefixNamer)("upper", s => s.replace(" ", "")); // TODO - add backticks where appropriate
151
152
  }
152
153
  emitDescriptionBlock(lines) {
153
- this.emitCommentLines(lines, " * ", "/**", " */");
154
+ this.emitCommentLines(lines, { lineStart: " * ", beforeComment: "/**", afterComment: " */" });
154
155
  }
155
156
  emitBlock(line, f, delimiter = "curly") {
156
157
  const [open, close] = delimiter === "curly"
@@ -199,13 +200,13 @@ class Smithy4sRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
199
200
  }
200
201
  emitHeader() {
201
202
  if (this.leadingComments !== undefined) {
202
- this.emitCommentLines(this.leadingComments);
203
+ this.emitComments(this.leadingComments);
203
204
  }
204
205
  else {
205
206
  this.emitUsageHeader();
206
207
  }
207
208
  this.ensureBlankLine();
208
- this.emitLine("$version: \"2\"");
209
+ this.emitLine('$version: "2"');
209
210
  this.emitLine("namespace ", this._scalaOptions.packageName);
210
211
  this.ensureBlankLine();
211
212
  this.emitLine("document NullValue");
@@ -279,9 +280,21 @@ class Smithy4sRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
279
280
  return;
280
281
  }
281
282
  (0, TypeUtils_1.matchCompoundType)(p.type, at => {
282
- this.emitLine(["list ", this.scalaType(at, true), "{ member: ", this.scalaType(at.items, true), "}"]);
283
+ this.emitLine([
284
+ "list ",
285
+ this.scalaType(at, true),
286
+ "{ member: ",
287
+ this.scalaType(at.items, true),
288
+ "}"
289
+ ]);
283
290
  }, ignore, mt => {
284
- this.emitLine(["map ", this.scalaType(mt, true), "{ key: String , value: ", this.scalaType(mt.values, true), "}"]);
291
+ this.emitLine([
292
+ "map ",
293
+ this.scalaType(mt, true),
294
+ "{ key: String , value: ",
295
+ this.scalaType(mt.values, true),
296
+ "}"
297
+ ]);
285
298
  }, ignore, ignore);
286
299
  });
287
300
  }
@@ -291,20 +304,20 @@ class Smithy4sRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
291
304
  this.emitItem(["enum ", enumName, " { "]);
292
305
  let count = e.cases.size;
293
306
  this.forEachEnumCase(e, "none", (name, jsonName) => {
294
- // if (!(jsonName == "")) {
307
+ // if (!(jsonName == "")) {
295
308
  /* const backticks =
296
- shouldAddBacktick(jsonName) ||
297
- jsonName.includes(" ") ||
298
- !isNaN(parseInt(jsonName.charAt(0)))
299
- if (backticks) {this.emitItem("`")} else */
309
+ shouldAddBacktick(jsonName) ||
310
+ jsonName.includes(" ") ||
311
+ !isNaN(parseInt(jsonName.charAt(0)))
312
+ if (backticks) {this.emitItem("`")} else */
300
313
  this.emitLine();
301
- this.emitItem([name, " = \"", jsonName, "\""]);
314
+ this.emitItem([name, ' = "', jsonName, '"']);
302
315
  // if (backticks) {this.emitItem("`")}
303
316
  if (--count > 0)
304
317
  this.emitItem([","]);
305
318
  //} else {
306
319
  //--count
307
- //}
320
+ //}
308
321
  });
309
322
  this.ensureBlankLine();
310
323
  this.emitItem(["}"]);
@@ -343,9 +356,21 @@ class Smithy4sRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
343
356
  return;
344
357
  }
345
358
  (0, TypeUtils_1.matchCompoundType)(p, at => {
346
- this.emitLine(["list ", this.scalaType(at, true), "{ member: ", this.scalaType(at.items, true), "}"]);
359
+ this.emitLine([
360
+ "list ",
361
+ this.scalaType(at, true),
362
+ "{ member: ",
363
+ this.scalaType(at.items, true),
364
+ "}"
365
+ ]);
347
366
  }, ignore, mt => {
348
- this.emitLine(["map ", this.scalaType(mt, true), "{ key: String , value: ", this.scalaType(mt.values, true), "}"]);
367
+ this.emitLine([
368
+ "map ",
369
+ this.scalaType(mt, true),
370
+ "{ key: String , value: ",
371
+ this.scalaType(mt.values, true),
372
+ "}"
373
+ ]);
349
374
  }, ignore, ignore);
350
375
  });
351
376
  }
@@ -558,7 +558,7 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
558
558
  return kind === "array" || kind === "map";
559
559
  }
560
560
  emitDescriptionBlock(lines) {
561
- this.emitCommentLines(lines, "/// ");
561
+ this.emitCommentLines(lines, { lineStart: "/// " });
562
562
  }
563
563
  emitBlock(line, f) {
564
564
  this.emitLine(line, " {");
@@ -631,7 +631,7 @@ class SwiftRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
631
631
  }
632
632
  renderHeader(type, name) {
633
633
  if (this.leadingComments !== undefined) {
634
- this.emitCommentLines(this.leadingComments);
634
+ this.emitComments(this.leadingComments);
635
635
  }
636
636
  else if (!this._options.justTypes) {
637
637
  if (this._options.multiFileOutput) {
@@ -147,7 +147,7 @@ class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRe
147
147
  }
148
148
  emitSourceStructure() {
149
149
  if (this.leadingComments !== undefined) {
150
- this.emitCommentLines(this.leadingComments);
150
+ this.emitComments(this.leadingComments);
151
151
  }
152
152
  this.emitImports();
153
153
  this.emitSchemas();
@@ -152,7 +152,7 @@ class TypeScriptZodRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
152
152
  }
153
153
  emitSourceStructure() {
154
154
  if (this.leadingComments !== undefined) {
155
- this.emitCommentLines(this.leadingComments);
155
+ this.emitComments(this.leadingComments);
156
156
  }
157
157
  this.emitImports();
158
158
  this.emitSchemas();
@@ -494,7 +494,7 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
494
494
  }
495
495
  emitSourceStructure() {
496
496
  if (this.leadingComments !== undefined) {
497
- this.emitCommentLines(this.leadingComments);
497
+ this.emitComments(this.leadingComments);
498
498
  }
499
499
  else if (!this._options.justTypes) {
500
500
  this.emitLine("# This code may look unusually verbose for Ruby (and it is), but");
@@ -0,0 +1,21 @@
1
+ import { Sourcelike } from "../Source";
2
+ export type CommentOptions = {
3
+ lineStart?: string;
4
+ lineEnd?: string;
5
+ beforeComment?: string;
6
+ afterComment?: string;
7
+ firstLineStart?: string;
8
+ };
9
+ type DescriptionBlockCommentConfig = {
10
+ descriptionBlock: Sourcelike[];
11
+ };
12
+ type InlineCommentConfig = {
13
+ lines: Sourcelike[];
14
+ };
15
+ type CustomCommentConfig = CommentOptions & {
16
+ customLines: Sourcelike[];
17
+ };
18
+ export type CommentConfig = DescriptionBlockCommentConfig | InlineCommentConfig | CustomCommentConfig;
19
+ export type Comment = string | CommentConfig;
20
+ export declare const isStringComment: (comment: Comment) => comment is string;
21
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isStringComment = void 0;
4
+ const isStringComment = (comment) => {
5
+ return typeof comment === "string";
6
+ };
7
+ exports.isStringComment = isStringComment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.94",
3
+ "version": "23.0.96",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",