@sdkgen/parser 1.5.4 → 1.6.2
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/spec/parser.spec.js +35 -0
- package/dist/src/ast.d.ts +1 -1
- package/dist/src/parser.d.ts +1 -1
- package/dist/src/parser.js +15 -9
- package/dist/src/restparser.js +9 -12
- package/dist/tsconfig.tsbuildinfo +1028 -374
- package/package.json +6 -7
package/dist/spec/parser.spec.js
CHANGED
|
@@ -469,6 +469,41 @@ describe(parser_1.Parser, () => {
|
|
|
469
469
|
typeTable: {},
|
|
470
470
|
});
|
|
471
471
|
expectParses(`
|
|
472
|
+
@rest POST /insertCustomerLead [header api_key: {apiKey}] [header api_secret: {apiSecret}] [body {customerLead}]
|
|
473
|
+
fn insertCustomerLead(customerLead: string, apiKey: bigint, apiSecret: string)
|
|
474
|
+
`, {
|
|
475
|
+
annotations: {
|
|
476
|
+
"fn.insertCustomerLead": [
|
|
477
|
+
{
|
|
478
|
+
type: "rest",
|
|
479
|
+
value: {
|
|
480
|
+
bodyVariable: "customerLead",
|
|
481
|
+
headers: [
|
|
482
|
+
["api_key", "apiKey"],
|
|
483
|
+
["api_secret", "apiSecret"],
|
|
484
|
+
],
|
|
485
|
+
method: "POST",
|
|
486
|
+
path: "/insertCustomerLead",
|
|
487
|
+
pathVariables: [],
|
|
488
|
+
queryVariables: [],
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
],
|
|
492
|
+
},
|
|
493
|
+
errors: ["Fatal"],
|
|
494
|
+
functionTable: {
|
|
495
|
+
insertCustomerLead: {
|
|
496
|
+
args: {
|
|
497
|
+
customerLead: "string",
|
|
498
|
+
apiKey: "bigint",
|
|
499
|
+
apiSecret: "string",
|
|
500
|
+
},
|
|
501
|
+
ret: "void",
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
typeTable: {},
|
|
505
|
+
});
|
|
506
|
+
expectParses(`
|
|
472
507
|
type NewUser {
|
|
473
508
|
name: string
|
|
474
509
|
}
|
package/dist/src/ast.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare abstract class AstNode {
|
|
|
8
8
|
}
|
|
9
9
|
export declare abstract class Type extends AstNode {
|
|
10
10
|
abstract get name(): string;
|
|
11
|
-
toJSON():
|
|
11
|
+
toJSON(): Omit<this, "name">;
|
|
12
12
|
}
|
|
13
13
|
export declare class ErrorNode extends AstNode {
|
|
14
14
|
name: string;
|
package/dist/src/parser.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export declare class Parser {
|
|
|
7
7
|
private token;
|
|
8
8
|
private annotations;
|
|
9
9
|
private warnings;
|
|
10
|
+
private readFileSync;
|
|
10
11
|
constructor(source: Lexer | string);
|
|
11
12
|
private nextToken;
|
|
12
|
-
private get currentFileName();
|
|
13
13
|
private multiExpect;
|
|
14
14
|
private expect;
|
|
15
15
|
parse(): AstRoot;
|
package/dist/src/parser.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable no-sync */
|
|
3
|
+
/* eslint-disable no-loop-func */
|
|
2
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
5
|
exports.Parser = exports.ParserError = void 0;
|
|
4
|
-
/* eslint-disable no-loop-func */
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
6
|
const ast_1 = require("./ast");
|
|
8
7
|
const lexer_1 = require("./lexer");
|
|
9
8
|
const restparser_1 = require("./restparser");
|
|
@@ -18,11 +17,21 @@ class Parser {
|
|
|
18
17
|
this.token = null;
|
|
19
18
|
this.annotations = [];
|
|
20
19
|
this.warnings = [];
|
|
20
|
+
this.readFileSync = () => {
|
|
21
|
+
throw "Not implemented";
|
|
22
|
+
};
|
|
23
|
+
try {
|
|
24
|
+
// eslint-disable-next-line
|
|
25
|
+
this.readFileSync = require("fs").readFileSync;
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
// do nothing
|
|
29
|
+
}
|
|
21
30
|
if (source instanceof lexer_1.Lexer) {
|
|
22
31
|
this.lexers = [source];
|
|
23
32
|
}
|
|
24
33
|
else {
|
|
25
|
-
this.lexers = [new lexer_1.Lexer(
|
|
34
|
+
this.lexers = [new lexer_1.Lexer(this.readFileSync(source).toString(), source)];
|
|
26
35
|
}
|
|
27
36
|
this.nextToken();
|
|
28
37
|
}
|
|
@@ -35,9 +44,6 @@ class Parser {
|
|
|
35
44
|
this.lexers.pop();
|
|
36
45
|
}
|
|
37
46
|
}
|
|
38
|
-
get currentFileName() {
|
|
39
|
-
return this.token === null ? null : this.token.location.filename;
|
|
40
|
-
}
|
|
41
47
|
multiExpect(matcher) {
|
|
42
48
|
if (!this.token) {
|
|
43
49
|
throw new ParserError(`Expected ${Object.keys(matcher)
|
|
@@ -96,8 +102,8 @@ class Parser {
|
|
|
96
102
|
this.checkCannotHaveAnnotationsHere();
|
|
97
103
|
this.nextToken();
|
|
98
104
|
const pathToken = this.expect(token_1.StringLiteralToken);
|
|
99
|
-
const resolvedPath =
|
|
100
|
-
this.lexers.push(new lexer_1.Lexer(
|
|
105
|
+
const resolvedPath = pathToken.location.filename.replace(/[^/\\]+$/u, `${pathToken.value}.sdkgen`);
|
|
106
|
+
this.lexers.push(new lexer_1.Lexer(this.readFileSync(resolvedPath).toString(), resolvedPath));
|
|
101
107
|
this.nextToken();
|
|
102
108
|
},
|
|
103
109
|
TypeKeywordToken: () => {
|
package/dist/src/restparser.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseRestAnnotation = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
4
|
const ast_1 = require("./ast");
|
|
6
5
|
function scanHeaders(text) {
|
|
7
6
|
var _a;
|
|
8
|
-
|
|
7
|
+
// Header name: https://tools.ietf.org/html/rfc2616#section-4.2
|
|
8
|
+
const headerRegex = /\[header (?<header>[^()<>@,;:\\"/[\]?={}\s\t]+): \{(?<name>\w+)\}\]/gu;
|
|
9
9
|
const headers = new Map();
|
|
10
10
|
let match;
|
|
11
11
|
while ((match = headerRegex.exec(text)) !== null) {
|
|
12
12
|
if (((_a = match.groups) === null || _a === void 0 ? void 0 : _a.header) && match.groups.name) {
|
|
13
|
-
headers.set(match.groups.header, match.groups.name);
|
|
13
|
+
headers.set(match.groups.header.toLowerCase(), match.groups.name);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
return headers;
|
|
@@ -41,24 +41,21 @@ function parseRestAnnotation(text) {
|
|
|
41
41
|
if (!["GET", "POST", "PUT", "DELETE", "PATCH"].includes(method)) {
|
|
42
42
|
throw new Error(`Unsupported method '${method}'`);
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// eslint-disable-next-line prefer-destructuring
|
|
45
|
+
let path = fragments[1];
|
|
46
|
+
if (!path.startsWith("/")) {
|
|
46
47
|
throw new Error(`Invalid path`);
|
|
47
48
|
}
|
|
48
|
-
if (parsedPath.dir === "/") {
|
|
49
|
-
parsedPath.dir = "";
|
|
50
|
-
}
|
|
51
49
|
let queryVariables = [];
|
|
52
|
-
if (
|
|
53
|
-
const [base, ...queryArray] =
|
|
54
|
-
|
|
50
|
+
if (path.includes("?")) {
|
|
51
|
+
const [base, ...queryArray] = path.split("?");
|
|
52
|
+
path = base;
|
|
55
53
|
const query = queryArray.join("?");
|
|
56
54
|
if (!/^\{\w+\}(?:&\{\w+\})*$/u.test(query)) {
|
|
57
55
|
throw new Error(`Invalid querystring on path`);
|
|
58
56
|
}
|
|
59
57
|
queryVariables = scanVariables(query);
|
|
60
58
|
}
|
|
61
|
-
const path = `${parsedPath.dir}/${parsedPath.base}`;
|
|
62
59
|
const pathVariables = scanVariables(path);
|
|
63
60
|
const remaining = fragments.slice(2).join(" ");
|
|
64
61
|
const headers = scanHeaders(remaining);
|