@sdkgen/parser 0.0.0-dev.20231221180829 → 0.0.0-dev.20240110140542
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/ast.js +298 -0
- package/dist/compatibility/index.js +206 -0
- package/dist/helpers.js +20 -0
- package/dist/index.js +9 -0
- package/dist/json.js +225 -0
- package/dist/lexer.js +283 -0
- package/dist/parser.js +419 -0
- package/dist/restparser.js +59 -0
- package/dist/semantic/01_check_multiple_declaration.js +19 -0
- package/dist/semantic/02_give_struct_and_enum_names.js +58 -0
- package/dist/semantic/03_match_type_definitions.js +15 -0
- package/dist/semantic/04_check_dont_return_secret.js +39 -0
- package/dist/semantic/05_expand_spreads.js +57 -0
- package/dist/semantic/06_check_empty_struct_or_enum.js +18 -0
- package/dist/semantic/07_validate_recursive_types.js +46 -0
- package/dist/semantic/08_collect_struct_and_enum_types.js +22 -0
- package/dist/semantic/09_validate_annotations.js +122 -0
- package/dist/semantic/10_check_duplicate_members_on_enum.js +13 -0
- package/dist/semantic/analyser.js +27 -0
- package/dist/semantic/transformer.js +46 -0
- package/dist/semantic/visitor.js +61 -0
- package/dist/token.js +93 -0
- package/dist/utils.js +25 -0
- package/package.json +24 -8
- package/.eslintrc.json +0 -3
- package/.prettierrc +0 -12
- package/dist/spec/lexer.spec.d.ts +0 -1
- package/dist/spec/lexer.spec.js +0 -152
- package/dist/spec/parser.spec.d.ts +0 -1
- package/dist/spec/parser.spec.js +0 -967
- package/dist/src/ast.js +0 -355
- package/dist/src/compatibility/index.js +0 -211
- package/dist/src/helpers.js +0 -23
- package/dist/src/index.js +0 -29
- package/dist/src/json.js +0 -234
- package/dist/src/lexer.js +0 -287
- package/dist/src/parser.js +0 -423
- package/dist/src/restparser.js +0 -65
- package/dist/src/semantic/01_check_multiple_declaration.js +0 -22
- package/dist/src/semantic/02_give_struct_and_enum_names.js +0 -61
- package/dist/src/semantic/03_match_type_definitions.js +0 -18
- package/dist/src/semantic/04_check_dont_return_secret.js +0 -42
- package/dist/src/semantic/05_expand_spreads.js +0 -60
- package/dist/src/semantic/06_check_empty_struct_or_enum.js +0 -21
- package/dist/src/semantic/07_validate_recursive_types.js +0 -49
- package/dist/src/semantic/08_collect_struct_and_enum_types.js +0 -25
- package/dist/src/semantic/09_validate_annotations.js +0 -125
- package/dist/src/semantic/10_check_duplicate_members_on_enum.js +0 -16
- package/dist/src/semantic/analyser.js +0 -30
- package/dist/src/semantic/transformer.js +0 -50
- package/dist/src/semantic/visitor.js +0 -65
- package/dist/src/token.js +0 -119
- package/dist/src/utils.js +0 -27
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/dist/{src/ast.d.ts → ast.d.ts} +0 -0
- /package/dist/{src/compatibility → compatibility}/index.d.ts +0 -0
- /package/dist/{src/helpers.d.ts → helpers.d.ts} +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/json.d.ts → json.d.ts} +0 -0
- /package/dist/{src/lexer.d.ts → lexer.d.ts} +0 -0
- /package/dist/{src/parser.d.ts → parser.d.ts} +0 -0
- /package/dist/{src/restparser.d.ts → restparser.d.ts} +0 -0
- /package/dist/{src/semantic → semantic}/01_check_multiple_declaration.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/02_give_struct_and_enum_names.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/03_match_type_definitions.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/04_check_dont_return_secret.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/05_expand_spreads.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/06_check_empty_struct_or_enum.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/07_validate_recursive_types.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/08_collect_struct_and_enum_types.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/09_validate_annotations.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/10_check_duplicate_members_on_enum.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/analyser.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/transformer.d.ts +0 -0
- /package/dist/{src/semantic → semantic}/visitor.d.ts +0 -0
- /package/dist/{src/token.d.ts → token.d.ts} +0 -0
- /package/dist/{src/utils.d.ts → utils.d.ts} +0 -0
package/dist/src/ast.js
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.AstRoot = exports.FunctionOperation = exports.TypeDefinition = exports.StructType = exports.TypeReference = exports.Spread = exports.Field = exports.EnumType = exports.EnumValue = exports.ArrayType = exports.OptionalType = exports.JsonPrimitiveType = exports.XmlPrimitiveType = exports.Base64PrimitiveType = exports.HtmlPrimitiveType = exports.HexPrimitiveType = exports.UuidPrimitiveType = exports.UrlPrimitiveType = exports.EmailPrimitiveType = exports.CnpjPrimitiveType = exports.CpfPrimitiveType = exports.DecimalPrimitiveType = exports.MoneyPrimitiveType = exports.VoidPrimitiveType = exports.BytesPrimitiveType = exports.BoolPrimitiveType = exports.DateTimePrimitiveType = exports.DatePrimitiveType = exports.BigIntPrimitiveType = exports.FloatPrimitiveType = exports.UIntPrimitiveType = exports.IntPrimitiveType = exports.StringPrimitiveType = exports.PrimitiveType = exports.StatusCodeAnnotation = exports.HiddenAnnotation = exports.RestAnnotation = exports.ArgDescriptionAnnotation = exports.ThrowsAnnotation = exports.DescriptionAnnotation = exports.Annotation = exports.ErrorNode = exports.Type = exports.AstNode = void 0;
|
|
15
|
-
const token_1 = require("./token");
|
|
16
|
-
class AstNode {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.location = new token_1.TokenLocation();
|
|
19
|
-
Object.defineProperty(this, "location", { enumerable: false });
|
|
20
|
-
}
|
|
21
|
-
at(token) {
|
|
22
|
-
this.location = token.location;
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
atLocation(location) {
|
|
26
|
-
this.location = location;
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.AstNode = AstNode;
|
|
31
|
-
class Type extends AstNode {
|
|
32
|
-
toJSON() {
|
|
33
|
-
const _a = Object.assign({}, this), { name: _name } = _a, rest = __rest(_a, ["name"]);
|
|
34
|
-
return rest;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.Type = Type;
|
|
38
|
-
class ErrorNode extends AstNode {
|
|
39
|
-
constructor(name, dataType) {
|
|
40
|
-
super();
|
|
41
|
-
this.name = name;
|
|
42
|
-
this.dataType = dataType;
|
|
43
|
-
this.annotations = [];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.ErrorNode = ErrorNode;
|
|
47
|
-
class Annotation extends AstNode {
|
|
48
|
-
}
|
|
49
|
-
exports.Annotation = Annotation;
|
|
50
|
-
class DescriptionAnnotation extends Annotation {
|
|
51
|
-
constructor(text) {
|
|
52
|
-
super();
|
|
53
|
-
this.text = text;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.DescriptionAnnotation = DescriptionAnnotation;
|
|
57
|
-
class ThrowsAnnotation extends Annotation {
|
|
58
|
-
constructor(error) {
|
|
59
|
-
super();
|
|
60
|
-
this.error = error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.ThrowsAnnotation = ThrowsAnnotation;
|
|
64
|
-
class ArgDescriptionAnnotation extends Annotation {
|
|
65
|
-
constructor(argName, text) {
|
|
66
|
-
super();
|
|
67
|
-
this.argName = argName;
|
|
68
|
-
this.text = text;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.ArgDescriptionAnnotation = ArgDescriptionAnnotation;
|
|
72
|
-
class RestAnnotation extends Annotation {
|
|
73
|
-
constructor(method, path, pathVariables, queryVariables, headers, bodyVariable) {
|
|
74
|
-
super();
|
|
75
|
-
this.method = method;
|
|
76
|
-
this.path = path;
|
|
77
|
-
this.pathVariables = pathVariables;
|
|
78
|
-
this.queryVariables = queryVariables;
|
|
79
|
-
this.headers = headers;
|
|
80
|
-
this.bodyVariable = bodyVariable;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.RestAnnotation = RestAnnotation;
|
|
84
|
-
class HiddenAnnotation extends Annotation {
|
|
85
|
-
}
|
|
86
|
-
exports.HiddenAnnotation = HiddenAnnotation;
|
|
87
|
-
class StatusCodeAnnotation extends Annotation {
|
|
88
|
-
constructor(statusCode) {
|
|
89
|
-
super();
|
|
90
|
-
this.statusCode = statusCode;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.StatusCodeAnnotation = StatusCodeAnnotation;
|
|
94
|
-
class PrimitiveType extends Type {
|
|
95
|
-
toJSON() {
|
|
96
|
-
return this.name;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.PrimitiveType = PrimitiveType;
|
|
100
|
-
class StringPrimitiveType extends PrimitiveType {
|
|
101
|
-
constructor() {
|
|
102
|
-
super(...arguments);
|
|
103
|
-
this.name = "string";
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.StringPrimitiveType = StringPrimitiveType;
|
|
107
|
-
class IntPrimitiveType extends PrimitiveType {
|
|
108
|
-
constructor() {
|
|
109
|
-
super(...arguments);
|
|
110
|
-
this.name = "int";
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.IntPrimitiveType = IntPrimitiveType;
|
|
114
|
-
class UIntPrimitiveType extends PrimitiveType {
|
|
115
|
-
constructor() {
|
|
116
|
-
super(...arguments);
|
|
117
|
-
this.name = "uint";
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.UIntPrimitiveType = UIntPrimitiveType;
|
|
121
|
-
class FloatPrimitiveType extends PrimitiveType {
|
|
122
|
-
constructor() {
|
|
123
|
-
super(...arguments);
|
|
124
|
-
this.name = "float";
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.FloatPrimitiveType = FloatPrimitiveType;
|
|
128
|
-
class BigIntPrimitiveType extends PrimitiveType {
|
|
129
|
-
constructor() {
|
|
130
|
-
super(...arguments);
|
|
131
|
-
this.name = "bigint";
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.BigIntPrimitiveType = BigIntPrimitiveType;
|
|
135
|
-
class DatePrimitiveType extends PrimitiveType {
|
|
136
|
-
constructor() {
|
|
137
|
-
super(...arguments);
|
|
138
|
-
this.name = "date";
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
exports.DatePrimitiveType = DatePrimitiveType;
|
|
142
|
-
class DateTimePrimitiveType extends PrimitiveType {
|
|
143
|
-
constructor() {
|
|
144
|
-
super(...arguments);
|
|
145
|
-
this.name = "datetime";
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.DateTimePrimitiveType = DateTimePrimitiveType;
|
|
149
|
-
class BoolPrimitiveType extends PrimitiveType {
|
|
150
|
-
constructor() {
|
|
151
|
-
super(...arguments);
|
|
152
|
-
this.name = "bool";
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
exports.BoolPrimitiveType = BoolPrimitiveType;
|
|
156
|
-
class BytesPrimitiveType extends PrimitiveType {
|
|
157
|
-
constructor() {
|
|
158
|
-
super(...arguments);
|
|
159
|
-
this.name = "bytes";
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.BytesPrimitiveType = BytesPrimitiveType;
|
|
163
|
-
class VoidPrimitiveType extends PrimitiveType {
|
|
164
|
-
constructor() {
|
|
165
|
-
super(...arguments);
|
|
166
|
-
this.name = "void";
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.VoidPrimitiveType = VoidPrimitiveType;
|
|
170
|
-
class MoneyPrimitiveType extends PrimitiveType {
|
|
171
|
-
constructor() {
|
|
172
|
-
super(...arguments);
|
|
173
|
-
this.name = "money";
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
exports.MoneyPrimitiveType = MoneyPrimitiveType;
|
|
177
|
-
class DecimalPrimitiveType extends PrimitiveType {
|
|
178
|
-
constructor() {
|
|
179
|
-
super(...arguments);
|
|
180
|
-
this.name = "decimal";
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
exports.DecimalPrimitiveType = DecimalPrimitiveType;
|
|
184
|
-
class CpfPrimitiveType extends PrimitiveType {
|
|
185
|
-
constructor() {
|
|
186
|
-
super(...arguments);
|
|
187
|
-
this.name = "cpf";
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
exports.CpfPrimitiveType = CpfPrimitiveType;
|
|
191
|
-
class CnpjPrimitiveType extends PrimitiveType {
|
|
192
|
-
constructor() {
|
|
193
|
-
super(...arguments);
|
|
194
|
-
this.name = "cnpj";
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.CnpjPrimitiveType = CnpjPrimitiveType;
|
|
198
|
-
class EmailPrimitiveType extends PrimitiveType {
|
|
199
|
-
constructor() {
|
|
200
|
-
super(...arguments);
|
|
201
|
-
this.name = "email";
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
exports.EmailPrimitiveType = EmailPrimitiveType;
|
|
205
|
-
class UrlPrimitiveType extends PrimitiveType {
|
|
206
|
-
constructor() {
|
|
207
|
-
super(...arguments);
|
|
208
|
-
this.name = "url";
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.UrlPrimitiveType = UrlPrimitiveType;
|
|
212
|
-
class UuidPrimitiveType extends PrimitiveType {
|
|
213
|
-
constructor() {
|
|
214
|
-
super(...arguments);
|
|
215
|
-
this.name = "uuid";
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
exports.UuidPrimitiveType = UuidPrimitiveType;
|
|
219
|
-
class HexPrimitiveType extends PrimitiveType {
|
|
220
|
-
constructor() {
|
|
221
|
-
super(...arguments);
|
|
222
|
-
this.name = "hex";
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exports.HexPrimitiveType = HexPrimitiveType;
|
|
226
|
-
class HtmlPrimitiveType extends PrimitiveType {
|
|
227
|
-
constructor() {
|
|
228
|
-
super(...arguments);
|
|
229
|
-
this.name = "html";
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
exports.HtmlPrimitiveType = HtmlPrimitiveType;
|
|
233
|
-
class Base64PrimitiveType extends PrimitiveType {
|
|
234
|
-
constructor() {
|
|
235
|
-
super(...arguments);
|
|
236
|
-
this.name = "base64";
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
exports.Base64PrimitiveType = Base64PrimitiveType;
|
|
240
|
-
class XmlPrimitiveType extends PrimitiveType {
|
|
241
|
-
constructor() {
|
|
242
|
-
super(...arguments);
|
|
243
|
-
this.name = "xml";
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
exports.XmlPrimitiveType = XmlPrimitiveType;
|
|
247
|
-
class JsonPrimitiveType extends PrimitiveType {
|
|
248
|
-
constructor() {
|
|
249
|
-
super(...arguments);
|
|
250
|
-
this.name = "json";
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
exports.JsonPrimitiveType = JsonPrimitiveType;
|
|
254
|
-
class OptionalType extends Type {
|
|
255
|
-
constructor(base) {
|
|
256
|
-
super();
|
|
257
|
-
this.base = base;
|
|
258
|
-
}
|
|
259
|
-
get name() {
|
|
260
|
-
return `${this.base.name}?`;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
exports.OptionalType = OptionalType;
|
|
264
|
-
class ArrayType extends Type {
|
|
265
|
-
constructor(base) {
|
|
266
|
-
super();
|
|
267
|
-
this.base = base;
|
|
268
|
-
}
|
|
269
|
-
get name() {
|
|
270
|
-
return `${this.base.name}[]`;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
exports.ArrayType = ArrayType;
|
|
274
|
-
class EnumValue extends AstNode {
|
|
275
|
-
constructor(value) {
|
|
276
|
-
super();
|
|
277
|
-
this.value = value;
|
|
278
|
-
this.annotations = [];
|
|
279
|
-
this.struct = null;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
exports.EnumValue = EnumValue;
|
|
283
|
-
class EnumType extends Type {
|
|
284
|
-
constructor(values) {
|
|
285
|
-
super();
|
|
286
|
-
this.values = values;
|
|
287
|
-
}
|
|
288
|
-
get hasStructValues() {
|
|
289
|
-
return this.values.some(v => v.struct !== null);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
exports.EnumType = EnumType;
|
|
293
|
-
class Field extends AstNode {
|
|
294
|
-
constructor(name, type, secret = false) {
|
|
295
|
-
super();
|
|
296
|
-
this.name = name;
|
|
297
|
-
this.type = type;
|
|
298
|
-
this.secret = secret;
|
|
299
|
-
this.annotations = [];
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
exports.Field = Field;
|
|
303
|
-
class Spread extends AstNode {
|
|
304
|
-
constructor(typeReference) {
|
|
305
|
-
super();
|
|
306
|
-
this.typeReference = typeReference;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
exports.Spread = Spread;
|
|
310
|
-
class TypeReference extends Type {
|
|
311
|
-
constructor(name) {
|
|
312
|
-
super();
|
|
313
|
-
this.name = name;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
exports.TypeReference = TypeReference;
|
|
317
|
-
class StructType extends Type {
|
|
318
|
-
constructor(fieldsAndSpreads) {
|
|
319
|
-
super();
|
|
320
|
-
this.fieldsAndSpreads = fieldsAndSpreads;
|
|
321
|
-
this.fields = [];
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
exports.StructType = StructType;
|
|
325
|
-
class TypeDefinition extends AstNode {
|
|
326
|
-
constructor(name, type) {
|
|
327
|
-
super();
|
|
328
|
-
this.name = name;
|
|
329
|
-
this.type = type;
|
|
330
|
-
this.annotations = [];
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
exports.TypeDefinition = TypeDefinition;
|
|
334
|
-
class FunctionOperation extends AstNode {
|
|
335
|
-
constructor(name, fieldsAndSpreads, returnType) {
|
|
336
|
-
super();
|
|
337
|
-
this.name = name;
|
|
338
|
-
this.fieldsAndSpreads = fieldsAndSpreads;
|
|
339
|
-
this.returnType = returnType;
|
|
340
|
-
this.annotations = [];
|
|
341
|
-
this.args = [];
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
exports.FunctionOperation = FunctionOperation;
|
|
345
|
-
class AstRoot {
|
|
346
|
-
constructor(typeDefinitions = [], operations = [], errors = []) {
|
|
347
|
-
this.typeDefinitions = typeDefinitions;
|
|
348
|
-
this.operations = operations;
|
|
349
|
-
this.errors = errors;
|
|
350
|
-
this.structTypes = [];
|
|
351
|
-
this.enumTypes = [];
|
|
352
|
-
this.warnings = [];
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
exports.AstRoot = AstRoot;
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compatibilityIssues = void 0;
|
|
4
|
-
const ast_1 = require("../ast");
|
|
5
|
-
/*
|
|
6
|
-
* 1 -> Old version
|
|
7
|
-
* 2 -> New version
|
|
8
|
-
*/
|
|
9
|
-
function checkClientToServer(path, issues, t1, t2) {
|
|
10
|
-
var _a, _b;
|
|
11
|
-
if (t1 instanceof ast_1.TypeReference) {
|
|
12
|
-
checkClientToServer(path, issues, t1.type, t2);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (t2 instanceof ast_1.TypeReference) {
|
|
16
|
-
checkClientToServer(path, issues, t1, t2.type);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (!(t1 instanceof ast_1.OptionalType) && t2 instanceof ast_1.OptionalType) {
|
|
20
|
-
checkClientToServer(path, issues, t1, t2.base);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (t1 instanceof ast_1.OptionalType && t2 instanceof ast_1.OptionalType) {
|
|
24
|
-
checkClientToServer(path, issues, t1.base, t2.base);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (t1 instanceof ast_1.OptionalType && !(t2 instanceof ast_1.OptionalType)) {
|
|
28
|
-
issues.push(`${path} was optional, but now it isn't. If the client sends a null, it will be invalid. Add the optional annotation back.`);
|
|
29
|
-
checkClientToServer(path, issues, t1.base, t2);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (t1 instanceof ast_1.ArrayType && t2 instanceof ast_1.ArrayType) {
|
|
33
|
-
checkClientToServer(path, issues, t1.base, t2.base);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (t1 instanceof ast_1.StructType && t2 instanceof ast_1.StructType) {
|
|
37
|
-
for (const field2 of t2.fields) {
|
|
38
|
-
const field1 = t1.fields.find(x => x.name === field2.name);
|
|
39
|
-
if (!field1) {
|
|
40
|
-
if (field2.type instanceof ast_1.OptionalType) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
issues.push(`${path}.${field2.name} didn't exist before and isn't optional. Make it optional.`);
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
checkClientToServer(`${path}.${field1.name}`, issues, field1.type, field2.type);
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if ((t1 instanceof ast_1.UIntPrimitiveType && t2 instanceof ast_1.IntPrimitiveType) ||
|
|
53
|
-
(t1 instanceof ast_1.IntPrimitiveType && t2 instanceof ast_1.FloatPrimitiveType) ||
|
|
54
|
-
(t1 instanceof ast_1.MoneyPrimitiveType && t2 instanceof ast_1.IntPrimitiveType) ||
|
|
55
|
-
(t1 instanceof ast_1.MoneyPrimitiveType && t2 instanceof ast_1.UIntPrimitiveType) ||
|
|
56
|
-
(t1 instanceof ast_1.UIntPrimitiveType && t2 instanceof ast_1.BigIntPrimitiveType) ||
|
|
57
|
-
(t1 instanceof ast_1.IntPrimitiveType && t2 instanceof ast_1.BigIntPrimitiveType) ||
|
|
58
|
-
(t1 instanceof ast_1.MoneyPrimitiveType && t2 instanceof ast_1.BigIntPrimitiveType) ||
|
|
59
|
-
(t1 instanceof ast_1.BigIntPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
60
|
-
(t1 instanceof ast_1.UuidPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
61
|
-
(t1 instanceof ast_1.XmlPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
62
|
-
(t1 instanceof ast_1.DatePrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
63
|
-
(t1 instanceof ast_1.DateTimePrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
64
|
-
(t1 instanceof ast_1.CpfPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
65
|
-
(t1 instanceof ast_1.CnpjPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
66
|
-
(t1 instanceof ast_1.HexPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
67
|
-
(t1 instanceof ast_1.HtmlPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
68
|
-
(t1 instanceof ast_1.Base64PrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
69
|
-
(t1 instanceof ast_1.BytesPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
70
|
-
(t1 instanceof ast_1.BytesPrimitiveType && t2 instanceof ast_1.Base64PrimitiveType) ||
|
|
71
|
-
(t1 instanceof ast_1.UrlPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
72
|
-
(t1 instanceof ast_1.EmailPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
73
|
-
(t1 instanceof ast_1.DecimalPrimitiveType && t2 instanceof ast_1.StringPrimitiveType) ||
|
|
74
|
-
(t1 instanceof ast_1.EnumType && t2 instanceof ast_1.StringPrimitiveType)) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (t1 instanceof ast_1.EnumType && t2 instanceof ast_1.EnumType) {
|
|
78
|
-
for (const value of t1.values) {
|
|
79
|
-
const other = t2.values.find(v => v.value === value.value);
|
|
80
|
-
if (other) {
|
|
81
|
-
checkClientToServer(`${path}.${value.value}`, issues, (_a = value.struct) !== null && _a !== void 0 ? _a : new ast_1.StructType([]), (_b = other.struct) !== null && _b !== void 0 ? _b : new ast_1.StructType([]));
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
issues.push(`The enum at ${path} used to accept the value "${value.value}" that doesn't exist now. Clients that send it will fail.`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (t1.constructor.name === t2.constructor.name) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
issues.push(`${path} was ${t1.name} and now it is ${t2.name}. They are not compatible.`);
|
|
93
|
-
}
|
|
94
|
-
function checkServerToClient(path, issues, t1, t2) {
|
|
95
|
-
var _a, _b;
|
|
96
|
-
if (t1 instanceof ast_1.TypeReference) {
|
|
97
|
-
checkServerToClient(path, issues, t1.type, t2);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (t2 instanceof ast_1.TypeReference) {
|
|
101
|
-
checkServerToClient(path, issues, t1, t2.type);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (t1 instanceof ast_1.OptionalType && !(t2 instanceof ast_1.OptionalType)) {
|
|
105
|
-
checkServerToClient(path, issues, t1.base, t2);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (t1 instanceof ast_1.OptionalType && t2 instanceof ast_1.OptionalType) {
|
|
109
|
-
checkServerToClient(path, issues, t1.base, t2.base);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (!(t1 instanceof ast_1.OptionalType) && t2 instanceof ast_1.OptionalType) {
|
|
113
|
-
issues.push(`${path} wasn't optional, but now it is. If the client receives a null, it will crash. Remove the optional annotation.`);
|
|
114
|
-
checkServerToClient(path, issues, t1, t2.base);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (t1 instanceof ast_1.ArrayType && t2 instanceof ast_1.ArrayType) {
|
|
118
|
-
checkServerToClient(path, issues, t1.base, t2.base);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (t1 instanceof ast_1.StructType && t2 instanceof ast_1.StructType) {
|
|
122
|
-
for (const field1 of t1.fields) {
|
|
123
|
-
const field2 = t2.fields.find(x => x.name === field1.name);
|
|
124
|
-
if (!field2) {
|
|
125
|
-
if (field1.type instanceof ast_1.OptionalType) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
issues.push(`${path}.${field1.name} used to exist with type ${field1.type.name}, but it's now missing. Add it back.`);
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
checkServerToClient(`${path}.${field1.name}`, issues, field1.type, field2.type);
|
|
134
|
-
}
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if ((t1 instanceof ast_1.IntPrimitiveType && t2 instanceof ast_1.UIntPrimitiveType) ||
|
|
138
|
-
(t1 instanceof ast_1.FloatPrimitiveType && t2 instanceof ast_1.IntPrimitiveType) ||
|
|
139
|
-
(t1 instanceof ast_1.IntPrimitiveType && t2 instanceof ast_1.MoneyPrimitiveType) ||
|
|
140
|
-
(t1 instanceof ast_1.UIntPrimitiveType && t2 instanceof ast_1.MoneyPrimitiveType) ||
|
|
141
|
-
(t1 instanceof ast_1.BigIntPrimitiveType && t2 instanceof ast_1.UIntPrimitiveType) ||
|
|
142
|
-
(t1 instanceof ast_1.BigIntPrimitiveType && t2 instanceof ast_1.IntPrimitiveType) ||
|
|
143
|
-
(t1 instanceof ast_1.BigIntPrimitiveType && t2 instanceof ast_1.MoneyPrimitiveType) ||
|
|
144
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.BigIntPrimitiveType) ||
|
|
145
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.UuidPrimitiveType) ||
|
|
146
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.XmlPrimitiveType) ||
|
|
147
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.DatePrimitiveType) ||
|
|
148
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.DateTimePrimitiveType) ||
|
|
149
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.CpfPrimitiveType) ||
|
|
150
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.CnpjPrimitiveType) ||
|
|
151
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.HexPrimitiveType) ||
|
|
152
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.HtmlPrimitiveType) ||
|
|
153
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.Base64PrimitiveType) ||
|
|
154
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.BytesPrimitiveType) ||
|
|
155
|
-
(t1 instanceof ast_1.Base64PrimitiveType && t2 instanceof ast_1.BytesPrimitiveType) ||
|
|
156
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.UrlPrimitiveType) ||
|
|
157
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.EmailPrimitiveType) ||
|
|
158
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.DecimalPrimitiveType) ||
|
|
159
|
-
(t1 instanceof ast_1.StringPrimitiveType && t2 instanceof ast_1.EnumType)) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (t1 instanceof ast_1.EnumType && t2 instanceof ast_1.EnumType) {
|
|
163
|
-
for (const value of t2.values) {
|
|
164
|
-
const other = t1.values.find(v => v.value === value.value);
|
|
165
|
-
if (other) {
|
|
166
|
-
checkServerToClient(`${path}.${value.value}`, issues, (_a = other.struct) !== null && _a !== void 0 ? _a : new ast_1.StructType([]), (_b = value.struct) !== null && _b !== void 0 ? _b : new ast_1.StructType([]));
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
issues.push(`The enum at ${path} now has the value "${value.value}" that didn't exist before. Client will crash if it receives it`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (t1.constructor.name === t2.constructor.name) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
issues.push(`${path} was ${t1.name} and now it is ${t2.name}. They are not compatible.`);
|
|
178
|
-
}
|
|
179
|
-
function compatibilityIssues(ast1, ast2) {
|
|
180
|
-
const issues = [];
|
|
181
|
-
for (const op1 of ast1.operations) {
|
|
182
|
-
const op2 = ast2.operations.find(x => x.name === op1.name);
|
|
183
|
-
if (!op2) {
|
|
184
|
-
issues.push(`function ${op1.name} used to exist, but it's now missing. Add it back.`);
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
checkServerToClient(`${op1.name}.ret`, issues, op1.returnType, op2.returnType);
|
|
188
|
-
for (const arg2 of op2.args) {
|
|
189
|
-
const arg1 = op1.args.find(x => x.name === arg2.name);
|
|
190
|
-
if (!arg1) {
|
|
191
|
-
if (arg2.type instanceof ast_1.OptionalType) {
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
issues.push(`${op1.name}.args.${arg2.name} didn't exist before and isn't optional. Make it optional.`);
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
checkClientToServer(`${op1.name}.args.${arg1.name}`, issues, arg1.type, arg2.type);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
for (const err1 of ast1.errors) {
|
|
203
|
-
const err2 = ast2.errors.find(x => x.name === err1.name);
|
|
204
|
-
if (!err2) {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
checkServerToClient(`${err1.name}.data`, issues, err1.dataType, err2.dataType);
|
|
208
|
-
}
|
|
209
|
-
return issues;
|
|
210
|
-
}
|
|
211
|
-
exports.compatibilityIssues = compatibilityIssues;
|
package/dist/src/helpers.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasType = void 0;
|
|
4
|
-
const visitor_1 = require("./semantic/visitor");
|
|
5
|
-
class HasTypeVisitor extends visitor_1.Visitor {
|
|
6
|
-
constructor(root, type) {
|
|
7
|
-
super(root);
|
|
8
|
-
this.type = type;
|
|
9
|
-
this.found = false;
|
|
10
|
-
}
|
|
11
|
-
visit(node) {
|
|
12
|
-
if (node.constructor === this.type) {
|
|
13
|
-
this.found = true;
|
|
14
|
-
}
|
|
15
|
-
super.visit(node);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function hasType(root, type) {
|
|
19
|
-
const visitor = new HasTypeVisitor(root, type);
|
|
20
|
-
visitor.process();
|
|
21
|
-
return visitor.found;
|
|
22
|
-
}
|
|
23
|
-
exports.hasType = hasType;
|
package/dist/src/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.hasType = exports.Visitor = exports.jsonToAst = exports.astToJson = void 0;
|
|
18
|
-
__exportStar(require("./ast"), exports);
|
|
19
|
-
__exportStar(require("./compatibility"), exports);
|
|
20
|
-
var json_1 = require("./json");
|
|
21
|
-
Object.defineProperty(exports, "astToJson", { enumerable: true, get: function () { return json_1.astToJson; } });
|
|
22
|
-
Object.defineProperty(exports, "jsonToAst", { enumerable: true, get: function () { return json_1.jsonToAst; } });
|
|
23
|
-
__exportStar(require("./lexer"), exports);
|
|
24
|
-
__exportStar(require("./parser"), exports);
|
|
25
|
-
__exportStar(require("./token"), exports);
|
|
26
|
-
var visitor_1 = require("./semantic/visitor");
|
|
27
|
-
Object.defineProperty(exports, "Visitor", { enumerable: true, get: function () { return visitor_1.Visitor; } });
|
|
28
|
-
var helpers_1 = require("./helpers");
|
|
29
|
-
Object.defineProperty(exports, "hasType", { enumerable: true, get: function () { return helpers_1.hasType; } });
|