@resolveio/server-lib 20.10.7 → 20.11.0

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.
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
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 = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ var __read = (this && this.__read) || function (o, n) {
50
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
51
+ if (!m) return o;
52
+ var i = m.call(o), r, ar = [], e;
53
+ try {
54
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
+ }
56
+ catch (error) { e = { error: error }; }
57
+ finally {
58
+ try {
59
+ if (r && !r.done && (m = i["return"])) m.call(i);
60
+ }
61
+ finally { if (e) throw e.error; }
62
+ }
63
+ return ar;
64
+ };
65
+ Object.defineProperty(exports, "__esModule", { value: true });
66
+ exports.ErrorReporter = void 0;
67
+ var crypto_1 = require("crypto");
68
+ var resolveio_server_app_1 = require("../resolveio-server-app");
69
+ var DEFAULT_ERROR_API_URL = 'https://backend.resolveio.com/api/errors/report';
70
+ var ErrorReporter = /** @class */ (function () {
71
+ function ErrorReporter() {
72
+ }
73
+ ErrorReporter.report = function (options) {
74
+ var _a;
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ var logger, config, normalizedApiUrl, clientName, sourceApp, environment, message, severity, stack, context, metadata, attachments, fingerprint, idempotencyKey, reportedAt, normalizedReportedSourceEnv, payload, transport, response, err_1;
77
+ return __generator(this, function (_b) {
78
+ switch (_b.label) {
79
+ case 0:
80
+ logger = options.logger || console;
81
+ config = getServerConfig();
82
+ normalizedApiUrl = options.apiUrl || DEFAULT_ERROR_API_URL;
83
+ clientName = options.clientName || (config === null || config === void 0 ? void 0 : config.CLIENT_NAME) || ((_a = resolveio_server_app_1.ResolveIOServer.getClientName) === null || _a === void 0 ? void 0 : _a.call(resolveio_server_app_1.ResolveIOServer)) || 'resolveio';
84
+ sourceApp = options.sourceApp || clientName || 'resolveio-server-lib';
85
+ environment = options.environment || process.env.RESOLVEIO_ENV || (config === null || config === void 0 ? void 0 : config.RESOLVEIO_ENV) || (config === null || config === void 0 ? void 0 : config.ENVIRONMENT) || (config === null || config === void 0 ? void 0 : config.ROOT_URL) || process.env.NODE_ENV || 'unknown';
86
+ message = options.message || options.subject || 'ResolveIO Error Detected';
87
+ severity = options.severity || 'error';
88
+ stack = normalizeStack(options.stack || options.error);
89
+ context = normalizeStructured(options.context, options.correlationId);
90
+ metadata = normalizeStructured(mergeMetadata(options.metadata, options.correlationId));
91
+ attachments = Array.isArray(options.attachments) ? normalizeAttachments(options.attachments) : undefined;
92
+ fingerprint = options.fingerprint || computeFingerprint(sourceApp, environment, message, stack);
93
+ idempotencyKey = options.idempotencyKey;
94
+ reportedAt = normalizeReportedAt(options.reportedAt);
95
+ normalizedReportedSourceEnv = normalizeStructured(options.reportedSourceEnv);
96
+ payload = removeEmptyFields({
97
+ sourceApp: sourceApp,
98
+ message: message,
99
+ environment: environment,
100
+ clientId: options.clientId,
101
+ clientSlug: options.clientSlug,
102
+ clientName: clientName,
103
+ clientRepo: options.clientRepo,
104
+ clientEmail: options.clientEmail,
105
+ severity: severity,
106
+ stack: stack,
107
+ context: context,
108
+ metadata: metadata,
109
+ attachments: attachments,
110
+ fingerprint: fingerprint,
111
+ idempotencyKey: idempotencyKey,
112
+ reportedBy: options.reportedBy,
113
+ reportedAt: reportedAt,
114
+ reportedFor: options.reportedFor,
115
+ reportedCount: options.reportedCount,
116
+ reportedSourceHost: options.reportedSourceHost,
117
+ reportedSourceIp: options.reportedSourceIp,
118
+ reportedSourceVersion: options.reportedSourceVersion,
119
+ reportedSourcePid: options.reportedSourcePid,
120
+ reportedSourceInstance: options.reportedSourceInstance,
121
+ reportedSourceRegion: options.reportedSourceRegion,
122
+ reportedSourceCluster: options.reportedSourceCluster,
123
+ reportedSourceProcess: options.reportedSourceProcess,
124
+ reportedSourceEnv: typeof normalizedReportedSourceEnv === 'string' ? undefined : normalizedReportedSourceEnv
125
+ });
126
+ transport = options.fetch || globalThis.fetch;
127
+ if (typeof transport !== 'function') {
128
+ logger.error('ErrorReporter failed: fetch is not available in this runtime');
129
+ logger.error('ErrorReporter payload (not sent):', payload);
130
+ return [2 /*return*/, { delivered: false, reason: 'missing-fetch' }];
131
+ }
132
+ _b.label = 1;
133
+ case 1:
134
+ _b.trys.push([1, 3, , 4]);
135
+ return [4 /*yield*/, transport(normalizedApiUrl, {
136
+ method: 'POST',
137
+ headers: removeEmptyFields({
138
+ 'Content-Type': 'application/json',
139
+ 'X-ResolveIO-Error-Key': clientName,
140
+ 'X-ResolveIO-Error-Hash': fingerprint,
141
+ 'X-ResolveIO-Idempotency-Key': idempotencyKey
142
+ }),
143
+ body: JSON.stringify(payload)
144
+ })];
145
+ case 2:
146
+ response = _b.sent();
147
+ if (!response.ok) {
148
+ logger.error('ErrorReporter failed to deliver payload', { status: response.status, statusText: response.statusText });
149
+ return [2 /*return*/, { delivered: false, status: response.status, reason: 'http-error' }];
150
+ }
151
+ return [2 /*return*/, { delivered: true, status: response.status }];
152
+ case 3:
153
+ err_1 = _b.sent();
154
+ logger.error('ErrorReporter exception while delivering payload', err_1);
155
+ logger.error('ErrorReporter payload (not sent):', payload);
156
+ return [2 /*return*/, { delivered: false, reason: 'network-error' }];
157
+ case 4: return [2 /*return*/];
158
+ }
159
+ });
160
+ });
161
+ };
162
+ return ErrorReporter;
163
+ }());
164
+ exports.ErrorReporter = ErrorReporter;
165
+ function getServerConfig() {
166
+ var _a;
167
+ try {
168
+ return ((_a = resolveio_server_app_1.ResolveIOServer.getServerConfig) === null || _a === void 0 ? void 0 : _a.call(resolveio_server_app_1.ResolveIOServer)) || null;
169
+ }
170
+ catch (err) {
171
+ console.error('Failed to read ResolveIO server config', err);
172
+ return null;
173
+ }
174
+ }
175
+ function normalizeStack(stack) {
176
+ if (!stack) {
177
+ return undefined;
178
+ }
179
+ if (typeof stack === 'string') {
180
+ return stack;
181
+ }
182
+ if (stack instanceof Error) {
183
+ return stack.stack || stack.message;
184
+ }
185
+ if (typeof stack === 'object' && stack !== null && typeof stack.stack === 'string') {
186
+ return stack.stack;
187
+ }
188
+ if (typeof stack === 'object' && stack !== null && typeof stack.message === 'string') {
189
+ return stack.message;
190
+ }
191
+ return JSON.stringify(stack);
192
+ }
193
+ function normalizeStructured(value, correlationId) {
194
+ if (value === null || value === undefined) {
195
+ return undefined;
196
+ }
197
+ if (typeof value === 'string') {
198
+ return value;
199
+ }
200
+ var serialized = serializeValue(value);
201
+ if (correlationId && typeof serialized === 'object' && serialized !== null && !serialized.correlationId) {
202
+ serialized.correlationId = correlationId;
203
+ }
204
+ return serialized;
205
+ }
206
+ function serializeValue(value, seen) {
207
+ var e_1, _a;
208
+ if (seen === void 0) { seen = new WeakSet(); }
209
+ if (value === null || value === undefined) {
210
+ return value;
211
+ }
212
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
213
+ return value;
214
+ }
215
+ if (typeof value === 'bigint') {
216
+ return value.toString();
217
+ }
218
+ if (value instanceof Date) {
219
+ return value.toISOString();
220
+ }
221
+ if (value instanceof Error) {
222
+ var base = {
223
+ name: value.name,
224
+ message: value.message,
225
+ stack: value.stack
226
+ };
227
+ return Object.assign({}, base, serializeValue(Object.assign({}, value), seen));
228
+ }
229
+ if (Array.isArray(value)) {
230
+ if (seen.has(value)) {
231
+ return '[Circular]';
232
+ }
233
+ seen.add(value);
234
+ var arr = value.map(function (item) { return serializeValue(item, seen); });
235
+ seen.delete(value);
236
+ return arr;
237
+ }
238
+ if (typeof value === 'object') {
239
+ if (seen.has(value)) {
240
+ return '[Circular]';
241
+ }
242
+ seen.add(value);
243
+ var obj = {};
244
+ try {
245
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
246
+ var _d = __read(_c.value, 2), key = _d[0], val = _d[1];
247
+ obj[key] = serializeValue(val, seen);
248
+ }
249
+ }
250
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
251
+ finally {
252
+ try {
253
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
254
+ }
255
+ finally { if (e_1) throw e_1.error; }
256
+ }
257
+ seen.delete(value);
258
+ return obj;
259
+ }
260
+ return String(value);
261
+ }
262
+ function normalizeAttachments(attachments) {
263
+ return attachments
264
+ .filter(function (att) { return !!att && typeof att === 'object'; })
265
+ .map(function (att) { return removeEmptyFields({
266
+ name: att.name,
267
+ url: att.url,
268
+ contentType: att.contentType,
269
+ size: typeof att.size === 'number' ? att.size : undefined
270
+ }); })
271
+ .filter(function (att) { return !!att.name; });
272
+ }
273
+ function normalizeReportedAt(value) {
274
+ if (!value) {
275
+ return new Date().toISOString();
276
+ }
277
+ if (value instanceof Date) {
278
+ return value.toISOString();
279
+ }
280
+ var date = new Date(value);
281
+ if (!isNaN(date.getTime())) {
282
+ return date.toISOString();
283
+ }
284
+ return new Date().toISOString();
285
+ }
286
+ function computeFingerprint(sourceApp, environment, message, stack) {
287
+ var signature = "".concat(sourceApp || '', ":").concat(environment || '', ":").concat(message || '', ":").concat(stack ? stack.split('\n').slice(0, 5).join('|') : '');
288
+ return (0, crypto_1.createHash)('sha256').update(signature).digest('hex');
289
+ }
290
+ function removeEmptyFields(obj) {
291
+ var e_2, _a;
292
+ var cleaned = {};
293
+ try {
294
+ for (var _b = __values(Object.entries(obj || {})), _c = _b.next(); !_c.done; _c = _b.next()) {
295
+ var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
296
+ if (value === undefined || value === null || value === '') {
297
+ continue;
298
+ }
299
+ cleaned[key] = value;
300
+ }
301
+ }
302
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
303
+ finally {
304
+ try {
305
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
306
+ }
307
+ finally { if (e_2) throw e_2.error; }
308
+ }
309
+ return cleaned;
310
+ }
311
+ function mergeMetadata(metadata, correlationId) {
312
+ if (!metadata && !correlationId) {
313
+ return undefined;
314
+ }
315
+ var base = metadata ? normalizeStructured(metadata) : undefined;
316
+ if (!correlationId) {
317
+ return base;
318
+ }
319
+ if (typeof base === 'string') {
320
+ return {
321
+ correlationId: correlationId,
322
+ message: base
323
+ };
324
+ }
325
+ var metadataObj = (base || {});
326
+ if (!metadataObj.correlationId) {
327
+ metadataObj.correlationId = correlationId;
328
+ }
329
+ return metadataObj;
330
+ }
331
+
332
+ //# sourceMappingURL=error-reporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/error-reporter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAoC;AACpC,gEAA0D;AAE1D,IAAM,qBAAqB,GAAG,iDAAiD,CAAC;AAsFhF;IAAA;IAiFA,CAAC;IAhFoB,oBAAM,GAA1B,UAA2B,OAA2B;;;;;;;wBAC/C,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;wBACnC,MAAM,GAAG,eAAe,EAAE,CAAC;wBAC3B,gBAAgB,GAAG,OAAO,CAAC,MAAM,IAAI,qBAAqB,CAAC;wBAC3D,UAAU,GAAG,OAAO,CAAC,UAAU,KAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,CAAA,KAAI,MAAA,sCAAe,CAAC,aAAa,sFAAI,CAAA,IAAI,WAAW,CAAC;wBAC3G,SAA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G,IAAI,CAAC,QAAQ,IAAI,CAAC,aAAa,EAAE;QAChC,OAAO,SAAS,CAAC;KACjB;IAED,IAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,IAAI,CAAC,aAAa,EAAE;QACnB,OAAO,IAAI,CAAC;KACZ;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC7B,OAAO;YACN,aAAa,eAAA;YACb,OAAO,EAAE,IAAI;SACb,CAAC;KACF;IAED,IAAM,WAAW,GAAG,CAAC,IAAI,IAAI,EAAE,CAAwB,CAAC;IACxD,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE;QAC/B,WAAW,CAAC,aAAa,GAAG,aAAa,CAAC;KAC1C;IACD,OAAO,WAAW,CAAC;AACpB,CAAC","file":"error-reporter.js","sourcesContent":["import { createHash } from 'crypto';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nconst DEFAULT_ERROR_API_URL = 'https://backend.resolveio.com/api/errors/report';\n\n// eslint-disable-next-line no-unused-vars\ntype FetchLike = (input: RequestInfo, init?: RequestInit) => Promise<Response>;\n\nexport interface ErrorReportAttachment {\n\tname: string;\n\turl?: string;\n\tcontentType?: string;\n\tsize?: number;\n}\n\nexport interface ErrorReportOptions {\n\tsourceApp?: string;\n\tmessage?: string;\n\tsubject?: string;\n\tenvironment?: string;\n\tclientId?: string;\n\tclientSlug?: string;\n\tclientName?: string;\n\tclientRepo?: string;\n\tclientEmail?: string;\n\tseverity?: string;\n\tstack?: string | Error;\n\terror?: unknown;\n\tcontext?: Record<string, any> | string | null;\n\tmetadata?: Record<string, any> | string | null;\n\tattachments?: ErrorReportAttachment[];\n\tfingerprint?: string;\n\tidempotencyKey?: string;\n\treportedBy?: string;\n\treportedAt?: string | Date;\n\treportedFor?: string;\n\treportedCount?: number;\n\treportedSourceHost?: string;\n\treportedSourceIp?: string;\n\treportedSourceVersion?: string;\n\treportedSourcePid?: number;\n\treportedSourceInstance?: string;\n\treportedSourceRegion?: string;\n\treportedSourceCluster?: string;\n\treportedSourceProcess?: string;\n\treportedSourceEnv?: Record<string, any>;\n\tcorrelationId?: string;\n\tapiUrl?: string;\n\tfetch?: FetchLike;\n\tlogger?: Pick<typeof console, 'error' | 'warn' | 'info' | 'log'>;\n}\n\nexport interface ErrorReportResult {\n\tdelivered: boolean;\n\tstatus?: number;\n\treason?: string;\n}\n\ninterface ErrorReportPayload {\n\tsourceApp: string;\n\tmessage: string;\n\tenvironment?: string;\n\tclientId?: string;\n\tclientSlug?: string;\n\tclientName?: string;\n\tclientRepo?: string;\n\tclientEmail?: string;\n\tseverity: string;\n\tstack?: string;\n\tcontext?: Record<string, any> | string;\n\tmetadata?: Record<string, any> | string;\n\tattachments?: ErrorReportAttachment[];\n\tfingerprint?: string;\n\tidempotencyKey?: string;\n\treportedBy?: string;\n\treportedAt?: string;\n\treportedFor?: string;\n\treportedCount?: number;\n\treportedSourceHost?: string;\n\treportedSourceIp?: string;\n\treportedSourceVersion?: string;\n\treportedSourcePid?: number;\n\treportedSourceInstance?: string;\n\treportedSourceRegion?: string;\n\treportedSourceCluster?: string;\n\treportedSourceProcess?: string;\n\treportedSourceEnv?: Record<string, any>;\n}\n\nexport class ErrorReporter {\n\tpublic static async report(options: ErrorReportOptions): Promise<ErrorReportResult> {\n\t\tconst logger = options.logger || console;\n\t\tconst config = getServerConfig();\n\t\tconst normalizedApiUrl = options.apiUrl || DEFAULT_ERROR_API_URL;\n\t\tconst clientName = options.clientName || config?.CLIENT_NAME || ResolveIOServer.getClientName?.() || 'resolveio';\n\t\tconst sourceApp = options.sourceApp || clientName || 'resolveio-server-lib';\n\t\tconst environment = options.environment || process.env.RESOLVEIO_ENV || config?.RESOLVEIO_ENV || config?.ENVIRONMENT || config?.ROOT_URL || process.env.NODE_ENV || 'unknown';\n\t\tconst message = options.message || options.subject || 'ResolveIO Error Detected';\n\t\tconst severity = options.severity || 'error';\n\t\tconst stack = normalizeStack(options.stack || options.error);\n\t\tconst context = normalizeStructured(options.context, options.correlationId);\n\t\tconst metadata = normalizeStructured(mergeMetadata(options.metadata, options.correlationId));\n\t\tconst attachments = Array.isArray(options.attachments) ? normalizeAttachments(options.attachments) : undefined;\n\t\tconst fingerprint = options.fingerprint || computeFingerprint(sourceApp, environment, message, stack);\n\t\tconst idempotencyKey = options.idempotencyKey;\n\t\tconst reportedAt = normalizeReportedAt(options.reportedAt);\n\t\tconst normalizedReportedSourceEnv = normalizeStructured(options.reportedSourceEnv);\n\t\tconst payload: ErrorReportPayload = removeEmptyFields({\n\t\t\tsourceApp,\n\t\t\tmessage,\n\t\t\tenvironment,\n\t\t\tclientId: options.clientId,\n\t\t\tclientSlug: options.clientSlug,\n\t\t\tclientName,\n\t\t\tclientRepo: options.clientRepo,\n\t\t\tclientEmail: options.clientEmail,\n\t\t\tseverity,\n\t\t\tstack,\n\t\t\tcontext,\n\t\t\tmetadata,\n\t\t\tattachments,\n\t\t\tfingerprint,\n\t\t\tidempotencyKey,\n\t\t\treportedBy: options.reportedBy,\n\t\t\treportedAt,\n\t\t\treportedFor: options.reportedFor,\n\t\t\treportedCount: options.reportedCount,\n\t\t\treportedSourceHost: options.reportedSourceHost,\n\t\t\treportedSourceIp: options.reportedSourceIp,\n\t\t\treportedSourceVersion: options.reportedSourceVersion,\n\t\t\treportedSourcePid: options.reportedSourcePid,\n\t\t\treportedSourceInstance: options.reportedSourceInstance,\n\t\t\treportedSourceRegion: options.reportedSourceRegion,\n\t\t\treportedSourceCluster: options.reportedSourceCluster,\n\t\t\treportedSourceProcess: options.reportedSourceProcess,\n\t\t\treportedSourceEnv: typeof normalizedReportedSourceEnv === 'string' ? undefined : normalizedReportedSourceEnv as Record<string, any>\n\t\t});\n\n\t\tconst transport = options.fetch || globalThis.fetch;\n\t\tif (typeof transport !== 'function') {\n\t\t\tlogger.error('ErrorReporter failed: fetch is not available in this runtime');\n\t\t\tlogger.error('ErrorReporter payload (not sent):', payload);\n\t\t\treturn { delivered: false, reason: 'missing-fetch' };\n\t\t}\n\n\t\ttry {\n\t\t\tconst response = await transport(normalizedApiUrl, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: removeEmptyFields({\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'X-ResolveIO-Error-Key': clientName,\n\t\t\t\t\t'X-ResolveIO-Error-Hash': fingerprint,\n\t\t\t\t\t'X-ResolveIO-Idempotency-Key': idempotencyKey\n\t\t\t\t}),\n\t\t\t\tbody: JSON.stringify(payload)\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tlogger.error('ErrorReporter failed to deliver payload', { status: response.status, statusText: response.statusText });\n\t\t\t\treturn { delivered: false, status: response.status, reason: 'http-error' };\n\t\t\t}\n\n\t\t\treturn { delivered: true, status: response.status };\n\t\t}\n\t\tcatch (err) {\n\t\t\tlogger.error('ErrorReporter exception while delivering payload', err);\n\t\t\tlogger.error('ErrorReporter payload (not sent):', payload);\n\t\t\treturn { delivered: false, reason: 'network-error' };\n\t\t}\n\t}\n}\n\nfunction getServerConfig(): Record<string, any> | null {\n\ttry {\n\t\treturn ResolveIOServer.getServerConfig?.() || null;\n\t}\n\tcatch (err) {\n\t\tconsole.error('Failed to read ResolveIO server config', err);\n\t\treturn null;\n\t}\n}\n\nfunction normalizeStack(stack?: string | Error | unknown): string | undefined {\n\tif (!stack) {\n\t\treturn undefined;\n\t}\n\n\tif (typeof stack === 'string') {\n\t\treturn stack;\n\t}\n\n\tif (stack instanceof Error) {\n\t\treturn stack.stack || stack.message;\n\t}\n\n\tif (typeof stack === 'object' && stack !== null && typeof (stack as Record<string, any>).stack === 'string') {\n\t\treturn (stack as Record<string, any>).stack;\n\t}\n\n\tif (typeof stack === 'object' && stack !== null && typeof (stack as Record<string, any>).message === 'string') {\n\t\treturn (stack as Record<string, any>).message;\n\t}\n\n\treturn JSON.stringify(stack);\n}\n\nfunction normalizeStructured(value: any, correlationId?: string): Record<string, any> | string | undefined {\n\tif (value === null || value === undefined) {\n\t\treturn undefined;\n\t}\n\n\tif (typeof value === 'string') {\n\t\treturn value;\n\t}\n\n\tconst serialized = serializeValue(value);\n\tif (correlationId && typeof serialized === 'object' && serialized !== null && !serialized.correlationId) {\n\t\tserialized.correlationId = correlationId;\n\t}\n\treturn serialized;\n}\n\nfunction serializeValue(value: any, seen: WeakSet<object> = new WeakSet()): any {\n\tif (value === null || value === undefined) {\n\t\treturn value;\n\t}\n\n\tif (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n\t\treturn value;\n\t}\n\n\tif (typeof value === 'bigint') {\n\t\treturn value.toString();\n\t}\n\n\tif (value instanceof Date) {\n\t\treturn value.toISOString();\n\t}\n\n\tif (value instanceof Error) {\n\t\tconst base = {\n\t\t\tname: value.name,\n\t\t\tmessage: value.message,\n\t\t\tstack: value.stack\n\t\t};\n\t\treturn Object.assign({}, base, serializeValue(Object.assign({}, value), seen));\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tif (seen.has(value)) {\n\t\t\treturn '[Circular]';\n\t\t}\n\t\tseen.add(value);\n\t\tconst arr = value.map(item => serializeValue(item, seen));\n\t\tseen.delete(value);\n\t\treturn arr;\n\t}\n\n\tif (typeof value === 'object') {\n\t\tif (seen.has(value)) {\n\t\t\treturn '[Circular]';\n\t\t}\n\t\tseen.add(value);\n\t\tconst obj: Record<string, any> = {};\n\t\tfor (const [key, val] of Object.entries(value)) {\n\t\t\tobj[key] = serializeValue(val, seen);\n\t\t}\n\t\tseen.delete(value);\n\t\treturn obj;\n\t}\n\n\treturn String(value);\n}\n\nfunction normalizeAttachments(attachments: ErrorReportAttachment[]): ErrorReportAttachment[] {\n\treturn attachments\n\t\t.filter(att => !!att && typeof att === 'object')\n\t\t.map(att => removeEmptyFields({\n\t\t\tname: att.name,\n\t\t\turl: att.url,\n\t\t\tcontentType: att.contentType,\n\t\t\tsize: typeof att.size === 'number' ? att.size : undefined\n\t\t}))\n\t\t.filter(att => !!att.name);\n}\n\nfunction normalizeReportedAt(value?: string | Date): string | undefined {\n\tif (!value) {\n\t\treturn new Date().toISOString();\n\t}\n\n\tif (value instanceof Date) {\n\t\treturn value.toISOString();\n\t}\n\n\tconst date = new Date(value);\n\tif (!isNaN(date.getTime())) {\n\t\treturn date.toISOString();\n\t}\n\n\treturn new Date().toISOString();\n}\n\nfunction computeFingerprint(sourceApp: string, environment: string | undefined, message: string, stack?: string): string | undefined {\n\tconst signature = `${sourceApp || ''}:${environment || ''}:${message || ''}:${stack ? stack.split('\\n').slice(0, 5).join('|') : ''}`;\n\treturn createHash('sha256').update(signature).digest('hex');\n}\n\nfunction removeEmptyFields<T extends Record<string, any>>(obj: T): T {\n\tconst cleaned: Record<string, any> = {};\n\tfor (const [key, value] of Object.entries(obj || {})) {\n\t\tif (value === undefined || value === null || value === '') {\n\t\t\tcontinue;\n\t\t}\n\t\tcleaned[key] = value;\n\t}\n\treturn cleaned as T;\n}\n\nfunction mergeMetadata(metadata: Record<string, any> | string | null | undefined, correlationId?: string) {\n\tif (!metadata && !correlationId) {\n\t\treturn undefined;\n\t}\n\n\tconst base = metadata ? normalizeStructured(metadata) : undefined;\n\tif (!correlationId) {\n\t\treturn base;\n\t}\n\n\tif (typeof base === 'string') {\n\t\treturn {\n\t\t\tcorrelationId,\n\t\t\tmessage: base\n\t\t};\n\t}\n\n\tconst metadataObj = (base || {}) as Record<string, any>;\n\tif (!metadataObj.correlationId) {\n\t\tmetadataObj.correlationId = correlationId;\n\t}\n\treturn metadataObj;\n}\n"]}
@@ -40,21 +40,14 @@ exports.mongoCommand = exports.getLeafFormatTypes = exports.getLeafValueTypes =
40
40
  var resolveio_server_app_1 = require("../resolveio-server-app");
