@flink-app/flink 0.12.1-alpha.0 → 0.12.1-alpha.10

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 (45) hide show
  1. package/bin/flink.ts +6 -13
  2. package/dist/bin/flink.js +3 -10
  3. package/dist/cli/build.js +3 -3
  4. package/dist/cli/clean.js +2 -2
  5. package/dist/cli/cli-utils.js +1 -1
  6. package/dist/cli/run.js +2 -2
  7. package/dist/src/FlinkApp.d.ts +6 -3
  8. package/dist/src/FlinkApp.js +109 -78
  9. package/dist/src/FlinkErrors.d.ts +1 -1
  10. package/dist/src/FlinkErrors.js +5 -5
  11. package/dist/src/FlinkHttpHandler.d.ts +7 -7
  12. package/dist/src/FlinkHttpHandler.js +1 -1
  13. package/dist/src/FlinkJob.d.ts +2 -2
  14. package/dist/src/FlinkLog.d.ts +2 -2
  15. package/dist/src/FlinkRepo.d.ts +17 -8
  16. package/dist/src/FlinkRepo.js +44 -20
  17. package/dist/src/FlinkResponse.d.ts +2 -2
  18. package/dist/src/FsUtils.js +7 -7
  19. package/dist/src/TypeScriptCompiler.js +83 -68
  20. package/dist/src/TypeScriptUtils.js +11 -33
  21. package/dist/src/index.js +5 -1
  22. package/dist/src/mock-data-generator.js +1 -1
  23. package/dist/src/utils.js +6 -6
  24. package/package.json +7 -7
  25. package/spec/FlinkRepo.spec.ts +11 -0
  26. package/spec/mock-project/dist/src/handlers/GetCar.js +10 -12
  27. package/spec/mock-project/dist/src/handlers/GetCar2.js +11 -13
  28. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +8 -10
  29. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +8 -10
  30. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +8 -10
  31. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +10 -12
  32. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +10 -12
  33. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +10 -12
  34. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +10 -12
  35. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +10 -12
  36. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +10 -12
  37. package/spec/mock-project/dist/src/handlers/PostCar.js +10 -12
  38. package/spec/mock-project/dist/src/handlers/PostLogin.js +11 -13
  39. package/spec/mock-project/dist/src/handlers/PutCar.js +10 -12
  40. package/spec/mock-project/dist/src/index.js +6 -2
  41. package/src/FlinkApp.ts +33 -8
  42. package/src/FlinkRepo.ts +30 -11
  43. package/src/TypeScriptCompiler.ts +13 -2
  44. package/src/TypeScriptUtils.ts +110 -164
  45. package/cli/generate-schemas.ts +0 -153
