@cellaware/utils 7.2.5 → 8.0.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.
- package/dist/chatwms/alerts.d.ts +86 -0
- package/dist/chatwms/alerts.js +62 -0
- package/dist/chatwms/client.d.ts +4 -0
- package/dist/chatwms/client.js +3 -0
- package/dist/chatwms/dashboards.d.ts +80 -0
- package/dist/chatwms/dashboards.js +17 -0
- package/dist/chatwms/datagrid.d.ts +120 -0
- package/dist/chatwms/datagrid.js +781 -0
- package/dist/chatwms/developer.d.ts +27 -0
- package/dist/chatwms/developer.js +12 -0
- package/dist/chatwms/reports.d.ts +66 -0
- package/dist/chatwms/reports.js +24 -0
- package/dist/chatwms/search.d.ts +12 -0
- package/dist/chatwms/search.js +9 -0
- package/dist/util.d.ts +10 -2
- package/dist/util.js +64 -19
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { KeyValuePair } from "../util.js";
|
|
2
|
+
import { DataContext } from "./client.js";
|
|
3
|
+
export interface SqlCacheContext {
|
|
4
|
+
contextName: DataContext;
|
|
5
|
+
variables: KeyValuePair[];
|
|
6
|
+
tables: {
|
|
7
|
+
table_name: string;
|
|
8
|
+
table_description: string;
|
|
9
|
+
}[];
|
|
10
|
+
columns: {
|
|
11
|
+
table_name: string;
|
|
12
|
+
column_id: number;
|
|
13
|
+
column_name: string;
|
|
14
|
+
data_type: string;
|
|
15
|
+
column_description: string;
|
|
16
|
+
column_comment: string;
|
|
17
|
+
}[];
|
|
18
|
+
functions: {
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
args: string[];
|
|
22
|
+
description: string;
|
|
23
|
+
}[];
|
|
24
|
+
tableMappings: KeyValuePair[];
|
|
25
|
+
columnMappings: KeyValuePair[];
|
|
26
|
+
}
|
|
27
|
+
export declare function initSqlCacheContext(): SqlCacheContext;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CHATWMS_CONTEXT_NAME } from "./client.js";
|
|
2
|
+
export function initSqlCacheContext() {
|
|
3
|
+
return {
|
|
4
|
+
contextName: CHATWMS_CONTEXT_NAME,
|
|
5
|
+
variables: [],
|
|
6
|
+
tables: [],
|
|
7
|
+
columns: [],
|
|
8
|
+
functions: [],
|
|
9
|
+
tableMappings: [],
|
|
10
|
+
columnMappings: []
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { DataContext } from "./client.js";
|
|
2
|
+
import { DatagridStateBase } from "./datagrid.js";
|
|
3
|
+
export declare const REPORT_VISIBILITY_PRIVATE = "private";
|
|
4
|
+
export declare const REPORT_VISIBILITY_PUBLIC = "public";
|
|
5
|
+
export declare const REPORT_VISIBILITY_GLOBAL = "global";
|
|
6
|
+
export interface ReportParameter {
|
|
7
|
+
sequence: number;
|
|
8
|
+
name: string;
|
|
9
|
+
/** `text` | `number` | `date` | `boolean` */
|
|
10
|
+
type: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Report {
|
|
13
|
+
reportId: string;
|
|
14
|
+
reportTitle: string;
|
|
15
|
+
reportRoute: string;
|
|
16
|
+
visibility: string;
|
|
17
|
+
readonly: boolean;
|
|
18
|
+
parameters: ReportParameter[];
|
|
19
|
+
folder: string;
|
|
20
|
+
brief: string;
|
|
21
|
+
clientId: string;
|
|
22
|
+
userId: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function initReport(): Report;
|
|
25
|
+
export interface LineReportParameter {
|
|
26
|
+
sequence: number;
|
|
27
|
+
parameterName: string;
|
|
28
|
+
columnName: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ReportLineContentInfo extends DatagridStateBase {
|
|
31
|
+
visualizationOption: string;
|
|
32
|
+
reportParameters: LineReportParameter[];
|
|
33
|
+
contextName: DataContext;
|
|
34
|
+
specification: string;
|
|
35
|
+
query: string;
|
|
36
|
+
summary: string;
|
|
37
|
+
reviewOk?: boolean;
|
|
38
|
+
reviewConfidence?: string;
|
|
39
|
+
reviewFeedback?: string;
|
|
40
|
+
tableGroups?: string[];
|
|
41
|
+
developer?: boolean;
|
|
42
|
+
archive?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface ReportLine {
|
|
45
|
+
lineId: string;
|
|
46
|
+
lineTitle: string;
|
|
47
|
+
reportId: string;
|
|
48
|
+
contentInfo: ReportLineContentInfo;
|
|
49
|
+
sequence: number;
|
|
50
|
+
clientId: string;
|
|
51
|
+
userId: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ReportLineResult {
|
|
54
|
+
rows: any[];
|
|
55
|
+
rowsStr: string;
|
|
56
|
+
chartRows: any[];
|
|
57
|
+
}
|
|
58
|
+
export declare function initReportLineResult(): ReportLineResult;
|
|
59
|
+
export interface ReportUsage {
|
|
60
|
+
reportId: string;
|
|
61
|
+
reportTitle: string;
|
|
62
|
+
visibility: string;
|
|
63
|
+
clientId: string;
|
|
64
|
+
userId: string;
|
|
65
|
+
datetime: Date;
|
|
66
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const REPORT_VISIBILITY_PRIVATE = 'private';
|
|
2
|
+
export const REPORT_VISIBILITY_PUBLIC = 'public';
|
|
3
|
+
export const REPORT_VISIBILITY_GLOBAL = 'global';
|
|
4
|
+
export function initReport() {
|
|
5
|
+
return {
|
|
6
|
+
reportId: '',
|
|
7
|
+
reportTitle: '',
|
|
8
|
+
reportRoute: '',
|
|
9
|
+
visibility: REPORT_VISIBILITY_PRIVATE,
|
|
10
|
+
readonly: false,
|
|
11
|
+
parameters: [],
|
|
12
|
+
folder: '',
|
|
13
|
+
brief: '',
|
|
14
|
+
clientId: '',
|
|
15
|
+
userId: ''
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function initReportLineResult() {
|
|
19
|
+
return {
|
|
20
|
+
rows: [],
|
|
21
|
+
rowsStr: '',
|
|
22
|
+
chartRows: []
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum SearchRecordType {
|
|
2
|
+
DASHBOARD = "dashboard",
|
|
3
|
+
DASHBOARD_WIDGET = "dashboard_widget",
|
|
4
|
+
DASHBOARD_FOLDER = "dashboard_folder",
|
|
5
|
+
REPORT = "report",
|
|
6
|
+
REPORT_LINE = "report_line",
|
|
7
|
+
REPORT_FOLDER = "report_folder"
|
|
8
|
+
}
|
|
9
|
+
export interface SearchRecord {
|
|
10
|
+
type: SearchRecordType;
|
|
11
|
+
data: any;
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var SearchRecordType;
|
|
2
|
+
(function (SearchRecordType) {
|
|
3
|
+
SearchRecordType["DASHBOARD"] = "dashboard";
|
|
4
|
+
SearchRecordType["DASHBOARD_WIDGET"] = "dashboard_widget";
|
|
5
|
+
SearchRecordType["DASHBOARD_FOLDER"] = "dashboard_folder";
|
|
6
|
+
SearchRecordType["REPORT"] = "report";
|
|
7
|
+
SearchRecordType["REPORT_LINE"] = "report_line";
|
|
8
|
+
SearchRecordType["REPORT_FOLDER"] = "report_folder";
|
|
9
|
+
})(SearchRecordType || (SearchRecordType = {}));
|
package/dist/util.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
export interface KeyValuePair {
|
|
2
|
+
key: string;
|
|
3
|
+
value: any;
|
|
4
|
+
}
|
|
1
5
|
export declare function sleep(ms: number): Promise<any>;
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
6
|
+
export declare function reverse(str: string): string;
|
|
7
|
+
export declare function base64Encode(str: string): string;
|
|
8
|
+
export declare function base64Decode(str: string): string;
|
|
4
9
|
export declare function initDate(timeZone?: string): Date;
|
|
5
10
|
export declare function convertDateTimeZone(date: Date, timeZone: string): Date;
|
|
6
11
|
export declare function isDaylightSavingTime(timeZone?: string): boolean;
|
|
@@ -10,6 +15,7 @@ export declare function getCurrentDayInMonth(timeZone?: string): number;
|
|
|
10
15
|
export declare function getDaysInYear(timeZone?: string): 366 | 365;
|
|
11
16
|
export declare function getCurrentMonth(timeZone?: string): number;
|
|
12
17
|
export declare function getCurrentYear(timeZone?: string): number;
|
|
18
|
+
export declare function isDateString(value: any): boolean;
|
|
13
19
|
/**
|
|
14
20
|
* NOTE: `stopIdx` represents last character index of word
|
|
15
21
|
* ex: ABC -> `startIdx`: 0 `stopIdx`: 2
|
|
@@ -26,3 +32,5 @@ export interface QueryRegexMatch {
|
|
|
26
32
|
export declare function getQueryMatches(query: string, regex: RegExp): QueryRegexMatch[];
|
|
27
33
|
export declare function removeQueryMatches(query: string, matches: QueryRegexMatch[]): string;
|
|
28
34
|
export declare function replaceQueryMatches(query: string, matches: QueryRegexMatch[], replacement: string): string;
|
|
35
|
+
export declare function removeMarkdownIndicators(input: string): string;
|
|
36
|
+
export declare function removePrefixIndicators(input: string, prefixes: string[]): string;
|
package/dist/util.js
CHANGED
|
@@ -2,26 +2,14 @@
|
|
|
2
2
|
export async function sleep(ms) {
|
|
3
3
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
4
4
|
}
|
|
5
|
-
export function
|
|
6
|
-
|
|
7
|
-
// Make sure markdown indicator exists.
|
|
8
|
-
if (output.includes('```')) {
|
|
9
|
-
// Remove first markdown indicator.
|
|
10
|
-
output = output.substring(output.indexOf('```'));
|
|
11
|
-
output = output.substring(output.indexOf('\n'));
|
|
12
|
-
// First markdown indicator removed, now do the last.
|
|
13
|
-
output = output.substring(0, output.indexOf('```')).trim();
|
|
14
|
-
}
|
|
15
|
-
return output;
|
|
5
|
+
export function reverse(str) {
|
|
6
|
+
return str.split('').reverse().join('');
|
|
16
7
|
}
|
|
17
|
-
export function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return output;
|
|
8
|
+
export function base64Encode(str) {
|
|
9
|
+
return Buffer.from(str, 'utf-8').toString('base64');
|
|
10
|
+
}
|
|
11
|
+
export function base64Decode(str) {
|
|
12
|
+
return Buffer.from(str, 'base64').toString('utf-8');
|
|
25
13
|
}
|
|
26
14
|
// Dates --------------------------------------------------------------------------
|
|
27
15
|
export function initDate(timeZone) {
|
|
@@ -72,6 +60,41 @@ export function getCurrentYear(timeZone) {
|
|
|
72
60
|
let date = initDate(timeZone);
|
|
73
61
|
return date.getFullYear();
|
|
74
62
|
}
|
|
63
|
+
export function isDateString(value) {
|
|
64
|
+
if (typeof value !== 'string')
|
|
65
|
+
return false;
|
|
66
|
+
const str = value.trim();
|
|
67
|
+
/* To be considered a date string, the string:
|
|
68
|
+
- Must contain at least one digit
|
|
69
|
+
- Must include a common date separator (e.g. '-', '/', ':', '.', or 'T')
|
|
70
|
+
- Must not contain any letters other than 'T' or 'Z'
|
|
71
|
+
- Must successfully parse
|
|
72
|
+
|
|
73
|
+
NOTE: We are not worried about month/day names or AM/PM. If these exist,
|
|
74
|
+
the user has clearly elected to format the date in the query itself. */
|
|
75
|
+
if (/[^TZ0-9\s:./-]/i.test(str))
|
|
76
|
+
return false;
|
|
77
|
+
/* Handle some edge cases:
|
|
78
|
+
- If 2 separators, should be at least 6 total characters
|
|
79
|
+
- Every part separated by '-' or '/' must be 1, 2, or >=4 chars long */
|
|
80
|
+
if (str.includes('-')) {
|
|
81
|
+
const dashes = str.split('-');
|
|
82
|
+
if (dashes.length > 1 && str.length < 6) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (str.includes('/')) {
|
|
87
|
+
const slashes = str.split('/');
|
|
88
|
+
if (slashes.length > 1 && str.length < 6) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const sections = str.split(/[-/]+/).filter(Boolean);
|
|
93
|
+
if (sections.some(s => !(s.length === 1 || s.length === 2 || s.length >= 4))) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return !isNaN(Date.parse(str));
|
|
97
|
+
}
|
|
75
98
|
/**
|
|
76
99
|
* Will only return matches that **are not** contained in single quotes,
|
|
77
100
|
* double quotes, single line, or multiline comments.
|
|
@@ -210,3 +233,25 @@ export function replaceQueryMatches(query, matches, replacement) {
|
|
|
210
233
|
}
|
|
211
234
|
return adjQuery;
|
|
212
235
|
}
|
|
236
|
+
// LLMs --------------------------------------------------------------------------
|
|
237
|
+
export function removeMarkdownIndicators(input) {
|
|
238
|
+
let output = input;
|
|
239
|
+
// Make sure markdown indicator exists.
|
|
240
|
+
if (output.includes('```')) {
|
|
241
|
+
// Remove first markdown indicator.
|
|
242
|
+
output = output.substring(output.indexOf('```'));
|
|
243
|
+
output = output.substring(output.indexOf('\n'));
|
|
244
|
+
// First markdown indicator removed, now do the last.
|
|
245
|
+
output = output.substring(0, output.indexOf('```')).trim();
|
|
246
|
+
}
|
|
247
|
+
return output;
|
|
248
|
+
}
|
|
249
|
+
export function removePrefixIndicators(input, prefixes) {
|
|
250
|
+
let output = input;
|
|
251
|
+
for (const prefix of prefixes) {
|
|
252
|
+
if (output.includes(prefix)) {
|
|
253
|
+
output = output.substring(output.indexOf(prefix) + prefix.length);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return output;
|
|
257
|
+
}
|