@flink-app/flink 0.12.1-alpha.9 → 0.13.1
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/CHANGELOG.md +13 -0
- package/dist/cli/build.js +2 -2
- package/dist/cli/clean.js +2 -2
- package/dist/cli/cli-utils.js +1 -2
- package/dist/cli/run.js +2 -2
- package/dist/src/FlinkApp.d.ts +6 -1
- package/dist/src/FlinkApp.js +28 -14
- package/dist/src/FlinkErrors.d.ts +69 -0
- package/dist/src/FlinkErrors.js +87 -8
- package/dist/src/FlinkHttpHandler.d.ts +14 -1
- package/dist/src/FlinkLog.d.ts +2 -2
- package/dist/src/FlinkRepo.d.ts +8 -1
- package/dist/src/FlinkRepo.js +9 -2
- package/dist/src/FlinkResponse.d.ts +0 -3
- package/dist/src/FsUtils.js +5 -6
- package/dist/src/TypeScriptCompiler.d.ts +10 -0
- package/dist/src/TypeScriptCompiler.js +196 -49
- package/dist/src/TypeScriptUtils.js +7 -8
- package/dist/src/index.d.ts +1 -0
- package/dist/src/utils.js +13 -14
- package/package.json +67 -69
- package/spec/TypeScriptCompiler.spec.ts +11 -1
- package/spec/mock-project/dist/src/handlers/GetCar.js +2 -2
- package/spec/mock-project/dist/src/handlers/GetCar2.js +2 -2
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +2 -2
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +2 -2
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +2 -2
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +2 -2
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +2 -2
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +2 -2
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +2 -2
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +3 -4
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +3 -4
- package/spec/mock-project/dist/src/handlers/PostCar.js +2 -2
- package/spec/mock-project/dist/src/handlers/PostLogin.js +2 -2
- package/spec/mock-project/dist/src/handlers/{GetCarWithOmitSchema.js → PostLogout.js} +16 -20
- package/spec/mock-project/dist/src/handlers/PutCar.js +2 -2
- package/spec/mock-project/dist/src/index.js +2 -2
- package/spec/mock-project/src/handlers/PostLogout.ts +19 -0
- package/spec/mock-project/tsconfig.json +1 -1
- package/src/FlinkApp.ts +24 -5
- package/src/FlinkErrors.ts +86 -6
- package/src/FlinkHttpHandler.ts +95 -96
- package/src/FlinkRepo.ts +8 -1
- package/src/FlinkResponse.ts +36 -39
- package/src/TypeScriptCompiler.ts +172 -39
- package/src/index.ts +12 -0
- package/tsconfig.json +1 -1
- package/dist/cli/generate-schemas.d.ts +0 -2
- package/dist/cli/generate-schemas.js +0 -140
- package/spec/mock-project/dist/src/handlers/GetCarWithTypeSchema.js +0 -60
- package/spec/mock-project/package-lock.json +0 -108
package/CHANGELOG.md
ADDED
package/dist/cli/build.js
CHANGED
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
-
return g =
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
14
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
15
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
16
|
function step(op) {
|
|
17
17
|
if (f) throw new TypeError("Generator is already executing.");
|
package/dist/cli/clean.js
CHANGED
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
-
return g =
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
14
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
15
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
16
|
function step(op) {
|
|
17
17
|
if (f) throw new TypeError("Generator is already executing.");
|
package/dist/cli/cli-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOption =
|
|
3
|
+
exports.getOption = getOption;
|
|
4
4
|
function getOption(args, name, defaultValue, opts) {
|
|
5
5
|
if (opts === void 0) { opts = {}; }
|
|
6
6
|
var option = "--".concat(name);
|
|
@@ -17,4 +17,3 @@ function getOption(args, name, defaultValue, opts) {
|
|
|
17
17
|
}
|
|
18
18
|
return defaultValue;
|
|
19
19
|
}
|
|
20
|
-
exports.getOption = getOption;
|
package/dist/cli/run.js
CHANGED
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
-
return g =
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
14
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
15
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
16
|
function step(op) {
|
|
17
17
|
if (f) throw new TypeError("Generator is already executing.");
|
package/dist/src/FlinkApp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OptionsJson } from "body-parser";
|
|
2
|
-
import { Express } from "express";
|
|
2
|
+
import express, { Express } from "express";
|
|
3
3
|
import { JSONSchema7 } from "json-schema";
|
|
4
4
|
import { Db, MongoClient } from "mongodb";
|
|
5
5
|
import { ToadScheduler } from "toad-scheduler";
|
|
@@ -10,6 +10,11 @@ import { FlinkJobFile } from "./FlinkJob";
|
|
|
10
10
|
import { FlinkPlugin } from "./FlinkPlugin";
|
|
11
11
|
import { FlinkRepo } from "./FlinkRepo";
|
|
12
12
|
export type JSONSchema = JSONSchema7;
|
|
13
|
+
/**
|
|
14
|
+
* Re-export express factory function so sub packages
|
|
15
|
+
* do not need its own express
|
|
16
|
+
*/
|
|
17
|
+
export declare const expressFn: typeof express;
|
|
13
18
|
/**
|
|
14
19
|
* This will be populated at compile time when the apps handlers
|
|
15
20
|
* are picked up by TypeScript compiler
|
package/dist/src/FlinkApp.js
CHANGED
|
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g =
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.FlinkApp = exports.autoRegisteredJobs = exports.autoRegisteredRepos = exports.autoRegisteredHandlers = void 0;
|
|
53
|
+
exports.FlinkApp = exports.autoRegisteredJobs = exports.autoRegisteredRepos = exports.autoRegisteredHandlers = exports.expressFn = void 0;
|
|
54
54
|
var ajv_1 = __importDefault(require("ajv"));
|
|
55
55
|
var ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
56
56
|
var body_parser_1 = __importDefault(require("body-parser"));
|
|
@@ -72,6 +72,11 @@ var defaultCorsOptions = {
|
|
|
72
72
|
credentials: true,
|
|
73
73
|
origin: [/.*/],
|
|
74
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Re-export express factory function so sub packages
|
|
77
|
+
* do not need its own express
|
|
78
|
+
*/
|
|
79
|
+
exports.expressFn = express_1.default;
|
|
75
80
|
/**
|
|
76
81
|
* This will be populated at compile time when the apps handlers
|
|
77
82
|
* are picked up by TypeScript compiler
|
|
@@ -442,11 +447,11 @@ var FlinkApp = /** @class */ (function () {
|
|
|
442
447
|
*/
|
|
443
448
|
FlinkApp.prototype.registerAutoRegisterableHandlers = function () {
|
|
444
449
|
return __awaiter(this, void 0, void 0, function () {
|
|
445
|
-
var _i,
|
|
446
|
-
var
|
|
447
|
-
return __generator(this, function (
|
|
448
|
-
for (_i = 0,
|
|
449
|
-
|
|
450
|
+
var _i, _a, _b, handler, assumedHttpMethod, pathParams, _c, _d, param;
|
|
451
|
+
var _e, _f, _g;
|
|
452
|
+
return __generator(this, function (_h) {
|
|
453
|
+
for (_i = 0, _a = exports.autoRegisteredHandlers.sort(function (a, b) { var _a, _b; return (((_a = a.handler.Route) === null || _a === void 0 ? void 0 : _a.order) || 0) - (((_b = b.handler.Route) === null || _b === void 0 ? void 0 : _b.order) || 0); }); _i < _a.length; _i++) {
|
|
454
|
+
_b = _a[_i], handler = _b.handler, assumedHttpMethod = _b.assumedHttpMethod;
|
|
450
455
|
if (!handler.Route) {
|
|
451
456
|
FlinkLog_1.log.error("Missing Props in handler ".concat(handler.__file));
|
|
452
457
|
continue;
|
|
@@ -455,10 +460,10 @@ var FlinkApp = /** @class */ (function () {
|
|
|
455
460
|
FlinkLog_1.log.error("Missing exported handler function in handler ".concat(handler.__file));
|
|
456
461
|
continue;
|
|
457
462
|
}
|
|
458
|
-
if (!!((
|
|
463
|
+
if (!!((_e = handler.__params) === null || _e === void 0 ? void 0 : _e.length)) {
|
|
459
464
|
pathParams = (0, utils_1.getPathParams)(handler.Route.path);
|
|
460
|
-
for (
|
|
461
|
-
param = _c
|
|
465
|
+
for (_c = 0, _d = handler.__params; _c < _d.length; _c++) {
|
|
466
|
+
param = _d[_c];
|
|
462
467
|
if (!pathParams.includes(param.name)) {
|
|
463
468
|
FlinkLog_1.log.error("Handler ".concat(handler.__file, " has param ").concat(param.name, " but it is not present in the path '").concat(handler.Route.path, "'"));
|
|
464
469
|
throw new Error("Invalid/missing handler path param");
|
|
@@ -471,8 +476,8 @@ var FlinkApp = /** @class */ (function () {
|
|
|
471
476
|
this.registerHandler({
|
|
472
477
|
routeProps: __assign(__assign({}, handler.Route), { method: handler.Route.method || assumedHttpMethod, origin: this.name }),
|
|
473
478
|
schema: {
|
|
474
|
-
reqSchema: (
|
|
475
|
-
resSchema: (
|
|
479
|
+
reqSchema: (_f = handler.__schemas) === null || _f === void 0 ? void 0 : _f.reqSchema,
|
|
480
|
+
resSchema: (_g = handler.__schemas) === null || _g === void 0 ? void 0 : _g.resSchema,
|
|
476
481
|
},
|
|
477
482
|
queryMetadata: handler.__query || [],
|
|
478
483
|
paramsMetadata: handler.__params || [],
|
|
@@ -583,7 +588,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
583
588
|
if (this.dbOpts) {
|
|
584
589
|
for (_i = 0, autoRegisteredRepos_1 = exports.autoRegisteredRepos; _i < autoRegisteredRepos_1.length; _i++) {
|
|
585
590
|
_a = autoRegisteredRepos_1[_i], collectionName = _a.collectionName, repoInstanceName = _a.repoInstanceName, Repo = _a.Repo;
|
|
586
|
-
repoInstance = new Repo(collectionName, this.db);
|
|
591
|
+
repoInstance = new Repo(collectionName, this.db, this.dbClient);
|
|
587
592
|
this.repos[repoInstanceName] = repoInstance;
|
|
588
593
|
FlinkLog_1.log.info("Registered repo ".concat(repoInstanceName));
|
|
589
594
|
}
|
|
@@ -716,6 +721,15 @@ var FlinkApp = /** @class */ (function () {
|
|
|
716
721
|
if (!this.dbOpts) {
|
|
717
722
|
throw new Error("No db configured");
|
|
718
723
|
}
|
|
724
|
+
var driverVersion = require("mongodb/package.json").version;
|
|
725
|
+
if (driverVersion.startsWith("3")) {
|
|
726
|
+
FlinkLog_1.log.debug("Using legacy mongodb connection options as mongo client is version ".concat(driverVersion));
|
|
727
|
+
return {
|
|
728
|
+
useNewUrlParser: true,
|
|
729
|
+
useUnifiedTopology: true,
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
FlinkLog_1.log.debug("Using modern MongoDB client options (driver version ".concat(driverVersion, ")"));
|
|
719
733
|
return {
|
|
720
734
|
serverApi: {
|
|
721
735
|
version: mongodb_1.ServerApiVersion.v1,
|
|
@@ -1,7 +1,76 @@
|
|
|
1
1
|
import { FlinkResponse } from "./FlinkResponse";
|
|
2
2
|
export type FlinkError = undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Returns a 404 Not Found error response.
|
|
5
|
+
* Use when a requested resource doesn't exist (e.g., invalid ID, missing entity).
|
|
6
|
+
*
|
|
7
|
+
* @param detail - Optional custom error message
|
|
8
|
+
* @param code - Optional custom error code
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* if (!user) return notFound("User not found");
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
3
14
|
export declare function notFound(detail?: string, code?: string): FlinkResponse<FlinkError>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a 409 Conflict error response.
|
|
17
|
+
* Use when a request conflicts with existing data (e.g., duplicate username/email).
|
|
18
|
+
*
|
|
19
|
+
* @param detail - Optional custom error message
|
|
20
|
+
* @param code - Optional custom error code
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* if (existingUser) return conflict("Email already registered");
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
4
26
|
export declare function conflict(detail?: string, code?: string): FlinkResponse<FlinkError>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a 400 Bad Request error response.
|
|
29
|
+
* Use when the request is malformed or contains invalid data (e.g., validation errors).
|
|
30
|
+
*
|
|
31
|
+
* @param detail - Optional custom error message
|
|
32
|
+
* @param code - Optional custom error code
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* if (!email || !password) return badRequest("Email and password are required");
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
5
38
|
export declare function badRequest(detail?: string, code?: string): FlinkResponse<FlinkError>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a 401 Unauthorized error response.
|
|
41
|
+
* Use when authentication is required but missing or invalid (e.g., no token, expired token).
|
|
42
|
+
* This means "who are you?" - the user needs to identify themselves first.
|
|
43
|
+
*
|
|
44
|
+
* @param detail - Optional custom error message
|
|
45
|
+
* @param code - Optional custom error code
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* if (!ctx.auth?.user) return unauthorized("Authentication required");
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
6
51
|
export declare function unauthorized(detail?: string, code?: string): FlinkResponse<FlinkError>;
|
|
52
|
+
/**
|
|
53
|
+
* Returns a 403 Forbidden error response.
|
|
54
|
+
* Use when the user is authenticated but lacks permission to access the resource.
|
|
55
|
+
* This means "I know who you are, but you're not allowed to do this."
|
|
56
|
+
*
|
|
57
|
+
* @param detail - Optional custom error message
|
|
58
|
+
* @param code - Optional custom error code
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* if (ctx.auth?.user?.role !== "admin") return forbidden("Admin access required");
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function forbidden(detail?: string, code?: string): FlinkResponse<FlinkError>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns a 500 Internal Server Error response.
|
|
67
|
+
* Use when an unexpected error occurs on the server side.
|
|
68
|
+
*
|
|
69
|
+
* @param detail - Optional custom error message
|
|
70
|
+
* @param code - Optional custom error code
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* try { ... } catch (error) { return internalServerError("Failed to process request"); }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
7
76
|
export declare function internalServerError(detail?: string, code?: string): FlinkResponse<FlinkError>;
|
package/dist/src/FlinkErrors.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.notFound = notFound;
|
|
4
|
+
exports.conflict = conflict;
|
|
5
|
+
exports.badRequest = badRequest;
|
|
6
|
+
exports.unauthorized = unauthorized;
|
|
7
|
+
exports.forbidden = forbidden;
|
|
8
|
+
exports.internalServerError = internalServerError;
|
|
4
9
|
var uuid_1 = require("uuid");
|
|
10
|
+
/**
|
|
11
|
+
* Returns a 404 Not Found error response.
|
|
12
|
+
* Use when a requested resource doesn't exist (e.g., invalid ID, missing entity).
|
|
13
|
+
*
|
|
14
|
+
* @param detail - Optional custom error message
|
|
15
|
+
* @param code - Optional custom error code
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* if (!user) return notFound("User not found");
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
5
21
|
function notFound(detail, code) {
|
|
6
22
|
return {
|
|
7
23
|
status: 404,
|
|
@@ -13,7 +29,17 @@ function notFound(detail, code) {
|
|
|
13
29
|
},
|
|
14
30
|
};
|
|
15
31
|
}
|
|
16
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Returns a 409 Conflict error response.
|
|
34
|
+
* Use when a request conflicts with existing data (e.g., duplicate username/email).
|
|
35
|
+
*
|
|
36
|
+
* @param detail - Optional custom error message
|
|
37
|
+
* @param code - Optional custom error code
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* if (existingUser) return conflict("Email already registered");
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
17
43
|
function conflict(detail, code) {
|
|
18
44
|
return {
|
|
19
45
|
status: 409,
|
|
@@ -25,7 +51,17 @@ function conflict(detail, code) {
|
|
|
25
51
|
},
|
|
26
52
|
};
|
|
27
53
|
}
|
|
28
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Returns a 400 Bad Request error response.
|
|
56
|
+
* Use when the request is malformed or contains invalid data (e.g., validation errors).
|
|
57
|
+
*
|
|
58
|
+
* @param detail - Optional custom error message
|
|
59
|
+
* @param code - Optional custom error code
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* if (!email || !password) return badRequest("Email and password are required");
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
29
65
|
function badRequest(detail, code) {
|
|
30
66
|
return {
|
|
31
67
|
status: 400,
|
|
@@ -37,19 +73,63 @@ function badRequest(detail, code) {
|
|
|
37
73
|
},
|
|
38
74
|
};
|
|
39
75
|
}
|
|
40
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Returns a 401 Unauthorized error response.
|
|
78
|
+
* Use when authentication is required but missing or invalid (e.g., no token, expired token).
|
|
79
|
+
* This means "who are you?" - the user needs to identify themselves first.
|
|
80
|
+
*
|
|
81
|
+
* @param detail - Optional custom error message
|
|
82
|
+
* @param code - Optional custom error code
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* if (!ctx.auth?.user) return unauthorized("Authentication required");
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
41
88
|
function unauthorized(detail, code) {
|
|
42
89
|
return {
|
|
43
90
|
status: 401,
|
|
44
91
|
error: {
|
|
45
92
|
id: (0, uuid_1.v4)(),
|
|
46
93
|
title: "Unauthorized",
|
|
47
|
-
detail: detail || "
|
|
48
|
-
code: code || "
|
|
94
|
+
detail: detail || "Authentication required",
|
|
95
|
+
code: code || "unauthorized"
|
|
49
96
|
},
|
|
50
97
|
};
|
|
51
98
|
}
|
|
52
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Returns a 403 Forbidden error response.
|
|
101
|
+
* Use when the user is authenticated but lacks permission to access the resource.
|
|
102
|
+
* This means "I know who you are, but you're not allowed to do this."
|
|
103
|
+
*
|
|
104
|
+
* @param detail - Optional custom error message
|
|
105
|
+
* @param code - Optional custom error code
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* if (ctx.auth?.user?.role !== "admin") return forbidden("Admin access required");
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
function forbidden(detail, code) {
|
|
112
|
+
return {
|
|
113
|
+
status: 403,
|
|
114
|
+
error: {
|
|
115
|
+
id: (0, uuid_1.v4)(),
|
|
116
|
+
title: "Forbidden",
|
|
117
|
+
detail: detail || "You do not have permission to access this resource",
|
|
118
|
+
code: code || "forbidden"
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns a 500 Internal Server Error response.
|
|
124
|
+
* Use when an unexpected error occurs on the server side.
|
|
125
|
+
*
|
|
126
|
+
* @param detail - Optional custom error message
|
|
127
|
+
* @param code - Optional custom error code
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* try { ... } catch (error) { return internalServerError("Failed to process request"); }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
53
133
|
function internalServerError(detail, code) {
|
|
54
134
|
return {
|
|
55
135
|
status: 500,
|
|
@@ -61,4 +141,3 @@ function internalServerError(detail, code) {
|
|
|
61
141
|
},
|
|
62
142
|
};
|
|
63
143
|
}
|
|
64
|
-
exports.internalServerError = internalServerError;
|
|
@@ -10,7 +10,12 @@ export declare enum HttpMethod {
|
|
|
10
10
|
delete = "delete"
|
|
11
11
|
}
|
|
12
12
|
type Params = Request["params"];
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Query type for request query parameters.
|
|
15
|
+
* Does currently not allow nested objects, although
|
|
16
|
+
* underlying express Request does allow it.
|
|
17
|
+
*/
|
|
18
|
+
type Query = Record<string, string | string[] | undefined>;
|
|
14
19
|
/**
|
|
15
20
|
* Flink request extends express Request but adds reqId and user object.
|
|
16
21
|
*/
|
|
@@ -63,6 +68,14 @@ export interface RouteProps {
|
|
|
63
68
|
* I.e. filename or plugin name that describes where handler origins from
|
|
64
69
|
*/
|
|
65
70
|
origin?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Order handler should be registered in.
|
|
73
|
+
*
|
|
74
|
+
* By default all handlers has order 0 and in most cases this is fine,
|
|
75
|
+
* but if for example you want to register a handler before all others
|
|
76
|
+
* to avoid conflicts you can set a negative order.
|
|
77
|
+
*/
|
|
78
|
+
order?: number;
|
|
66
79
|
}
|
|
67
80
|
/**
|
|
68
81
|
* Http handler function that handlers implements in order to
|
package/dist/src/FlinkLog.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const log: {
|
|
|
11
11
|
dim?: boolean | undefined;
|
|
12
12
|
underscore?: boolean | undefined;
|
|
13
13
|
strikethrough?: boolean | undefined;
|
|
14
|
-
}
|
|
14
|
+
}) => void;
|
|
15
15
|
fontColorLog: (ticket: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white", text: string, setting?: {
|
|
16
16
|
reverse?: boolean | undefined;
|
|
17
17
|
bold?: boolean | undefined;
|
|
@@ -19,6 +19,6 @@ export declare const log: {
|
|
|
19
19
|
dim?: boolean | undefined;
|
|
20
20
|
underscore?: boolean | undefined;
|
|
21
21
|
strikethrough?: boolean | undefined;
|
|
22
|
-
}
|
|
22
|
+
}) => void;
|
|
23
23
|
setLevel: (level: "debug" | "info" | "warn" | "error") => void;
|
|
24
24
|
};
|
package/dist/src/FlinkRepo.d.ts
CHANGED
|
@@ -25,7 +25,14 @@ export declare abstract class FlinkRepo<C extends FlinkContext, Model extends Do
|
|
|
25
25
|
updateOne(id: string | ObjectId, model: PartialModel<Model>): Promise<Model | null>;
|
|
26
26
|
updateMany<U = PartialModel<Model>>(query: any, model: U): Promise<number>;
|
|
27
27
|
deleteById(id: string | ObjectId): Promise<number>;
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Helper to ensure the id is always an ObjectId.
|
|
30
|
+
* If a string is passed, it will be converted to an ObjectId.
|
|
31
|
+
* If an ObjectId is passed, it will be returned as is.
|
|
32
|
+
* @param id
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
buildId(id: string | ObjectId): ObjectId;
|
|
29
36
|
private objectIdToString;
|
|
30
37
|
}
|
|
31
38
|
export {};
|
package/dist/src/FlinkRepo.js
CHANGED
|
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g =
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -193,6 +193,13 @@ var FlinkRepo = /** @class */ (function () {
|
|
|
193
193
|
});
|
|
194
194
|
});
|
|
195
195
|
};
|
|
196
|
+
/**
|
|
197
|
+
* Helper to ensure the id is always an ObjectId.
|
|
198
|
+
* If a string is passed, it will be converted to an ObjectId.
|
|
199
|
+
* If an ObjectId is passed, it will be returned as is.
|
|
200
|
+
* @param id
|
|
201
|
+
* @returns
|
|
202
|
+
*/
|
|
196
203
|
FlinkRepo.prototype.buildId = function (id) {
|
|
197
204
|
var oid;
|
|
198
205
|
if (typeof id === "string") {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Response, Request } from "express";
|
|
2
1
|
export interface FlinkResponse<T = any> {
|
|
3
2
|
/**
|
|
4
3
|
* Unique id of request.
|
|
@@ -37,5 +36,3 @@ export interface FlinkResponse<T = any> {
|
|
|
37
36
|
[x: string]: string;
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
|
-
export type ExpressResponse = Response;
|
|
41
|
-
export type ExpressRequest = Request;
|
package/dist/src/FsUtils.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -39,7 +39,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.
|
|
42
|
+
exports.readJsonFile = readJsonFile;
|
|
43
|
+
exports.readJsonFiles = readJsonFiles;
|
|
44
|
+
exports.writeJsonFile = writeJsonFile;
|
|
43
45
|
var fs_1 = require("fs");
|
|
44
46
|
var path_1 = require("path");
|
|
45
47
|
var tiny_glob_1 = __importDefault(require("tiny-glob"));
|
|
@@ -64,7 +66,6 @@ function readJsonFile(path) {
|
|
|
64
66
|
});
|
|
65
67
|
});
|
|
66
68
|
}
|
|
67
|
-
exports.readJsonFile = readJsonFile;
|
|
68
69
|
function readJsonFiles(globPattern) {
|
|
69
70
|
return __awaiter(this, void 0, void 0, function () {
|
|
70
71
|
var files, readPromises;
|
|
@@ -88,7 +89,6 @@ function readJsonFiles(globPattern) {
|
|
|
88
89
|
});
|
|
89
90
|
});
|
|
90
91
|
}
|
|
91
|
-
exports.readJsonFiles = readJsonFiles;
|
|
92
92
|
function writeJsonFile(path_2, content_1) {
|
|
93
93
|
return __awaiter(this, arguments, void 0, function (path, content, opts) {
|
|
94
94
|
var i, jsonStr;
|
|
@@ -117,4 +117,3 @@ function writeJsonFile(path_2, content_1) {
|
|
|
117
117
|
});
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
-
exports.writeJsonFile = writeJsonFile;
|
|
@@ -3,6 +3,7 @@ declare class TypeScriptCompiler {
|
|
|
3
3
|
private cwd;
|
|
4
4
|
private project;
|
|
5
5
|
private schemaGenerator?;
|
|
6
|
+
private isEsm;
|
|
6
7
|
/**
|
|
7
8
|
* Parsed typescript schemas that will be added to intermediate
|
|
8
9
|
* schemas.ts file.
|
|
@@ -17,6 +18,15 @@ declare class TypeScriptCompiler {
|
|
|
17
18
|
*/
|
|
18
19
|
private tsSchemasSymbolsToImports;
|
|
19
20
|
constructor(cwd: string);
|
|
21
|
+
/**
|
|
22
|
+
* Detects if the project is using ESM (ECMAScript Modules)
|
|
23
|
+
* by checking type in package.json.
|
|
24
|
+
*/
|
|
25
|
+
private isEsmProject;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the module specifier for imports, adding .js extension for ESM
|
|
28
|
+
*/
|
|
29
|
+
private getModuleSpecifier;
|
|
20
30
|
/**
|
|
21
31
|
* Deletes all generated files.
|
|
22
32
|
* @param cwd
|