@flink-app/flink 0.4.2 → 0.4.5
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/cli/build.ts +18 -22
- package/cli/run.ts +12 -2
- package/dist/bin/flink.js +2 -2
- package/dist/cli/build.js +4 -8
- package/dist/cli/clean.js +2 -2
- package/dist/cli/cli-utils.js +1 -1
- package/dist/cli/forked-compiler.d.ts +2 -0
- package/dist/cli/forked-compiler.js +33 -0
- package/dist/cli/generate-schemas.js +16 -20
- package/dist/cli/run.js +10 -3
- package/dist/src/FlinkApp.d.ts +1 -1
- package/dist/src/FlinkApp.js +54 -54
- package/dist/src/FlinkErrors.d.ts +1 -1
- package/dist/src/FlinkErrors.js +5 -5
- package/dist/src/FlinkHttpHandler.d.ts +7 -7
- package/dist/src/FlinkJob.d.ts +2 -2
- package/dist/src/FlinkRepo.js +1 -1
- package/dist/src/FlinkResponse.d.ts +2 -2
- package/dist/src/FsUtils.js +4 -4
- package/dist/src/TypeScriptCompiler.js +63 -67
- package/dist/src/TypeScriptUtils.js +1 -1
- package/dist/src/index.js +1 -5
- package/dist/src/mock-data-generator.js +1 -1
- package/dist/src/utils.js +27 -9
- package/package.json +2 -2
- package/spec/utils.spec.ts +245 -201
- package/src/utils.ts +111 -105
package/src/utils.ts
CHANGED
|
@@ -7,60 +7,57 @@ import { log } from "./FlinkLog";
|
|
|
7
7
|
import { FlinkResponse } from "./FlinkResponse";
|
|
8
8
|
|
|
9
9
|
export function handlersPath(appRoot: string) {
|
|
10
|
-
|
|
10
|
+
return join(appRoot, "src", "handlers");
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function schemasPath(appRoot: string) {
|
|
14
|
-
|
|
14
|
+
return join(appRoot, "src", "schemas");
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function isRouteMatch(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return !!match;
|
|
17
|
+
export function isRouteMatch(req: Request, routes: { method: HttpMethod; path: string }[]) {
|
|
18
|
+
const match = routes.find(({ method, path }) => {
|
|
19
|
+
const sameMethod = req.method.toLowerCase() === method;
|
|
20
|
+
const samePath = req.route.path === path;
|
|
21
|
+
return sameMethod && samePath;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return !!match;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
export function isError(message: FlinkResponse) {
|
|
31
|
-
|
|
28
|
+
return message.status && message.status > 399;
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
export async function getHandlerFiles(appRoot: string) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
try {
|
|
33
|
+
return await tinyGlob(`**/*.ts`, {
|
|
34
|
+
cwd: handlersPath(appRoot),
|
|
35
|
+
absolute: true,
|
|
36
|
+
});
|
|
37
|
+
} catch (err) {
|
|
38
|
+
log.debug(`Failed getting handler files: ${err}`);
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
export async function getSchemaFiles(appRoot: string) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
try {
|
|
45
|
+
return await tinyGlob(`**/*.ts`, {
|
|
46
|
+
cwd: schemasPath(appRoot),
|
|
47
|
+
absolute: true,
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
export function getCollectionNameForRepo(repoFilename: string) {
|
|
58
|
-
|
|
55
|
+
return repoFilename.replace("Repo.ts", "").toLowerCase();
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
export function getRepoInstanceName(fn: string) {
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const [name] = fn.split(".ts");
|
|
60
|
+
return name.charAt(0).toLowerCase() + name.substr(1);
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
/**
|
|
@@ -68,17 +65,17 @@ export function getRepoInstanceName(fn: string) {
|
|
|
68
65
|
* if it starts with i.e "GetFoo"
|
|
69
66
|
*/
|
|
70
67
|
export function getHttpMethodFromHandlerName(handlerFilename: string) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
if (handlerFilename.includes(sep)) {
|
|
69
|
+
const split = handlerFilename.split(sep);
|
|
70
|
+
handlerFilename = split[split.length - 1];
|
|
71
|
+
}
|
|
75
72
|
|
|
76
|
-
|
|
73
|
+
handlerFilename = handlerFilename.toLocaleLowerCase();
|
|
77
74
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
if (handlerFilename.startsWith(HttpMethod.get)) return HttpMethod.get;
|
|
76
|
+
if (handlerFilename.startsWith(HttpMethod.post)) return HttpMethod.post;
|
|
77
|
+
if (handlerFilename.startsWith(HttpMethod.put)) return HttpMethod.put;
|
|
78
|
+
if (handlerFilename.startsWith(HttpMethod.delete)) return HttpMethod.delete;
|
|
82
79
|
}
|
|
83
80
|
|
|
84
81
|
/**
|
|
@@ -89,75 +86,84 @@ export function getHttpMethodFromHandlerName(handlerFilename: string) {
|
|
|
89
86
|
* @param jsonSchemas
|
|
90
87
|
* @returns
|
|
91
88
|
*/
|
|
92
|
-
export function deRefSchema(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
) {
|
|
96
|
-
if (typeof schemaToDeRef === "boolean") {
|
|
97
|
-
return schemaToDeRef;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (schemaToDeRef.type === "array") {
|
|
101
|
-
const items = schemaToDeRef.items as JSONSchema7;
|
|
102
|
-
|
|
103
|
-
if (items.$ref) {
|
|
104
|
-
const [_0, _1, defKey] = items.$ref.split("/");
|
|
105
|
-
const refedSchema = (jsonSchemas.definitions || {})[defKey];
|
|
106
|
-
|
|
107
|
-
if (refedSchema) {
|
|
108
|
-
schemaToDeRef.items = deRefSchema(refedSchema, jsonSchemas);
|
|
109
|
-
} else {
|
|
110
|
-
console.warn(`Failed to find deref ${schemaToDeRef.$ref}`);
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
schemaToDeRef.items = deRefSchema(
|
|
114
|
-
schemaToDeRef.items as JSONSchema7,
|
|
115
|
-
jsonSchemas
|
|
116
|
-
);
|
|
89
|
+
export function deRefSchema(schemaToDeRef: JSONSchema7Definition, jsonSchemas: JSONSchema7) {
|
|
90
|
+
if (typeof schemaToDeRef === "boolean") {
|
|
91
|
+
return schemaToDeRef;
|
|
117
92
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
93
|
+
|
|
94
|
+
if (schemaToDeRef.type === "array") {
|
|
95
|
+
const items = schemaToDeRef.items as JSONSchema7;
|
|
96
|
+
|
|
97
|
+
if (items.$ref) {
|
|
98
|
+
const [_0, _1, defKey] = items.$ref.split("/");
|
|
99
|
+
const refedSchema = (jsonSchemas.definitions || {})[defKey];
|
|
100
|
+
|
|
101
|
+
if (refedSchema) {
|
|
102
|
+
schemaToDeRef.items = deRefSchema(refedSchema, jsonSchemas);
|
|
103
|
+
} else {
|
|
104
|
+
console.warn(`Failed to find deref ${schemaToDeRef.$ref}`);
|
|
105
|
+
}
|
|
131
106
|
} else {
|
|
132
|
-
|
|
107
|
+
schemaToDeRef.items = deRefSchema(schemaToDeRef.items as JSONSchema7, jsonSchemas);
|
|
133
108
|
}
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
109
|
+
} else if (schemaToDeRef.properties) {
|
|
110
|
+
for (const k in schemaToDeRef.properties) {
|
|
111
|
+
let prop = schemaToDeRef.properties[k];
|
|
112
|
+
|
|
113
|
+
if (typeof prop === "boolean") {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (prop.$ref) {
|
|
118
|
+
const [_0, _1, defKey] = prop.$ref.split("/");
|
|
119
|
+
const refedSchema = (jsonSchemas.definitions || {})[defKey];
|
|
120
|
+
if (refedSchema) {
|
|
121
|
+
schemaToDeRef.properties[k] = deRefSchema(refedSchema, jsonSchemas);
|
|
122
|
+
} else {
|
|
123
|
+
console.warn(`Failed to find deref ${prop.$ref}`);
|
|
124
|
+
}
|
|
125
|
+
} else if (prop.type === "array" && (prop.items as JSONSchema7).$ref) {
|
|
126
|
+
const [_0, _1, defKey] = (prop.items as JSONSchema7).$ref!.split("/");
|
|
127
|
+
const refedSchema = (jsonSchemas.definitions || {})[defKey];
|
|
128
|
+
if (refedSchema) {
|
|
129
|
+
(schemaToDeRef.properties[k] as JSONSchema7).items = deRefSchema(refedSchema, jsonSchemas);
|
|
130
|
+
} else {
|
|
131
|
+
console.warn(`Failed to find deref ${prop.$ref}`);
|
|
132
|
+
}
|
|
133
|
+
} else if (prop.type === "object" || prop.type === "array") {
|
|
134
|
+
schemaToDeRef.properties[k] = deRefSchema(prop, jsonSchemas);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} else if (schemaToDeRef.anyOf) {
|
|
138
|
+
let i = 0;
|
|
139
|
+
for (const anyOf of schemaToDeRef.anyOf) {
|
|
140
|
+
const anyOfSchema = anyOf as JSONSchema7;
|
|
141
|
+
|
|
142
|
+
if (anyOfSchema.$ref) {
|
|
143
|
+
const [_0, _1, defKey] = anyOfSchema.$ref.split("/");
|
|
144
|
+
const refedSchema = (jsonSchemas.definitions || {})[defKey];
|
|
145
|
+
if (refedSchema) {
|
|
146
|
+
schemaToDeRef.anyOf[i] = deRefSchema(refedSchema, jsonSchemas);
|
|
147
|
+
} else {
|
|
148
|
+
console.warn(`Failed to find deref ${anyOfSchema.$ref}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
i++;
|
|
144
153
|
}
|
|
145
|
-
} else if (prop.type === "object" || prop.type === "array") {
|
|
146
|
-
schemaToDeRef.properties[k] = deRefSchema(prop, jsonSchemas);
|
|
147
|
-
}
|
|
148
154
|
}
|
|
149
|
-
|
|
150
|
-
|
|
155
|
+
|
|
156
|
+
return schemaToDeRef;
|
|
151
157
|
}
|
|
152
158
|
|
|
153
159
|
export function getJsDocComment(comment: string) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
const rows = comment.split("\n").map((line) => {
|
|
161
|
+
line = line.trim();
|
|
162
|
+
if (line.startsWith("//")) {
|
|
163
|
+
return line.replace("//", line).trim();
|
|
164
|
+
}
|
|
165
|
+
return line.replace(/\/\*\*|\*\/|\*/, "").trim();
|
|
166
|
+
});
|
|
161
167
|
|
|
162
|
-
|
|
168
|
+
return rows.join("\n").trim();
|
|
163
169
|
}
|