@flink-app/flink 0.12.1-alpha.6 → 0.12.1-alpha.9
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/cli/generate-schemas.d.ts +2 -0
- package/dist/cli/generate-schemas.js +140 -0
- package/dist/src/FlinkApp.d.ts +2 -1
- package/dist/src/FlinkApp.js +1 -0
- package/dist/src/FlinkRepo.d.ts +5 -4
- package/dist/src/FlinkRepo.js +2 -1
- package/package.json +3 -3
- package/src/FlinkApp.ts +2 -0
- package/src/FlinkRepo.ts +2 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __assign = (this && this.__assign) || function () {
|
|
4
|
+
__assign = Object.assign || function(t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
return __assign.apply(this, arguments);
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
24
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
25
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
26
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
27
|
+
function step(op) {
|
|
28
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
29
|
+
while (_) try {
|
|
30
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
31
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
32
|
+
switch (op[0]) {
|
|
33
|
+
case 0: case 1: t = op; break;
|
|
34
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
35
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
36
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
37
|
+
default:
|
|
38
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
39
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
40
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
41
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
42
|
+
if (t[2]) _.ops.pop();
|
|
43
|
+
_.trys.pop(); continue;
|
|
44
|
+
}
|
|
45
|
+
op = body.call(thisArg, _);
|
|
46
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
47
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
51
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
52
|
+
to[j] = from[i];
|
|
53
|
+
return to;
|
|
54
|
+
};
|
|
55
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
+
var path_1 = require("path");
|
|
57
|
+
var ts_json_schema_generator_1 = require("ts-json-schema-generator");
|
|
58
|
+
var ts_morph_1 = require("ts-morph");
|
|
59
|
+
var FsUtils_1 = require("../src/FsUtils");
|
|
60
|
+
var cli_utils_1 = require("./cli-utils");
|
|
61
|
+
module.exports = function run(args) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
var dir, verbose, typesDir, outFile, project, schemaDeclarations, generator, jsonSchemas, _i, _a, sf, sourceFileInterfaceDeclarations, sourceFileEnumDeclarations, sourceFileDeclarations, schema, mergedSchemas, file;
|
|
64
|
+
return __generator(this, function (_b) {
|
|
65
|
+
switch (_b.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
if (args.includes("--help")) {
|
|
68
|
+
console.log("\n Description\n Generates JSON schemas for types located in schemas directory or if any other directory\n is specified with option --types-dir. \n\n Outputs generated file(s) to dir '.flink' or if any other --out-dir is specified.\n\n Usage\n $ flink generate-schemas <dir> --types-dir <types-dir> --out-file <out-file>\n\n <dir> is project root as directory where tsconfig.son resides.\n \n Options \n --types-dir Directory where typescript types are located relative to <dir>, default \"./src/schemas\"\n --out-file Path to file that will contain generated json schemas relative to <dir>, default \"./.flink/generated-schemas.json\"\n --help Displays this message\n ");
|
|
69
|
+
process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
dir = "./";
|
|
72
|
+
if (args[0] && !args[0].startsWith("--")) {
|
|
73
|
+
dir = args[0];
|
|
74
|
+
}
|
|
75
|
+
verbose = cli_utils_1.getOption(args, "verbose", false, {
|
|
76
|
+
isBoolean: true,
|
|
77
|
+
});
|
|
78
|
+
typesDir = cli_utils_1.getOption(args, "types-dir", "./src/schemas");
|
|
79
|
+
outFile = cli_utils_1.getOption(args, "out-file", "./.flink/generated-schemas.json");
|
|
80
|
+
project = new ts_morph_1.Project({
|
|
81
|
+
tsConfigFilePath: path_1.join(dir, "tsconfig.json"),
|
|
82
|
+
skipAddingFilesFromTsConfig: true,
|
|
83
|
+
compilerOptions: {
|
|
84
|
+
noEmit: true,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
project.addSourceFilesAtPaths(path_1.join(dir, typesDir, "**/*.ts"));
|
|
88
|
+
console.log("Found", project.getSourceFiles().length, "files");
|
|
89
|
+
schemaDeclarations = [];
|
|
90
|
+
generator = initJsonSchemaGenerator(project);
|
|
91
|
+
jsonSchemas = [];
|
|
92
|
+
for (_i = 0, _a = project.getSourceFiles(); _i < _a.length; _i++) {
|
|
93
|
+
sf = _a[_i];
|
|
94
|
+
if (sf.getDefaultExportSymbol()) {
|
|
95
|
+
console.warn("WARN: Schema file " + sf.getBaseName() + " has default export, but only named exports are picked up by json schemas parser");
|
|
96
|
+
}
|
|
97
|
+
sourceFileInterfaceDeclarations = sf.getChildrenOfKind(ts_morph_1.SyntaxKind.InterfaceDeclaration);
|
|
98
|
+
sourceFileEnumDeclarations = sf.getChildrenOfKind(ts_morph_1.SyntaxKind.EnumDeclaration);
|
|
99
|
+
sourceFileDeclarations = __spreadArray(__spreadArray([], sourceFileEnumDeclarations), sourceFileInterfaceDeclarations);
|
|
100
|
+
schemaDeclarations.push.apply(schemaDeclarations, sourceFileDeclarations.map(function (d) { return d.compilerNode; }));
|
|
101
|
+
verbose &&
|
|
102
|
+
console.log("Found", sourceFileDeclarations.length, "schema(s) in file", sf.getBaseName());
|
|
103
|
+
try {
|
|
104
|
+
schema = generator.createSchemaFromNodes(sourceFileInterfaceDeclarations.map(function (d) { return d.compilerNode; }));
|
|
105
|
+
jsonSchemas.push(schema);
|
|
106
|
+
// console.log("Created schemas");
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
console.error("Failed to generate schema in file", sf.getBaseName() + ":", err);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
mergedSchemas = jsonSchemas.reduce(function (out, schema) {
|
|
113
|
+
if (schema)
|
|
114
|
+
if (schema.definitions) {
|
|
115
|
+
out.definitions = __assign(__assign({}, out.definitions), schema.definitions);
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}, {
|
|
119
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
120
|
+
$ref: "#/definitions/Schemas",
|
|
121
|
+
definitions: {},
|
|
122
|
+
});
|
|
123
|
+
file = path_1.join(dir, outFile);
|
|
124
|
+
return [4 /*yield*/, FsUtils_1.writeJsonFile(file, mergedSchemas, {
|
|
125
|
+
ensureDir: true,
|
|
126
|
+
})];
|
|
127
|
+
case 1:
|
|
128
|
+
_b.sent();
|
|
129
|
+
console.log("Wrote file", file);
|
|
130
|
+
return [2 /*return*/];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
function initJsonSchemaGenerator(project) {
|
|
136
|
+
var formatter = ts_json_schema_generator_1.createFormatter({});
|
|
137
|
+
var parser = ts_json_schema_generator_1.createParser(project.getProgram().compilerObject, {});
|
|
138
|
+
var generator = new ts_json_schema_generator_1.SchemaGenerator(project.getProgram().compilerObject, parser, formatter, { expose: "export" });
|
|
139
|
+
return generator;
|
|
140
|
+
}
|
package/dist/src/FlinkApp.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OptionsJson } from "body-parser";
|
|
2
2
|
import { Express } from "express";
|
|
3
3
|
import { JSONSchema7 } from "json-schema";
|
|
4
|
-
import { Db } from "mongodb";
|
|
4
|
+
import { Db, MongoClient } from "mongodb";
|
|
5
5
|
import { ToadScheduler } from "toad-scheduler";
|
|
6
6
|
import { FlinkAuthPlugin } from "./auth/FlinkAuthPlugin";
|
|
7
7
|
import { FlinkContext } from "./FlinkContext";
|
|
@@ -156,6 +156,7 @@ export declare class FlinkApp<C extends FlinkContext> {
|
|
|
156
156
|
name: string;
|
|
157
157
|
expressApp?: Express;
|
|
158
158
|
db?: Db;
|
|
159
|
+
dbClient?: MongoClient;
|
|
159
160
|
handlers: HandlerConfig[];
|
|
160
161
|
port?: number;
|
|
161
162
|
started: boolean;
|
package/dist/src/FlinkApp.js
CHANGED
package/dist/src/FlinkRepo.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Collection, Db, Document, ObjectId } from "mongodb";
|
|
1
|
+
import { Collection, Db, Document, MongoClient, ObjectId } from "mongodb";
|
|
2
2
|
import { FlinkContext } from "./FlinkContext";
|
|
3
3
|
/**
|
|
4
4
|
* Partial model to have intellisense for partial updates but
|
|
@@ -8,13 +8,14 @@ type PartialModel<Model> = Partial<Model> & {
|
|
|
8
8
|
[x: string]: any;
|
|
9
9
|
};
|
|
10
10
|
export declare abstract class FlinkRepo<C extends FlinkContext, Model extends Document> {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
collectionName: string;
|
|
12
|
+
db: Db;
|
|
13
|
+
client?: MongoClient | undefined;
|
|
13
14
|
collection: Collection;
|
|
14
15
|
private _ctx?;
|
|
15
16
|
set ctx(ctx: FlinkContext);
|
|
16
17
|
get ctx(): FlinkContext;
|
|
17
|
-
constructor(collectionName: string, db: Db);
|
|
18
|
+
constructor(collectionName: string, db: Db, client?: MongoClient | undefined);
|
|
18
19
|
findAll(query?: {}): Promise<Model[]>;
|
|
19
20
|
getById(id: string | ObjectId): Promise<Model | null>;
|
|
20
21
|
getOne(query?: {}): Promise<Model | null>;
|
package/dist/src/FlinkRepo.js
CHANGED
|
@@ -61,9 +61,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
61
61
|
exports.FlinkRepo = void 0;
|
|
62
62
|
var mongodb_1 = require("mongodb");
|
|
63
63
|
var FlinkRepo = /** @class */ (function () {
|
|
64
|
-
function FlinkRepo(collectionName, db) {
|
|
64
|
+
function FlinkRepo(collectionName, db, client) {
|
|
65
65
|
this.collectionName = collectionName;
|
|
66
66
|
this.db = db;
|
|
67
|
+
this.client = client;
|
|
67
68
|
this.collection = db.collection(this.collectionName);
|
|
68
69
|
}
|
|
69
70
|
Object.defineProperty(FlinkRepo.prototype, "ctx", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/flink",
|
|
3
|
-
"version": "0.12.1-alpha.
|
|
3
|
+
"version": "0.12.1-alpha.9",
|
|
4
4
|
"description": "Typescript only framework for creating REST-like APIs on top of Express and mongodb",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"test": "jasmine-ts --preserve-symlinks --config=./spec/support/jasmine.json",
|
|
10
10
|
"test:watch": "nodemon --ext ts --exec 'jasmine-ts --config=./spec/support/jasmine.json'",
|
|
11
11
|
"start": "ts-node src/index.ts",
|
|
12
|
-
"
|
|
12
|
+
"prepare": "npm run build",
|
|
13
13
|
"build": "tsc --project tsconfig.dist.json",
|
|
14
14
|
"watch": "nodemon --exec 'tsc --project tsconfig.dist.json'",
|
|
15
15
|
"clean": "rimraf dist"
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"rimraf": "^3.0.2",
|
|
67
67
|
"ts-node": "^9.1.1"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "3007ad036607014176930446fde56203bde8d6f5"
|
|
70
70
|
}
|
package/src/FlinkApp.ts
CHANGED
|
@@ -217,6 +217,7 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
217
217
|
public name: string;
|
|
218
218
|
public expressApp?: Express;
|
|
219
219
|
public db?: Db;
|
|
220
|
+
public dbClient?: MongoClient;
|
|
220
221
|
public handlers: HandlerConfig[] = [];
|
|
221
222
|
public port?: number;
|
|
222
223
|
public started = false;
|
|
@@ -778,6 +779,7 @@ export class FlinkApp<C extends FlinkContext> {
|
|
|
778
779
|
log.debug("Connecting to db");
|
|
779
780
|
const client = await MongoClient.connect(this.dbOpts.uri, this.getMongoConnectionOptions());
|
|
780
781
|
this.db = client.db();
|
|
782
|
+
this.dbClient = client;
|
|
781
783
|
} catch (err) {
|
|
782
784
|
log.error("Failed to connect to db: " + err);
|
|
783
785
|
process.exit(1);
|
package/src/FlinkRepo.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Collection, Db, Document, InsertOneResult, ObjectId } from "mongodb";
|
|
1
|
+
import { Collection, Db, Document, InsertOneResult, MongoClient, ObjectId } from "mongodb";
|
|
2
2
|
import { FlinkContext } from "./FlinkContext";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -21,7 +21,7 @@ export abstract class FlinkRepo<C extends FlinkContext, Model extends Document>
|
|
|
21
21
|
return this._ctx;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
constructor(
|
|
24
|
+
constructor(public collectionName: string, public db: Db, public client?: MongoClient) {
|
|
25
25
|
this.collection = db.collection(this.collectionName);
|
|
26
26
|
}
|
|
27
27
|
|