@flink-app/flink 1.0.0 → 2.0.0-alpha.48

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 (109) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/cli/build.ts +8 -1
  3. package/cli/run.ts +8 -1
  4. package/dist/cli/build.js +8 -1
  5. package/dist/cli/run.js +8 -1
  6. package/dist/src/FlinkApp.d.ts +33 -0
  7. package/dist/src/FlinkApp.js +247 -27
  8. package/dist/src/FlinkContext.d.ts +21 -0
  9. package/dist/src/FlinkHttpHandler.d.ts +90 -1
  10. package/dist/src/TypeScriptCompiler.d.ts +42 -0
  11. package/dist/src/TypeScriptCompiler.js +346 -4
  12. package/dist/src/TypeScriptUtils.js +4 -0
  13. package/dist/src/ai/AgentRunner.d.ts +39 -0
  14. package/dist/src/ai/AgentRunner.js +625 -0
  15. package/dist/src/ai/FlinkAgent.d.ts +446 -0
  16. package/dist/src/ai/FlinkAgent.js +633 -0
  17. package/dist/src/ai/FlinkTool.d.ts +37 -0
  18. package/dist/src/ai/FlinkTool.js +2 -0
  19. package/dist/src/ai/LLMAdapter.d.ts +119 -0
  20. package/dist/src/ai/LLMAdapter.js +2 -0
  21. package/dist/src/ai/SubAgentExecutor.d.ts +36 -0
  22. package/dist/src/ai/SubAgentExecutor.js +220 -0
  23. package/dist/src/ai/ToolExecutor.d.ts +35 -0
  24. package/dist/src/ai/ToolExecutor.js +237 -0
  25. package/dist/src/ai/index.d.ts +5 -0
  26. package/dist/src/ai/index.js +21 -0
  27. package/dist/src/handlers/StreamWriterFactory.d.ts +20 -0
  28. package/dist/src/handlers/StreamWriterFactory.js +83 -0
  29. package/dist/src/index.d.ts +4 -0
  30. package/dist/src/index.js +4 -0
  31. package/dist/src/utils.d.ts +30 -0
  32. package/dist/src/utils.js +52 -0
  33. package/package.json +14 -2
  34. package/readme.md +425 -0
  35. package/spec/AgentDuplicateDetection.spec.ts +112 -0
  36. package/spec/AgentRunner.spec.ts +527 -0
  37. package/spec/ConversationHooks.spec.ts +290 -0
  38. package/spec/FlinkAgent.spec.ts +310 -0
  39. package/spec/FlinkApp.onError.spec.ts +1 -2
  40. package/spec/StreamingIntegration.spec.ts +138 -0
  41. package/spec/SubAgentSupport.spec.ts +941 -0
  42. package/spec/ToolExecutor.spec.ts +360 -0
  43. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar.js +57 -0
  44. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar2.js +59 -0
  45. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema.js +53 -0
  46. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema2.js +53 -0
  47. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema3.js +53 -0
  48. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema.js +55 -0
  49. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema2.js +55 -0
  50. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile.js +58 -0
  51. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile2.js +58 -0
  52. package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler.js +53 -0
  53. package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler2.js +55 -0
  54. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchCar.js +58 -0
  55. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOnboardingSession.js +76 -0
  56. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOrderWithComplexTypes.js +58 -0
  57. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchProductWithIntersection.js +59 -0
  58. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchUserWithUnion.js +59 -0
  59. package/spec/mock-project/dist/spec/mock-project/src/handlers/PostCar.js +55 -0
  60. package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogin.js +56 -0
  61. package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogout.js +55 -0
  62. package/spec/mock-project/dist/spec/mock-project/src/handlers/PutCar.js +55 -0
  63. package/spec/mock-project/dist/spec/mock-project/src/index.js +83 -0
  64. package/spec/mock-project/dist/spec/mock-project/src/repos/CarRepo.js +26 -0
  65. package/spec/mock-project/dist/spec/mock-project/src/schemas/Car.js +2 -0
  66. package/spec/mock-project/dist/spec/mock-project/src/schemas/DefaultExportSchema.js +2 -0
  67. package/spec/mock-project/dist/spec/mock-project/src/schemas/FileWithTwoSchemas.js +2 -0
  68. package/spec/mock-project/dist/src/FlinkApp.js +1012 -0
  69. package/spec/mock-project/dist/src/FlinkContext.js +2 -0
  70. package/spec/mock-project/dist/src/FlinkErrors.js +143 -0
  71. package/spec/mock-project/dist/src/FlinkHttpHandler.js +47 -0
  72. package/spec/mock-project/dist/src/FlinkJob.js +2 -0
  73. package/spec/mock-project/dist/src/FlinkLog.js +26 -0
  74. package/spec/mock-project/dist/src/FlinkPlugin.js +2 -0
  75. package/spec/mock-project/dist/src/FlinkRepo.js +224 -0
  76. package/spec/mock-project/dist/src/FlinkResponse.js +2 -0
  77. package/spec/mock-project/dist/src/ai/AgentExecutor.js +279 -0
  78. package/spec/mock-project/dist/src/ai/AgentRunner.js +625 -0
  79. package/spec/mock-project/dist/src/ai/FlinkAgent.js +633 -0
  80. package/spec/mock-project/dist/src/ai/FlinkTool.js +2 -0
  81. package/spec/mock-project/dist/src/ai/LLMAdapter.js +2 -0
  82. package/spec/mock-project/dist/src/ai/SubAgentExecutor.js +220 -0
  83. package/spec/mock-project/dist/src/ai/ToolExecutor.js +237 -0
  84. package/spec/mock-project/dist/src/auth/FlinkAuthPlugin.js +2 -0
  85. package/spec/mock-project/dist/src/auth/FlinkAuthUser.js +2 -0
  86. package/spec/mock-project/dist/src/handlers/StreamWriterFactory.js +83 -0
  87. package/spec/mock-project/dist/src/index.js +17 -69
  88. package/spec/mock-project/dist/src/mock-data-generator.js +9 -0
  89. package/spec/mock-project/dist/src/utils.js +290 -0
  90. package/spec/mock-project/tsconfig.json +6 -1
  91. package/spec/testHelpers.ts +49 -0
  92. package/spec/utils.caseConversion.spec.ts +80 -0
  93. package/spec/utils.spec.ts +13 -13
  94. package/src/FlinkApp.ts +251 -7
  95. package/src/FlinkContext.ts +22 -0
  96. package/src/FlinkHttpHandler.ts +100 -2
  97. package/src/TypeScriptCompiler.ts +398 -7
  98. package/src/TypeScriptUtils.ts +5 -0
  99. package/src/ai/AgentRunner.ts +549 -0
  100. package/src/ai/FlinkAgent.ts +770 -0
  101. package/src/ai/FlinkTool.ts +40 -0
  102. package/src/ai/LLMAdapter.ts +96 -0
  103. package/src/ai/SubAgentExecutor.ts +199 -0
  104. package/src/ai/ToolExecutor.ts +193 -0
  105. package/src/ai/index.ts +5 -0
  106. package/src/handlers/StreamWriterFactory.ts +84 -0
  107. package/src/index.ts +4 -0
  108. package/src/utils.ts +52 -0
  109. package/tsconfig.json +6 -1
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.notFound = notFound;
4
+ exports.conflict = conflict;
5
+ exports.badRequest = badRequest;
6
+ exports.unauthorized = unauthorized;
7
+ exports.forbidden = forbidden;
8
+ exports.internalServerError = internalServerError;
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
+ */
21
+ function notFound(detail, code) {
22
+ return {
23
+ status: 404,
24
+ error: {
25
+ id: (0, uuid_1.v4)(),
26
+ title: "Not Found",
27
+ detail: detail || "The requested resource does not exist",
28
+ code: code || "notFound"
29
+ },
30
+ };
31
+ }
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
+ */
43
+ function conflict(detail, code) {
44
+ return {
45
+ status: 409,
46
+ error: {
47
+ id: (0, uuid_1.v4)(),
48
+ title: "Conflict",
49
+ detail: detail || "An identical entity exits",
50
+ code: code || "conflict"
51
+ },
52
+ };
53
+ }
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
+ */
65
+ function badRequest(detail, code) {
66
+ return {
67
+ status: 400,
68
+ error: {
69
+ id: (0, uuid_1.v4)(),
70
+ title: "Bad Request",
71
+ detail: detail || "Invalid request",
72
+ code: code || "badRequest"
73
+ },
74
+ };
75
+ }
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
+ */
88
+ function unauthorized(detail, code) {
89
+ return {
90
+ status: 401,
91
+ error: {
92
+ id: (0, uuid_1.v4)(),
93
+ title: "Unauthorized",
94
+ detail: detail || "Authentication required",
95
+ code: code || "unauthorized"
96
+ },
97
+ };
98
+ }
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
+ */
133
+ function internalServerError(detail, code) {
134
+ return {
135
+ status: 500,
136
+ error: {
137
+ id: (0, uuid_1.v4)(),
138
+ title: "Internal Server Error",
139
+ detail: detail || "Something unexpected went wrong",
140
+ code: code || "internalServerError"
141
+ },
142
+ };
143
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationMode = exports.HttpMethod = void 0;
4
+ var HttpMethod;
5
+ (function (HttpMethod) {
6
+ HttpMethod["get"] = "get";
7
+ HttpMethod["post"] = "post";
8
+ HttpMethod["put"] = "put";
9
+ HttpMethod["delete"] = "delete";
10
+ HttpMethod["patch"] = "patch";
11
+ })(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
12
+ /**
13
+ * Validation mode for handler request and response schemas.
14
+ *
15
+ * Controls whether request and/or response data is validated against JSON schemas.
16
+ *
17
+ * **Security Note:** Skipping validation can introduce security risks. Only use
18
+ * SkipValidation or ValidateResponse when you have implemented custom validation
19
+ * or the endpoint is internal/trusted.
20
+ *
21
+ * - Validate: Validate both request and response (default behavior)
22
+ * - SkipValidation: Skip both request and response validation
23
+ * - ValidateRequest: Validate only request, skip response validation
24
+ * - ValidateResponse: Validate only response, skip request validation
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Skip validation for webhook with custom signature verification
29
+ * export const Route: RouteProps = {
30
+ * path: "/webhook",
31
+ * validation: ValidationMode.SkipValidation
32
+ * };
33
+ *
34
+ * // Validate request but allow flexible response during development
35
+ * export const Route: RouteProps = {
36
+ * path: "/api/data",
37
+ * validation: ValidationMode.ValidateRequest
38
+ * };
39
+ * ```
40
+ */
41
+ var ValidationMode;
42
+ (function (ValidationMode) {
43
+ ValidationMode["Validate"] = "Validate";
44
+ ValidationMode["SkipValidation"] = "SkipValidation";
45
+ ValidationMode["ValidateRequest"] = "ValidateRequest";
46
+ ValidationMode["ValidateResponse"] = "ValidateResponse";
47
+ })(ValidationMode || (exports.ValidationMode = ValidationMode = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.log = void 0;
7
+ var node_color_log_1 = __importDefault(require("node-color-log"));
8
+ exports.log = {
9
+ debug: node_color_log_1.default.debug.bind(node_color_log_1.default),
10
+ info: node_color_log_1.default.info.bind(node_color_log_1.default),
11
+ warn: node_color_log_1.default.warn.bind(node_color_log_1.default),
12
+ error: node_color_log_1.default.error.bind(node_color_log_1.default),
13
+ json: function () {
14
+ var args = [];
15
+ for (var _i = 0; _i < arguments.length; _i++) {
16
+ args[_i] = arguments[_i];
17
+ }
18
+ for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
19
+ var o = args_1[_a];
20
+ console.log(JSON.stringify(o, null, 2));
21
+ }
22
+ },
23
+ bgColorLog: node_color_log_1.default.bgColorLog.bind(node_color_log_1.default),
24
+ fontColorLog: node_color_log_1.default.fontColorLog.bind(node_color_log_1.default),
25
+ setLevel: function (level) { return node_color_log_1.default.setLevel.bind(node_color_log_1.default)(level); },
26
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
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 = 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
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
60
+ Object.defineProperty(exports, "__esModule", { value: true });
61
+ exports.FlinkRepo = void 0;
62
+ var mongodb_1 = require("mongodb");
63
+ var FlinkRepo = /** @class */ (function () {
64
+ function FlinkRepo(collectionName, db, client) {
65
+ this.collectionName = collectionName;
66
+ this.db = db;
67
+ this.client = client;
68
+ this.collection = db.collection(this.collectionName);
69
+ }
70
+ Object.defineProperty(FlinkRepo.prototype, "ctx", {
71
+ get: function () {
72
+ if (!this._ctx)
73
+ throw new Error("Missing FlinkContext");
74
+ return this._ctx;
75
+ },
76
+ set: function (ctx) {
77
+ this._ctx = ctx;
78
+ },
79
+ enumerable: false,
80
+ configurable: true
81
+ });
82
+ FlinkRepo.prototype.findAll = function () {
83
+ return __awaiter(this, arguments, void 0, function (query) {
84
+ var res;
85
+ if (query === void 0) { query = {}; }
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0: return [4 /*yield*/, this.collection.find(query).toArray()];
89
+ case 1:
90
+ res = _a.sent();
91
+ return [2 /*return*/, res.map(this.objectIdToString)];
92
+ }
93
+ });
94
+ });
95
+ };
96
+ FlinkRepo.prototype.getById = function (id) {
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ var res;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0: return [4 /*yield*/, this.collection.findOne({ _id: this.buildId(id) })];
102
+ case 1:
103
+ res = _a.sent();
104
+ if (res) {
105
+ return [2 /*return*/, this.objectIdToString(res)];
106
+ }
107
+ return [2 /*return*/, null];
108
+ }
109
+ });
110
+ });
111
+ };
112
+ FlinkRepo.prototype.getOne = function () {
113
+ return __awaiter(this, arguments, void 0, function (query) {
114
+ var res;
115
+ if (query === void 0) { query = {}; }
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0: return [4 /*yield*/, this.collection.findOne(query)];
119
+ case 1:
120
+ res = _a.sent();
121
+ if (res) {
122
+ return [2 /*return*/, this.objectIdToString(res)];
123
+ }
124
+ return [2 /*return*/, null];
125
+ }
126
+ });
127
+ });
128
+ };
129
+ FlinkRepo.prototype.create = function (model) {
130
+ return __awaiter(this, void 0, void 0, function () {
131
+ var result;
132
+ return __generator(this, function (_a) {
133
+ switch (_a.label) {
134
+ case 0: return [4 /*yield*/, this.collection.insertOne(model)];
135
+ case 1:
136
+ result = _a.sent();
137
+ return [2 /*return*/, __assign(__assign({}, model), { _id: result.insertedId.toString() })];
138
+ }
139
+ });
140
+ });
141
+ };
142
+ FlinkRepo.prototype.updateOne = function (id, model) {
143
+ return __awaiter(this, void 0, void 0, function () {
144
+ var oid, _id, modelWithoutId, res;
145
+ return __generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0:
148
+ oid = this.buildId(id);
149
+ _id = model._id, modelWithoutId = __rest(model, ["_id"]);
150
+ return [4 /*yield*/, this.collection.updateOne({ _id: oid }, { $set: modelWithoutId })];
151
+ case 1:
152
+ _a.sent();
153
+ return [4 /*yield*/, this.collection.findOne({ _id: oid })];
154
+ case 2:
155
+ res = _a.sent();
156
+ if (res) {
157
+ return [2 /*return*/, this.objectIdToString(res)];
158
+ }
159
+ return [2 /*return*/, null];
160
+ }
161
+ });
162
+ });
163
+ };
164
+ FlinkRepo.prototype.updateMany = function (query, model) {
165
+ return __awaiter(this, void 0, void 0, function () {
166
+ var _a, _id, modelWithoutId, modifiedCount;
167
+ return __generator(this, function (_b) {
168
+ switch (_b.label) {
169
+ case 0:
170
+ _a = model, _id = _a._id, modelWithoutId = __rest(_a, ["_id"]);
171
+ return [4 /*yield*/, this.collection.updateMany(query, {
172
+ $set: modelWithoutId,
173
+ })];
174
+ case 1:
175
+ modifiedCount = (_b.sent()).modifiedCount;
176
+ return [2 /*return*/, modifiedCount];
177
+ }
178
+ });
179
+ });
180
+ };
181
+ FlinkRepo.prototype.deleteById = function (id) {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ var deletedCount;
184
+ return __generator(this, function (_a) {
185
+ switch (_a.label) {
186
+ case 0: return [4 /*yield*/, this.collection.deleteOne({
187
+ _id: this.buildId(id),
188
+ })];
189
+ case 1:
190
+ deletedCount = (_a.sent()).deletedCount;
191
+ return [2 /*return*/, deletedCount || 0];
192
+ }
193
+ });
194
+ });
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
+ */
203
+ FlinkRepo.prototype.buildId = function (id) {
204
+ var oid;
205
+ if (typeof id === "string") {
206
+ oid = new mongodb_1.ObjectId(id);
207
+ }
208
+ else if (id instanceof mongodb_1.ObjectId) {
209
+ oid = id;
210
+ }
211
+ else {
212
+ throw new Error("Invalid id type");
213
+ }
214
+ return oid;
215
+ };
216
+ FlinkRepo.prototype.objectIdToString = function (doc) {
217
+ if (doc && doc._id) {
218
+ doc._id = doc._id.toString();
219
+ }
220
+ return doc;
221
+ };
222
+ return FlinkRepo;
223
+ }());
224
+ exports.FlinkRepo = FlinkRepo;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });