@deephaven/jsapi-utils 0.43.0 → 0.44.1-beta.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/ConnectionUtils.js +39 -0
- package/dist/ConnectionUtils.js.map +1 -0
- package/dist/DateUtils.js +246 -0
- package/dist/DateUtils.js.map +1 -0
- package/dist/Formatter.js +144 -0
- package/dist/Formatter.js.map +1 -0
- package/dist/FormatterUtils.js +36 -0
- package/dist/FormatterUtils.js.map +1 -0
- package/dist/MessageUtils.js +124 -0
- package/dist/MessageUtils.js.map +1 -0
- package/dist/NoConsolesError.js +14 -0
- package/dist/NoConsolesError.js.map +1 -0
- package/dist/SessionUtils.js +101 -0
- package/dist/SessionUtils.js.map +1 -0
- package/dist/Settings.js +2 -0
- package/dist/Settings.js.map +1 -0
- package/dist/TableUtils.js +1367 -0
- package/dist/TableUtils.js.map +1 -0
- package/dist/ViewportDataUtils.js +136 -0
- package/dist/ViewportDataUtils.js.map +1 -0
- package/dist/formatters/BooleanColumnFormatter.js +20 -0
- package/dist/formatters/BooleanColumnFormatter.js.map +1 -0
- package/dist/formatters/CharColumnFormatter.js +11 -0
- package/dist/formatters/CharColumnFormatter.js.map +1 -0
- package/dist/formatters/DateTimeColumnFormatter.js +106 -0
- package/dist/formatters/DateTimeColumnFormatter.js.map +1 -0
- package/dist/formatters/DecimalColumnFormatter.js +115 -0
- package/dist/formatters/DecimalColumnFormatter.js.map +1 -0
- package/dist/formatters/DefaultColumnFormatter.js +10 -0
- package/dist/formatters/DefaultColumnFormatter.js.map +1 -0
- package/dist/formatters/IntegerColumnFormatter.js +112 -0
- package/dist/formatters/IntegerColumnFormatter.js.map +1 -0
- package/dist/formatters/StringColumnFormatter.js +10 -0
- package/dist/formatters/StringColumnFormatter.js.map +1 -0
- package/dist/formatters/TableColumnFormatter.js +59 -0
- package/dist/formatters/TableColumnFormatter.js.map +1 -0
- package/dist/formatters/index.js +10 -0
- package/dist/formatters/index.js.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TimeoutError } from '@deephaven/utils';
|
|
2
|
+
|
|
3
|
+
/** Default timeout for fetching a variable definition */
|
|
4
|
+
export var FETCH_TIMEOUT = 10000;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fetch the definition for a variable given a connection. Subscribes to field updates and triggers when the variable is found.
|
|
8
|
+
* @param connection Connection to get the variable from
|
|
9
|
+
* @param name Name of the definition to fetch
|
|
10
|
+
* @param timeout Timeout for the fetch
|
|
11
|
+
* @returns Promise the resolves to the variable definition if found, or rejects if there's an error or the timeout has exceeded
|
|
12
|
+
*/
|
|
13
|
+
export function fetchVariableDefinition(connection, name) {
|
|
14
|
+
var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : FETCH_TIMEOUT;
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
var removeListener;
|
|
17
|
+
var timeoutId = setTimeout(() => {
|
|
18
|
+
var _removeListener;
|
|
19
|
+
(_removeListener = removeListener) === null || _removeListener === void 0 ? void 0 : _removeListener();
|
|
20
|
+
reject(new TimeoutError("Variable ".concat(name, " not found")));
|
|
21
|
+
}, timeout);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the variable we're looking for is in the changes, and resolves the promise if it does
|
|
25
|
+
* @param changes Variables changes that have occurred
|
|
26
|
+
*/
|
|
27
|
+
function handleFieldUpdates(changes) {
|
|
28
|
+
var definition = changes.created.find(def => def.title === name);
|
|
29
|
+
if (definition != null) {
|
|
30
|
+
var _removeListener2;
|
|
31
|
+
clearTimeout(timeoutId);
|
|
32
|
+
(_removeListener2 = removeListener) === null || _removeListener2 === void 0 ? void 0 : _removeListener2();
|
|
33
|
+
resolve(definition);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
removeListener = connection.subscribeToFieldUpdates(handleFieldUpdates);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=ConnectionUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionUtils.js","names":["TimeoutError","FETCH_TIMEOUT","fetchVariableDefinition","connection","name","timeout","Promise","resolve","reject","removeListener","timeoutId","setTimeout","handleFieldUpdates","changes","definition","created","find","def","title","clearTimeout","subscribeToFieldUpdates"],"sources":["../src/ConnectionUtils.ts"],"sourcesContent":["import type {\n IdeConnection,\n VariableChanges,\n VariableDefinition,\n} from '@deephaven/jsapi-types';\nimport { TimeoutError } from '@deephaven/utils';\n\n/** Default timeout for fetching a variable definition */\nexport const FETCH_TIMEOUT = 10_000;\n\n/**\n * Fetch the definition for a variable given a connection. Subscribes to field updates and triggers when the variable is found.\n * @param connection Connection to get the variable from\n * @param name Name of the definition to fetch\n * @param timeout Timeout for the fetch\n * @returns Promise the resolves to the variable definition if found, or rejects if there's an error or the timeout has exceeded\n */\nexport function fetchVariableDefinition(\n connection: IdeConnection,\n name: string,\n timeout = FETCH_TIMEOUT\n): Promise<VariableDefinition> {\n return new Promise<VariableDefinition>((resolve, reject) => {\n let removeListener: () => void;\n\n const timeoutId = setTimeout(() => {\n removeListener?.();\n reject(new TimeoutError(`Variable ${name} not found`));\n }, timeout);\n\n /**\n * Checks if the variable we're looking for is in the changes, and resolves the promise if it does\n * @param changes Variables changes that have occurred\n */\n function handleFieldUpdates(changes: VariableChanges): void {\n const definition = changes.created.find(def => def.title === name);\n if (definition != null) {\n clearTimeout(timeoutId);\n removeListener?.();\n resolve(definition);\n }\n }\n\n removeListener = connection.subscribeToFieldUpdates(handleFieldUpdates);\n });\n}\n"],"mappings":"AAKA,SAASA,YAAY,QAAQ,kBAAkB;;AAE/C;AACA,OAAO,IAAMC,aAAa,GAAG,KAAM;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuB,CACrCC,UAAyB,EACzBC,IAAY,EAEiB;EAAA,IAD7BC,OAAO,uEAAGJ,aAAa;EAEvB,OAAO,IAAIK,OAAO,CAAqB,CAACC,OAAO,EAAEC,MAAM,KAAK;IAC1D,IAAIC,cAA0B;IAE9B,IAAMC,SAAS,GAAGC,UAAU,CAAC,MAAM;MAAA;MACjC,mBAAAF,cAAc,oDAAd,iBAAkB;MAClBD,MAAM,CAAC,IAAIR,YAAY,oBAAaI,IAAI,gBAAa,CAAC;IACxD,CAAC,EAAEC,OAAO,CAAC;;IAEX;AACJ;AACA;AACA;IACI,SAASO,kBAAkB,CAACC,OAAwB,EAAQ;MAC1D,IAAMC,UAAU,GAAGD,OAAO,CAACE,OAAO,CAACC,IAAI,CAACC,GAAG,IAAIA,GAAG,CAACC,KAAK,KAAKd,IAAI,CAAC;MAClE,IAAIU,UAAU,IAAI,IAAI,EAAE;QAAA;QACtBK,YAAY,CAACT,SAAS,CAAC;QACvB,oBAAAD,cAAc,qDAAd,kBAAkB;QAClBF,OAAO,CAACO,UAAU,CAAC;MACrB;IACF;IAEAL,cAAc,GAAGN,UAAU,CAACiB,uBAAuB,CAACR,kBAAkB,CAAC;EACzE,CAAC,CAAC;AACJ"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
3
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
4
|
+
export class DateUtils {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param timeZone The time zone to parse this time in. E.g. America/New_York
|
|
8
|
+
* @param year The year for the date
|
|
9
|
+
* @param month The month, starting at 0
|
|
10
|
+
* @param day The day, starting at 1
|
|
11
|
+
* @param hour The hours
|
|
12
|
+
* @param minute The minutes
|
|
13
|
+
* @param second The seconds
|
|
14
|
+
* @param ns The nanoseconds
|
|
15
|
+
*/
|
|
16
|
+
static makeDateWrapper(dh, timeZone, year) {
|
|
17
|
+
var month = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
18
|
+
var day = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
19
|
+
var hour = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
20
|
+
var minute = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
|
|
21
|
+
var second = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 0;
|
|
22
|
+
var ns = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : 0;
|
|
23
|
+
if (!timeZone) {
|
|
24
|
+
throw new Error('No timezone provided');
|
|
25
|
+
}
|
|
26
|
+
var yearString = "".concat(year).padStart(4, '0');
|
|
27
|
+
var monthString = "".concat(month + 1).padStart(2, '0');
|
|
28
|
+
var dayString = "".concat(day).padStart(2, '0');
|
|
29
|
+
var hourString = "".concat(hour).padStart(2, '0');
|
|
30
|
+
var minuteString = "".concat(minute).padStart(2, '0');
|
|
31
|
+
var secondString = "".concat(second).padStart(2, '0');
|
|
32
|
+
var nanoString = "".concat(ns).padStart(9, '0');
|
|
33
|
+
var dateString = "".concat(yearString, "-").concat(monthString, "-").concat(dayString, " ").concat(hourString, ":").concat(minuteString, ":").concat(secondString, ".").concat(nanoString);
|
|
34
|
+
return dh.i18n.DateTimeFormat.parse(DateUtils.FULL_DATE_FORMAT, dateString, dh.i18n.TimeZone.getTimeZone(timeZone));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Takes the string the user entered and returns the next nanos value
|
|
39
|
+
* @param nanoString The nano string to get the next one of
|
|
40
|
+
* @returns The value of the next nanos
|
|
41
|
+
*/
|
|
42
|
+
static getNextNanos(nanoString) {
|
|
43
|
+
var sigNanos = parseInt(nanoString, 10);
|
|
44
|
+
// Get the zeroes needed for padding before adding one so we handle overflow properly.
|
|
45
|
+
var zeros = '0'.repeat(9 - nanoString.length);
|
|
46
|
+
var nextNanoString = "".concat(sigNanos + 1).concat(zeros);
|
|
47
|
+
return parseInt(nextNanoString, 10);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param components The string components that were parsed from the original string
|
|
52
|
+
* @param values The values that were parsed from the components
|
|
53
|
+
* @param timeZone The time zone to parse the date in. E.g. America/New_York
|
|
54
|
+
* @returns Returns the DateWrapper for the next date, or null if a full date was passed in
|
|
55
|
+
*/
|
|
56
|
+
static getNextDate(dh, components, values, timeZone) {
|
|
57
|
+
var {
|
|
58
|
+
year,
|
|
59
|
+
month,
|
|
60
|
+
date,
|
|
61
|
+
hours,
|
|
62
|
+
minutes,
|
|
63
|
+
seconds,
|
|
64
|
+
nanos
|
|
65
|
+
} = values;
|
|
66
|
+
if (components.nanos != null) {
|
|
67
|
+
if (components.nanos.length === 9) {
|
|
68
|
+
// They want an exact match
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
nanos = DateUtils.getNextNanos(components.nanos);
|
|
72
|
+
if (nanos > 999999999) {
|
|
73
|
+
// There's an overflow, add it to the seconds manually
|
|
74
|
+
seconds += 1;
|
|
75
|
+
nanos = 0;
|
|
76
|
+
}
|
|
77
|
+
} else if (components.seconds != null) {
|
|
78
|
+
seconds += 1;
|
|
79
|
+
} else if (components.minutes != null) {
|
|
80
|
+
minutes += 1;
|
|
81
|
+
} else if (components.hours != null) {
|
|
82
|
+
hours += 1;
|
|
83
|
+
} else if (components.date != null) {
|
|
84
|
+
date += 1;
|
|
85
|
+
} else if (components.month != null) {
|
|
86
|
+
month += 1;
|
|
87
|
+
} else {
|
|
88
|
+
year += 1;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Use the JS date to handle overflow rather than doing our own logic
|
|
92
|
+
// Because handling leap years and stuff is a pain
|
|
93
|
+
// Still need to add nanos after, and the overflow from that is already added to seconds above
|
|
94
|
+
var jsDate = new Date(year, month, date, hours, minutes, seconds);
|
|
95
|
+
return DateUtils.makeDateWrapper(dh, timeZone, jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate(), jsDate.getHours(), jsDate.getMinutes(), jsDate.getSeconds(), nanos);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get the JS month value for the provided string.
|
|
100
|
+
* Matches digits or a month name (eg. '1', '01', 'jan', 'january' should all work)
|
|
101
|
+
* @param monthString The string to parse to a JS month value
|
|
102
|
+
* @returns number The JS month value, which starts at 0 for january, or NaN if nothing could be parsed
|
|
103
|
+
*/
|
|
104
|
+
static parseMonth(monthString) {
|
|
105
|
+
var month = parseInt(monthString, 10);
|
|
106
|
+
if (!Number.isNaN(month)) {
|
|
107
|
+
if (month >= 1 && month <= 12) {
|
|
108
|
+
return month - 1;
|
|
109
|
+
}
|
|
110
|
+
return NaN;
|
|
111
|
+
}
|
|
112
|
+
var cleanMonthString = monthString.trim().toLowerCase();
|
|
113
|
+
if (cleanMonthString.length >= 3) {
|
|
114
|
+
for (var i = 0; i < DateUtils.months.length; i += 1) {
|
|
115
|
+
if (DateUtils.months[i].startsWith(cleanMonthString)) {
|
|
116
|
+
return i;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return NaN;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Parse a date object out of the provided string segments.
|
|
125
|
+
* Also using `parseMonth` to get month names like Aug/August rather than
|
|
126
|
+
* simply doing `parseInt`.
|
|
127
|
+
* @param yearString The year part of the string
|
|
128
|
+
* @param monthString The month part of the string
|
|
129
|
+
* @param dayString The day part of the string
|
|
130
|
+
* @param hourString The hour part of the string
|
|
131
|
+
* @param minuteString The minute part of the string
|
|
132
|
+
* @param secondString The second part of the string
|
|
133
|
+
* @param nanoString The milli part of the string
|
|
134
|
+
*/
|
|
135
|
+
static parseDateValues(yearString, monthString, dayString, hourString, minuteString, secondString, nanoString) {
|
|
136
|
+
var year = parseInt(yearString, 10);
|
|
137
|
+
var month = monthString != null ? this.parseMonth(monthString) : 0;
|
|
138
|
+
var date = dayString != null ? parseInt(dayString, 10) : 1;
|
|
139
|
+
var hours = hourString != null ? parseInt(hourString, 10) : 0;
|
|
140
|
+
var minutes = minuteString != null ? parseInt(minuteString, 10) : 0;
|
|
141
|
+
var seconds = secondString != null ? parseInt(secondString, 10) : 0;
|
|
142
|
+
var nanos = nanoString != null ? parseInt(nanoString.padEnd(9, '0'), 10) : 0;
|
|
143
|
+
if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(date) || Number.isNaN(hours) || Number.isNaN(minutes) || Number.isNaN(seconds) || Number.isNaN(nanos)) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
year,
|
|
148
|
+
month,
|
|
149
|
+
date,
|
|
150
|
+
hours,
|
|
151
|
+
minutes,
|
|
152
|
+
seconds,
|
|
153
|
+
nanos
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Parse out a date time string into it's string components.
|
|
159
|
+
* Anything that is not captured in the string will be undefined.
|
|
160
|
+
*
|
|
161
|
+
* @param dateTimeString The date time string to parse
|
|
162
|
+
* @returns Containing the date time components
|
|
163
|
+
*/
|
|
164
|
+
static parseDateTimeString(dateTimeString) {
|
|
165
|
+
var regex = /\s*(\d{4})([-./]([\da-z]+))?([-./](\d{1,2}))?([tT\s](\d{2})([:](\d{2}))?([:](\d{2}))?([.](\d{1,9}))?)?(.*)/;
|
|
166
|
+
var result = regex.exec(dateTimeString);
|
|
167
|
+
if (result == null) {
|
|
168
|
+
throw new Error("Unexpected date string: ".concat(dateTimeString));
|
|
169
|
+
}
|
|
170
|
+
var [, year,, month,, date,, hours,, minutes,, seconds,, nanos, overflow] = result;
|
|
171
|
+
if (overflow != null && overflow.length > 0) {
|
|
172
|
+
throw new Error("Unexpected characters after date string '".concat(dateTimeString, "': ").concat(overflow));
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
year,
|
|
176
|
+
month,
|
|
177
|
+
date,
|
|
178
|
+
hours,
|
|
179
|
+
minutes,
|
|
180
|
+
seconds,
|
|
181
|
+
nanos
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Parses the date range provided from a string of text.
|
|
187
|
+
* @param text The string to parse the date from. Can be a keyword like "today", or in the format "2018-08-04"
|
|
188
|
+
* @param timeZone The time zone to parse this range in. E.g. America/New_York
|
|
189
|
+
* @returns A tuple with the start and end value/null for that date range, or both null
|
|
190
|
+
*/
|
|
191
|
+
static parseDateRange(dh, text, timeZone) {
|
|
192
|
+
var cleanText = text.trim().toLowerCase();
|
|
193
|
+
if (cleanText.length === 0) {
|
|
194
|
+
throw new Error('Cannot parse date range from empty string');
|
|
195
|
+
}
|
|
196
|
+
if (cleanText === 'null') {
|
|
197
|
+
return [null, null];
|
|
198
|
+
}
|
|
199
|
+
if (cleanText === 'today') {
|
|
200
|
+
var now = new Date(Date.now());
|
|
201
|
+
var _startDate = DateUtils.makeDateWrapper(dh, timeZone, now.getFullYear(), now.getMonth(), now.getDate());
|
|
202
|
+
var tomorrow = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
|
|
203
|
+
var _endDate = DateUtils.makeDateWrapper(dh, timeZone, tomorrow.getFullYear(), tomorrow.getMonth(), tomorrow.getDate());
|
|
204
|
+
return [_startDate, _endDate];
|
|
205
|
+
}
|
|
206
|
+
if (cleanText === 'yesterday') {
|
|
207
|
+
var _now = new Date(Date.now());
|
|
208
|
+
var yesterday = new Date(_now.getFullYear(), _now.getMonth(), _now.getDate() - 1);
|
|
209
|
+
var _startDate2 = DateUtils.makeDateWrapper(dh, timeZone, yesterday.getFullYear(), yesterday.getMonth(), yesterday.getDate());
|
|
210
|
+
var _endDate2 = DateUtils.makeDateWrapper(dh, timeZone, _now.getFullYear(), _now.getMonth(), _now.getDate());
|
|
211
|
+
return [_startDate2, _endDate2];
|
|
212
|
+
}
|
|
213
|
+
if (cleanText === 'now') {
|
|
214
|
+
var _now2 = new Date(Date.now());
|
|
215
|
+
var date = dh.DateWrapper.ofJsDate(_now2);
|
|
216
|
+
return [date, null];
|
|
217
|
+
}
|
|
218
|
+
var components = DateUtils.parseDateTimeString(cleanText);
|
|
219
|
+
if (components.year == null && components.month == null && components.date == null) {
|
|
220
|
+
throw new Error("Unable to extract year, month, or day ".concat(cleanText));
|
|
221
|
+
}
|
|
222
|
+
var values = DateUtils.parseDateValues(components.year, components.month, components.date, components.hours, components.minutes, components.seconds, components.nanos);
|
|
223
|
+
if (values == null) {
|
|
224
|
+
throw new Error("Unable to extract date values from ".concat(components));
|
|
225
|
+
}
|
|
226
|
+
var startDate = DateUtils.makeDateWrapper(dh, timeZone, values.year, values.month, values.date, values.hours, values.minutes, values.seconds, values.nanos);
|
|
227
|
+
var endDate = DateUtils.getNextDate(dh, components, values, timeZone);
|
|
228
|
+
return [startDate, endDate];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Gets the Js Date object from the provided DateWrapper.
|
|
233
|
+
* In unit test, DateWrapper is just a number provided in millis, so handles that case.
|
|
234
|
+
* @param dateWrapper The DateWrapper object, or time in millis
|
|
235
|
+
*/
|
|
236
|
+
static getJsDate(dateWrapper) {
|
|
237
|
+
if (typeof dateWrapper === 'number') {
|
|
238
|
+
return new Date(dateWrapper);
|
|
239
|
+
}
|
|
240
|
+
return dateWrapper.asDate();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
_defineProperty(DateUtils, "FULL_DATE_FORMAT", 'yyyy-MM-dd HH:mm:ss.SSSSSSSSS');
|
|
244
|
+
_defineProperty(DateUtils, "months", ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december']);
|
|
245
|
+
export default DateUtils;
|
|
246
|
+
//# sourceMappingURL=DateUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateUtils.js","names":["DateUtils","makeDateWrapper","dh","timeZone","year","month","day","hour","minute","second","ns","Error","yearString","padStart","monthString","dayString","hourString","minuteString","secondString","nanoString","dateString","i18n","DateTimeFormat","parse","FULL_DATE_FORMAT","TimeZone","getTimeZone","getNextNanos","sigNanos","parseInt","zeros","repeat","length","nextNanoString","getNextDate","components","values","date","hours","minutes","seconds","nanos","jsDate","Date","getFullYear","getMonth","getDate","getHours","getMinutes","getSeconds","parseMonth","Number","isNaN","NaN","cleanMonthString","trim","toLowerCase","i","months","startsWith","parseDateValues","padEnd","parseDateTimeString","dateTimeString","regex","result","exec","overflow","parseDateRange","text","cleanText","now","startDate","tomorrow","endDate","yesterday","DateWrapper","ofJsDate","getJsDate","dateWrapper","asDate"],"sources":["../src/DateUtils.ts"],"sourcesContent":["import type { DateWrapper, dh as DhType } from '@deephaven/jsapi-types';\n\ninterface DateParts<T> {\n year: T;\n month: T;\n date: T;\n hours: T;\n minutes: T;\n seconds: T;\n nanos: T;\n}\n\nexport class DateUtils {\n static FULL_DATE_FORMAT = 'yyyy-MM-dd HH:mm:ss.SSSSSSSSS';\n\n static months = [\n 'january',\n 'february',\n 'march',\n 'april',\n 'may',\n 'june',\n 'july',\n 'august',\n 'september',\n 'october',\n 'november',\n 'december',\n ];\n\n /**\n *\n * @param timeZone The time zone to parse this time in. E.g. America/New_York\n * @param year The year for the date\n * @param month The month, starting at 0\n * @param day The day, starting at 1\n * @param hour The hours\n * @param minute The minutes\n * @param second The seconds\n * @param ns The nanoseconds\n */\n static makeDateWrapper(\n dh: DhType,\n timeZone: string,\n year: number,\n month = 0,\n day = 1,\n hour = 0,\n minute = 0,\n second = 0,\n ns = 0\n ): DateWrapper {\n if (!timeZone) {\n throw new Error('No timezone provided');\n }\n const yearString = `${year}`.padStart(4, '0');\n const monthString = `${month + 1}`.padStart(2, '0');\n const dayString = `${day}`.padStart(2, '0');\n const hourString = `${hour}`.padStart(2, '0');\n const minuteString = `${minute}`.padStart(2, '0');\n const secondString = `${second}`.padStart(2, '0');\n const nanoString = `${ns}`.padStart(9, '0');\n\n const dateString = `${yearString}-${monthString}-${dayString} ${hourString}:${minuteString}:${secondString}.${nanoString}`;\n return dh.i18n.DateTimeFormat.parse(\n DateUtils.FULL_DATE_FORMAT,\n dateString,\n dh.i18n.TimeZone.getTimeZone(timeZone)\n );\n }\n\n /**\n * Takes the string the user entered and returns the next nanos value\n * @param nanoString The nano string to get the next one of\n * @returns The value of the next nanos\n */\n static getNextNanos(nanoString: string): number {\n const sigNanos = parseInt(nanoString, 10);\n // Get the zeroes needed for padding before adding one so we handle overflow properly.\n const zeros = '0'.repeat(9 - nanoString.length);\n const nextNanoString = `${sigNanos + 1}${zeros}`;\n return parseInt(nextNanoString, 10);\n }\n\n /**\n * @param components The string components that were parsed from the original string\n * @param values The values that were parsed from the components\n * @param timeZone The time zone to parse the date in. E.g. America/New_York\n * @returns Returns the DateWrapper for the next date, or null if a full date was passed in\n */\n static getNextDate(\n dh: DhType,\n components: DateParts<string>,\n values: DateParts<number>,\n timeZone: string\n ): DateWrapper | null {\n let { year, month, date, hours, minutes, seconds, nanos } = values;\n\n if (components.nanos != null) {\n if (components.nanos.length === 9) {\n // They want an exact match\n return null;\n }\n nanos = DateUtils.getNextNanos(components.nanos);\n if (nanos > 999999999) {\n // There's an overflow, add it to the seconds manually\n seconds += 1;\n nanos = 0;\n }\n } else if (components.seconds != null) {\n seconds += 1;\n } else if (components.minutes != null) {\n minutes += 1;\n } else if (components.hours != null) {\n hours += 1;\n } else if (components.date != null) {\n date += 1;\n } else if (components.month != null) {\n month += 1;\n } else {\n year += 1;\n }\n\n // Use the JS date to handle overflow rather than doing our own logic\n // Because handling leap years and stuff is a pain\n // Still need to add nanos after, and the overflow from that is already added to seconds above\n const jsDate = new Date(year, month, date, hours, minutes, seconds);\n return DateUtils.makeDateWrapper(\n dh,\n timeZone,\n jsDate.getFullYear(),\n jsDate.getMonth(),\n jsDate.getDate(),\n jsDate.getHours(),\n jsDate.getMinutes(),\n jsDate.getSeconds(),\n nanos\n );\n }\n\n /**\n * Get the JS month value for the provided string.\n * Matches digits or a month name (eg. '1', '01', 'jan', 'january' should all work)\n * @param monthString The string to parse to a JS month value\n * @returns number The JS month value, which starts at 0 for january, or NaN if nothing could be parsed\n */\n static parseMonth(monthString: string): number {\n const month = parseInt(monthString, 10);\n if (!Number.isNaN(month)) {\n if (month >= 1 && month <= 12) {\n return month - 1;\n }\n return NaN;\n }\n\n const cleanMonthString = monthString.trim().toLowerCase();\n if (cleanMonthString.length >= 3) {\n for (let i = 0; i < DateUtils.months.length; i += 1) {\n if (DateUtils.months[i].startsWith(cleanMonthString)) {\n return i;\n }\n }\n }\n\n return NaN;\n }\n\n /**\n * Parse a date object out of the provided string segments.\n * Also using `parseMonth` to get month names like Aug/August rather than\n * simply doing `parseInt`.\n * @param yearString The year part of the string\n * @param monthString The month part of the string\n * @param dayString The day part of the string\n * @param hourString The hour part of the string\n * @param minuteString The minute part of the string\n * @param secondString The second part of the string\n * @param nanoString The milli part of the string\n */\n static parseDateValues(\n yearString: string,\n monthString: string,\n dayString: string,\n hourString: string,\n minuteString: string,\n secondString: string,\n nanoString: string\n ): DateParts<number> | null {\n const year = parseInt(yearString, 10);\n const month = monthString != null ? this.parseMonth(monthString) : 0;\n const date = dayString != null ? parseInt(dayString, 10) : 1;\n const hours = hourString != null ? parseInt(hourString, 10) : 0;\n const minutes = minuteString != null ? parseInt(minuteString, 10) : 0;\n const seconds = secondString != null ? parseInt(secondString, 10) : 0;\n const nanos =\n nanoString != null ? parseInt(nanoString.padEnd(9, '0'), 10) : 0;\n if (\n Number.isNaN(year) ||\n Number.isNaN(month) ||\n Number.isNaN(date) ||\n Number.isNaN(hours) ||\n Number.isNaN(minutes) ||\n Number.isNaN(seconds) ||\n Number.isNaN(nanos)\n ) {\n return null;\n }\n\n return { year, month, date, hours, minutes, seconds, nanos };\n }\n\n /**\n * Parse out a date time string into it's string components.\n * Anything that is not captured in the string will be undefined.\n *\n * @param dateTimeString The date time string to parse\n * @returns Containing the date time components\n */\n static parseDateTimeString(dateTimeString: string): DateParts<string> {\n const regex = /\\s*(\\d{4})([-./]([\\da-z]+))?([-./](\\d{1,2}))?([tT\\s](\\d{2})([:](\\d{2}))?([:](\\d{2}))?([.](\\d{1,9}))?)?(.*)/;\n const result = regex.exec(dateTimeString);\n if (result == null) {\n throw new Error(`Unexpected date string: ${dateTimeString}`);\n }\n\n const [\n ,\n year,\n ,\n month,\n ,\n date,\n ,\n hours,\n ,\n minutes,\n ,\n seconds,\n ,\n nanos,\n overflow,\n ] = result;\n if (overflow != null && overflow.length > 0) {\n throw new Error(\n `Unexpected characters after date string '${dateTimeString}': ${overflow}`\n );\n }\n\n return { year, month, date, hours, minutes, seconds, nanos };\n }\n\n /**\n * Parses the date range provided from a string of text.\n * @param text The string to parse the date from. Can be a keyword like \"today\", or in the format \"2018-08-04\"\n * @param timeZone The time zone to parse this range in. E.g. America/New_York\n * @returns A tuple with the start and end value/null for that date range, or both null\n */\n static parseDateRange(\n dh: DhType,\n text: string,\n timeZone: string\n ): [DateWrapper, DateWrapper | null] | [null, null] {\n const cleanText = text.trim().toLowerCase();\n if (cleanText.length === 0) {\n throw new Error('Cannot parse date range from empty string');\n }\n\n if (cleanText === 'null') {\n return [null, null];\n }\n\n if (cleanText === 'today') {\n const now = new Date(Date.now());\n const startDate = DateUtils.makeDateWrapper(\n dh,\n timeZone,\n now.getFullYear(),\n now.getMonth(),\n now.getDate()\n );\n const tomorrow = new Date(\n now.getFullYear(),\n now.getMonth(),\n now.getDate() + 1\n );\n const endDate = DateUtils.makeDateWrapper(\n dh,\n timeZone,\n tomorrow.getFullYear(),\n tomorrow.getMonth(),\n tomorrow.getDate()\n );\n return [startDate, endDate];\n }\n\n if (cleanText === 'yesterday') {\n const now = new Date(Date.now());\n const yesterday = new Date(\n now.getFullYear(),\n now.getMonth(),\n now.getDate() - 1\n );\n const startDate = DateUtils.makeDateWrapper(\n dh,\n timeZone,\n yesterday.getFullYear(),\n yesterday.getMonth(),\n yesterday.getDate()\n );\n const endDate = DateUtils.makeDateWrapper(\n dh,\n timeZone,\n now.getFullYear(),\n now.getMonth(),\n now.getDate()\n );\n return [startDate, endDate];\n }\n\n if (cleanText === 'now') {\n const now = new Date(Date.now());\n const date = dh.DateWrapper.ofJsDate(now);\n return [date, null];\n }\n\n const components = DateUtils.parseDateTimeString(cleanText);\n if (\n components.year == null &&\n components.month == null &&\n components.date == null\n ) {\n throw new Error(`Unable to extract year, month, or day ${cleanText}`);\n }\n\n const values = DateUtils.parseDateValues(\n components.year,\n components.month,\n components.date,\n components.hours,\n components.minutes,\n components.seconds,\n components.nanos\n );\n\n if (values == null) {\n throw new Error(`Unable to extract date values from ${components}`);\n }\n\n const startDate = DateUtils.makeDateWrapper(\n dh,\n timeZone,\n values.year,\n values.month,\n values.date,\n values.hours,\n values.minutes,\n values.seconds,\n values.nanos\n );\n\n const endDate = DateUtils.getNextDate(dh, components, values, timeZone);\n return [startDate, endDate];\n }\n\n /**\n * Gets the Js Date object from the provided DateWrapper.\n * In unit test, DateWrapper is just a number provided in millis, so handles that case.\n * @param dateWrapper The DateWrapper object, or time in millis\n */\n static getJsDate(dateWrapper: DateWrapper | number): Date {\n if (typeof dateWrapper === 'number') {\n return new Date(dateWrapper);\n }\n return dateWrapper.asDate();\n }\n}\n\nexport default DateUtils;\n"],"mappings":";;;AAYA,OAAO,MAAMA,SAAS,CAAC;EAkBrB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,eAAe,CACpBC,EAAU,EACVC,QAAgB,EAChBC,IAAY,EAOC;IAAA,IANbC,KAAK,uEAAG,CAAC;I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AAU,EAAEC,MAAM,EAAEjC,QAAQ,CAAC;IACvE,OAAO,CAACqE,SAAS,EAAEE,OAAO,CAAC;EAC7B;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOI,SAAS,CAACC,WAAiC,EAAQ;IACxD,IAAI,OAAOA,WAAW,KAAK,QAAQ,EAAE;MACnC,OAAO,IAAIpC,IAAI,CAACoC,WAAW,CAAC;IAC9B;IACA,OAAOA,WAAW,CAACC,MAAM,EAAE;EAC7B;AACF;AAAC,gBA3WYhF,SAAS,sBACM,+BAA+B;AAAA,gBAD9CA,SAAS,YAGJ,CACd,SAAS,EACT,UAAU,EACV,OAAO,EACP,OAAO,EACP,KAAK,EACL,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,CACX;AA6VH,eAAeA,SAAS"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
3
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
4
|
+
import TableUtils from "./TableUtils.js";
|
|
5
|
+
import { BooleanColumnFormatter, CharColumnFormatter, DateTimeColumnFormatter, DecimalColumnFormatter, DefaultColumnFormatter, IntegerColumnFormatter, StringColumnFormatter } from "./formatters/index.js";
|
|
6
|
+
export class Formatter {
|
|
7
|
+
/**
|
|
8
|
+
* Converts FormattingRule[] to Map
|
|
9
|
+
* @param columnFormattingRules Array or column formatting rules
|
|
10
|
+
* @returns Map of columnName-to-format Maps indexed by normalized dataType
|
|
11
|
+
*/
|
|
12
|
+
static makeColumnFormatMap(columnFormattingRules) {
|
|
13
|
+
if (columnFormattingRules == null) {
|
|
14
|
+
return new Map();
|
|
15
|
+
}
|
|
16
|
+
return columnFormattingRules.reduce((map, next) => {
|
|
17
|
+
var dataType = TableUtils.getNormalizedType(next.columnType);
|
|
18
|
+
if (dataType === null) {
|
|
19
|
+
return map;
|
|
20
|
+
}
|
|
21
|
+
if (!map.has(dataType)) {
|
|
22
|
+
map.set(dataType, new Map());
|
|
23
|
+
}
|
|
24
|
+
var formatMap = map.get(dataType);
|
|
25
|
+
formatMap === null || formatMap === void 0 ? void 0 : formatMap.set(next.columnName, next.format);
|
|
26
|
+
return map;
|
|
27
|
+
}, new Map());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a column formatting rule
|
|
32
|
+
* @param columnType Normalized data type
|
|
33
|
+
* @param columnName Column name
|
|
34
|
+
* @param format Format object
|
|
35
|
+
*/
|
|
36
|
+
static makeColumnFormattingRule(columnType, columnName, format) {
|
|
37
|
+
return {
|
|
38
|
+
columnType,
|
|
39
|
+
columnName,
|
|
40
|
+
format
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param dh JSAPI instance
|
|
46
|
+
* @param columnFormattingRules Optional array of column formatting rules
|
|
47
|
+
* @param dateTimeOptions Optional object with DateTime configuration
|
|
48
|
+
* @param decimalFormatOptions Optional object with Decimal configuration
|
|
49
|
+
* @param integerFormatOptions Optional object with Integer configuration
|
|
50
|
+
* @param truncateNumbersWithPound Determine if numbers should be truncated w/ repeating # instead of ellipsis at the end
|
|
51
|
+
*/
|
|
52
|
+
constructor(dh) {
|
|
53
|
+
var columnFormattingRules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
54
|
+
var dateTimeOptions = arguments.length > 2 ? arguments[2] : undefined;
|
|
55
|
+
var decimalFormatOptions = arguments.length > 3 ? arguments[3] : undefined;
|
|
56
|
+
var integerFormatOptions = arguments.length > 4 ? arguments[4] : undefined;
|
|
57
|
+
var truncateNumbersWithPound = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
58
|
+
_defineProperty(this, "defaultColumnFormatter", void 0);
|
|
59
|
+
_defineProperty(this, "typeFormatterMap", void 0);
|
|
60
|
+
_defineProperty(this, "columnFormatMap", void 0);
|
|
61
|
+
_defineProperty(this, "truncateNumbersWithPound", void 0);
|
|
62
|
+
// Formatting order:
|
|
63
|
+
// - columnFormatMap[type][name]
|
|
64
|
+
// - typeFormatterMap[type]
|
|
65
|
+
// - defaultColumnFormatter
|
|
66
|
+
|
|
67
|
+
this.defaultColumnFormatter = new DefaultColumnFormatter();
|
|
68
|
+
|
|
69
|
+
// Default formatters by data type
|
|
70
|
+
this.typeFormatterMap = new Map([[TableUtils.dataType.BOOLEAN, new BooleanColumnFormatter()], [TableUtils.dataType.CHAR, new CharColumnFormatter()], [TableUtils.dataType.DATETIME, new DateTimeColumnFormatter(dh, dateTimeOptions)], [TableUtils.dataType.DECIMAL, new DecimalColumnFormatter(dh, decimalFormatOptions)], [TableUtils.dataType.INT, new IntegerColumnFormatter(dh, integerFormatOptions)], [TableUtils.dataType.STRING, new StringColumnFormatter()]]);
|
|
71
|
+
|
|
72
|
+
// Formats indexed by data type and column name
|
|
73
|
+
this.columnFormatMap = Formatter.makeColumnFormatMap(columnFormattingRules);
|
|
74
|
+
this.truncateNumbersWithPound = truncateNumbersWithPound;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Gets columnFormatMap indexed by name for a given column type, creates new Map entry if necessary
|
|
78
|
+
* @param columnType column type
|
|
79
|
+
* @param createIfNecessary create new entry if true
|
|
80
|
+
* @returns Map of format strings indexed by column name or undefined if it doesn't exist
|
|
81
|
+
*/
|
|
82
|
+
getColumnFormatMapForType(columnType) {
|
|
83
|
+
var createIfNecessary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
84
|
+
var dataType = TableUtils.getNormalizedType(columnType);
|
|
85
|
+
if (dataType === null) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
if (createIfNecessary && !this.columnFormatMap.has(dataType)) {
|
|
89
|
+
this.columnFormatMap.set(dataType, new Map());
|
|
90
|
+
}
|
|
91
|
+
return this.columnFormatMap.get(dataType);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets a column format object for a given column type and name
|
|
96
|
+
* @param columnType column type
|
|
97
|
+
* @param columnName column name
|
|
98
|
+
* @returns format object or null for Default
|
|
99
|
+
*/
|
|
100
|
+
getColumnFormat(columnType, columnName) {
|
|
101
|
+
var _columnFormatMap$get;
|
|
102
|
+
var columnFormatMap = this.getColumnFormatMapForType(columnType);
|
|
103
|
+
return (_columnFormatMap$get = columnFormatMap === null || columnFormatMap === void 0 ? void 0 : columnFormatMap.get(columnName)) !== null && _columnFormatMap$get !== void 0 ? _columnFormatMap$get : null;
|
|
104
|
+
}
|
|
105
|
+
getColumnTypeFormatter(columnType) {
|
|
106
|
+
var dataType = TableUtils.getNormalizedType(columnType);
|
|
107
|
+
var columnTypeFormatter = this.defaultColumnFormatter;
|
|
108
|
+
if (dataType) {
|
|
109
|
+
var _this$typeFormatterMa;
|
|
110
|
+
columnTypeFormatter = (_this$typeFormatterMa = this.typeFormatterMap.get(dataType)) !== null && _this$typeFormatterMa !== void 0 ? _this$typeFormatterMa : columnTypeFormatter;
|
|
111
|
+
}
|
|
112
|
+
return columnTypeFormatter;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Gets formatted string for a given value, column type and name
|
|
117
|
+
* @param value Value to format
|
|
118
|
+
* @param columnType Column type used to determine the formatting settings
|
|
119
|
+
* @param columnName Column name used to determine the formatting settings
|
|
120
|
+
* @param formatOverride Format object passed to the formatter in place of the format defined in columnFormatMap
|
|
121
|
+
*/
|
|
122
|
+
getFormattedString(value, columnType) {
|
|
123
|
+
var columnName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
124
|
+
var formatOverride = arguments.length > 3 ? arguments[3] : undefined;
|
|
125
|
+
if (value == null) {
|
|
126
|
+
return '';
|
|
127
|
+
}
|
|
128
|
+
var formatter = this.getColumnTypeFormatter(columnType);
|
|
129
|
+
var format = formatOverride || this.getColumnFormat(columnType, columnName);
|
|
130
|
+
return formatter.format(value, format !== null && format !== void 0 ? format : undefined);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Gets the timeZone name
|
|
135
|
+
* @returns The time zone name E.g. America/New_York
|
|
136
|
+
*/
|
|
137
|
+
get timeZone() {
|
|
138
|
+
var _formatter$dhTimeZone;
|
|
139
|
+
var formatter = this.typeFormatterMap.get(TableUtils.dataType.DATETIME);
|
|
140
|
+
return formatter === null || formatter === void 0 ? void 0 : (_formatter$dhTimeZone = formatter.dhTimeZone) === null || _formatter$dhTimeZone === void 0 ? void 0 : _formatter$dhTimeZone.id;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export default Formatter;
|
|
144
|
+
//# sourceMappingURL=Formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Formatter.js","names":["TableUtils","BooleanColumnFormatter","CharColumnFormatter","DateTimeColumnFormatter","DecimalColumnFormatter","DefaultColumnFormatter","IntegerColumnFormatter","StringColumnFormatter","Formatter","makeColumnFormatMap","columnFormattingRules","Map","reduce","map","next","dataType","getNormalizedType","columnType","has","set","formatMap","get","columnName","format","makeColumnFormattingRule","constructor","dh","dateTimeOptions","decimalFormatOptions","integerFormatOptions","truncateNumbersWithPound","defaultColumnFormatter","typeFormatterMap","BOOLEAN","CHAR","DATETIME","DECIMAL","INT","STRING","columnFormatMap","getColumnFormatMapForType","createIfNecessary","undefined","getColumnFormat","getColumnTypeFormatter","columnTypeFormatter","getFormattedString","value","formatOverride","formatter","timeZone","dhTimeZone","id"],"sources":["../src/Formatter.ts"],"sourcesContent":["import type { dh as DhType } from '@deephaven/jsapi-types';\nimport TableUtils, { DataType } from './TableUtils';\nimport {\n BooleanColumnFormatter,\n CharColumnFormatter,\n DateTimeColumnFormatter,\n DecimalColumnFormatter,\n DefaultColumnFormatter,\n IntegerColumnFormatter,\n StringColumnFormatter,\n TableColumnFormat,\n TableColumnFormatter,\n} from './formatters';\n\nexport type ColumnName = string;\n\nexport interface FormattingRule {\n columnType: string;\n columnName: ColumnName;\n format: TableColumnFormat;\n}\n\nexport class Formatter {\n /**\n * Converts FormattingRule[] to Map\n * @param columnFormattingRules Array or column formatting rules\n * @returns Map of columnName-to-format Maps indexed by normalized dataType\n */\n static makeColumnFormatMap(\n columnFormattingRules: FormattingRule[]\n ): Map<DataType, Map<ColumnName, TableColumnFormat>> {\n if (columnFormattingRules == null) {\n return new Map();\n }\n return columnFormattingRules.reduce((map, next) => {\n const dataType = TableUtils.getNormalizedType(next.columnType);\n if (dataType === null) {\n return map;\n }\n\n if (!map.has(dataType)) {\n map.set(dataType, new Map());\n }\n const formatMap = map.get(dataType);\n formatMap?.set(next.columnName, next.format);\n return map;\n }, new Map<DataType, Map<ColumnName, TableColumnFormat>>());\n }\n\n /**\n * Creates a column formatting rule\n * @param columnType Normalized data type\n * @param columnName Column name\n * @param format Format object\n */\n static makeColumnFormattingRule(\n columnType: DataType,\n columnName: ColumnName,\n format: TableColumnFormat\n ): FormattingRule {\n return {\n columnType,\n columnName,\n format,\n };\n }\n\n /**\n * @param dh JSAPI instance\n * @param columnFormattingRules Optional array of column formatting rules\n * @param dateTimeOptions Optional object with DateTime configuration\n * @param decimalFormatOptions Optional object with Decimal configuration\n * @param integerFormatOptions Optional object with Integer configuration\n * @param truncateNumbersWithPound Determine if numbers should be truncated w/ repeating # instead of ellipsis at the end\n */\n constructor(\n dh: DhType,\n columnFormattingRules: FormattingRule[] = [],\n dateTimeOptions?: ConstructorParameters<typeof DateTimeColumnFormatter>[1],\n decimalFormatOptions?: ConstructorParameters<\n typeof DecimalColumnFormatter\n >[1],\n integerFormatOptions?: ConstructorParameters<\n typeof IntegerColumnFormatter\n >[1],\n truncateNumbersWithPound = false\n ) {\n // Formatting order:\n // - columnFormatMap[type][name]\n // - typeFormatterMap[type]\n // - defaultColumnFormatter\n\n this.defaultColumnFormatter = new DefaultColumnFormatter();\n\n // Default formatters by data type\n this.typeFormatterMap = new Map<DataType, TableColumnFormatter>([\n [TableUtils.dataType.BOOLEAN, new BooleanColumnFormatter()],\n [TableUtils.dataType.CHAR, new CharColumnFormatter()],\n [\n TableUtils.dataType.DATETIME,\n new DateTimeColumnFormatter(dh, dateTimeOptions),\n ],\n [\n TableUtils.dataType.DECIMAL,\n new DecimalColumnFormatter(dh, decimalFormatOptions),\n ],\n [\n TableUtils.dataType.INT,\n new IntegerColumnFormatter(dh, integerFormatOptions),\n ],\n [TableUtils.dataType.STRING, new StringColumnFormatter()],\n ]);\n\n // Formats indexed by data type and column name\n this.columnFormatMap = Formatter.makeColumnFormatMap(columnFormattingRules);\n this.truncateNumbersWithPound = truncateNumbersWithPound;\n }\n\n defaultColumnFormatter: TableColumnFormatter;\n\n typeFormatterMap: Map<DataType, TableColumnFormatter>;\n\n columnFormatMap: Map<DataType, Map<string, TableColumnFormat>>;\n\n truncateNumbersWithPound: boolean;\n\n /**\n * Gets columnFormatMap indexed by name for a given column type, creates new Map entry if necessary\n * @param columnType column type\n * @param createIfNecessary create new entry if true\n * @returns Map of format strings indexed by column name or undefined if it doesn't exist\n */\n getColumnFormatMapForType(\n columnType: string,\n createIfNecessary = false\n ): Map<string, TableColumnFormat> | undefined {\n const dataType = TableUtils.getNormalizedType(columnType);\n if (dataType === null) {\n return undefined;\n }\n\n if (createIfNecessary && !this.columnFormatMap.has(dataType)) {\n this.columnFormatMap.set(dataType, new Map());\n }\n return this.columnFormatMap.get(dataType);\n }\n\n /**\n * Gets a column format object for a given column type and name\n * @param columnType column type\n * @param columnName column name\n * @returns format object or null for Default\n */\n getColumnFormat(\n columnType: string,\n columnName: ColumnName\n ): TableColumnFormat | null {\n const columnFormatMap = this.getColumnFormatMapForType(columnType);\n return columnFormatMap?.get(columnName) ?? null;\n }\n\n getColumnTypeFormatter(columnType: string): TableColumnFormatter {\n const dataType = TableUtils.getNormalizedType(columnType);\n let columnTypeFormatter = this.defaultColumnFormatter;\n if (dataType) {\n columnTypeFormatter =\n this.typeFormatterMap.get(dataType) ?? columnTypeFormatter;\n }\n return columnTypeFormatter;\n }\n\n /**\n * Gets formatted string for a given value, column type and name\n * @param value Value to format\n * @param columnType Column type used to determine the formatting settings\n * @param columnName Column name used to determine the formatting settings\n * @param formatOverride Format object passed to the formatter in place of the format defined in columnFormatMap\n */\n getFormattedString(\n value: unknown,\n columnType: string,\n columnName = '',\n formatOverride?: Partial<TableColumnFormat>\n ): string {\n if (value == null) {\n return '';\n }\n\n const formatter = this.getColumnTypeFormatter(columnType);\n const format =\n formatOverride || this.getColumnFormat(columnType, columnName);\n\n return formatter.format(value, format ?? undefined);\n }\n\n /**\n * Gets the timeZone name\n * @returns The time zone name E.g. America/New_York\n */\n get timeZone(): string {\n const formatter = this.typeFormatterMap.get(\n TableUtils.dataType.DATETIME\n ) as DateTimeColumnFormatter;\n return formatter?.dhTimeZone?.id;\n }\n}\n\nexport default Formatter;\n"],"mappings":";;;OACOA,UAAU;AAAA,SAEfC,sBAAsB,EACtBC,mBAAmB,EACnBC,uBAAuB,EACvBC,sBAAsB,EACtBC,sBAAsB,EACtBC,sBAAsB,EACtBC,qBAAqB;AAavB,OAAO,MAAMC,SAAS,CAAC;EACrB;AACF;AACA;AACA;AACA;EACE,OAAOC,mBAAmB,CACxBC,qBAAuC,EACY;IACnD,IAAIA,qBAAqB,IAAI,IAAI,EAAE;MACjC,OAAO,IAAIC,GAAG,EAAE;IAClB;IACA,OAAOD,qBAAqB,CAACE,MAAM,CAAC,CAACC,GAAG,EAAEC,IAAI,KAAK;MACjD,IAAMC,QAAQ,GAAGf,UAAU,C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I,IAAI;EACjD;EAEAsB,sBAAsB,CAAC3B,UAAkB,EAAwB;IAC/D,IAAMF,QAAQ,GAAGf,UAAU,CAACgB,iBAAiB,CAACC,UAAU,CAAC;IACzD,IAAI4B,mBAAmB,GAAG,IAAI,CAACd,sBAAsB;IACrD,IAAIhB,QAAQ,EAAE;MAAA;MACZ8B,mBAAmB,4BACjB,IAAI,CAACb,gBAAgB,CAACX,GAAG,CAACN,QAAQ,CAAC,yEAAI8B,mBAAmB;IAC9D;IACA,OAAOA,mBAAmB;EAC5B;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,kBAAkB,CAChBC,KAAc,EACd9B,UAAkB,EAGV;IAAA,IAFRK,UAAU,uEAAG,EAAE;IAAA,IACf0B,cAA2C;IAE3C,IAAID,KAAK,IAAI,IAAI,EAAE;MACjB,OAAO,EAAE;IACX;IAEA,IAAME,SAAS,GAAG,IAAI,CAACL,sBAAsB,CAAC3B,UAAU,CAAC;IACzD,IAAMM,MAAM,GACVyB,cAAc,IAAI,IAAI,CAACL,eAAe,CAAC1B,UAAU,EAAEK,UAAU,CAAC;IAEhE,OAAO2B,SAAS,CAAC1B,MAAM,CAACwB,KAAK,EAAExB,MAAM,aAANA,MAAM,cAANA,MAAM,GAAImB,SAAS,CAAC;EACrD;;EAEA;AACF;AACA;AACA;EACE,IAAIQ,QAAQ,GAAW;IAAA;IACrB,IAAMD,SAAS,GAAG,IAAI,CAACjB,gBAAgB,CAACX,GAAG,CACzCrB,UAAU,CAACe,QAAQ,CAACoB,QAAQ,CACF;IAC5B,OAAOc,SAAS,aAATA,SAAS,gDAATA,SAAS,CAAEE,UAAU,0DAArB,sBAAuBC,EAAE;EAClC;AACF;AAEA,eAAe5C,SAAS"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TableColumnFormatter } from "./formatters/index.js";
|
|
2
|
+
export function getColumnFormats(settings) {
|
|
3
|
+
if (settings && settings.formatter) {
|
|
4
|
+
var {
|
|
5
|
+
formatter
|
|
6
|
+
} = settings;
|
|
7
|
+
return formatter;
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
export function getDateTimeFormatterOptions(settings) {
|
|
12
|
+
return {
|
|
13
|
+
timeZone: settings === null || settings === void 0 ? void 0 : settings.timeZone,
|
|
14
|
+
defaultDateTimeFormatString: settings === null || settings === void 0 ? void 0 : settings.defaultDateTimeFormat,
|
|
15
|
+
showTimeZone: settings === null || settings === void 0 ? void 0 : settings.showTimeZone,
|
|
16
|
+
showTSeparator: settings === null || settings === void 0 ? void 0 : settings.showTSeparator
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Check if the formatter has a custom format defined for the column name and type
|
|
22
|
+
* @param formatter Formatter to check
|
|
23
|
+
* @param columnName Column name
|
|
24
|
+
* @param columnType Column type
|
|
25
|
+
* @returns True, if a custom format is defined
|
|
26
|
+
*/
|
|
27
|
+
export function isCustomColumnFormatDefined(formatter, columnName, columnType) {
|
|
28
|
+
var columnFormat = formatter.getColumnFormat(columnType, columnName);
|
|
29
|
+
return columnFormat != null && (columnFormat.type === TableColumnFormatter.TYPE_CONTEXT_PRESET || columnFormat.type === TableColumnFormatter.TYPE_CONTEXT_CUSTOM);
|
|
30
|
+
}
|
|
31
|
+
export default {
|
|
32
|
+
getColumnFormats,
|
|
33
|
+
getDateTimeFormatterOptions,
|
|
34
|
+
isCustomColumnFormatDefined
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=FormatterUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormatterUtils.js","names":["TableColumnFormatter","getColumnFormats","settings","formatter","undefined","getDateTimeFormatterOptions","timeZone","defaultDateTimeFormatString","defaultDateTimeFormat","showTimeZone","showTSeparator","isCustomColumnFormatDefined","columnName","columnType","columnFormat","getColumnFormat","type","TYPE_CONTEXT_PRESET","TYPE_CONTEXT_CUSTOM"],"sources":["../src/FormatterUtils.ts"],"sourcesContent":["import type { FormattingRule } from './Formatter';\nimport Formatter from './Formatter';\nimport { DateTimeColumnFormatter, TableColumnFormatter } from './formatters';\nimport { ColumnFormatSettings, DateTimeFormatSettings } from './Settings';\n\nexport function getColumnFormats(\n settings?: ColumnFormatSettings\n): FormattingRule[] | undefined {\n if (settings && settings.formatter) {\n const { formatter } = settings;\n return formatter;\n }\n return undefined;\n}\n\nexport function getDateTimeFormatterOptions(\n settings?: DateTimeFormatSettings | null\n): ConstructorParameters<typeof DateTimeColumnFormatter>[1] {\n return {\n timeZone: settings?.timeZone,\n defaultDateTimeFormatString: settings?.defaultDateTimeFormat,\n showTimeZone: settings?.showTimeZone,\n showTSeparator: settings?.showTSeparator,\n };\n}\n\n/**\n * Check if the formatter has a custom format defined for the column name and type\n * @param formatter Formatter to check\n * @param columnName Column name\n * @param columnType Column type\n * @returns True, if a custom format is defined\n */\nexport function isCustomColumnFormatDefined(\n formatter: Formatter,\n columnName: string,\n columnType: string\n): boolean {\n const columnFormat = formatter.getColumnFormat(columnType, columnName);\n return (\n columnFormat != null &&\n (columnFormat.type === TableColumnFormatter.TYPE_CONTEXT_PRESET ||\n columnFormat.type === TableColumnFormatter.TYPE_CONTEXT_CUSTOM)\n );\n}\n\nexport default {\n getColumnFormats,\n getDateTimeFormatterOptions,\n isCustomColumnFormatDefined,\n};\n"],"mappings":"SAEkCA,oBAAoB;AAGtD,OAAO,SAASC,gBAAgB,CAC9BC,QAA+B,EACD;EAC9B,IAAIA,QAAQ,IAAIA,QAAQ,CAACC,SAAS,EAAE;IAClC,IAAM;MAAEA;IAAU,CAAC,GAAGD,QAAQ;IAC9B,OAAOC,SAAS;EAClB;EACA,OAAOC,SAAS;AAClB;AAEA,OAAO,SAASC,2BAA2B,CACzCH,QAAwC,EACkB;EAC1D,OAAO;IACLI,QAAQ,EAAEJ,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEI,QAAQ;IAC5BC,2BAA2B,EAAEL,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEM,qBAAqB;IAC5DC,YAAY,EAAEP,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEO,YAAY;IACpCC,cAAc,EAAER,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEQ;EAC5B,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,2BAA2B,CACzCR,SAAoB,EACpBS,UAAkB,EAClBC,UAAkB,EACT;EACT,IAAMC,YAAY,GAAGX,SAAS,CAACY,eAAe,CAACF,UAAU,EAAED,UAAU,CAAC;EACtE,OACEE,YAAY,IAAI,IAAI,KACnBA,YAAY,CAACE,IAAI,KAAKhB,oBAAoB,CAACiB,mBAAmB,IAC7DH,YAAY,CAACE,IAAI,KAAKhB,oBAAoB,CAACkB,mBAAmB,CAAC;AAErE;AAEA,eAAe;EACbjB,gBAAgB;EAChBI,2BAA2B;EAC3BM;AACF,CAAC"}
|