quicktype-core 23.0.48 → 23.0.50

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.
@@ -26,6 +26,7 @@ const Pike_1 = require("./Pike");
26
26
  const Haskell_1 = require("./Haskell");
27
27
  const TypeScriptZod_1 = require("./TypeScriptZod");
28
28
  const Php_1 = require("./Php");
29
+ const TypeScriptEffectSchema_1 = require("./TypeScriptEffectSchema");
29
30
  exports.all = [
30
31
  new CSharp_1.CSharpTargetLanguage(),
31
32
  new Golang_1.GoTargetLanguage(),
@@ -51,6 +52,7 @@ exports.all = [
51
52
  new Pike_1.PikeTargetLanguage(),
52
53
  new Haskell_1.HaskellTargetLanguage(),
53
54
  new TypeScriptZod_1.TypeScriptZodTargetLanguage(),
55
+ new TypeScriptEffectSchema_1.TypeScriptEffectSchemaTargetLanguage(),
54
56
  new Php_1.PhpTargetLanguage()
55
57
  ];
56
58
  function languageNamed(name, targetLanguages) {
@@ -0,0 +1,35 @@
1
+ import { ClassProperty, Type } from "../Type";
2
+ import { Namer } from "../Naming";
3
+ import { RenderContext } from "../Renderer";
4
+ import { BooleanOption, Option, OptionValues } from "../RendererOptions";
5
+ import { TargetLanguage } from "../TargetLanguage";
6
+ import { Sourcelike } from "../Source";
7
+ import { ConvenienceRenderer } from "../ConvenienceRenderer";
8
+ export declare const typeScriptEffectSchemaOptions: {
9
+ justSchema: BooleanOption;
10
+ };
11
+ export declare class TypeScriptEffectSchemaTargetLanguage extends TargetLanguage {
12
+ protected getOptions(): Option<any>[];
13
+ constructor(displayName?: string, names?: string[], extension?: string);
14
+ protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
15
+ [name: string]: any;
16
+ }): TypeScriptEffectSchemaRenderer;
17
+ }
18
+ export declare class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer {
19
+ private readonly _options;
20
+ constructor(targetLanguage: TargetLanguage, renderContext: RenderContext, _options: OptionValues<typeof typeScriptEffectSchemaOptions>);
21
+ protected forbiddenNamesForGlobalNamespace(): string[];
22
+ protected nameStyle(original: string, upper: boolean): string;
23
+ protected makeNamedTypeNamer(): Namer;
24
+ protected makeUnionMemberNamer(): Namer;
25
+ protected namerForObjectProperty(): Namer;
26
+ protected makeEnumCaseNamer(): Namer;
27
+ private importStatement;
28
+ protected emitImports(): void;
29
+ typeMapTypeForProperty(p: ClassProperty): Sourcelike;
30
+ typeMapTypeFor(t: Type, required?: boolean): Sourcelike;
31
+ private emitObject;
32
+ private emitEnum;
33
+ protected emitSchemas(): void;
34
+ protected emitSourceStructure(): void;
35
+ }
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeScriptEffectSchemaRenderer = exports.TypeScriptEffectSchemaTargetLanguage = exports.typeScriptEffectSchemaOptions = void 0;
4
+ const collection_utils_1 = require("collection-utils");
5
+ const TypeUtils_1 = require("../TypeUtils");
6
+ const Naming_1 = require("../Naming");
7
+ const RendererOptions_1 = require("../RendererOptions");
8
+ const Acronyms_1 = require("../support/Acronyms");
9
+ const Strings_1 = require("../support/Strings");
10
+ const TargetLanguage_1 = require("../TargetLanguage");
11
+ const JavaScript_1 = require("./JavaScript");
12
+ const Support_1 = require("../support/Support");
13
+ const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
14
+ exports.typeScriptEffectSchemaOptions = {
15
+ justSchema: new RendererOptions_1.BooleanOption("just-schema", "Schema only", false)
16
+ };
17
+ class TypeScriptEffectSchemaTargetLanguage extends TargetLanguage_1.TargetLanguage {
18
+ getOptions() {
19
+ return [];
20
+ }
21
+ constructor(displayName = "TypeScript Effect Schema", names = ["typescript-effect-schema"], extension = "ts") {
22
+ super(displayName, names, extension);
23
+ }
24
+ makeRenderer(renderContext, untypedOptionValues) {
25
+ return new TypeScriptEffectSchemaRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.typeScriptEffectSchemaOptions, untypedOptionValues));
26
+ }
27
+ }
28
+ exports.TypeScriptEffectSchemaTargetLanguage = TypeScriptEffectSchemaTargetLanguage;
29
+ class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
30
+ constructor(targetLanguage, renderContext, _options) {
31
+ super(targetLanguage, renderContext);
32
+ this._options = _options;
33
+ }
34
+ forbiddenNamesForGlobalNamespace() {
35
+ return ["Class", "Date", "Object", "String", "Array", "JSON", "Error"];
36
+ }
37
+ nameStyle(original, upper) {
38
+ const acronyms = (0, Acronyms_1.acronymStyle)(Acronyms_1.AcronymStyleOptions.Camel);
39
+ const words = (0, Strings_1.splitIntoWords)(original);
40
+ return (0, Strings_1.combineWords)(words, JavaScript_1.legalizeName, upper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, upper ? s => (0, Strings_1.capitalize)(acronyms(s)) : Strings_1.allLowerWordStyle, acronyms, "", Strings_1.isLetterOrUnderscore);
41
+ }
42
+ makeNamedTypeNamer() {
43
+ return (0, Naming_1.funPrefixNamer)("types", s => this.nameStyle(s, true));
44
+ }
45
+ makeUnionMemberNamer() {
46
+ return (0, Naming_1.funPrefixNamer)("properties", s => this.nameStyle(s, true));
47
+ }
48
+ namerForObjectProperty() {
49
+ return (0, Naming_1.funPrefixNamer)("properties", s => this.nameStyle(s, true));
50
+ }
51
+ makeEnumCaseNamer() {
52
+ return (0, Naming_1.funPrefixNamer)("enum-cases", s => this.nameStyle(s, false));
53
+ }
54
+ importStatement(lhs, moduleName) {
55
+ return ["import ", lhs, " from ", moduleName, ";"];
56
+ }
57
+ emitImports() {
58
+ this.ensureBlankLine();
59
+ this.emitLine(this.importStatement("* as Schema", '"@effect/schema/Schema"'));
60
+ }
61
+ typeMapTypeForProperty(p) {
62
+ const typeMap = this.typeMapTypeFor(p.type);
63
+ return p.isOptional ? ["Schema.optional(", typeMap, ")"] : typeMap;
64
+ }
65
+ typeMapTypeFor(t, required = true) {
66
+ if (["class", "object", "enum"].indexOf(t.kind) >= 0) {
67
+ return ["Schema.lazy(() => ", this.nameForNamedType(t), "Schema)"];
68
+ }
69
+ const match = (0, TypeUtils_1.matchType)(t, _anyType => "Schema.any", _nullType => "Schema.null", _boolType => "Schema.boolean", _integerType => "Schema.number", _doubleType => "Schema.number", _stringType => "Schema.string", arrayType => ["Schema.array(", this.typeMapTypeFor(arrayType.items, false), ")"], _classType => (0, Support_1.panic)("Should already be handled."), _mapType => ["Schema.record(Schema.string, ", this.typeMapTypeFor(_mapType.values, false), ")"], _enumType => (0, Support_1.panic)("Should already be handled."), unionType => {
70
+ const children = Array.from(unionType.getChildren()).map((type) => this.typeMapTypeFor(type, false));
71
+ return ["Schema.union(", ...(0, collection_utils_1.arrayIntercalate)(", ", children), ")"];
72
+ }, _transformedStringType => {
73
+ return "Schema.string";
74
+ });
75
+ if (required) {
76
+ return [match];
77
+ }
78
+ return match;
79
+ }
80
+ emitObject(name, t) {
81
+ this.ensureBlankLine();
82
+ this.emitLine("\nexport const ", name, "Schema = ", "Schema.struct({");
83
+ this.indent(() => {
84
+ this.forEachClassProperty(t, "none", (_, jsonName, property) => {
85
+ this.emitLine(`"${(0, Strings_1.utf16StringEscape)(jsonName)}"`, ": ", this.typeMapTypeForProperty(property), ",");
86
+ });
87
+ });
88
+ this.emitLine("});");
89
+ if (!this._options.justSchema) {
90
+ this.emitLine("export type ", name, " = Schema.From<typeof ", name, "Schema>;");
91
+ }
92
+ }
93
+ emitEnum(e, enumName) {
94
+ this.ensureBlankLine();
95
+ this.emitDescription(this.descriptionForType(e));
96
+ this.emitLine("\nexport const ", enumName, "Schema = ", "Schema.enums({");
97
+ this.indent(() => this.forEachEnumCase(e, "none", (_, jsonName) => {
98
+ const name = (0, Strings_1.stringEscape)(jsonName);
99
+ this.emitLine('"', name, '": "', name, '",');
100
+ }));
101
+ this.emitLine("});");
102
+ if (!this._options.justSchema) {
103
+ this.emitLine("export type ", enumName, " = Schema.From<typeof ", enumName, "Schema>;");
104
+ }
105
+ }
106
+ emitSchemas() {
107
+ this.ensureBlankLine();
108
+ this.forEachEnum("leading-and-interposing", (u, enumName) => {
109
+ this.emitEnum(u, enumName);
110
+ });
111
+ const order = [];
112
+ const mapKey = [];
113
+ const mapValue = [];
114
+ this.forEachObject("none", (type, name) => {
115
+ mapKey.push(name);
116
+ mapValue.push(this.gatherSource(() => this.emitObject(name, type)));
117
+ });
118
+ mapKey.forEach((_, index) => {
119
+ // assume first
120
+ let ordinal = 0;
121
+ // pull out all names
122
+ const source = mapValue[index];
123
+ const names = source.filter(value => value);
124
+ // must be behind all these names
125
+ for (let i = 0; i < names.length; i++) {
126
+ const depName = names[i];
127
+ // find this name's ordinal, if it has already been added
128
+ for (let j = 0; j < order.length; j++) {
129
+ const depIndex = order[j];
130
+ if (mapKey[depIndex] === depName) {
131
+ // this is the index of the dependency, so make sure we come after it
132
+ ordinal = Math.max(ordinal, depIndex + 1);
133
+ }
134
+ }
135
+ }
136
+ // insert index
137
+ order.splice(ordinal, 0, index);
138
+ });
139
+ // now emit ordered source
140
+ order.forEach(i => this.emitGatheredSource(mapValue[i]));
141
+ }
142
+ emitSourceStructure() {
143
+ if (this.leadingComments !== undefined) {
144
+ this.emitCommentLines(this.leadingComments);
145
+ }
146
+ this.emitImports();
147
+ this.emitSchemas();
148
+ }
149
+ }
150
+ exports.TypeScriptEffectSchemaRenderer = TypeScriptEffectSchemaRenderer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.48",
3
+ "version": "23.0.50",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",