@@ -1,153 +0,0 @@
1
- #!/usr/bin/env node
2
- import { JSONSchema7, JSONSchema7Definition } from "json-schema";
3
- import { join } from "path";
4
- import {
5
- createFormatter,
6
- createParser,
7
- SchemaGenerator,
8
- } from "ts-json-schema-generator";
9
- import { Project, SyntaxKind, ts } from "ts-morph";
10
- import { writeJsonFile } from "../src/FsUtils";
11
- import { getOption } from "./cli-utils";
12
-
13
- module.exports = async function run(args: string[]) {
14
- if (args.includes("--help")) {
15
- console.log(`
16
- Description
17
- Generates JSON schemas for types located in schemas directory or if any other directory
18
- is specified with option --types-dir.
19
-
20
- Outputs generated file(s) to dir '.flink' or if any other --out-dir is specified.
21
-
22
- Usage
23
- $ flink generate-schemas <dir> --types-dir <types-dir> --out-file <out-file>
24
-
25
- <dir> is project root as directory where tsconfig.son resides.
26
-
27
- Options
28
- --types-dir Directory where typescript types are located relative to <dir>, default "./src/schemas"
29
- --out-file Path to file that will contain generated json schemas relative to <dir>, default "./.flink/generated-schemas.json"
30
- --help Displays this message
31
- `);
32
-
33
- process.exit(0);
34
- }
35
-
36
- let dir = "./";
37
- if (args[0] && !args[0].startsWith("--")) {
38
- dir = args[0];
39
- }
40
-
41
- const verbose = getOption(args, "verbose", false, {
42
- isBoolean: true,
43
- }) as boolean;
44
-
45
- const typesDir = getOption(args, "types-dir", "./src/schemas") as string;
46
-
47
- const outFile = getOption(
48
- args,
49
- "out-file",
50
- "./.flink/generated-schemas.json"
51
- ) as string;
52
-
53
- const project = new Project({
54
- tsConfigFilePath: join(dir, "tsconfig.json"),
55
- skipAddingFilesFromTsConfig: true,
56
- compilerOptions: {
57
- noEmit: true,
58
- },
59
- });
60
-
61
- project.addSourceFilesAtPaths(join(dir, typesDir, "**/*.ts"));
62
-
63
- console.log("Found", project.getSourceFiles().length, "files");
64
-
65
- const schemaDeclarations: ts.Node[] = [];
66
-
67
- const generator = initJsonSchemaGenerator(project);
68
-
69
- const jsonSchemas: JSONSchema7[] = [];
70
-
71
- for (const sf of project.getSourceFiles()) {
72
- if (sf.getDefaultExportSymbol()) {
73
- console.warn(
74
- `WARN: Schema file ${sf.getBaseName()} has default export, but only named exports are picked up by json schemas parser`
75
- );
76
- }
77
-
78
- const sourceFileInterfaceDeclarations = sf.getChildrenOfKind(
79
- SyntaxKind.InterfaceDeclaration
80
- );
81
-
82
- const sourceFileEnumDeclarations = sf.getChildrenOfKind(
83
- SyntaxKind.EnumDeclaration
84
- );
85
-
86
- const sourceFileDeclarations = [
87
- ...sourceFileEnumDeclarations,
88
- ...sourceFileInterfaceDeclarations,
89
- ];
90
-
91
- schemaDeclarations.push(
92
- ...sourceFileDeclarations.map((d) => d.compilerNode)
93
- );
94
-
95
- verbose &&
96
- console.log(
97
- "Found",
98
- sourceFileDeclarations.length,
99
- "schema(s) in file",
100
- sf.getBaseName()
101
- );
102
-
103
- try {
104
- const schema = generator.createSchemaFromNodes(
105
- sourceFileInterfaceDeclarations.map((d) => d.compilerNode)
106
- );
107
- jsonSchemas.push(schema);
108
- // console.log("Created schemas");
109
- } catch (err) {
110
- console.error(
111
- "Failed to generate schema in file",
112
- sf.getBaseName() + ":",
113
- err
114
- );
115
- }
116
- }
117
-
118
- const mergedSchemas = jsonSchemas.reduce(
119
- (out, schema) => {
120
- if (schema)
121
- if (schema.definitions) {
122
- out.definitions = { ...out.definitions, ...schema.definitions };
123
- }
124
- return out;
125
- },
126
- {
127
- $schema: "http://json-schema.org/draft-07/schema#",
128
- $ref: "#/definitions/Schemas",
129
- definitions: {},
130
- }
131
- );
132
-
133
- const file = join(dir, outFile);
134
-
135
- await writeJsonFile(file, mergedSchemas, {
136
- ensureDir: true,
137
- });
138
-
139
- console.log("Wrote file", file);
140
- };
141
-
142
- function initJsonSchemaGenerator(project: Project) {
143
- const formatter = createFormatter({});
144
- const parser = createParser(project.getProgram().compilerObject, {});
145
- const generator = new SchemaGenerator(
146
- project.getProgram().compilerObject,
147
- parser,
148
- formatter,
149
- { expose: "export" }
150
- );
151
-
152
- return generator;
153
- }