41
41
  var common_1 = require("./common");
42
42
  function getReportLookupSchemas(collection_root) {
43
- var rootCollection = resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection_root);
44
- if (!rootCollection || !rootCollection['rbSchema']) {
45
- throw new Error('Report builder schema not available for collection ' + String(collection_root) + '. Ensure useReportBuilder is enabled.');
46
- }
47
43
  var lookupTrees = [];
48
- lookupTrees.push({ collection_name: collection_root, tree: rootCollection['rbSchema'], is_root: true });
49
- var schemaObj = rootCollection['rbSchema'];
44
+ lookupTrees.push({ collection_name: collection_root, tree: resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection_root)['rbSchema'], is_root: true });
45
+ var schemaObj = resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection_root)['rbSchema'];
50
46
  var modelKeys = Object.keys(schemaObj);
51
47
  modelKeys.forEach(function (field) {
52
48
  if (schemaObj[field].lookup_collection) {
53
49
  var collectionName_1 = schemaObj[field].lookup_collection;
54
50
  var collectionModel = resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collectionName_1);
55
- if (!collectionModel || !collectionModel['rbSchema']) {
56
- throw new Error('Report builder lookup schema missing for collection ' + collectionName_1 + ' referenced from ' + String(collection_root) + '.');
57
- }
58
51
  if (!lookupTrees.filter(function (a) { return a.collection_name === collectionName_1; }).length) {
59
52
  lookupTrees.push({ collection_name: collectionName_1, tree: collectionModel['rbSchema'], is_root: false });
60
53
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/schema-report-builder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAA0D;AAC1D,mCAAuC;AAEvC,SAAgB,sBAAsB,CAAC,eAAuB;IAC7D,IAAI,cAAc,GAAG,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IACnF,IAAI,CAAC,cAAc,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;QACnD,MAAM,IAAI,KAAK,CAAC,qDAAqD,GAAG,MAAM,CAAC,eAAe,CAAC,GAAG,uCAAuC,CAAC,CAAC;KAC3I;IAED,IAAI,WAAW,GAAqB,EAAE,CAAC;IACvC,WAAW,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,eAAe,EAAE,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rB,GAAG,GAAG;wBACT,KAAK,EAAE,UAAU;wBACjB,KAAK,EAAE,EAAE;qBACT,CAAC;oBACF,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAC,GAAG,EAAE,IAAI,EAAC,CAAC;oBACtB,qBAAM,sCAAe,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAA;;oBAAvD,MAAM,GAAG,SAA8C,CAAC;;;yBAGhD,CAAA,UAAU,KAAK,UAAU,CAAA,EAAzB,wBAAyB;oBAC7B,GAAG,GAAG;wBACT,QAAQ,EAAE,UAAU;wBACpB,KAAK,EAAE,EAAE;wBACT,GAAG,EAAE,KAAK;qBACV,CAAC;oBACO,qBAAM,sCAAe,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAA;;oBAAvD,MAAM,GAAG,SAA8C,CAAC;;;oBAEpD,IAAI,UAAU,KAAK,aAAa,EAAE;wBACtC,0DAA0D;wBAC1D,2CAA2C;wBAC3C,iDAAiD;qBACjD;;;;;oBAED,sDAAsD;oBACtD,sBAAO,CAAC,CAAC,EAAC;;oBAEX,IAAI,MAAM,EAAE;wBACX,sBAAO,MAAM,CAAC,MAAM,EAAC;qBACrB;;;;;CACD;AAjCD,oCAiCC","file":"schema-report-builder.js","sourcesContent":["import { CollectionTree } from '../models/report-builder.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { toTitleCase } from './common';\n\nexport function getReportLookupSchemas(collection_root: string) {\n\tlet rootCollection = ResolveIOServer.getMongoManager().collection(collection_root);\n\tif (!rootCollection || !rootCollection['rbSchema']) {\n\t\tthrow new Error('Report builder schema not available for collection ' + String(collection_root) + '. Ensure useReportBuilder is enabled.');\n\t}\n\n\tlet lookupTrees: CollectionTree[] = [];\n\tlookupTrees.push({ collection_name: collection_root, tree: rootCollection['rbSchema'], is_root: true });\n\tlet schemaObj = rootCollection['rbSchema'];\n\tlet modelKeys = Object.keys(schemaObj);\n\tmodelKeys.forEach(field => {\n\t\tif (schemaObj[field].lookup_collection) {\n\t\t\tlet collectionName = schemaObj[field].lookup_collection;\n\t\t\tlet collectionModel = ResolveIOServer.getMongoManager().collection(collectionName);\n\t\t\tif (!collectionModel || !collectionModel['rbSchema']) {\n\t\t\t\tthrow new Error('Report builder lookup schema missing for collection ' + collectionName + ' referenced from ' + String(collection_root) + '.');\n\t\t\t}\n\n\t\t\tif (!lookupTrees.filter(a => a.collection_name === collectionName).length) {\n\t\t\t\tlookupTrees.push({ collection_name: collectionName, tree: collectionModel['rbSchema'], is_root: false });\n\t\t\t}\n\t\t}\n\t});\n\n\treturn lookupTrees;\n}\n\nexport function buildTree(current_root, schemaTree, lookup?) {\n\tlet res = [];\n\n\tObject.keys(schemaTree).filter(a => a !== '_id' && a !== 'id' && a !== '__v').forEach(key => {\n\t// Object.keys(schemaTree).filter(a => a !== '__v').forEach(key => {\n\t\tif (!lookup || (lookup && !schemaTree[key].lookup_collection)) {\n\t\t\tlet treeItemSplit = key.split('.');\n\t\t\n\t\t\t// debugger;\n\n\t\t\tif (treeItemSplit.length === 1) {\n\t\t\t\tif (schemaTree[key].rbType === 'String' || schemaTree[key].rbType === 'Number' || schemaTree[key].rbType === 'Boolean' || schemaTree[key].rbType === 'Date') {\n\t\t\t\t\tres.push({\n\t\t\t\t\t\tcollection_name: current_root,\n\t\t\t\t\t\tcolumnName: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\tfieldName: key,\n\t\t\t\t\t\tfieldType: schemaTree[key].rbType,\n\t\t\t\t\t\tfieldTypeName: schemaTree[key].rbType === 'String' ? 'Text' : (schemaTree[key].rbType === 'Boolean' ? 'T/F' : schemaTree[key].rbType),\n\t\t\t\t\t\tdistinctFieldValues: [],\n\t\t\t\t\t\tfieldPath: lookup ? lookup.lookup_as + '.$.' + key : key,\n\t\t\t\t\t\tfieldPathName: lookup ? (toTitleCase(lookup.lookup_as.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) + ' (List) -> ' + (toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) : toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> ')),\n\t\t\t\t\t\tlookup_collection: lookup ? lookup.lookup_collection : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_collection : ''),\n\t\t\t\t\t\tlookup_local_key: lookup ? lookup.lookup_local_key : (schemaTree[key].lookup_collection ? schemaTree[key].local_key : ''),\n\t\t\t\t\t\tlookup_foreign_key: lookup ? lookup.lookup_foreign_key : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_key : ''),\n\t\t\t\t\t\tlookup_as: lookup ? lookup.lookup_as : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_as : ''),\n\t\t\t\t\t\ttext: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\tvalue: key,\n\t\t\t\t\t\tisLeaf: true,\n\t\t\t\t\t\tisActive: false,\n\t\t\t\t\t\tisSelected: false,\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tleafValueType: '',\n\t\t\t\t\t\tleafValueTypes: getLeafValueTypes(schemaTree[key], key),\n\t\t\t\t\t\tleafFormatType: '',\n\t\t\t\t\t\tleafFormatTypes: getLeafFormatTypes(schemaTree[key], key)\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tres.push({\n\t\t\t\t\t\tcollection_name: current_root,\n\t\t\t\t\t\tcolumnName: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\tfieldName: key,\n\t\t\t\t\t\tfieldType: schemaTree[key].lookup_collection ? 'Lookup' : schemaTree[key].rbType,\n\t\t\t\t\t\tfieldTypeName: schemaTree[key].lookup_collection ? 'Lookup' : (schemaTree[key].rbType === 'Array' ? 'List' : 'Group'),\n\t\t\t\t\t\tdistinctFieldValues: [],\n\t\t\t\t\t\tfieldPath: lookup ? lookup.lookup_as + '.$.' + key : key,\n\t\t\t\t\t\tfieldPathName: lookup ? (toTitleCase(lookup.lookup_as.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) + ' (List) -> ' + (toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) : toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> ')),\n\t\t\t\t\t\tlookup_collection: lookup ? lookup.lookup_collection : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_collection : ''),\n\t\t\t\t\t\tlookup_local_key: lookup ? lookup.lookup_local_key : (schemaTree[key].lookup_collection ? schemaTree[key].local_key : ''),\n\t\t\t\t\t\tlookup_foreign_key: lookup ? lookup.lookup_foreign_key : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_key : ''),\n\t\t\t\t\t\tlookup_as: lookup ? lookup.lookup_as : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_as : ''),\n\t\t\t\t\t\ttext: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\tvalue: key,\n\t\t\t\t\t\tisLeaf: false,\n\t\t\t\t\t\tisActive: false,\n\t\t\t\t\t\tisSelected: false,\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tleafValueType: '',\n\t\t\t\t\t\tleafFormatType: '',\n\t\t\t\t\t\tchildren: []\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tres = res.sort((a, b) => a.fieldName.localeCompare(b.fieldName));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet child = null;\n\n\t\t\t\ttreeItemSplit.forEach((layer, index) => {\n\t\t\t\t\tif (!child) {\n\t\t\t\t\t\tchild = res.find(a => a.fieldName === layer);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (child.children.find(a => a.fieldName === layer)) {\n\t\t\t\t\t\t\tchild = child.children.find(a => a.fieldName === layer);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tif (schemaTree[key].rbType === 'String' || schemaTree[key].rbType === 'Number' || schemaTree[key].rbType === 'Boolean' || schemaTree[key].rbType === 'Date') {\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tchild.children.push({\n\t\t\t\t\t\t\t\t\tcollection_name: current_root,\n\t\t\t\t\t\t\t\t\tcolumnName: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\t\t\t\tfieldName: layer,\n\t\t\t\t\t\t\t\t\tfieldType: schemaTree[key].rbType,\n\t\t\t\t\t\t\t\t\tfieldTypeName: schemaTree[key].rbType === 'String' ? 'Text' : (schemaTree[key].rbType === 'Boolean' ? 'T/F' : schemaTree[key].rbType),\n\t\t\t\t\t\t\t\t\tdistinctFieldValues: [],\n\t\t\t\t\t\t\t\t\tfieldPath: lookup ? lookup.lookup_as + '.$.' + key : key,\n\t\t\t\t\t\t\t\t\tfieldPathName: lookup ? (toTitleCase(lookup.lookup_as.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) + ' (List) -> ' + (toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) : toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> ')),\n\t\t\t\t\t\t\t\t\tlookup_collection: lookup ? lookup.lookup_collection : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_collection : ''),\n\t\t\t\t\t\t\t\t\tlookup_local_key: lookup ? lookup.lookup_local_key : (schemaTree[key].lookup_collection ? schemaTree[key].local_key : ''),\n\t\t\t\t\t\t\t\t\tlookup_foreign_key: lookup ? lookup.lookup_foreign_key : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_key : ''),\n\t\t\t\t\t\t\t\t\tlookup_as: lookup ? lookup.lookup_as : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_as : ''),\n\t\t\t\t\t\t\t\t\ttext: toTitleCase(layer.replace(/\\_/g, ' ')),\n\t\t\t\t\t\t\t\t\tvalue: layer,\n\t\t\t\t\t\t\t\t\tisLeaf: true,\n\t\t\t\t\t\t\t\t\tisActive: false,\n\t\t\t\t\t\t\t\t\tisSelected: false,\n\t\t\t\t\t\t\t\t\tdepth: index,\n\t\t\t\t\t\t\t\t\tleafValueType: '',\n\t\t\t\t\t\t\t\t\tleafValueTypes: getLeafValueTypes(schemaTree[key], key),\n\t\t\t\t\t\t\t\t\tleafFormatType: '',\n\t\t\t\t\t\t\t\t\tleafFormatTypes: getLeafFormatTypes(schemaTree[key], key)\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tchild.children.push({\n\t\t\t\t\t\t\t\t\tcollection_name: current_root,\n\t\t\t\t\t\t\t\t\tcolumnName: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\t\t\t\tfieldName: layer,\n\t\t\t\t\t\t\t\t\tfieldType: schemaTree[key].lookup_collection ? 'Lookup' : schemaTree[key].rbType,\n\t\t\t\t\t\t\t\t\tfieldTypeName: schemaTree[key].lookup_collection ? 'Lookup' : (schemaTree[key].rbType === 'Array' ? 'List' : 'Group'),\n\t\t\t\t\t\t\t\t\tdistinctFieldValues: [],\n\t\t\t\t\t\t\t\t\tfieldPath: lookup ? lookup.lookup_as + '.$.' + key : key,\n\t\t\t\t\t\t\t\t\tfieldPathName: lookup ? (toTitleCase(lookup.lookup_as.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) + ' (List) -> ' + (toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) : toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> ')),\n\t\t\t\t\t\t\t\t\tlookup_collection: lookup ? lookup.lookup_collection : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_collection : ''),\n\t\t\t\t\t\t\t\t\tlookup_local_key: lookup ? lookup.lookup_local_key : (schemaTree[key].lookup_collection ? schemaTree[key].local_key : ''),\n\t\t\t\t\t\t\t\t\tlookup_foreign_key: lookup ? lookup.lookup_foreign_key : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_key : ''),\n\t\t\t\t\t\t\t\t\tlookup_as: lookup ? lookup.lookup_as : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_as : ''),\n\t\t\t\t\t\t\t\t\ttext: toTitleCase(layer.replace(/\\_/g, ' ')),\n\t\t\t\t\t\t\t\t\tvalue: layer,\n\t\t\t\t\t\t\t\t\tisLeaf: false,\n\t\t\t\t\t\t\t\t\tisActive: false,\n\t\t\t\t\t\t\t\t\tisSelected: false,\n\t\t\t\t\t\t\t\t\tdepth: index,\n\t\t\t\t\t\t\t\t\tleafValueType: '',\n\t\t\t\t\t\t\t\t\tleafFormatType: '',\n\t\t\t\t\t\t\t\t\tchildren: []\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tchild.children = child.children.sort((a, b) => a.fieldName.localeCompare(b.fieldName));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n\n\treturn res;\n}\n\n// eslint-disable-next-line no-unused-vars\nexport function getLeafValueTypes(schemaTree, fieldPath) {\n\tlet leafTypes = [];\n\n\tif (schemaTree.rbType === 'String') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Value',\n\t\t\t\tvalue: 'Value'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Unique',\n\t\t\t\tvalue: 'Unique'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Count',\n\t\t\t\tvalue: 'Count'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'First',\n\t\t\t\tvalue: 'First'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Last',\n\t\t\t\tvalue: 'Last'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Number') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Value',\n\t\t\t\tvalue: 'Value'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Unique',\n\t\t\t\tvalue: 'Unique'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Average',\n\t\t\t\tvalue: 'Average'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Count',\n\t\t\t\tvalue: 'Count'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Sum',\n\t\t\t\tvalue: 'Sum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Minimum',\n\t\t\t\tvalue: 'Minimum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Maximum',\n\t\t\t\tvalue: 'Maximum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'First',\n\t\t\t\tvalue: 'First'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Last',\n\t\t\t\tvalue: 'Last'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Boolean') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Value',\n\t\t\t\tvalue: 'Value'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Unique',\n\t\t\t\tvalue: 'Unique'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Count',\n\t\t\t\tvalue: 'Count'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'First',\n\t\t\t\tvalue: 'First'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Last',\n\t\t\t\tvalue: 'Last'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Date') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Value',\n\t\t\t\tvalue: 'Value'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Unique',\n\t\t\t\tvalue: 'Unique'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Count',\n\t\t\t\tvalue: 'Count'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Minimum',\n\t\t\t\tvalue: 'Minimum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Maximum',\n\t\t\t\tvalue: 'Maximum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'First',\n\t\t\t\tvalue: 'First'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Last',\n\t\t\t\tvalue: 'Last'\n\t\t\t}\n\t\t];\n\t}\n\treturn leafTypes;\n}\n\n// eslint-disable-next-line no-unused-vars\nexport function getLeafFormatTypes(schemaTree, fieldPath) {\n\tlet leafTypes = [];\n\n\tif (schemaTree.rbType === 'String') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Text',\n\t\t\t\tvalue: 'String'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Number',\n\t\t\t\tvalue: 'Number'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Number') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Number',\n\t\t\t\tvalue: 'Number'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Currency',\n\t\t\t\tvalue: 'Currency'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Text',\n\t\t\t\tvalue: 'String'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Boolean') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Number',\n\t\t\t\tvalue: 'Number'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Boolean (True/False)',\n\t\t\t\tvalue: 'Boolean'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Text (Yes/No)',\n\t\t\t\tvalue: 'String'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Number (1/0)',\n\t\t\t\tvalue: 'Boolean_Number'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Date') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Number',\n\t\t\t\tvalue: 'Number'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Date (Short Format)',\n\t\t\t\tvalue: 'Date'\n\t\t\t}, \n\t\t\t{\n\t\t\t\ttext: 'As Time (Short Format)',\n\t\t\t\tvalue: 'Time'\n\t\t\t}, \n\t\t\t{\n\t\t\t\ttext: 'As Date/Time (Short Format)',\n\t\t\t\tvalue: 'DateTime'\n\t\t\t}, \n\t\t\t{\n\t\t\t\ttext: 'As Date (Long Format)',\n\t\t\t\tvalue: 'Date_long'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Date/Time (Long Format)',\n\t\t\t\tvalue: 'DateTime_long'\n\t\t\t}, \n\t\t\t{\n\t\t\t\ttext: 'As Timestamp (MS since 1970)',\n\t\t\t\tvalue: 'Timestamp'\n\t\t\t}\n\t\t];\n\t}\n\treturn leafTypes;\n}\n\n\n\n\n\nexport async function mongoCommand(commandstr: string, collection: string, field?: any) {\n\tlet tmpObj;\n\ttry {\n\t\t// Count the number of non-empty fields in a given collection:\n\t\tif (commandstr === 'count') {\n\t\t\tlet obj = {\n\t\t\t\tcount: collection,\n\t\t\t\tquery: {}\n\t\t\t};\n\t\t\tobj.query[field] = {$ne: null};\n\t\t\ttmpObj = await ResolveIOServer.getMainDB().command(obj);\n\t\t}\n\t\t// Get all distinct values in a given field.\n\t\telse if (commandstr === 'distinct') {\n\t\t\tlet obj = {\n\t\t\t\tdistinct: collection,\n\t\t\t\tquery: {},\n\t\t\t\tkey: field,\n\t\t\t};\n\t\t\ttmpObj = await ResolveIOServer.getMainDB().command(obj);\n\t\t}\n\t\telse if (commandstr === 'listIndexes') {\n\t\t\t// tmpObj = await this.mainDb.db[collection].getIndexes();\n\t\t\t// let obj = { 'listIndexes': collection };\n\t\t\t// tmpObj = await this.mainDb.db.getIndexes(obj);\n\t\t}\n\t} catch {\n\t\t// console.log('----------- mongoCommand err: ', err);\n\t\treturn -1;\n\t}\n\tif (tmpObj) {\n\t\treturn tmpObj.values;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../src/util/schema-report-builder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAA0D;AAC1D,mCAAuC;AAEvC,SAAgB,sBAAsB,CAAC,eAAuB;IAC7D,IAAI,WAAW,GAAqB,EAAE,CAAC;IACvC,WAAW,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACvJ,IAAI,SAAS,GAAG,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,UAAU,CAAC,CAAC;IAC1F,IAAI,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvC,SAAS,CAAC,OAAO,CAAC,UAAA,KAAK;QACtB,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE;YACvC,IAAI,gBAAc,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,iBAAiB,CAAC;YACxD,IAAI,eAAe,GAAG,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,gBAAc,CAAC,CAAC;YAEnF,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,eAAe,KAAK,gBAAc,EAApC,CAAoC,CAAC,CAAC,MAAM,EAAE;gBAC1E,WAAW,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,gBAAc,EAAE,IAAI,EAAE,eAAe,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,C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AClB;YACD;gBACC,IAAI,EAAE,4BAA4B;gBAClC,KAAK,EAAE,eAAe;aACtB;YACD;gBACC,IAAI,EAAE,8BAA8B;gBACpC,KAAK,EAAE,WAAW;aAClB;SACD,CAAC;KACF;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AApFD,gDAoFC;AAMD,SAAsB,YAAY,CAAC,UAAkB,EAAE,UAAkB,EAAE,KAAW;;;;;;;yBAIhF,CAAA,UAAU,KAAK,OAAO,CAAA,EAAtB,wBAAsB;oBACrB,GAAG,GAAG;wBACT,KAAK,EAAE,UAAU;wBACjB,KAAK,EAAE,EAAE;qBACT,CAAC;oBACF,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAC,GAAG,EAAE,IAAI,EAAC,CAAC;oBACtB,qBAAM,sCAAe,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAA;;oBAAvD,MAAM,GAAG,SAA8C,CAAC;;;yBAGhD,CAAA,UAAU,KAAK,UAAU,CAAA,EAAzB,wBAAyB;oBAC7B,GAAG,GAAG;wBACT,QAAQ,EAAE,UAAU;wBACpB,KAAK,EAAE,EAAE;wBACT,GAAG,EAAE,KAAK;qBACV,CAAC;oBACO,qBAAM,sCAAe,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAA;;oBAAvD,MAAM,GAAG,SAA8C,CAAC;;;oBAEpD,IAAI,UAAU,KAAK,aAAa,EAAE;wBACtC,0DAA0D;wBAC1D,2CAA2C;wBAC3C,iDAAiD;qBACjD;;;;;oBAED,sDAAsD;oBACtD,sBAAO,CAAC,CAAC,EAAC;;oBAEX,IAAI,MAAM,EAAE;wBACX,sBAAO,MAAM,CAAC,MAAM,EAAC;qBACrB;;;;;CACD;AAjCD,oCAiCC","file":"schema-report-builder.js","sourcesContent":["import { CollectionTree } from '../models/report-builder.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { toTitleCase } from './common';\n\nexport function getReportLookupSchemas(collection_root: string) {\n\tlet lookupTrees: CollectionTree[] = [];\n\tlookupTrees.push({ collection_name: collection_root, tree: ResolveIOServer.getMongoManager().collection(collection_root)['rbSchema'], is_root: true });\n\tlet schemaObj = ResolveIOServer.getMongoManager().collection(collection_root)['rbSchema'];\n\tlet modelKeys = Object.keys(schemaObj);\n\tmodelKeys.forEach(field => {\n\t\tif (schemaObj[field].lookup_collection) {\n\t\t\tlet collectionName = schemaObj[field].lookup_collection;\n\t\t\tlet collectionModel = ResolveIOServer.getMongoManager().collection(collectionName);\n\n\t\t\tif (!lookupTrees.filter(a => a.collection_name === collectionName).length) {\n\t\t\t\tlookupTrees.push({ collection_name: collectionName, tree: collectionModel['rbSchema'], is_root: false });\n\t\t\t}\n\t\t}\n\t});\n\n\treturn lookupTrees;\n}\n\nexport function buildTree(current_root, schemaTree, lookup?) {\n\tlet res = [];\n\n\tObject.keys(schemaTree).filter(a => a !== '_id' && a !== 'id' && a !== '__v').forEach(key => {\n\t// Object.keys(schemaTree).filter(a => a !== '__v').forEach(key => {\n\t\tif (!lookup || (lookup && !schemaTree[key].lookup_collection)) {\n\t\t\tlet treeItemSplit = key.split('.');\n\t\t\n\t\t\t// debugger;\n\n\t\t\tif (treeItemSplit.length === 1) {\n\t\t\t\tif (schemaTree[key].rbType === 'String' || schemaTree[key].rbType === 'Number' || schemaTree[key].rbType === 'Boolean' || schemaTree[key].rbType === 'Date') {\n\t\t\t\t\tres.push({\n\t\t\t\t\t\tcollection_name: current_root,\n\t\t\t\t\t\tcolumnName: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\tfieldName: key,\n\t\t\t\t\t\tfieldType: schemaTree[key].rbType,\n\t\t\t\t\t\tfieldTypeName: schemaTree[key].rbType === 'String' ? 'Text' : (schemaTree[key].rbType === 'Boolean' ? 'T/F' : schemaTree[key].rbType),\n\t\t\t\t\t\tdistinctFieldValues: [],\n\t\t\t\t\t\tfieldPath: lookup ? lookup.lookup_as + '.$.' + key : key,\n\t\t\t\t\t\tfieldPathName: lookup ? (toTitleCase(lookup.lookup_as.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) + ' (List) -> ' + (toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) : toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> ')),\n\t\t\t\t\t\tlookup_collection: lookup ? lookup.lookup_collection : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_collection : ''),\n\t\t\t\t\t\tlookup_local_key: lookup ? lookup.lookup_local_key : (schemaTree[key].lookup_collection ? schemaTree[key].local_key : ''),\n\t\t\t\t\t\tlookup_foreign_key: lookup ? lookup.lookup_foreign_key : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_key : ''),\n\t\t\t\t\t\tlookup_as: lookup ? lookup.lookup_as : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_as : ''),\n\t\t\t\t\t\ttext: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\tvalue: key,\n\t\t\t\t\t\tisLeaf: true,\n\t\t\t\t\t\tisActive: false,\n\t\t\t\t\t\tisSelected: false,\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tleafValueType: '',\n\t\t\t\t\t\tleafValueTypes: getLeafValueTypes(schemaTree[key], key),\n\t\t\t\t\t\tleafFormatType: '',\n\t\t\t\t\t\tleafFormatTypes: getLeafFormatTypes(schemaTree[key], key)\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tres.push({\n\t\t\t\t\t\tcollection_name: current_root,\n\t\t\t\t\t\tcolumnName: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\tfieldName: key,\n\t\t\t\t\t\tfieldType: schemaTree[key].lookup_collection ? 'Lookup' : schemaTree[key].rbType,\n\t\t\t\t\t\tfieldTypeName: schemaTree[key].lookup_collection ? 'Lookup' : (schemaTree[key].rbType === 'Array' ? 'List' : 'Group'),\n\t\t\t\t\t\tdistinctFieldValues: [],\n\t\t\t\t\t\tfieldPath: lookup ? lookup.lookup_as + '.$.' + key : key,\n\t\t\t\t\t\tfieldPathName: lookup ? (toTitleCase(lookup.lookup_as.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) + ' (List) -> ' + (toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) : toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> ')),\n\t\t\t\t\t\tlookup_collection: lookup ? lookup.lookup_collection : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_collection : ''),\n\t\t\t\t\t\tlookup_local_key: lookup ? lookup.lookup_local_key : (schemaTree[key].lookup_collection ? schemaTree[key].local_key : ''),\n\t\t\t\t\t\tlookup_foreign_key: lookup ? lookup.lookup_foreign_key : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_key : ''),\n\t\t\t\t\t\tlookup_as: lookup ? lookup.lookup_as : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_as : ''),\n\t\t\t\t\t\ttext: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\tvalue: key,\n\t\t\t\t\t\tisLeaf: false,\n\t\t\t\t\t\tisActive: false,\n\t\t\t\t\t\tisSelected: false,\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tleafValueType: '',\n\t\t\t\t\t\tleafFormatType: '',\n\t\t\t\t\t\tchildren: []\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tres = res.sort((a, b) => a.fieldName.localeCompare(b.fieldName));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet child = null;\n\n\t\t\t\ttreeItemSplit.forEach((layer, index) => {\n\t\t\t\t\tif (!child) {\n\t\t\t\t\t\tchild = res.find(a => a.fieldName === layer);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (child.children.find(a => a.fieldName === layer)) {\n\t\t\t\t\t\t\tchild = child.children.find(a => a.fieldName === layer);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tif (schemaTree[key].rbType === 'String' || schemaTree[key].rbType === 'Number' || schemaTree[key].rbType === 'Boolean' || schemaTree[key].rbType === 'Date') {\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tchild.children.push({\n\t\t\t\t\t\t\t\t\tcollection_name: current_root,\n\t\t\t\t\t\t\t\t\tcolumnName: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\t\t\t\tfieldName: layer,\n\t\t\t\t\t\t\t\t\tfieldType: schemaTree[key].rbType,\n\t\t\t\t\t\t\t\t\tfieldTypeName: schemaTree[key].rbType === 'String' ? 'Text' : (schemaTree[key].rbType === 'Boolean' ? 'T/F' : schemaTree[key].rbType),\n\t\t\t\t\t\t\t\t\tdistinctFieldValues: [],\n\t\t\t\t\t\t\t\t\tfieldPath: lookup ? lookup.lookup_as + '.$.' + key : key,\n\t\t\t\t\t\t\t\t\tfieldPathName: lookup ? (toTitleCase(lookup.lookup_as.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) + ' (List) -> ' + (toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) : toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> ')),\n\t\t\t\t\t\t\t\t\tlookup_collection: lookup ? lookup.lookup_collection : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_collection : ''),\n\t\t\t\t\t\t\t\t\tlookup_local_key: lookup ? lookup.lookup_local_key : (schemaTree[key].lookup_collection ? schemaTree[key].local_key : ''),\n\t\t\t\t\t\t\t\t\tlookup_foreign_key: lookup ? lookup.lookup_foreign_key : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_key : ''),\n\t\t\t\t\t\t\t\t\tlookup_as: lookup ? lookup.lookup_as : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_as : ''),\n\t\t\t\t\t\t\t\t\ttext: toTitleCase(layer.replace(/\\_/g, ' ')),\n\t\t\t\t\t\t\t\t\tvalue: layer,\n\t\t\t\t\t\t\t\t\tisLeaf: true,\n\t\t\t\t\t\t\t\t\tisActive: false,\n\t\t\t\t\t\t\t\t\tisSelected: false,\n\t\t\t\t\t\t\t\t\tdepth: index,\n\t\t\t\t\t\t\t\t\tleafValueType: '',\n\t\t\t\t\t\t\t\t\tleafValueTypes: getLeafValueTypes(schemaTree[key], key),\n\t\t\t\t\t\t\t\t\tleafFormatType: '',\n\t\t\t\t\t\t\t\t\tleafFormatTypes: getLeafFormatTypes(schemaTree[key], key)\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tchild.children.push({\n\t\t\t\t\t\t\t\t\tcollection_name: current_root,\n\t\t\t\t\t\t\t\t\tcolumnName: toTitleCase(key.replace(/\\_/g, ' ')),\n\t\t\t\t\t\t\t\t\tfieldName: layer,\n\t\t\t\t\t\t\t\t\tfieldType: schemaTree[key].lookup_collection ? 'Lookup' : schemaTree[key].rbType,\n\t\t\t\t\t\t\t\t\tfieldTypeName: schemaTree[key].lookup_collection ? 'Lookup' : (schemaTree[key].rbType === 'Array' ? 'List' : 'Group'),\n\t\t\t\t\t\t\t\t\tdistinctFieldValues: [],\n\t\t\t\t\t\t\t\t\tfieldPath: lookup ? lookup.lookup_as + '.$.' + key : key,\n\t\t\t\t\t\t\t\t\tfieldPathName: lookup ? (toTitleCase(lookup.lookup_as.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) + ' (List) -> ' + (toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> '))) : toTitleCase(key.replace(/\\.\\$\\./g, ' (List) -> ').replace(/\\./g, ' (Group) -> ')),\n\t\t\t\t\t\t\t\t\tlookup_collection: lookup ? lookup.lookup_collection : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_collection : ''),\n\t\t\t\t\t\t\t\t\tlookup_local_key: lookup ? lookup.lookup_local_key : (schemaTree[key].lookup_collection ? schemaTree[key].local_key : ''),\n\t\t\t\t\t\t\t\t\tlookup_foreign_key: lookup ? lookup.lookup_foreign_key : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_key : ''),\n\t\t\t\t\t\t\t\t\tlookup_as: lookup ? lookup.lookup_as : (schemaTree[key].lookup_collection ? schemaTree[key].lookup_as : ''),\n\t\t\t\t\t\t\t\t\ttext: toTitleCase(layer.replace(/\\_/g, ' ')),\n\t\t\t\t\t\t\t\t\tvalue: layer,\n\t\t\t\t\t\t\t\t\tisLeaf: false,\n\t\t\t\t\t\t\t\t\tisActive: false,\n\t\t\t\t\t\t\t\t\tisSelected: false,\n\t\t\t\t\t\t\t\t\tdepth: index,\n\t\t\t\t\t\t\t\t\tleafValueType: '',\n\t\t\t\t\t\t\t\t\tleafFormatType: '',\n\t\t\t\t\t\t\t\t\tchildren: []\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tchild.children = child.children.sort((a, b) => a.fieldName.localeCompare(b.fieldName));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n\n\treturn res;\n}\n\n// eslint-disable-next-line no-unused-vars\nexport function getLeafValueTypes(schemaTree, fieldPath) {\n\tlet leafTypes = [];\n\n\tif (schemaTree.rbType === 'String') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Value',\n\t\t\t\tvalue: 'Value'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Unique',\n\t\t\t\tvalue: 'Unique'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Count',\n\t\t\t\tvalue: 'Count'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'First',\n\t\t\t\tvalue: 'First'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Last',\n\t\t\t\tvalue: 'Last'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Number') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Value',\n\t\t\t\tvalue: 'Value'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Unique',\n\t\t\t\tvalue: 'Unique'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Average',\n\t\t\t\tvalue: 'Average'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Count',\n\t\t\t\tvalue: 'Count'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Sum',\n\t\t\t\tvalue: 'Sum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Minimum',\n\t\t\t\tvalue: 'Minimum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Maximum',\n\t\t\t\tvalue: 'Maximum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'First',\n\t\t\t\tvalue: 'First'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Last',\n\t\t\t\tvalue: 'Last'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Boolean') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Value',\n\t\t\t\tvalue: 'Value'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Unique',\n\t\t\t\tvalue: 'Unique'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Count',\n\t\t\t\tvalue: 'Count'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'First',\n\t\t\t\tvalue: 'First'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Last',\n\t\t\t\tvalue: 'Last'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Date') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Value',\n\t\t\t\tvalue: 'Value'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Unique',\n\t\t\t\tvalue: 'Unique'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Count',\n\t\t\t\tvalue: 'Count'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Minimum',\n\t\t\t\tvalue: 'Minimum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Maximum',\n\t\t\t\tvalue: 'Maximum'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'First',\n\t\t\t\tvalue: 'First'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'Last',\n\t\t\t\tvalue: 'Last'\n\t\t\t}\n\t\t];\n\t}\n\treturn leafTypes;\n}\n\n// eslint-disable-next-line no-unused-vars\nexport function getLeafFormatTypes(schemaTree, fieldPath) {\n\tlet leafTypes = [];\n\n\tif (schemaTree.rbType === 'String') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Text',\n\t\t\t\tvalue: 'String'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Number',\n\t\t\t\tvalue: 'Number'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Number') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Number',\n\t\t\t\tvalue: 'Number'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Currency',\n\t\t\t\tvalue: 'Currency'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Text',\n\t\t\t\tvalue: 'String'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Boolean') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Number',\n\t\t\t\tvalue: 'Number'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Boolean (True/False)',\n\t\t\t\tvalue: 'Boolean'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Text (Yes/No)',\n\t\t\t\tvalue: 'String'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Number (1/0)',\n\t\t\t\tvalue: 'Boolean_Number'\n\t\t\t}\n\t\t];\n\t}\n\telse if (schemaTree.rbType === 'Date') {\n\t\tleafTypes = [\n\t\t\t{\n\t\t\t\ttext: 'As Number',\n\t\t\t\tvalue: 'Number'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Date (Short Format)',\n\t\t\t\tvalue: 'Date'\n\t\t\t}, \n\t\t\t{\n\t\t\t\ttext: 'As Time (Short Format)',\n\t\t\t\tvalue: 'Time'\n\t\t\t}, \n\t\t\t{\n\t\t\t\ttext: 'As Date/Time (Short Format)',\n\t\t\t\tvalue: 'DateTime'\n\t\t\t}, \n\t\t\t{\n\t\t\t\ttext: 'As Date (Long Format)',\n\t\t\t\tvalue: 'Date_long'\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: 'As Date/Time (Long Format)',\n\t\t\t\tvalue: 'DateTime_long'\n\t\t\t}, \n\t\t\t{\n\t\t\t\ttext: 'As Timestamp (MS since 1970)',\n\t\t\t\tvalue: 'Timestamp'\n\t\t\t}\n\t\t];\n\t}\n\treturn leafTypes;\n}\n\n\n\n\n\nexport async function mongoCommand(commandstr: string, collection: string, field?: any) {\n\tlet tmpObj;\n\ttry {\n\t\t// Count the number of non-empty fields in a given collection:\n\t\tif (commandstr === 'count') {\n\t\t\tlet obj = {\n\t\t\t\tcount: collection,\n\t\t\t\tquery: {}\n\t\t\t};\n\t\t\tobj.query[field] = {$ne: null};\n\t\t\ttmpObj = await ResolveIOServer.getMainDB().command(obj);\n\t\t}\n\t\t// Get all distinct values in a given field.\n\t\telse if (commandstr === 'distinct') {\n\t\t\tlet obj = {\n\t\t\t\tdistinct: collection,\n\t\t\t\tquery: {},\n\t\t\t\tkey: field,\n\t\t\t};\n\t\t\ttmpObj = await ResolveIOServer.getMainDB().command(obj);\n\t\t}\n\t\telse if (commandstr === 'listIndexes') {\n\t\t\t// tmpObj = await this.mainDb.db[collection].getIndexes();\n\t\t\t// let obj = { 'listIndexes': collection };\n\t\t\t// tmpObj = await this.mainDb.db.getIndexes(obj);\n\t\t}\n\t} catch {\n\t\t// console.log('----------- mongoCommand err: ', err);\n\t\treturn -1;\n\t}\n\tif (tmpObj) {\n\t\treturn tmpObj.values;\n\t}\n}"]}