quicktype 17.0.0 → 17.0.1
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.
- package/dist/cli/CompressedJSONFromStream.js +38 -26
- package/dist/cli/GraphQLIntrospection.js +41 -33
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +3 -4
- package/dist/cli/index.js +364 -363
- package/dist/quicktype-core/Annotation.js +0 -2
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +81 -104
- package/dist/quicktype-core/DateTime.js +0 -1
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +10 -13
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -1
- package/dist/quicktype-core/GatherNames.js +25 -47
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +19 -23
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +54 -65
- package/dist/quicktype-core/MakeTransformations.js +22 -23
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +8 -9
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +3 -8
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +61 -76
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +17 -34
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +3 -6
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +67 -72
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +18 -19
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +2 -6
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +66 -94
- package/dist/quicktype-core/Type.d.ts +43 -41
- package/dist/quicktype-core/Type.js +71 -96
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +47 -53
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +40 -49
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +22 -23
- package/dist/quicktype-core/UnifyClasses.js +12 -16
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +30 -33
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +17 -18
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +4 -8
- package/dist/quicktype-core/attributes/Description.js +5 -6
- package/dist/quicktype-core/attributes/EnumValues.js +3 -4
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +21 -24
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +10 -12
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +21 -49
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +6 -10
- package/dist/quicktype-core/index.js +125 -128
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +54 -49
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +13 -5
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +17 -25
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +54 -38
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +523 -503
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +35 -24
- package/dist/quicktype-core/input/PostmanCollection.js +1 -2
- package/dist/quicktype-core/input/io/NodeIO.js +44 -55
- package/dist/quicktype-core/input/io/get-stream/index.js +2 -6
- package/dist/quicktype-core/language/All.js +2 -3
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +151 -185
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +72 -82
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +17 -18
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +34 -36
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +45 -47
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +20 -23
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +23 -25
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +16 -17
- package/dist/quicktype-core/language/Java.d.ts +2 -2
- package/dist/quicktype-core/language/Java.js +97 -97
- package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
- package/dist/quicktype-core/language/JavaScript.js +17 -19
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +13 -15
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +11 -12
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +37 -39
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +41 -45
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +41 -66
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +17 -18
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +64 -63
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +19 -21
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +804 -807
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +26 -28
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +24 -49
- package/dist/quicktype-core/language/ruby/keywords.js +0 -1
- package/dist/quicktype-core/rewrites/CombineClasses.js +8 -9
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +17 -18
- package/dist/quicktype-core/rewrites/FlattenStrings.js +6 -7
- package/dist/quicktype-core/rewrites/FlattenUnions.js +8 -9
- package/dist/quicktype-core/rewrites/InferMaps.js +10 -11
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +7 -8
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +67 -68
- package/dist/quicktype-core/support/Acronyms.js +1 -3
- package/dist/quicktype-core/support/Chance.js +0 -10
- package/dist/quicktype-core/support/Converters.js +0 -1
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +16 -17
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +6 -30
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -1
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +212 -229
- package/dist/quicktype-typescript-input/index.js +4 -28
- package/package.json +19 -25
|
@@ -17,11 +17,11 @@ export declare const phpOptions: {
|
|
|
17
17
|
export declare class PhpTargetLanguage extends TargetLanguage {
|
|
18
18
|
constructor();
|
|
19
19
|
protected getOptions(): Option<any>[];
|
|
20
|
-
|
|
20
|
+
readonly supportsUnionsWithBothNumberTypes: boolean;
|
|
21
21
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
22
22
|
[name: string]: any;
|
|
23
23
|
}): PhpRenderer;
|
|
24
|
-
|
|
24
|
+
readonly stringTypeMapping: StringTypeMapping;
|
|
25
25
|
}
|
|
26
26
|
export declare const stringEscape: (s: string) => string;
|
|
27
27
|
export declare function phpNameStyle(startWithUpper: boolean, upperUnderscore: boolean, original: string, acronymsStyle?: (s: string) => string): string;
|
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.PhpRenderer = exports.phpNameStyle = exports.stringEscape = exports.PhpTargetLanguage = exports.phpOptions = void 0;
|
|
27
3
|
const Annotation_1 = require("../Annotation");
|
|
28
4
|
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
29
5
|
const Naming_1 = require("../Naming");
|
|
@@ -34,13 +10,13 @@ const Strings_1 = require("../support/Strings");
|
|
|
34
10
|
const Support_1 = require("../support/Support");
|
|
35
11
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
36
12
|
const TypeUtils_1 = require("../TypeUtils");
|
|
37
|
-
const _ =
|
|
13
|
+
const _ = require("lodash");
|
|
38
14
|
exports.phpOptions = {
|
|
39
15
|
withGet: new RendererOptions_1.BooleanOption("with-get", "Create Getter", true),
|
|
40
16
|
fastGet: new RendererOptions_1.BooleanOption("fast-get", "getter without validation", false),
|
|
41
17
|
withSet: new RendererOptions_1.BooleanOption("with-set", "Create Setter", false),
|
|
42
18
|
withClosing: new RendererOptions_1.BooleanOption("with-closing", "PHP Closing Tag", false),
|
|
43
|
-
acronymStyle:
|
|
19
|
+
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal)
|
|
44
20
|
};
|
|
45
21
|
class PhpTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
46
22
|
constructor() {
|
|
@@ -53,7 +29,7 @@ class PhpTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
53
29
|
return true;
|
|
54
30
|
}
|
|
55
31
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
56
|
-
const options =
|
|
32
|
+
const options = RendererOptions_1.getOptionValues(exports.phpOptions, untypedOptionValues);
|
|
57
33
|
return new PhpRenderer(this, renderContext, options);
|
|
58
34
|
}
|
|
59
35
|
get stringTypeMapping() {
|
|
@@ -66,30 +42,29 @@ class PhpTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
66
42
|
}
|
|
67
43
|
}
|
|
68
44
|
exports.PhpTargetLanguage = PhpTargetLanguage;
|
|
69
|
-
exports.stringEscape =
|
|
45
|
+
exports.stringEscape = Strings_1.utf16ConcatMap(Strings_1.escapeNonPrintableMapper(Strings_1.isAscii, Strings_1.standardUnicodeHexEscape));
|
|
70
46
|
function isStartCharacter(codePoint) {
|
|
71
47
|
if (codePoint === 0x5f)
|
|
72
48
|
return true; // underscore
|
|
73
|
-
return
|
|
49
|
+
return Strings_1.isAscii(codePoint) && Strings_1.isLetter(codePoint);
|
|
74
50
|
}
|
|
75
51
|
function isPartCharacter(codePoint) {
|
|
76
|
-
return isStartCharacter(codePoint) || (
|
|
52
|
+
return isStartCharacter(codePoint) || (Strings_1.isAscii(codePoint) && Strings_1.isDigit(codePoint));
|
|
77
53
|
}
|
|
78
|
-
const legalizeName =
|
|
54
|
+
const legalizeName = Strings_1.utf16LegalizeCharacters(isPartCharacter);
|
|
79
55
|
function phpNameStyle(startWithUpper, upperUnderscore, original, acronymsStyle = Strings_1.allUpperWordStyle) {
|
|
80
|
-
const words =
|
|
81
|
-
return
|
|
56
|
+
const words = Strings_1.splitIntoWords(original);
|
|
57
|
+
return Strings_1.combineWords(words, legalizeName, upperUnderscore ? Strings_1.allUpperWordStyle : startWithUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, upperUnderscore ? Strings_1.allUpperWordStyle : Strings_1.firstUpperWordStyle, upperUnderscore || startWithUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, acronymsStyle, upperUnderscore ? "_" : "", isStartCharacter);
|
|
82
58
|
}
|
|
83
59
|
exports.phpNameStyle = phpNameStyle;
|
|
84
60
|
class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
85
|
-
_options;
|
|
86
|
-
_gettersAndSettersForPropertyName = new Map();
|
|
87
|
-
_haveEmittedLeadingComments = false;
|
|
88
|
-
_converterClassname = "Converter";
|
|
89
|
-
_converterKeywords = [];
|
|
90
61
|
constructor(targetLanguage, renderContext, _options) {
|
|
91
62
|
super(targetLanguage, renderContext);
|
|
92
63
|
this._options = _options;
|
|
64
|
+
this._gettersAndSettersForPropertyName = new Map();
|
|
65
|
+
this._haveEmittedLeadingComments = false;
|
|
66
|
+
this._converterClassname = "Converter";
|
|
67
|
+
this._converterKeywords = [];
|
|
93
68
|
}
|
|
94
69
|
forbiddenForObjectProperties(_c, _className) {
|
|
95
70
|
return { names: [], includeGlobalForbidden: true };
|
|
@@ -107,10 +82,10 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
107
82
|
return this.getNameStyling("enumCaseNamingFunction");
|
|
108
83
|
}
|
|
109
84
|
unionNeedsName(u) {
|
|
110
|
-
return
|
|
85
|
+
return TypeUtils_1.nullableFromUnion(u) === null;
|
|
111
86
|
}
|
|
112
87
|
namedTypeToNameForTopLevel(type) {
|
|
113
|
-
return
|
|
88
|
+
return TypeUtils_1.directlyReachableSingleNamedType(type);
|
|
114
89
|
}
|
|
115
90
|
makeNamesForPropertyGetterAndSetter(_c, _className, _p, _jsonName, name) {
|
|
116
91
|
const getterName = new Naming_1.DependencyName(this.getNameStyling("propertyNamingFunction"), name.order, lookup => `get_${lookup(name)}`);
|
|
@@ -142,9 +117,9 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
142
117
|
}
|
|
143
118
|
getNameStyling(convention) {
|
|
144
119
|
const styling = {
|
|
145
|
-
typeNamingFunction:
|
|
146
|
-
propertyNamingFunction:
|
|
147
|
-
enumCaseNamingFunction:
|
|
120
|
+
typeNamingFunction: Naming_1.funPrefixNamer("types", n => phpNameStyle(true, false, n, Acronyms_1.acronymStyle(this._options.acronymStyle))),
|
|
121
|
+
propertyNamingFunction: Naming_1.funPrefixNamer("properties", n => phpNameStyle(false, false, n, Acronyms_1.acronymStyle(this._options.acronymStyle))),
|
|
122
|
+
enumCaseNamingFunction: Naming_1.funPrefixNamer("enum-cases", n => phpNameStyle(true, true, n, Acronyms_1.acronymStyle(this._options.acronymStyle)))
|
|
148
123
|
};
|
|
149
124
|
return styling[convention];
|
|
150
125
|
}
|
|
@@ -176,8 +151,8 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
176
151
|
function optionalize(s) {
|
|
177
152
|
return [isOptional ? prefix : "", s, isOptional ? suffix : ""];
|
|
178
153
|
}
|
|
179
|
-
return
|
|
180
|
-
const nullable =
|
|
154
|
+
return TypeUtils_1.matchType(t, _anyType => Source_1.maybeAnnotated(isOptional, Annotation_1.anyTypeIssueAnnotation, "Object"), _nullType => Source_1.maybeAnnotated(isOptional, Annotation_1.nullTypeIssueAnnotation, "Object"), _boolType => optionalize("bool"), _integerType => optionalize("int"), _doubleType => optionalize("float"), _stringType => optionalize("string"), _arrayType => optionalize("array"), classType => optionalize(this.nameForNamedType(classType)), _mapType => optionalize("stdClass"), enumType => optionalize(this.nameForNamedType(enumType)), unionType => {
|
|
155
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
181
156
|
if (nullable !== null)
|
|
182
157
|
return this.phpType(true, nullable, true, prefix, suffix);
|
|
183
158
|
return this.nameForNamedType(unionType);
|
|
@@ -198,8 +173,8 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
198
173
|
});
|
|
199
174
|
}
|
|
200
175
|
phpDocConvertType(className, t) {
|
|
201
|
-
return
|
|
202
|
-
const nullable =
|
|
176
|
+
return TypeUtils_1.matchType(t, _anyType => "any", _nullType => "null", _boolType => "bool", _integerType => "int", _doubleType => "float", _stringType => "string", arrayType => [this.phpDocConvertType(className, arrayType.items), "[]"], _classType => _classType.getCombinedName(), _mapType => "stdClass", enumType => this.nameForNamedType(enumType), unionType => {
|
|
177
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
203
178
|
if (nullable !== null) {
|
|
204
179
|
return [this.phpDocConvertType(className, nullable), "|null"];
|
|
205
180
|
}
|
|
@@ -212,10 +187,10 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
212
187
|
});
|
|
213
188
|
}
|
|
214
189
|
phpConvertType(className, t) {
|
|
215
|
-
return
|
|
190
|
+
return TypeUtils_1.matchType(t, _anyType => "any", _nullType => "null", _boolType => "bool", _integerType => "int", _doubleType => "float", _stringType => "string", _arrayType => "array", _classType => "stdClass", _mapType => "stdClass", _enumType => "string", // TODO number this.nameForNamedType(enumType),
|
|
216
191
|
// TODO number this.nameForNamedType(enumType),
|
|
217
192
|
unionType => {
|
|
218
|
-
const nullable =
|
|
193
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
219
194
|
if (nullable !== null) {
|
|
220
195
|
return ["?", this.phpConvertType(className, nullable)];
|
|
221
196
|
}
|
|
@@ -228,7 +203,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
228
203
|
});
|
|
229
204
|
}
|
|
230
205
|
phpToObjConvert(className, t, lhs, args) {
|
|
231
|
-
return
|
|
206
|
+
return TypeUtils_1.matchType(t, _anyType => this.emitLine(...lhs, ...args, "; /*any*/"), _nullType => this.emitLine(...lhs, ...args, "; /*null*/"), _boolType => this.emitLine(...lhs, ...args, "; /*bool*/"), _integerType => this.emitLine(...lhs, ...args, "; /*int*/"), _doubleType => this.emitLine(...lhs, ...args, "; /*float*/"), _stringType => this.emitLine(...lhs, ...args, "; /*string*/"), arrayType => {
|
|
232
207
|
this.emitLine(...lhs, "array_map(function ($value) {");
|
|
233
208
|
this.indent(() => {
|
|
234
209
|
this.phpToObjConvert(className, arrayType.items, ["return "], ["$value"]);
|
|
@@ -245,7 +220,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
245
220
|
});
|
|
246
221
|
this.emitLine("return to(", ...args, ");");
|
|
247
222
|
}, enumType => this.emitLine(...lhs, this.nameForNamedType(enumType), "::to(", ...args, "); ", "/*enum*/"), unionType => {
|
|
248
|
-
const nullable =
|
|
223
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
249
224
|
if (nullable !== null) {
|
|
250
225
|
this.emitLine("if (!is_null(", ...args, ")) {");
|
|
251
226
|
this.indent(() => this.phpToObjConvert(className, nullable, lhs, args));
|
|
@@ -270,7 +245,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
270
245
|
// }
|
|
271
246
|
}
|
|
272
247
|
phpFromObjConvert(className, t, lhs, args) {
|
|
273
|
-
return
|
|
248
|
+
return TypeUtils_1.matchType(t, _anyType => this.emitLine(...lhs, ...args, "; /*any*/"), _nullType => this.emitLine(...lhs, ...args, "; /*null*/"), _boolType => this.emitLine(...lhs, ...args, "; /*bool*/"), _integerType => this.emitLine(...lhs, ...args, "; /*int*/"), _doubleType => this.emitLine(...lhs, ...args, "; /*float*/"), _stringType => this.emitLine(...lhs, ...args, "; /*string*/"), arrayType => {
|
|
274
249
|
this.emitLine(...lhs, " array_map(function ($value) {");
|
|
275
250
|
this.indent(() => {
|
|
276
251
|
this.phpFromObjConvert(className, arrayType.items, ["return "], ["$value"]);
|
|
@@ -287,7 +262,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
287
262
|
});
|
|
288
263
|
this.emitLine("return from(", ...args, ");");
|
|
289
264
|
}, enumType => this.emitLine(...lhs, this.nameForNamedType(enumType), "::from(", ...args, "); ", "/*enum*/"), unionType => {
|
|
290
|
-
const nullable =
|
|
265
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
291
266
|
if (nullable !== null) {
|
|
292
267
|
this.emitLine("if (!is_null(", ...args, ")) {");
|
|
293
268
|
this.indent(() => this.phpFromObjConvert(className, nullable, lhs, args));
|
|
@@ -308,7 +283,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
308
283
|
});
|
|
309
284
|
}
|
|
310
285
|
phpSampleConvert(className, t, lhs, args, idx, suffix) {
|
|
311
|
-
return
|
|
286
|
+
return TypeUtils_1.matchType(t, _anyType => this.emitLine(...lhs, "'AnyType::", className, "::", args, "::" + idx, "'", suffix, "/*", "" + idx, ":", args, "*/"), _nullType => this.emitLine(...lhs, "null", suffix, " /*", "" + idx, ":", args, "*/"), _boolType => this.emitLine(...lhs, "true", suffix, " /*", "" + idx, ":", args, "*/"), _integerType => this.emitLine(...lhs, "" + idx, suffix, " /*", "" + idx, ":", args, "*/"), _doubleType => this.emitLine(...lhs, "" + (idx + idx / 1000), suffix, " /*", "" + idx, ":", args, "*/"), _stringType => this.emitLine(...lhs, "'", className, "::", args, "::" + idx, "'", suffix, " /*", "" + idx, ":", args, "*/"), arrayType => {
|
|
312
287
|
this.emitLine(...lhs, " array(");
|
|
313
288
|
this.indent(() => {
|
|
314
289
|
this.phpSampleConvert(className, arrayType.items, [], [], idx, "");
|
|
@@ -322,7 +297,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
322
297
|
});
|
|
323
298
|
this.emitLine("return sample();");
|
|
324
299
|
}, enumType => this.emitLine(...lhs, this.nameForNamedType(enumType), "::sample()", suffix, " /*enum*/"), unionType => {
|
|
325
|
-
const nullable =
|
|
300
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
326
301
|
if (nullable !== null) {
|
|
327
302
|
this.phpSampleConvert(className, nullable, lhs, args, idx, suffix);
|
|
328
303
|
return;
|
|
@@ -342,7 +317,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
342
317
|
const is = (isfn, myT = className) => {
|
|
343
318
|
this.emitBlock(["if (!", isfn, "(", scopeAttrName, "))"], () => this.emitLine('throw new Exception("Attribute Error:', myT, "::", attrName, '");'));
|
|
344
319
|
};
|
|
345
|
-
return
|
|
320
|
+
return TypeUtils_1.matchType(t, _anyType => is("defined"), _nullType => is("is_null"), _boolType => is("is_bool"), _integerType => is("is_integer"), _doubleType => is("is_float"), _stringType => is("is_string"), arrayType => {
|
|
346
321
|
is("is_array");
|
|
347
322
|
this.emitLine("array_walk(", scopeAttrName, ", function(", scopeAttrName, "_v) {");
|
|
348
323
|
this.indent(() => {
|
|
@@ -360,7 +335,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
360
335
|
}, enumType => {
|
|
361
336
|
this.emitLine(this.phpType(false, enumType), "::to(", scopeAttrName, ");");
|
|
362
337
|
}, unionType => {
|
|
363
|
-
const nullable =
|
|
338
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
364
339
|
if (nullable !== null) {
|
|
365
340
|
this.emitBlock(["if (!is_null(", scopeAttrName, "))"], () => {
|
|
366
341
|
this.phpValidate(className, nullable, attrName, scopeAttrName);
|
|
@@ -511,7 +486,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
511
486
|
let idx = 31;
|
|
512
487
|
this.forEachClassProperty(c, "leading-and-interposing", (name, jsonName, p) => {
|
|
513
488
|
const desc = this.descriptionForClassProperty(c, jsonName);
|
|
514
|
-
const names =
|
|
489
|
+
const names = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
515
490
|
this.ensureBlankLine();
|
|
516
491
|
this.emitFromMethod(names, p, className, name, desc);
|
|
517
492
|
this.ensureBlankLine();
|
|
@@ -530,7 +505,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
530
505
|
let lines = [];
|
|
531
506
|
let p = "return ";
|
|
532
507
|
this.forEachClassProperty(c, "none", (name, _jsonName, _p) => {
|
|
533
|
-
const names =
|
|
508
|
+
const names = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
534
509
|
lines.push([p, className, "::", names.validate, "($this->", name, ")"]);
|
|
535
510
|
p = "|| ";
|
|
536
511
|
});
|
|
@@ -548,7 +523,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
548
523
|
], () => {
|
|
549
524
|
this.emitLine("$out = new stdClass();");
|
|
550
525
|
this.forEachClassProperty(c, "none", (name, jsonName) => {
|
|
551
|
-
const names =
|
|
526
|
+
const names = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
552
527
|
this.emitLine("$out->{'", jsonName, "'} = $this->", names.to, "();");
|
|
553
528
|
});
|
|
554
529
|
this.emitLine("return $out;");
|
|
@@ -567,14 +542,14 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
567
542
|
], () => {
|
|
568
543
|
if (this._options.fastGet) {
|
|
569
544
|
this.forEachClassProperty(c, "none", name => {
|
|
570
|
-
const names =
|
|
545
|
+
const names = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
571
546
|
this.emitLine(className, "::", names.validate, "($this->", name, ", true);");
|
|
572
547
|
});
|
|
573
548
|
}
|
|
574
549
|
this.emitLine("return new ", className, "(");
|
|
575
550
|
let comma = " ";
|
|
576
551
|
this.forEachClassProperty(c, "none", (name, jsonName) => {
|
|
577
|
-
const names =
|
|
552
|
+
const names = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
578
553
|
this.emitLine(comma, className, "::", names.from, "($obj->{'", jsonName, "'})");
|
|
579
554
|
comma = ",";
|
|
580
555
|
});
|
|
@@ -585,7 +560,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
585
560
|
this.emitLine("return new ", className, "(");
|
|
586
561
|
let comma = " ";
|
|
587
562
|
this.forEachClassProperty(c, "none", name => {
|
|
588
|
-
const names =
|
|
563
|
+
const names = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
589
564
|
this.emitLine(comma, className, "::", names.sample, "()");
|
|
590
565
|
comma = ",";
|
|
591
566
|
});
|
|
@@ -649,7 +624,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
649
624
|
this.indent(() => {
|
|
650
625
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
651
626
|
// Todo String or Number
|
|
652
|
-
this.emitLine("case ", enumName, "::$", name, "->enum: return '",
|
|
627
|
+
this.emitLine("case ", enumName, "::$", name, "->enum: return '", exports.stringEscape(jsonName), "';");
|
|
653
628
|
});
|
|
654
629
|
});
|
|
655
630
|
this.emitLine("}");
|
|
@@ -672,7 +647,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
672
647
|
this.indent(() => {
|
|
673
648
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
674
649
|
// Todo String or Enum
|
|
675
|
-
this.emitLine("case '",
|
|
650
|
+
this.emitLine("case '", exports.stringEscape(jsonName), "': return ", enumName, "::$", name, ";");
|
|
676
651
|
});
|
|
677
652
|
});
|
|
678
653
|
this.emitLine("}");
|
|
@@ -696,7 +671,7 @@ class PhpRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
696
671
|
if (this._options.withClosing) {
|
|
697
672
|
this.emitLine("?>");
|
|
698
673
|
}
|
|
699
|
-
super.finishFile(
|
|
674
|
+
super.finishFile(Support_1.defined(givenFilename));
|
|
700
675
|
}
|
|
701
676
|
}
|
|
702
677
|
exports.PhpRenderer = PhpRenderer;
|
|
@@ -13,7 +13,7 @@ export declare class PikeTargetLanguage extends TargetLanguage {
|
|
|
13
13
|
}
|
|
14
14
|
export declare class PikeRenderer extends ConvenienceRenderer {
|
|
15
15
|
protected emitSourceStructure(): void;
|
|
16
|
-
protected
|
|
16
|
+
protected readonly enumCasesInGlobalNamespace: boolean;
|
|
17
17
|
protected makeEnumCaseNamer(): Namer;
|
|
18
18
|
protected makeNamedTypeNamer(): Namer;
|
|
19
19
|
protected makeUnionMemberNamer(): Namer;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PikeRenderer = exports.PikeTargetLanguage = exports.pikeOptions = void 0;
|
|
4
3
|
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
5
4
|
const Naming_1 = require("../Naming");
|
|
6
5
|
const Source_1 = require("../Source");
|
|
@@ -63,10 +62,10 @@ const keywords = [
|
|
|
63
62
|
"typeof",
|
|
64
63
|
"global"
|
|
65
64
|
];
|
|
66
|
-
const legalizeName =
|
|
67
|
-
const enumNamingFunction =
|
|
68
|
-
const namingFunction =
|
|
69
|
-
const namedTypeNamingFunction =
|
|
65
|
+
const legalizeName = Strings_1.legalizeCharacters(Strings_1.isLetterOrUnderscoreOrDigit);
|
|
66
|
+
const enumNamingFunction = Naming_1.funPrefixNamer("enumNamer", Strings_1.makeNameStyle("upper-underscore", legalizeName));
|
|
67
|
+
const namingFunction = Naming_1.funPrefixNamer("genericNamer", Strings_1.makeNameStyle("underscore", legalizeName));
|
|
68
|
+
const namedTypeNamingFunction = Naming_1.funPrefixNamer("typeNamer", Strings_1.makeNameStyle("pascal", legalizeName));
|
|
70
69
|
class PikeTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
71
70
|
constructor() {
|
|
72
71
|
super("Pike", ["pike", "pikelang"], "pmod");
|
|
@@ -121,20 +120,20 @@ class PikeRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
121
120
|
}
|
|
122
121
|
sourceFor(t) {
|
|
123
122
|
if (["class", "object", "enum"].indexOf(t.kind) >= 0) {
|
|
124
|
-
return
|
|
123
|
+
return Source_1.singleWord(this.nameForNamedType(t));
|
|
125
124
|
}
|
|
126
|
-
return
|
|
125
|
+
return TypeUtils_1.matchType(t, _anyType => Source_1.singleWord("mixed"), _nullType => Source_1.singleWord("mixed"), _boolType => Source_1.singleWord("bool"), _integerType => Source_1.singleWord("int"), _doubleType => Source_1.singleWord("float"), _stringType => Source_1.singleWord("string"), arrayType => Source_1.singleWord(["array(", this.sourceFor(arrayType.items).source, ")"]), _classType => Source_1.singleWord(this.nameForNamedType(_classType)), mapType => {
|
|
127
126
|
let valueSource;
|
|
128
127
|
const v = mapType.values;
|
|
129
128
|
valueSource = this.sourceFor(v).source;
|
|
130
|
-
return
|
|
131
|
-
}, _enumType =>
|
|
132
|
-
if (
|
|
133
|
-
const children = Array.from(unionType.getChildren()).map(c =>
|
|
134
|
-
return
|
|
129
|
+
return Source_1.singleWord(["mapping(string:", valueSource, ")"]);
|
|
130
|
+
}, _enumType => Source_1.singleWord("enum"), unionType => {
|
|
131
|
+
if (TypeUtils_1.nullableFromUnion(unionType) !== null) {
|
|
132
|
+
const children = Array.from(unionType.getChildren()).map(c => Source_1.parenIfNeeded(this.sourceFor(c)));
|
|
133
|
+
return Source_1.multiWord("|", ...children);
|
|
135
134
|
}
|
|
136
135
|
else {
|
|
137
|
-
return
|
|
136
|
+
return Source_1.singleWord(this.nameForNamedType(unionType));
|
|
138
137
|
}
|
|
139
138
|
});
|
|
140
139
|
}
|
|
@@ -153,7 +152,7 @@ class PikeRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
153
152
|
let table = [];
|
|
154
153
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
155
154
|
table.push([
|
|
156
|
-
[name, ' = "',
|
|
155
|
+
[name, ' = "', Strings_1.stringEscape(jsonName), '", '],
|
|
157
156
|
['// json: "', jsonName, '"']
|
|
158
157
|
]);
|
|
159
158
|
});
|
|
@@ -161,12 +160,12 @@ class PikeRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
161
160
|
});
|
|
162
161
|
}
|
|
163
162
|
emitUnion(u, unionName) {
|
|
164
|
-
const isMaybeWithSingleType =
|
|
163
|
+
const isMaybeWithSingleType = TypeUtils_1.nullableFromUnion(u);
|
|
165
164
|
if (isMaybeWithSingleType !== null) {
|
|
166
165
|
return;
|
|
167
166
|
}
|
|
168
167
|
this.emitDescription(this.descriptionForType(u));
|
|
169
|
-
const [, nonNulls] =
|
|
168
|
+
const [, nonNulls] = TypeUtils_1.removeNullFromUnion(u);
|
|
170
169
|
let types = [];
|
|
171
170
|
this.forEachUnionMember(u, nonNulls, "none", null, (_name, t) => {
|
|
172
171
|
const pikeType = this.sourceFor(t).source;
|
|
@@ -254,7 +253,7 @@ class PikeRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
254
253
|
this.emitBlock(["string encode_json()"], () => {
|
|
255
254
|
this.emitMappingBlock(["mapping(string:mixed) json = "], () => {
|
|
256
255
|
this.forEachClassProperty(c, "none", (name, jsonName) => {
|
|
257
|
-
this.emitLine(['"',
|
|
256
|
+
this.emitLine(['"', Strings_1.stringEscape(jsonName), '" : ', name, ","]);
|
|
258
257
|
});
|
|
259
258
|
});
|
|
260
259
|
this.ensureBlankLine();
|
|
@@ -266,7 +265,7 @@ class PikeRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
266
265
|
this.emitLine([className, " retval = ", className, "();"]);
|
|
267
266
|
this.ensureBlankLine();
|
|
268
267
|
this.forEachClassProperty(c, "none", (name, jsonName) => {
|
|
269
|
-
this.emitLine(["retval.", name, ' = json["',
|
|
268
|
+
this.emitLine(["retval.", name, ' = json["', Strings_1.stringEscape(jsonName), '"];']);
|
|
270
269
|
});
|
|
271
270
|
this.ensureBlankLine();
|
|
272
271
|
this.emitLine(["return retval;"]);
|
|
@@ -7,7 +7,7 @@ import { ConvenienceRenderer, ForbiddenWordsInfo } from "../ConvenienceRenderer"
|
|
|
7
7
|
import { Namer, Name, DependencyName } from "../Naming";
|
|
8
8
|
import { Sourcelike, MultiWord } from "../Source";
|
|
9
9
|
import { Transformer } from "../Transformers";
|
|
10
|
-
export type PythonFeatures = {
|
|
10
|
+
export declare type PythonFeatures = {
|
|
11
11
|
typeHints: boolean;
|
|
12
12
|
dataClasses: boolean;
|
|
13
13
|
};
|
|
@@ -18,9 +18,9 @@ export declare const pythonOptions: {
|
|
|
18
18
|
};
|
|
19
19
|
export declare class PythonTargetLanguage extends TargetLanguage {
|
|
20
20
|
protected getOptions(): Option<any>[];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
readonly stringTypeMapping: StringTypeMapping;
|
|
22
|
+
readonly supportsUnionsWithBothNumberTypes: boolean;
|
|
23
|
+
readonly supportsOptionalClassProperties: boolean;
|
|
24
24
|
needsTransformerForType(t: Type): boolean;
|
|
25
25
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
26
26
|
[name: string]: any;
|
|
@@ -37,9 +37,9 @@ export declare class PythonRenderer extends ConvenienceRenderer {
|
|
|
37
37
|
protected namerForObjectProperty(): Namer;
|
|
38
38
|
protected makeUnionMemberNamer(): null;
|
|
39
39
|
protected makeEnumCaseNamer(): Namer;
|
|
40
|
-
protected
|
|
40
|
+
protected readonly commentLineStart: string;
|
|
41
41
|
protected emitDescriptionBlock(lines: Sourcelike[]): void;
|
|
42
|
-
protected
|
|
42
|
+
protected readonly needsTypeDeclarationBeforeUse: boolean;
|
|
43
43
|
protected canBeForwardDeclared(t: Type): boolean;
|
|
44
44
|
protected emitBlock(line: Sourcelike, f: () => void): void;
|
|
45
45
|
protected string(s: string): Sourcelike;
|
|
@@ -61,8 +61,8 @@ export declare class PythonRenderer extends ConvenienceRenderer {
|
|
|
61
61
|
protected emitClosingCode(): void;
|
|
62
62
|
protected emitSourceStructure(_givenOutputFilename: string): void;
|
|
63
63
|
}
|
|
64
|
-
export type ConverterFunction = "none" | "bool" | "int" | "from-float" | "to-float" | "str" | "to-enum" | "list" | "to-class" | "dict" | "union" | "from-datetime" | "from-stringified-bool" | "is-type";
|
|
65
|
-
export type ValueOrLambda = {
|
|
64
|
+
export declare type ConverterFunction = "none" | "bool" | "int" | "from-float" | "to-float" | "str" | "to-enum" | "list" | "to-class" | "dict" | "union" | "from-datetime" | "from-stringified-bool" | "is-type";
|
|
65
|
+
export declare type ValueOrLambda = {
|
|
66
66
|
value: Sourcelike | undefined;
|
|
67
67
|
lambda?: MultiWord;
|
|
68
68
|
};
|