@flink-app/flink 0.4.4 → 0.4.6

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