@okf/ootils 1.3.6 → 1.3.8
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/node.d.mts +297 -3
- package/dist/node.d.ts +297 -3
- package/dist/node.js +627 -270
- package/dist/node.mjs +648 -270
- package/package.json +3 -1
package/dist/node.js
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
8
11
|
var __commonJS = (cb, mod) => function __require() {
|
|
9
12
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
13
|
};
|
|
@@ -30,297 +33,323 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
33
|
));
|
|
31
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
35
|
|
|
33
|
-
// src/
|
|
34
|
-
var
|
|
35
|
-
"src/
|
|
36
|
+
// src/bullmq/WorkerManager.js
|
|
37
|
+
var require_WorkerManager = __commonJS({
|
|
38
|
+
"src/bullmq/WorkerManager.js"(exports2, module2) {
|
|
36
39
|
"use strict";
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
kp_contributed_by: {
|
|
60
|
-
type: Schema.Types.ObjectId,
|
|
61
|
-
ref: "user"
|
|
62
|
-
},
|
|
63
|
-
valuePath: String,
|
|
64
|
-
documentId: {
|
|
65
|
-
type: Schema.Types.ObjectId
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
// Main content data - using Schema.Types.Mixed for dynamic structure
|
|
69
|
-
main: {
|
|
70
|
-
type: Schema.Types.Mixed,
|
|
71
|
-
default: {}
|
|
72
|
-
},
|
|
73
|
-
// Annotation specific details
|
|
74
|
-
annotations: {
|
|
75
|
-
tags: {
|
|
76
|
-
type: Map,
|
|
77
|
-
_id: false,
|
|
78
|
-
of: new Schema({
|
|
79
|
-
collectionId: String,
|
|
80
|
-
data: [
|
|
81
|
-
{
|
|
82
|
-
_id: { type: Schema.Types.ObjectId },
|
|
83
|
-
display: String,
|
|
84
|
-
tagId: String
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
})
|
|
88
|
-
},
|
|
89
|
-
fragment: {
|
|
90
|
-
isLexical: Boolean,
|
|
91
|
-
editorState: Object,
|
|
92
|
-
allText: String
|
|
93
|
-
},
|
|
94
|
-
annoKey: String,
|
|
95
|
-
author: {
|
|
96
|
-
id: { type: Schema.Types.ObjectId },
|
|
97
|
-
name: String
|
|
40
|
+
var WorkerManager2 = class {
|
|
41
|
+
constructor(workers = []) {
|
|
42
|
+
this.workers = workers;
|
|
43
|
+
this.activeWorkers = [];
|
|
44
|
+
}
|
|
45
|
+
startAllWorkers() {
|
|
46
|
+
if (this.workers.length === 0) {
|
|
47
|
+
console.log("No workers provided to start");
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
console.log("\u{1F680} Starting all workers...");
|
|
51
|
+
this.workers.forEach((WorkerClass) => {
|
|
52
|
+
try {
|
|
53
|
+
const workerInstance = new WorkerClass();
|
|
54
|
+
workerInstance.start();
|
|
55
|
+
this.activeWorkers.push({
|
|
56
|
+
name: WorkerClass.name,
|
|
57
|
+
instance: workerInstance
|
|
58
|
+
});
|
|
59
|
+
console.log(`\u2705 Started ${WorkerClass.name}`);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(`\u274C Failed to start ${WorkerClass.name}:`, error);
|
|
98
62
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
timestamps: true,
|
|
121
|
-
toJSON: { virtuals: true },
|
|
122
|
-
toObject: { virtuals: true },
|
|
123
|
-
strict: false
|
|
124
|
-
// This allows for flexible document structure beyond the defined schema
|
|
63
|
+
});
|
|
64
|
+
console.log(`\u{1F389} Successfully started ${this.activeWorkers.length} workers`);
|
|
65
|
+
return this.activeWorkers;
|
|
66
|
+
}
|
|
67
|
+
async shutdown() {
|
|
68
|
+
console.log("\u{1F6D1} Stopping all workers...");
|
|
69
|
+
const stopPromises = this.activeWorkers.map(
|
|
70
|
+
({ name, instance }) => instance.stop().catch(
|
|
71
|
+
(err) => console.error(`\u274C Error stopping ${name}:`, err)
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
await Promise.all(stopPromises);
|
|
75
|
+
this.activeWorkers = [];
|
|
76
|
+
console.log("\u2705 All workers stopped");
|
|
77
|
+
}
|
|
78
|
+
getStatus() {
|
|
79
|
+
return this.activeWorkers.map(({ name, instance }) => ({
|
|
80
|
+
name,
|
|
81
|
+
queueId: instance.config?.id || "unknown",
|
|
82
|
+
isActive: !!instance.worker
|
|
83
|
+
}));
|
|
125
84
|
}
|
|
126
|
-
);
|
|
127
|
-
AnnotationSchema.index({ "meta.contentType": 1 });
|
|
128
|
-
AnnotationSchema.index({ "meta.documentId": 1 });
|
|
129
|
-
AnnotationSchema.index({ createdAt: -1 });
|
|
130
|
-
AnnotationSchema.index({ "annotations.annoKey": 1 });
|
|
131
|
-
AnnotationSchema.pre("save", function(next) {
|
|
132
|
-
this.updatedAt = /* @__PURE__ */ new Date();
|
|
133
|
-
next();
|
|
134
|
-
});
|
|
135
|
-
AnnotationSchema.methods.getMainField = function(fieldPath) {
|
|
136
|
-
if (!fieldPath) return null;
|
|
137
|
-
const parts = fieldPath.split(".");
|
|
138
|
-
let value = this.main;
|
|
139
|
-
for (const part of parts) {
|
|
140
|
-
if (!value || typeof value !== "object") return null;
|
|
141
|
-
value = value[part];
|
|
142
|
-
}
|
|
143
|
-
return value;
|
|
144
85
|
};
|
|
145
|
-
|
|
146
|
-
return this.main.title || "Untitled Annotation";
|
|
147
|
-
});
|
|
148
|
-
module2.exports = AnnotationSchema;
|
|
86
|
+
module2.exports = { WorkerManager: WorkerManager2 };
|
|
149
87
|
}
|
|
150
88
|
});
|
|
151
89
|
|
|
152
|
-
// src/
|
|
153
|
-
var
|
|
154
|
-
"src/
|
|
90
|
+
// src/bullmq/BaseProducer.js
|
|
91
|
+
var require_BaseProducer = __commonJS({
|
|
92
|
+
"src/bullmq/BaseProducer.js"(exports2, module2) {
|
|
155
93
|
"use strict";
|
|
156
|
-
var
|
|
157
|
-
var
|
|
158
|
-
{
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
94
|
+
var { Queue } = require("bullmq");
|
|
95
|
+
var BaseProducer2 = class {
|
|
96
|
+
constructor(config) {
|
|
97
|
+
this.config = config;
|
|
98
|
+
this.queue = new Queue(config.id, config.queueConfig);
|
|
99
|
+
}
|
|
100
|
+
async execute(params) {
|
|
101
|
+
throw new Error("execute() method must be implemented by subclass");
|
|
102
|
+
}
|
|
103
|
+
async addBulkJobs(jobs) {
|
|
104
|
+
try {
|
|
105
|
+
const results = await this.queue.addBulk(jobs);
|
|
106
|
+
console.log(`\u2705 ${this.constructor.name}: Successfully queued ${results.length} jobs`);
|
|
107
|
+
return results;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(`\u274C ${this.constructor.name}: Failed to queue jobs:`, error);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async addJob(name, data, opts = {}) {
|
|
114
|
+
try {
|
|
115
|
+
const job = await this.queue.add(name, data, opts);
|
|
116
|
+
console.log(`\u2705 ${this.constructor.name}: Successfully queued job ${job.id}`);
|
|
117
|
+
return job;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(`\u274C ${this.constructor.name}: Failed to queue job:`, error);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async getStatus() {
|
|
124
|
+
const waiting = await this.queue.getWaiting();
|
|
125
|
+
const active = await this.queue.getActive();
|
|
126
|
+
const completed = await this.queue.getCompleted();
|
|
127
|
+
const failed = await this.queue.getFailed();
|
|
128
|
+
return {
|
|
129
|
+
waiting: waiting.length,
|
|
130
|
+
active: active.length,
|
|
131
|
+
completed: completed.length,
|
|
132
|
+
failed: failed.length,
|
|
133
|
+
total: waiting.length + active.length + completed.length + failed.length
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async getJobDetails(limit = 10) {
|
|
137
|
+
const waiting = await this.queue.getWaiting(0, limit - 1);
|
|
138
|
+
const active = await this.queue.getActive(0, limit - 1);
|
|
139
|
+
const completed = await this.queue.getCompleted(0, limit - 1);
|
|
140
|
+
const failed = await this.queue.getFailed(0, limit - 1);
|
|
141
|
+
return {
|
|
142
|
+
waiting: waiting.map((job) => ({
|
|
143
|
+
id: job.id,
|
|
144
|
+
batchIndex: job.data?.batchIndex,
|
|
145
|
+
totalBatches: job.data?.totalBatches,
|
|
146
|
+
rawRecordsCount: job.data?.rawBatchData?.length
|
|
147
|
+
})),
|
|
148
|
+
active: active.map((job) => ({
|
|
149
|
+
id: job.id,
|
|
150
|
+
batchIndex: job.data?.batchIndex,
|
|
151
|
+
totalBatches: job.data?.totalBatches,
|
|
152
|
+
progress: job.progress,
|
|
153
|
+
rawRecordsCount: job.data?.rawBatchData?.length
|
|
154
|
+
})),
|
|
155
|
+
completed: completed.map((job) => ({
|
|
156
|
+
id: job.id,
|
|
157
|
+
batchIndex: job.returnvalue?.batchIndex,
|
|
158
|
+
totalProcessed: job.returnvalue?.totalItemsProcessed,
|
|
159
|
+
summary: job.returnvalue?.summary
|
|
160
|
+
})),
|
|
161
|
+
failed: failed.map((job) => ({
|
|
162
|
+
id: job.id,
|
|
163
|
+
batchIndex: job.data?.batchIndex,
|
|
164
|
+
error: job.failedReason,
|
|
165
|
+
attempts: job.attemptsMade
|
|
166
|
+
}))
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async stop() {
|
|
170
|
+
if (this.queue) {
|
|
171
|
+
await this.queue.close();
|
|
172
|
+
console.log(`\u{1F6D1} ${this.constructor.name} queue closed`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
module2.exports = { BaseProducer: BaseProducer2 };
|
|
183
177
|
}
|
|
184
178
|
});
|
|
185
179
|
|
|
186
|
-
// src/
|
|
187
|
-
var
|
|
188
|
-
"src/
|
|
180
|
+
// src/bullmq/BaseWorker.js
|
|
181
|
+
var require_BaseWorker = __commonJS({
|
|
182
|
+
"src/bullmq/BaseWorker.js"(exports2, module2) {
|
|
189
183
|
"use strict";
|
|
190
|
-
var
|
|
191
|
-
var
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
{
|
|
228
|
-
|
|
184
|
+
var { Worker } = require("bullmq");
|
|
185
|
+
var BaseWorker2 = class {
|
|
186
|
+
constructor(config) {
|
|
187
|
+
this.config = config;
|
|
188
|
+
this.worker = null;
|
|
189
|
+
}
|
|
190
|
+
async execute(job) {
|
|
191
|
+
throw new Error("execute() method must be implemented by subclass");
|
|
192
|
+
}
|
|
193
|
+
start() {
|
|
194
|
+
this.worker = new Worker(
|
|
195
|
+
this.config.id,
|
|
196
|
+
this.execute.bind(this),
|
|
197
|
+
this.config.workerConfig
|
|
198
|
+
);
|
|
199
|
+
this.setupEventHandlers();
|
|
200
|
+
console.log(`\u{1F680} ${this.constructor.name} started for queue: ${this.config.id}`);
|
|
201
|
+
return this.worker;
|
|
202
|
+
}
|
|
203
|
+
setupEventHandlers() {
|
|
204
|
+
this.worker.on("completed", (job, returnValue) => {
|
|
205
|
+
this.onCompleted(job, returnValue);
|
|
206
|
+
});
|
|
207
|
+
this.worker.on("failed", (job, err) => {
|
|
208
|
+
this.onFailed(job, err);
|
|
209
|
+
});
|
|
210
|
+
this.worker.on("progress", (job, progress) => {
|
|
211
|
+
this.onProgress(job, progress);
|
|
212
|
+
});
|
|
213
|
+
this.worker.on("error", (error) => {
|
|
214
|
+
this.onError(error);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
onCompleted(job, returnValue) {
|
|
218
|
+
console.log(`\u2705 Job ${job.id} completed in ${this.constructor.name}`);
|
|
219
|
+
}
|
|
220
|
+
onFailed(job, err) {
|
|
221
|
+
console.error(`\u{1F4A5} Job ${job.id} failed in ${this.constructor.name}:`, err.message);
|
|
222
|
+
}
|
|
223
|
+
onProgress(job, progress) {
|
|
224
|
+
console.log(`\u{1F4CA} Job ${job.id} progress in ${this.constructor.name}: ${progress}%`);
|
|
225
|
+
}
|
|
226
|
+
onError(error) {
|
|
227
|
+
console.error(`\u274C Worker error in ${this.constructor.name}:`, error);
|
|
228
|
+
}
|
|
229
|
+
async stop() {
|
|
230
|
+
if (this.worker) {
|
|
231
|
+
await this.worker.close();
|
|
232
|
+
console.log(`\u{1F6D1} ${this.constructor.name} stopped`);
|
|
229
233
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
enable: Boolean
|
|
258
|
-
},
|
|
259
|
-
participantModule: {
|
|
260
|
-
enable: Boolean
|
|
261
|
-
},
|
|
262
|
-
formFieldNumbering: {
|
|
263
|
-
enable: Boolean
|
|
264
|
-
},
|
|
265
|
-
postPblRedirPath: Object,
|
|
266
|
-
templateIndex: Object,
|
|
267
|
-
sharing: {
|
|
268
|
-
enable: Boolean,
|
|
269
|
-
trackShareCount: {
|
|
270
|
-
type: Boolean,
|
|
271
|
-
default: false
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
module2.exports = { BaseWorker: BaseWorker2 };
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// src/bullmq/GLOBAL_BULLMQ_CONFIG.js
|
|
241
|
+
var GLOBAL_BULLMQ_CONFIG_exports = {};
|
|
242
|
+
__export(GLOBAL_BULLMQ_CONFIG_exports, {
|
|
243
|
+
BASE_BULLMQ_CONFIG: () => BASE_BULLMQ_CONFIG
|
|
244
|
+
});
|
|
245
|
+
var BASE_BULLMQ_CONFIG;
|
|
246
|
+
var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
247
|
+
"src/bullmq/GLOBAL_BULLMQ_CONFIG.js"() {
|
|
248
|
+
"use strict";
|
|
249
|
+
BASE_BULLMQ_CONFIG = {
|
|
250
|
+
PLUGIN__MAD_USERS_SYNC_QUEUE: {
|
|
251
|
+
id: "plugin--mad-users-sync-queue",
|
|
252
|
+
queueConfig: {
|
|
253
|
+
defaultJobOptions: {
|
|
254
|
+
backoff: {
|
|
255
|
+
type: "exponential",
|
|
256
|
+
delay: 2e3
|
|
257
|
+
},
|
|
258
|
+
attempts: 3,
|
|
259
|
+
removeOnComplete: 100,
|
|
260
|
+
removeOnFail: 50
|
|
272
261
|
}
|
|
273
262
|
},
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
263
|
+
workerConfig: {
|
|
264
|
+
concurrency: 1,
|
|
265
|
+
// Process jobs one at a time to avoid race conditions
|
|
266
|
+
limiter: {
|
|
267
|
+
max: 10,
|
|
268
|
+
// Max 10 jobs per...
|
|
269
|
+
duration: 6e4
|
|
270
|
+
// ...60 seconds (rate limiting)
|
|
278
271
|
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
// Chunk Processing Queue
|
|
275
|
+
CHUNK_PROCESSING_QUEUE: {
|
|
276
|
+
id: "chunk-processing-queue",
|
|
277
|
+
queueConfig: {
|
|
278
|
+
defaultJobOptions: {
|
|
279
|
+
backoff: {
|
|
280
|
+
type: "exponential",
|
|
281
|
+
delay: 2e3
|
|
282
|
+
},
|
|
283
|
+
attempts: 3,
|
|
284
|
+
removeOnComplete: 100,
|
|
285
|
+
removeOnFail: 50
|
|
288
286
|
}
|
|
289
287
|
},
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
288
|
+
workerConfig: {
|
|
289
|
+
concurrency: 10,
|
|
290
|
+
// Process 10 jobs at once for chunk processing
|
|
291
|
+
limiter: {
|
|
292
|
+
max: 5,
|
|
293
|
+
// Max 50 jobs per...
|
|
294
|
+
duration: 6e4
|
|
295
|
+
// ...60 seconds (higher throughput for chunking)
|
|
298
296
|
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
// src/bullmq/GET_GLOBAL_BULLMQ_CONFIG.js
|
|
304
|
+
var require_GET_GLOBAL_BULLMQ_CONFIG = __commonJS({
|
|
305
|
+
"src/bullmq/GET_GLOBAL_BULLMQ_CONFIG.js"(exports2, module2) {
|
|
306
|
+
"use strict";
|
|
307
|
+
var { default: Redis } = require("ioredis");
|
|
308
|
+
var { BASE_BULLMQ_CONFIG: BASE_BULLMQ_CONFIG2 } = (init_GLOBAL_BULLMQ_CONFIG(), __toCommonJS(GLOBAL_BULLMQ_CONFIG_exports));
|
|
309
|
+
function GET_GLOBAL_BULLMQ_CONFIG2({ env, redisCredentials }) {
|
|
310
|
+
const redisConnectionForBullMQ = new Redis({
|
|
311
|
+
host: redisCredentials.REDIS_HOST,
|
|
312
|
+
port: redisCredentials.REDIS_PORT,
|
|
313
|
+
password: redisCredentials.REDIS_PASSWORD,
|
|
314
|
+
maxRetriesPerRequest: null
|
|
315
|
+
});
|
|
316
|
+
return Object.keys(BASE_BULLMQ_CONFIG2).reduce((acc, key) => ({
|
|
317
|
+
...acc,
|
|
318
|
+
[key]: {
|
|
319
|
+
...BASE_BULLMQ_CONFIG2[key],
|
|
320
|
+
id: BASE_BULLMQ_CONFIG2[key].id + `_${env}`,
|
|
321
|
+
// suffix env to queue to keep it unique for each environment
|
|
322
|
+
queueConfig: {
|
|
323
|
+
connection: redisConnectionForBullMQ,
|
|
324
|
+
...BASE_BULLMQ_CONFIG2[key].queueConfig
|
|
325
|
+
},
|
|
326
|
+
workerConfig: {
|
|
327
|
+
connection: redisConnectionForBullMQ,
|
|
328
|
+
...BASE_BULLMQ_CONFIG2[key].workerConfig
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}), {});
|
|
332
|
+
}
|
|
333
|
+
module2.exports = { GET_GLOBAL_BULLMQ_CONFIG: GET_GLOBAL_BULLMQ_CONFIG2 };
|
|
314
334
|
}
|
|
315
335
|
});
|
|
316
336
|
|
|
317
337
|
// src/node.ts
|
|
318
338
|
var node_exports = {};
|
|
319
339
|
__export(node_exports, {
|
|
340
|
+
AIChatSchema: () => AIChat_default,
|
|
341
|
+
AnnotationSchema: () => Annotations_default,
|
|
342
|
+
BaseProducer: () => import_BaseProducer.BaseProducer,
|
|
343
|
+
BaseWorker: () => import_BaseWorker.BaseWorker,
|
|
344
|
+
GET_GLOBAL_BULLMQ_CONFIG: () => import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG,
|
|
345
|
+
PlatformConfigsSchema: () => PlatformConfigs_default,
|
|
346
|
+
TplSchema: () => Tpl_default,
|
|
347
|
+
WorkerManager: () => import_WorkerManager.WorkerManager,
|
|
320
348
|
connectToRedis: () => connectToRedis,
|
|
321
349
|
deleteVal: () => deleteVal,
|
|
322
350
|
extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
|
|
323
351
|
genTagId: () => genTagId,
|
|
352
|
+
getAIChatModelByTenant: () => getAIChatModelByTenant,
|
|
324
353
|
getAIConfigs: () => getAIConfigs,
|
|
325
354
|
getAnnotationsModelByTenant: () => getAnnotationsModelByTenant,
|
|
326
355
|
getDbByTenant: () => getDbByTenant,
|
|
@@ -709,10 +738,317 @@ var getDbByTenant = ({
|
|
|
709
738
|
throw new Error("getDbByTenant : mongodb object doesnt exist");
|
|
710
739
|
};
|
|
711
740
|
|
|
741
|
+
// src/models/AIChat.ts
|
|
742
|
+
var import_mongoose3 = __toESM(require("mongoose"));
|
|
743
|
+
|
|
744
|
+
// src/models/Annotations.ts
|
|
745
|
+
var import_mongoose2 = require("mongoose");
|
|
746
|
+
var AnnotationSchema = new import_mongoose2.Schema(
|
|
747
|
+
{
|
|
748
|
+
// Tags section - dynamic structure for various tag categories
|
|
749
|
+
tags: {
|
|
750
|
+
type: Map,
|
|
751
|
+
of: new import_mongoose2.Schema({
|
|
752
|
+
data: [
|
|
753
|
+
{
|
|
754
|
+
_id: { type: import_mongoose2.Schema.Types.ObjectId },
|
|
755
|
+
display: String,
|
|
756
|
+
tagId: String
|
|
757
|
+
}
|
|
758
|
+
],
|
|
759
|
+
collectionId: String
|
|
760
|
+
}, {
|
|
761
|
+
_id: false
|
|
762
|
+
})
|
|
763
|
+
},
|
|
764
|
+
// Meta information
|
|
765
|
+
meta: {
|
|
766
|
+
contentType: { type: String, required: true },
|
|
767
|
+
kp_contributed_by: {
|
|
768
|
+
type: import_mongoose2.Schema.Types.ObjectId,
|
|
769
|
+
ref: "user"
|
|
770
|
+
},
|
|
771
|
+
valuePath: String,
|
|
772
|
+
documentId: {
|
|
773
|
+
type: import_mongoose2.Schema.Types.ObjectId
|
|
774
|
+
}
|
|
775
|
+
},
|
|
776
|
+
// Main content data - using Schema.Types.Mixed for dynamic structure
|
|
777
|
+
main: {
|
|
778
|
+
type: import_mongoose2.Schema.Types.Mixed,
|
|
779
|
+
default: {}
|
|
780
|
+
},
|
|
781
|
+
// Annotation specific details
|
|
782
|
+
annotations: {
|
|
783
|
+
tags: {
|
|
784
|
+
type: Map,
|
|
785
|
+
of: new import_mongoose2.Schema({
|
|
786
|
+
collectionId: String,
|
|
787
|
+
data: [
|
|
788
|
+
{
|
|
789
|
+
_id: { type: import_mongoose2.Schema.Types.ObjectId },
|
|
790
|
+
display: String,
|
|
791
|
+
tagId: String
|
|
792
|
+
}
|
|
793
|
+
]
|
|
794
|
+
}, {
|
|
795
|
+
_id: false
|
|
796
|
+
})
|
|
797
|
+
},
|
|
798
|
+
fragment: {
|
|
799
|
+
isLexical: Boolean,
|
|
800
|
+
editorState: Object,
|
|
801
|
+
allText: String
|
|
802
|
+
},
|
|
803
|
+
annoKey: String,
|
|
804
|
+
author: {
|
|
805
|
+
id: { type: import_mongoose2.Schema.Types.ObjectId },
|
|
806
|
+
name: String
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
embeddings: Array,
|
|
810
|
+
contentEnhancedText: String,
|
|
811
|
+
// // Optional chunk related fields
|
|
812
|
+
// chunk: {
|
|
813
|
+
// embeddings: Schema.Types.Mixed,
|
|
814
|
+
// contentEnhancedText: String
|
|
815
|
+
// },
|
|
816
|
+
clusterId: String,
|
|
817
|
+
kp_date_published: Date,
|
|
818
|
+
createdAt: {
|
|
819
|
+
type: Date,
|
|
820
|
+
default: Date.now
|
|
821
|
+
},
|
|
822
|
+
updatedAt: {
|
|
823
|
+
type: Date,
|
|
824
|
+
default: Date.now
|
|
825
|
+
},
|
|
826
|
+
topicId: [{ type: import_mongoose2.Schema.Types.ObjectId, ref: "generatedTopics" }],
|
|
827
|
+
translations: Object
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
timestamps: true,
|
|
831
|
+
toJSON: { virtuals: true },
|
|
832
|
+
toObject: { virtuals: true },
|
|
833
|
+
strict: false
|
|
834
|
+
// This allows for flexible document structure beyond the defined schema
|
|
835
|
+
}
|
|
836
|
+
);
|
|
837
|
+
AnnotationSchema.index({ "meta.contentType": 1 });
|
|
838
|
+
AnnotationSchema.index({ "meta.documentId": 1 });
|
|
839
|
+
AnnotationSchema.index({ createdAt: -1 });
|
|
840
|
+
AnnotationSchema.index({ "annotations.annoKey": 1 });
|
|
841
|
+
AnnotationSchema.index({ "kp_date_published": -1 });
|
|
842
|
+
AnnotationSchema.pre("save", function(next) {
|
|
843
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
844
|
+
next();
|
|
845
|
+
});
|
|
846
|
+
AnnotationSchema.methods.getMainField = function(fieldPath) {
|
|
847
|
+
if (!fieldPath) return null;
|
|
848
|
+
const parts = fieldPath.split(".");
|
|
849
|
+
let value = this.main;
|
|
850
|
+
for (const part of parts) {
|
|
851
|
+
if (!value || typeof value !== "object") return null;
|
|
852
|
+
value = value[part];
|
|
853
|
+
}
|
|
854
|
+
return value;
|
|
855
|
+
};
|
|
856
|
+
AnnotationSchema.virtual("displayTitle").get(function() {
|
|
857
|
+
return this.main?.title || "Untitled Annotation";
|
|
858
|
+
});
|
|
859
|
+
var Annotations_default = AnnotationSchema;
|
|
860
|
+
|
|
861
|
+
// src/models/AIChat.ts
|
|
862
|
+
var AIChatSchema = new import_mongoose3.default.Schema(
|
|
863
|
+
{
|
|
864
|
+
userId: { type: import_mongoose3.default.Schema.Types.ObjectId, index: { unique: true } },
|
|
865
|
+
createdAt: Date,
|
|
866
|
+
lastAcitivity: Date,
|
|
867
|
+
messages: [
|
|
868
|
+
{
|
|
869
|
+
id: String,
|
|
870
|
+
author: {
|
|
871
|
+
type: String,
|
|
872
|
+
enum: ["system", "user", "assistant"]
|
|
873
|
+
},
|
|
874
|
+
content: {
|
|
875
|
+
type: { type: String },
|
|
876
|
+
value: String
|
|
877
|
+
},
|
|
878
|
+
vectorSearchInfo: {
|
|
879
|
+
chunks: [Annotations_default]
|
|
880
|
+
},
|
|
881
|
+
args: {
|
|
882
|
+
query: String,
|
|
883
|
+
reframedQuery: String,
|
|
884
|
+
summary: Object
|
|
885
|
+
},
|
|
886
|
+
userFeedback: {
|
|
887
|
+
reaction: { type: String, enum: ["positive", "negative"] },
|
|
888
|
+
comments: String
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
]
|
|
892
|
+
},
|
|
893
|
+
{ collection: "aiChat" }
|
|
894
|
+
);
|
|
895
|
+
var AIChat_default = AIChatSchema;
|
|
896
|
+
|
|
897
|
+
// src/models/PlatformConfigs.ts
|
|
898
|
+
var import_mongoose4 = __toESM(require("mongoose"));
|
|
899
|
+
var platformConfigTypes = [
|
|
900
|
+
"roles",
|
|
901
|
+
"nav",
|
|
902
|
+
"deployment",
|
|
903
|
+
"userAgreement",
|
|
904
|
+
"localeData",
|
|
905
|
+
"theme",
|
|
906
|
+
"AI"
|
|
907
|
+
];
|
|
908
|
+
var PlatformConfigsSchema = new import_mongoose4.default.Schema(
|
|
909
|
+
{
|
|
910
|
+
type: {
|
|
911
|
+
type: String,
|
|
912
|
+
enum: platformConfigTypes,
|
|
913
|
+
unique: true
|
|
914
|
+
},
|
|
915
|
+
roles: Array,
|
|
916
|
+
data: Object
|
|
917
|
+
},
|
|
918
|
+
{ collection: "platformConfigs" }
|
|
919
|
+
);
|
|
920
|
+
var PlatformConfigs_default = PlatformConfigsSchema;
|
|
921
|
+
|
|
922
|
+
// src/models/Tpl.ts
|
|
923
|
+
var import_mongoose5 = __toESM(require("mongoose"));
|
|
924
|
+
var TplSchema = new import_mongoose5.default.Schema({
|
|
925
|
+
dateFirstPublished: Date,
|
|
926
|
+
dateCreated: Date,
|
|
927
|
+
dateLastPublished: Date,
|
|
928
|
+
dateLastEdited: Date,
|
|
929
|
+
status: {
|
|
930
|
+
type: String,
|
|
931
|
+
default: "published",
|
|
932
|
+
// only cuz we dont want to go and add this property in all databases
|
|
933
|
+
enum: ["unpublished", "editPublished", "published"]
|
|
934
|
+
},
|
|
935
|
+
version: {
|
|
936
|
+
type: Number,
|
|
937
|
+
default: 0
|
|
938
|
+
},
|
|
939
|
+
versionPublishedBy: {
|
|
940
|
+
type: import_mongoose5.default.Schema.Types.ObjectId,
|
|
941
|
+
ref: "user"
|
|
942
|
+
// reference to the 'user' model
|
|
943
|
+
},
|
|
944
|
+
firstPublishedBy: {
|
|
945
|
+
type: import_mongoose5.default.Schema.Types.ObjectId,
|
|
946
|
+
ref: "user"
|
|
947
|
+
// reference to the 'user' model
|
|
948
|
+
},
|
|
949
|
+
kp_content_type: {
|
|
950
|
+
type: String,
|
|
951
|
+
required: true,
|
|
952
|
+
unique: true
|
|
953
|
+
},
|
|
954
|
+
category: {
|
|
955
|
+
//to deprecate and turn into 'layout'
|
|
956
|
+
type: String,
|
|
957
|
+
default: "knowledgeResources2"
|
|
958
|
+
},
|
|
959
|
+
kp_settings: [
|
|
960
|
+
{
|
|
961
|
+
type: Object
|
|
962
|
+
}
|
|
963
|
+
],
|
|
964
|
+
kp_templates: {
|
|
965
|
+
type: Object
|
|
966
|
+
},
|
|
967
|
+
tplMeta: Object,
|
|
968
|
+
tplLocales: Object,
|
|
969
|
+
indexed: Object,
|
|
970
|
+
drafts: {
|
|
971
|
+
active: Object
|
|
972
|
+
},
|
|
973
|
+
rollbacks: Object,
|
|
974
|
+
//for 'remembering' hidden configurations
|
|
975
|
+
// OTHER CONFIGS
|
|
976
|
+
listing: Object,
|
|
977
|
+
//listing page configurations. this is new, currently only used in nct
|
|
978
|
+
general: {
|
|
979
|
+
content: {
|
|
980
|
+
title: String,
|
|
981
|
+
singular: String,
|
|
982
|
+
ctaText: String,
|
|
983
|
+
listingDesc: String
|
|
984
|
+
},
|
|
985
|
+
allowQuickTagCreation: { enable: Boolean },
|
|
986
|
+
segment: String,
|
|
987
|
+
settingsUIStyle: String,
|
|
988
|
+
hasUpdateType: Boolean,
|
|
989
|
+
annotation: {
|
|
990
|
+
enable: Boolean
|
|
991
|
+
},
|
|
992
|
+
participantModule: {
|
|
993
|
+
enable: Boolean
|
|
994
|
+
},
|
|
995
|
+
formFieldNumbering: {
|
|
996
|
+
enable: Boolean
|
|
997
|
+
},
|
|
998
|
+
postPblRedirPath: Object,
|
|
999
|
+
templateIndex: Object,
|
|
1000
|
+
sharing: {
|
|
1001
|
+
enable: Boolean,
|
|
1002
|
+
trackShareCount: {
|
|
1003
|
+
type: Boolean,
|
|
1004
|
+
default: false
|
|
1005
|
+
}
|
|
1006
|
+
},
|
|
1007
|
+
viewsCount: {
|
|
1008
|
+
enable: {
|
|
1009
|
+
type: Boolean,
|
|
1010
|
+
default: false
|
|
1011
|
+
}
|
|
1012
|
+
},
|
|
1013
|
+
comments: {
|
|
1014
|
+
enable: Boolean
|
|
1015
|
+
},
|
|
1016
|
+
reactions: {
|
|
1017
|
+
type: Map,
|
|
1018
|
+
of: {
|
|
1019
|
+
enable: Boolean,
|
|
1020
|
+
icon: String
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
csvExport: {
|
|
1024
|
+
enable: Boolean,
|
|
1025
|
+
excludeFields: Array,
|
|
1026
|
+
enableUpdateExport: Boolean,
|
|
1027
|
+
fieldsToSortAtEnd: Array,
|
|
1028
|
+
fetchBatches: {
|
|
1029
|
+
enable: Boolean,
|
|
1030
|
+
batchSize: Number
|
|
1031
|
+
}
|
|
1032
|
+
},
|
|
1033
|
+
onboardingFlow: Object,
|
|
1034
|
+
//only on profile tpls
|
|
1035
|
+
selfServeSurveyConfig: Object,
|
|
1036
|
+
//tci helpers - these exist only to show / not show certain UIs in the tci
|
|
1037
|
+
disableKPSettings: Boolean
|
|
1038
|
+
}
|
|
1039
|
+
//general contenttype configs. mostly the stuff inside platformConfigs > contentTypes
|
|
1040
|
+
}, {
|
|
1041
|
+
toJSON: { virtuals: true },
|
|
1042
|
+
// So `res.json()` and other `JSON.stringify()` functions include virtuals
|
|
1043
|
+
toObject: { virtuals: true }
|
|
1044
|
+
// So `toObject()` output includes virtuals
|
|
1045
|
+
});
|
|
1046
|
+
TplSchema.virtual("layout").get(function() {
|
|
1047
|
+
return this.category;
|
|
1048
|
+
});
|
|
1049
|
+
var Tpl_default = TplSchema;
|
|
1050
|
+
|
|
712
1051
|
// src/db/getModelByTenant.ts
|
|
713
|
-
var AnnotationsSchema = require_Annotations();
|
|
714
|
-
var PlatformConfigsSchema = require_PlatformConfigs();
|
|
715
|
-
var TplSchema = require_Tpl();
|
|
716
1052
|
var getModelByTenant = ({
|
|
717
1053
|
tenant,
|
|
718
1054
|
modelName,
|
|
@@ -731,22 +1067,28 @@ var getModelByTenant = ({
|
|
|
731
1067
|
}
|
|
732
1068
|
return db.model(modelName);
|
|
733
1069
|
};
|
|
734
|
-
var getAnnotationsModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
1070
|
+
var getAnnotationsModelByTenant = ({ tenant, env, mongodb, dbConfigs, modelName }) => getModelByTenant({
|
|
735
1071
|
tenant,
|
|
736
|
-
modelName: "annotations",
|
|
737
|
-
schema:
|
|
1072
|
+
modelName: modelName || "annotations",
|
|
1073
|
+
schema: Annotations_default,
|
|
738
1074
|
env
|
|
739
1075
|
});
|
|
740
1076
|
var getPlatformConfigsModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
741
1077
|
tenant,
|
|
742
1078
|
modelName: "platformConfigs",
|
|
743
|
-
schema:
|
|
1079
|
+
schema: PlatformConfigs_default,
|
|
744
1080
|
env
|
|
745
1081
|
});
|
|
746
1082
|
var getTplModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
747
1083
|
tenant,
|
|
748
1084
|
modelName: "tpl",
|
|
749
|
-
schema:
|
|
1085
|
+
schema: Tpl_default,
|
|
1086
|
+
env
|
|
1087
|
+
});
|
|
1088
|
+
var getAIChatModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
1089
|
+
tenant,
|
|
1090
|
+
modelName: "aiChat",
|
|
1091
|
+
schema: AIChat_default,
|
|
750
1092
|
env
|
|
751
1093
|
});
|
|
752
1094
|
|
|
@@ -856,12 +1198,27 @@ var getAIConfigs = async ({
|
|
|
856
1198
|
}
|
|
857
1199
|
});
|
|
858
1200
|
};
|
|
1201
|
+
|
|
1202
|
+
// src/node.ts
|
|
1203
|
+
var import_WorkerManager = __toESM(require_WorkerManager());
|
|
1204
|
+
var import_BaseProducer = __toESM(require_BaseProducer());
|
|
1205
|
+
var import_BaseWorker = __toESM(require_BaseWorker());
|
|
1206
|
+
var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
|
|
859
1207
|
// Annotate the CommonJS export names for ESM import in node:
|
|
860
1208
|
0 && (module.exports = {
|
|
1209
|
+
AIChatSchema,
|
|
1210
|
+
AnnotationSchema,
|
|
1211
|
+
BaseProducer,
|
|
1212
|
+
BaseWorker,
|
|
1213
|
+
GET_GLOBAL_BULLMQ_CONFIG,
|
|
1214
|
+
PlatformConfigsSchema,
|
|
1215
|
+
TplSchema,
|
|
1216
|
+
WorkerManager,
|
|
861
1217
|
connectToRedis,
|
|
862
1218
|
deleteVal,
|
|
863
1219
|
extractAllBlocksFromTpl,
|
|
864
1220
|
genTagId,
|
|
1221
|
+
getAIChatModelByTenant,
|
|
865
1222
|
getAIConfigs,
|
|
866
1223
|
getAnnotationsModelByTenant,
|
|
867
1224
|
getDbByTenant,
|