@deephaven/jsapi-utils 1.22.1 → 1.22.2-alpha-pivot-builder.0730ba6.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/DateUtils.js +25 -13
- package/dist/DateUtils.js.map +1 -1
- package/dist/FormatterUtils.js +7 -10
- package/dist/FormatterUtils.js.map +1 -1
- package/dist/TableUtils.js +62 -68
- package/dist/TableUtils.js.map +1 -1
- package/dist/ViewportDataUtils.js +7 -9
- package/dist/ViewportDataUtils.js.map +1 -1
- package/dist/WorkerVariablesStore.d.ts +57 -0
- package/dist/WorkerVariablesStore.d.ts.map +1 -0
- package/dist/WorkerVariablesStore.js +231 -0
- package/dist/WorkerVariablesStore.js.map +1 -0
- package/dist/formatters/DateTimeColumnFormatter.js +9 -6
- package/dist/formatters/DateTimeColumnFormatter.js.map +1 -1
- package/dist/formatters/DecimalColumnFormatter.js +3 -3
- package/dist/formatters/DecimalColumnFormatter.js.map +1 -1
- package/dist/formatters/IntegerColumnFormatter.js +3 -3
- package/dist/formatters/IntegerColumnFormatter.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewportDataUtils.js","names":["clamp","Log","ITEM_KEY_PREFIX","log","module","createKeyedItemKey","index","concat","createOnTableUpdatedHandler","_ref","deserializeRow","bulkUpdate","onTableUpdated","event","columns","offset","rows","
|
|
1
|
+
{"version":3,"file":"ViewportDataUtils.js","names":["clamp","Log","ITEM_KEY_PREFIX","log","module","createKeyedItemKey","index","concat","createOnTableUpdatedHandler","_ref","deserializeRow","bulkUpdate","onTableUpdated","event","_event$detail","detail","columns","offset","rows","debug","updateKeyMap","Map","forEach","row","offsetInSnapshot","item","key","set","defaultRowDeserializer","reduce","result","col","name","get","generateEmptyKeyedItems","start","end","i","getSize","table","isClosed","size","widget","padFirstAndLastRow","firstRow","viewportSize","padding","tableSize","lastRow","min","max","first","last"],"sources":["../src/ViewportDataUtils.ts"],"sourcesContent":["import type { Key } from '@react-types/shared';\nimport clamp from 'lodash.clamp';\nimport type { dh } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport { type KeyedItem, type ValueOf } from '@deephaven/utils';\n\nexport const ITEM_KEY_PREFIX = 'DH_ITEM_KEY';\n\nexport type OnTableUpdatedEvent = dh.Event<{\n offset: number;\n columns: dh.Column[];\n rows: dh.Row[];\n}>;\n\nexport type RowDeserializer<T> = (row: dh.Row, columns: dh.Column[]) => T;\n\nconst log = Log.module('ViewportDataUtils');\n\n/**\n * Create a `KeyedItem.key` for a given index. The prefix is necessary to avoid\n * collisions with property values in the `item` property that may be used as\n * keys once the item is loaded and rendered.\n * @param index Index to create a key for.\n * @returns A unique key for the given index.\n */\nexport function createKeyedItemKey(index: number): string {\n return `${ITEM_KEY_PREFIX}_${index}`;\n}\n\n/**\n * Creates a handler function for a `dh.Table.EVENT_UPDATED` event. Rows that\n * get passed to the handler will be bulk updated in the given `viewportData`\n * object based on their derived item keys.\n * @param viewportData State object for managing a list of KeyedItem data.\n * @param deserializeRow Converts a DH Row to an item object.\n * @returns Handler function for a `dh.Table.EVENT_UPDATED` event.\n */\nexport function createOnTableUpdatedHandler<T>(\n { bulkUpdate }: { bulkUpdate: (itemMap: Map<Key, KeyedItem<T>>) => void },\n deserializeRow: RowDeserializer<T>\n): (event: OnTableUpdatedEvent) => void {\n /**\n * Handler for a `dh.Table.EVENT_UPDATED` event.\n */\n return function onTableUpdated(event: OnTableUpdatedEvent) {\n const { columns, offset, rows } = event.detail;\n\n log.debug('table updated', event.detail);\n\n const updateKeyMap = new Map<Key, KeyedItem<T>>();\n\n rows.forEach((row, offsetInSnapshot) => {\n const item = deserializeRow(row, columns);\n const key = createKeyedItemKey(offset + offsetInSnapshot);\n updateKeyMap.set(key, { key, item });\n });\n\n log.debug('update keys', updateKeyMap);\n\n bulkUpdate(updateKeyMap);\n };\n}\n\n/**\n * Maps a Row to a key / value object. Keys are mapped ver batim from column\n * names.\n * @param row Row to map to an item.\n * @param columns Columns to map.\n * @returns A key / value object for the row.\n */\nexport function defaultRowDeserializer<T>(\n row: dh.Row,\n columns: dh.Column[]\n): T {\n return columns.reduce((result, col) => {\n // eslint-disable-next-line no-param-reassign\n result[col.name as keyof T] = row.get(col) as ValueOf<T>;\n return result;\n }, {} as T);\n}\n\n/**\n * For windowing to work, the underlying list needs to maintain a KeyedItem for\n * each row in the backing table (even if these rows haven't been loaded yet).\n * This is needed internally by react-spectrum so it can calculate the content\n * area size. This generator can create a range of empty `KeyedItem` objects.\n * @param start The starting index to generate\n * @param end The ending index to generate\n */\nexport function* generateEmptyKeyedItems<T>(\n start: number,\n end: number\n): Generator<KeyedItem<T>, void, unknown> {\n // eslint-disable-next-line no-plusplus\n for (let i = start; i <= end; ++i) {\n yield { key: createKeyedItemKey(i) };\n }\n}\n\n/**\n * Check a Table to see if it is closed before checking its size property. This\n * is important because calling Table.size on a closed table throws an error. If\n * the table is null or closed, return zero. Otherwise, return the current size.\n * @param table The table to check for its size.\n * @returns The size of the table or zero if the table is null or closed.\n */\nexport function getSize(table?: dh.Table | dh.TreeTable | null): number {\n return table == null || isClosed(table) ? 0 : table.size;\n}\n\n/**\n * Check if a given widget is closed based on `isClosed` prop.\n * Tree tables and other widgets don't have an `isClosed` prop,\n * so will always return false.\n * @param table The widget to check if it is closed.\n */\nexport function isClosed(widget: unknown): boolean {\n if (\n widget != null &&\n typeof widget === 'object' &&\n 'isClosed' in widget &&\n typeof widget.isClosed === 'boolean'\n ) {\n return widget.isClosed;\n }\n\n return false;\n}\n\n/**\n * Determine the first and last row index for a viewport + extra leading and\n * trailing padding. Values will be \"clamped\" to stay within the table size.\n * @param firstRow Starting row index for the viewport.\n * @param viewportSize Size of the viewport.\n * @param padding Extra rows to add to the viewport. Will be used for leading\n * and trailing rows.\n * @param tableSize Total table size.\n * @returns Tuple containing indices for the first and last row.\n */\nexport function padFirstAndLastRow(\n firstRow: number,\n viewportSize: number,\n padding: number,\n tableSize: number\n): [number, number] {\n const lastRow = firstRow + viewportSize - 1;\n const [min, max] = [0, tableSize - 1];\n\n const first = clamp(firstRow - padding, min, max);\n const last = clamp(lastRow + padding, min, max);\n\n return [first, last];\n}\n"],"mappings":"AACA,OAAOA,KAAK,MAAM,cAAc;AAEhC,OAAOC,GAAG,MAAM,gBAAgB;AAGhC,OAAO,IAAMC,eAAe,GAAG,aAAa;AAU5C,IAAMC,GAAG,GAAGF,GAAG,CAACG,MAAM,CAAC,mBAAmB,CAAC;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAACC,KAAa,EAAU;EACxD,UAAAC,MAAA,CAAUL,eAAe,OAAAK,MAAA,CAAID,KAAK;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,2BAA2BA,CAAAC,IAAA,EAEzCC,cAAkC,EACI;EAAA,IAFpCC,UAAU,GAAAF,IAAA,CAAVE,UAAU;EAGZ;AACF;AACA;EACE,OAAO,SAASC,cAAcA,CAACC,KAA0B,EAAE;IACzD,IAAAC,aAAA,GAAkCD,KAAK,CAACE,MAAM;MAAtCC,OAAO,GAAAF,aAAA,CAAPE,OAAO;MAAEC,MAAM,GAAAH,aAAA,CAANG,MAAM;MAAEC,IAAI,GAAAJ,aAAA,CAAJI,IAAI;IAE7Bf,GAAG,CAACgB,KAAK,CAAC,eAAe,EAAEN,KAAK,CAACE,MAAM,CAAC;IAExC,IAAMK,YAAY,GAAG,IAAIC,GAAG,CAAoB,CAAC;IAEjDH,IAAI,CAACI,OAAO,CAAC,CAACC,GAAG,EAAEC,gBAAgB,KAAK;MACtC,IAAMC,IAAI,GAAGf,cAAc,CAACa,GAAG,EAAEP,OAAO,CAAC;MACzC,IAAMU,GAAG,GAAGrB,kBAAkB,CAACY,MAAM,GAAGO,gB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AAQ;EACxB;EAEA,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,kBAAkBA,CAChCC,QAAgB,EAChBC,YAAoB,EACpBC,OAAe,EACfC,SAAiB,EACC;EAClB,IAAMC,OAAO,GAAGJ,QAAQ,GAAGC,YAAY,GAAG,CAAC;EAC3C,IAAOI,GAAG,GAAU,CAAC;IAATC,GAAG,GAAQH,SAAS,GAAG,CAAC;EAEpC,IAAMI,KAAK,GAAGnD,KAAK,CAAC4C,QAAQ,GAAGE,OAAO,EAAEG,GAAG,EAAEC,GAAG,CAAC;EACjD,IAAME,IAAI,GAAGpD,KAAK,CAACgD,OAAO,GAAGF,OAAO,EAAEG,GAAG,EAAEC,GAAG,CAAC;EAE/C,OAAO,CAACC,KAAK,EAAEC,IAAI,CAAC;AACtB","ignoreList":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { dh } from '@deephaven/jsapi-types';
|
|
2
|
+
/**
|
|
3
|
+
* The current full list of variable definitions on a worker. Snapshot identity
|
|
4
|
+
* is stable until the next field-update delta is applied, so consumers using
|
|
5
|
+
* `useSyncExternalStore` will only re-render when the list actually changes.
|
|
6
|
+
*/
|
|
7
|
+
export type WorkerVariables = readonly dh.ide.VariableDefinition[];
|
|
8
|
+
/** Default key used when a host exposes a single connection (e.g. DHC). */
|
|
9
|
+
export declare const DEFAULT_WORKER_KEY = "default";
|
|
10
|
+
/**
|
|
11
|
+
* Derive a stable string key identifying the worker that owns the variable
|
|
12
|
+
* described by `descriptor`. Used by {@link WorkerVariablesStore} to dedup
|
|
13
|
+
* subscriptions across consumers that target the same worker.
|
|
14
|
+
*
|
|
15
|
+
* The base `dh.ide.VariableDescriptor` type only carries `type`/`id`/`name`,
|
|
16
|
+
* but DHE attaches routing fields (`querySerial`, `queryName`, `sessionId`).
|
|
17
|
+
* Those are read defensively so this helper works in DHC too — where every
|
|
18
|
+
* descriptor maps to {@link DEFAULT_WORKER_KEY}.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getWorkerKey(descriptor: Partial<dh.ide.VariableDescriptor> | Record<string, unknown> | null | undefined): string;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves the IDE connection that owns the worker identified by `key`. Return
|
|
23
|
+
* `null` if the worker is not currently reachable (e.g. query is stopped). The
|
|
24
|
+
* store will retry on the next subscribe or {@link WorkerVariablesStore.invalidate}.
|
|
25
|
+
*/
|
|
26
|
+
export type ResolveConnection = (key: string) => Promise<dh.IdeConnection | null>;
|
|
27
|
+
/**
|
|
28
|
+
* A ref-counted store of worker variable lists, keyed by worker. Wraps
|
|
29
|
+
* `IdeConnection.subscribeToFieldUpdates` so the underlying push subscription
|
|
30
|
+
* is opened once per worker regardless of the number of React consumers.
|
|
31
|
+
*/
|
|
32
|
+
export type WorkerVariablesStore = {
|
|
33
|
+
/** Current list for `key`, or `null` if not yet resolved. */
|
|
34
|
+
snapshot: (key: string) => WorkerVariables | null;
|
|
35
|
+
/**
|
|
36
|
+
* Subscribe to changes for `key`. The listener fires after each delta is
|
|
37
|
+
* applied. Returns an unsubscribe function; the underlying field-updates
|
|
38
|
+
* subscription is closed when the last listener for `key` unsubscribes.
|
|
39
|
+
*/
|
|
40
|
+
subscribe: (key: string, listener: () => void) => () => void;
|
|
41
|
+
/**
|
|
42
|
+
* Drop the cached list and subscription for `key`. Active subscribers will
|
|
43
|
+
* be notified (snapshot becomes `null`) and a fresh resolve+subscribe will
|
|
44
|
+
* kick off. Use when an external signal indicates the worker behind `key`
|
|
45
|
+
* has been replaced (e.g. DHE query restart).
|
|
46
|
+
*/
|
|
47
|
+
invalidate: (key: string) => void;
|
|
48
|
+
/** Tear down all entries. Call when the owning provider unmounts. */
|
|
49
|
+
destroy: () => void;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Create a {@link WorkerVariablesStore} backed by `resolveConnection`. The
|
|
53
|
+
* store is framework-free; pair it with a React provider/hook (see
|
|
54
|
+
* `@deephaven/jsapi-bootstrap`'s `WorkerVariablesContext`/`useWorkerVariables`).
|
|
55
|
+
*/
|
|
56
|
+
export declare function createWorkerVariablesStore(resolveConnection: ResolveConnection): WorkerVariablesStore;
|
|
57
|
+
//# sourceMappingURL=WorkerVariablesStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkerVariablesStore.d.ts","sourceRoot":"","sources":["../src/WorkerVariablesStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAKjD;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,EAAE,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC;AAEnE,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EACN,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,IAAI,GACJ,SAAS,GACZ,MAAM,CAaR;AAED;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,GAAG,EAAE,MAAM,KACR,OAAO,CAAC,EAAE,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;AAwBtC;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,6DAA6D;IAC7D,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,eAAe,GAAG,IAAI,CAAC;IAClD;;;;OAIG;IACH,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;IAC7D;;;;;OAKG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,qEAAqE;IACrE,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAUF;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,iBAAiB,EAAE,iBAAiB,GACnC,oBAAoB,CA6JtB"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
2
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
3
|
+
import Log from '@deephaven/log';
|
|
4
|
+
var log = Log.module('@deephaven/jsapi-utils.WorkerVariablesStore');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The current full list of variable definitions on a worker. Snapshot identity
|
|
8
|
+
* is stable until the next field-update delta is applied, so consumers using
|
|
9
|
+
* `useSyncExternalStore` will only re-render when the list actually changes.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Default key used when a host exposes a single connection (e.g. DHC). */
|
|
13
|
+
export var DEFAULT_WORKER_KEY = 'default';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Derive a stable string key identifying the worker that owns the variable
|
|
17
|
+
* described by `descriptor`. Used by {@link WorkerVariablesStore} to dedup
|
|
18
|
+
* subscriptions across consumers that target the same worker.
|
|
19
|
+
*
|
|
20
|
+
* The base `dh.ide.VariableDescriptor` type only carries `type`/`id`/`name`,
|
|
21
|
+
* but DHE attaches routing fields (`querySerial`, `queryName`, `sessionId`).
|
|
22
|
+
* Those are read defensively so this helper works in DHC too — where every
|
|
23
|
+
* descriptor maps to {@link DEFAULT_WORKER_KEY}.
|
|
24
|
+
*/
|
|
25
|
+
export function getWorkerKey(descriptor) {
|
|
26
|
+
if (descriptor == null) return DEFAULT_WORKER_KEY;
|
|
27
|
+
var d = descriptor;
|
|
28
|
+
if (typeof d.querySerial === 'string' && d.querySerial.length > 0) {
|
|
29
|
+
return "q:".concat(d.querySerial);
|
|
30
|
+
}
|
|
31
|
+
if (typeof d.queryName === 'string' && d.queryName.length > 0) {
|
|
32
|
+
return "qn:".concat(d.queryName);
|
|
33
|
+
}
|
|
34
|
+
if (typeof d.sessionId === 'string' && d.sessionId.length > 0) {
|
|
35
|
+
return "s:".concat(d.sessionId);
|
|
36
|
+
}
|
|
37
|
+
return DEFAULT_WORKER_KEY;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Resolves the IDE connection that owns the worker identified by `key`. Return
|
|
42
|
+
* `null` if the worker is not currently reachable (e.g. query is stopped). The
|
|
43
|
+
* store will retry on the next subscribe or {@link WorkerVariablesStore.invalidate}.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Identify a variable for delta matching. `dh.ide.VariableDefinition` declares
|
|
48
|
+
* a non-optional `id`, but at runtime instances are frequently created as just
|
|
49
|
+
* `{ name, type }` (e.g. field-update payloads and test fixtures), so `id` may
|
|
50
|
+
* be absent. Fall back to `name`, then `title`, and return `undefined` when no
|
|
51
|
+
* usable key exists so such items are never matched against a delta. Keys are
|
|
52
|
+
* namespaced by source field so an `id` of `"x"` never collides with a `name`
|
|
53
|
+
* of `"x"`.
|
|
54
|
+
*/
|
|
55
|
+
function getVariableKey(v) {
|
|
56
|
+
if (typeof v.id === 'string' && v.id.length > 0) {
|
|
57
|
+
return "id:".concat(v.id);
|
|
58
|
+
}
|
|
59
|
+
if (typeof v.name === 'string' && v.name.length > 0) {
|
|
60
|
+
return "name:".concat(v.name);
|
|
61
|
+
}
|
|
62
|
+
if (typeof v.title === 'string' && v.title.length > 0) {
|
|
63
|
+
return "title:".concat(v.title);
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A ref-counted store of worker variable lists, keyed by worker. Wraps
|
|
70
|
+
* `IdeConnection.subscribeToFieldUpdates` so the underlying push subscription
|
|
71
|
+
* is opened once per worker regardless of the number of React consumers.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Create a {@link WorkerVariablesStore} backed by `resolveConnection`. The
|
|
76
|
+
* store is framework-free; pair it with a React provider/hook (see
|
|
77
|
+
* `@deephaven/jsapi-bootstrap`'s `WorkerVariablesContext`/`useWorkerVariables`).
|
|
78
|
+
*/
|
|
79
|
+
export function createWorkerVariablesStore(resolveConnection) {
|
|
80
|
+
var entries = new Map();
|
|
81
|
+
|
|
82
|
+
/** Get the entry for `key`, creating an empty one if it doesn't exist. */
|
|
83
|
+
function getOrCreate(key) {
|
|
84
|
+
var entry = entries.get(key);
|
|
85
|
+
if (entry == null) {
|
|
86
|
+
entry = {
|
|
87
|
+
list: null,
|
|
88
|
+
listeners: new Set(),
|
|
89
|
+
unsubscribeFieldUpdates: null,
|
|
90
|
+
resolving: false,
|
|
91
|
+
generation: 0
|
|
92
|
+
};
|
|
93
|
+
entries.set(key, entry);
|
|
94
|
+
}
|
|
95
|
+
return entry;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Invoke every listener on `entry`, isolating listener errors. */
|
|
99
|
+
function notify(entry) {
|
|
100
|
+
entry.listeners.forEach(listener => {
|
|
101
|
+
try {
|
|
102
|
+
listener();
|
|
103
|
+
} catch (e) {
|
|
104
|
+
log.error('WorkerVariables listener threw', e);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Close the field-updates subscription for `key`, if any. */
|
|
110
|
+
function teardown(key) {
|
|
111
|
+
var entry = entries.get(key);
|
|
112
|
+
if ((entry === null || entry === void 0 ? void 0 : entry.unsubscribeFieldUpdates) != null) {
|
|
113
|
+
try {
|
|
114
|
+
entry.unsubscribeFieldUpdates();
|
|
115
|
+
} catch (e) {
|
|
116
|
+
log.warn('Error unsubscribing from field updates', e);
|
|
117
|
+
}
|
|
118
|
+
entry.unsubscribeFieldUpdates = null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Resolve the connection for `key` and open its field-updates subscription. */
|
|
123
|
+
function start(_x) {
|
|
124
|
+
return _start.apply(this, arguments);
|
|
125
|
+
}
|
|
126
|
+
/** Current list for `key`, or `null` if not yet resolved. */
|
|
127
|
+
function _start() {
|
|
128
|
+
_start = _asyncToGenerator(function* (key) {
|
|
129
|
+
var entry = entries.get(key);
|
|
130
|
+
if (entry == null || entry.resolving || entry.unsubscribeFieldUpdates != null) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
entry.resolving = true;
|
|
134
|
+
var gen = entry.generation;
|
|
135
|
+
try {
|
|
136
|
+
var connection = yield resolveConnection(key);
|
|
137
|
+
if (gen !== entry.generation || entry.listeners.size === 0 || entries.get(key) !== entry) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (connection == null) {
|
|
141
|
+
log.debug('No connection available for worker', key);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
// entry.list is replaced with a fresh array each delta so snapshot
|
|
145
|
+
// identity is stable for `useSyncExternalStore` consumers.
|
|
146
|
+
var unsubscribe = connection.subscribeToFieldUpdates(changes => {
|
|
147
|
+
var _entry$list;
|
|
148
|
+
if (gen !== entry.generation) return;
|
|
149
|
+
var removedKeys = new Set(changes.removed.map(getVariableKey).filter(k => k != null));
|
|
150
|
+
var updatedKeys = new Set(changes.updated.map(getVariableKey).filter(k => k != null));
|
|
151
|
+
// Keep keyless items (they can't be matched) and items whose key was
|
|
152
|
+
// not removed or updated; updated/created items are re-appended below.
|
|
153
|
+
var next = ((_entry$list = entry.list) !== null && _entry$list !== void 0 ? _entry$list : []).filter(v => {
|
|
154
|
+
var k = getVariableKey(v);
|
|
155
|
+
return k == null || !removedKeys.has(k) && !updatedKeys.has(k);
|
|
156
|
+
});
|
|
157
|
+
next.push(...changes.updated, ...changes.created);
|
|
158
|
+
entry.list = next;
|
|
159
|
+
notify(entry);
|
|
160
|
+
});
|
|
161
|
+
entry.unsubscribeFieldUpdates = unsubscribe;
|
|
162
|
+
} catch (e) {
|
|
163
|
+
log.error('Failed to resolve worker connection', key, e);
|
|
164
|
+
} finally {
|
|
165
|
+
entry.resolving = false;
|
|
166
|
+
// If `invalidate` ran while this resolve was in flight, it bumped
|
|
167
|
+
// `generation` but couldn't start a fresh resolve (this one was still
|
|
168
|
+
// marked `resolving`). The in-flight resolve above then bailed out as
|
|
169
|
+
// stale, so kick off another resolve now that `resolving` is cleared —
|
|
170
|
+
// otherwise the entry would be stuck with `list === null` and no
|
|
171
|
+
// subscription until the next `invalidate`/subscribe. `gen` now equals
|
|
172
|
+
// `entry.generation` when no invalidation occurred, so this never loops.
|
|
173
|
+
if (entries.get(key) === entry && gen !== entry.generation && entry.unsubscribeFieldUpdates == null && entry.listeners.size > 0) {
|
|
174
|
+
start(key).catch(() => undefined);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return _start.apply(this, arguments);
|
|
179
|
+
}
|
|
180
|
+
function snapshot(key) {
|
|
181
|
+
var _entries$get$list, _entries$get;
|
|
182
|
+
return (_entries$get$list = (_entries$get = entries.get(key)) === null || _entries$get === void 0 ? void 0 : _entries$get.list) !== null && _entries$get$list !== void 0 ? _entries$get$list : null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Register `listener` for `key`, starting the subscription on first listener. */
|
|
186
|
+
function subscribe(key, listener) {
|
|
187
|
+
var entry = getOrCreate(key);
|
|
188
|
+
entry.listeners.add(listener);
|
|
189
|
+
if (entry.unsubscribeFieldUpdates == null && !entry.resolving) {
|
|
190
|
+
// start handles its own errors; nothing to do on rejection
|
|
191
|
+
start(key).catch(() => undefined);
|
|
192
|
+
}
|
|
193
|
+
return () => {
|
|
194
|
+
entry.listeners.delete(listener);
|
|
195
|
+
if (entry.listeners.size === 0) {
|
|
196
|
+
teardown(key);
|
|
197
|
+
entry.list = null;
|
|
198
|
+
entries.delete(key);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Drop the cached list/subscription for `key` and re-resolve if observed. */
|
|
204
|
+
function invalidate(key) {
|
|
205
|
+
var entry = entries.get(key);
|
|
206
|
+
if (entry == null) return;
|
|
207
|
+
entry.generation += 1;
|
|
208
|
+
teardown(key);
|
|
209
|
+
entry.list = null;
|
|
210
|
+
notify(entry);
|
|
211
|
+
if (entry.listeners.size > 0) {
|
|
212
|
+
// start handles its own errors; nothing to do on rejection
|
|
213
|
+
start(key).catch(() => undefined);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Tear down every entry and clear all state. */
|
|
218
|
+
function destroy() {
|
|
219
|
+
Array.from(entries.keys()).forEach(key => {
|
|
220
|
+
teardown(key);
|
|
221
|
+
});
|
|
222
|
+
entries.clear();
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
snapshot,
|
|
226
|
+
subscribe,
|
|
227
|
+
invalidate,
|
|
228
|
+
destroy
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=WorkerVariablesStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkerVariablesStore.js","names":["Log","log","module","DEFAULT_WORKER_KEY","getWorkerKey","descriptor","d","querySerial","length","concat","queryName","sessionId","getVariableKey","v","id","name","title","undefined","createWorkerVariablesStore","resolveConnection","entries","Map","getOrCreate","key","entry","get","list","listeners","Set","unsubscribeFieldUpdates","resolving","generation","set","notify","forEach","listener","e","error","teardown","warn","start","_x","_start","apply","arguments","_asyncToGenerator","gen","connection","size","debug","unsubscribe","subscribeToFieldUpdates","changes","_entry$list","removedKeys","removed","map","filter","k","updatedKeys","updated","next","has","push","created","catch","snapshot","_entries$get$list","_entries$get","subscribe","add","delete","invalidate","destroy","Array","from","keys","clear"],"sources":["../src/WorkerVariablesStore.ts"],"sourcesContent":["import type { dh } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\n\nconst log = Log.module('@deephaven/jsapi-utils.WorkerVariablesStore');\n\n/**\n * The current full list of variable definitions on a worker. Snapshot identity\n * is stable until the next field-update delta is applied, so consumers using\n * `useSyncExternalStore` will only re-render when the list actually changes.\n */\nexport type WorkerVariables = readonly dh.ide.VariableDefinition[];\n\n/** Default key used when a host exposes a single connection (e.g. DHC). */\nexport const DEFAULT_WORKER_KEY = 'default';\n\n/**\n * Derive a stable string key identifying the worker that owns the variable\n * described by `descriptor`. Used by {@link WorkerVariablesStore} to dedup\n * subscriptions across consumers that target the same worker.\n *\n * The base `dh.ide.VariableDescriptor` type only carries `type`/`id`/`name`,\n * but DHE attaches routing fields (`querySerial`, `queryName`, `sessionId`).\n * Those are read defensively so this helper works in DHC too — where every\n * descriptor maps to {@link DEFAULT_WORKER_KEY}.\n */\nexport function getWorkerKey(\n descriptor:\n | Partial<dh.ide.VariableDescriptor>\n | Record<string, unknown>\n | null\n | undefined\n): string {\n if (descriptor == null) return DEFAULT_WORKER_KEY;\n const d = descriptor as Record<string, unknown>;\n if (typeof d.querySerial === 'string' && d.querySerial.length > 0) {\n return `q:${d.querySerial}`;\n }\n if (typeof d.queryName === 'string' && d.queryName.length > 0) {\n return `qn:${d.queryName}`;\n }\n if (typeof d.sessionId === 'string' && d.sessionId.length > 0) {\n return `s:${d.sessionId}`;\n }\n return DEFAULT_WORKER_KEY;\n}\n\n/**\n * Resolves the IDE connection that owns the worker identified by `key`. Return\n * `null` if the worker is not currently reachable (e.g. query is stopped). The\n * store will retry on the next subscribe or {@link WorkerVariablesStore.invalidate}.\n */\nexport type ResolveConnection = (\n key: string\n) => Promise<dh.IdeConnection | null>;\n\n/**\n * Identify a variable for delta matching. `dh.ide.VariableDefinition` declares\n * a non-optional `id`, but at runtime instances are frequently created as just\n * `{ name, type }` (e.g. field-update payloads and test fixtures), so `id` may\n * be absent. Fall back to `name`, then `title`, and return `undefined` when no\n * usable key exists so such items are never matched against a delta. Keys are\n * namespaced by source field so an `id` of `\"x\"` never collides with a `name`\n * of `\"x\"`.\n */\nfunction getVariableKey(v: dh.ide.VariableDefinition): string | undefined {\n if (typeof v.id === 'string' && v.id.length > 0) {\n return `id:${v.id}`;\n }\n if (typeof v.name === 'string' && v.name.length > 0) {\n return `name:${v.name}`;\n }\n if (typeof v.title === 'string' && v.title.length > 0) {\n return `title:${v.title}`;\n }\n return undefined;\n}\n\n/**\n * A ref-counted store of worker variable lists, keyed by worker. Wraps\n * `IdeConnection.subscribeToFieldUpdates` so the underlying push subscription\n * is opened once per worker regardless of the number of React consumers.\n */\nexport type WorkerVariablesStore = {\n /** Current list for `key`, or `null` if not yet resolved. */\n snapshot: (key: string) => WorkerVariables | null;\n /**\n * Subscribe to changes for `key`. The listener fires after each delta is\n * applied. Returns an unsubscribe function; the underlying field-updates\n * subscription is closed when the last listener for `key` unsubscribes.\n */\n subscribe: (key: string, listener: () => void) => () => void;\n /**\n * Drop the cached list and subscription for `key`. Active subscribers will\n * be notified (snapshot becomes `null`) and a fresh resolve+subscribe will\n * kick off. Use when an external signal indicates the worker behind `key`\n * has been replaced (e.g. DHE query restart).\n */\n invalidate: (key: string) => void;\n /** Tear down all entries. Call when the owning provider unmounts. */\n destroy: () => void;\n};\n\ntype Entry = {\n list: WorkerVariables | null;\n listeners: Set<() => void>;\n unsubscribeFieldUpdates: (() => void) | null;\n resolving: boolean;\n generation: number;\n};\n\n/**\n * Create a {@link WorkerVariablesStore} backed by `resolveConnection`. The\n * store is framework-free; pair it with a React provider/hook (see\n * `@deephaven/jsapi-bootstrap`'s `WorkerVariablesContext`/`useWorkerVariables`).\n */\nexport function createWorkerVariablesStore(\n resolveConnection: ResolveConnection\n): WorkerVariablesStore {\n const entries = new Map<string, Entry>();\n\n /** Get the entry for `key`, creating an empty one if it doesn't exist. */\n function getOrCreate(key: string): Entry {\n let entry = entries.get(key);\n if (entry == null) {\n entry = {\n list: null,\n listeners: new Set(),\n unsubscribeFieldUpdates: null,\n resolving: false,\n generation: 0,\n };\n entries.set(key, entry);\n }\n return entry;\n }\n\n /** Invoke every listener on `entry`, isolating listener errors. */\n function notify(entry: Entry): void {\n entry.listeners.forEach(listener => {\n try {\n listener();\n } catch (e) {\n log.error('WorkerVariables listener threw', e);\n }\n });\n }\n\n /** Close the field-updates subscription for `key`, if any. */\n function teardown(key: string): void {\n const entry = entries.get(key);\n if (entry?.unsubscribeFieldUpdates != null) {\n try {\n entry.unsubscribeFieldUpdates();\n } catch (e) {\n log.warn('Error unsubscribing from field updates', e);\n }\n entry.unsubscribeFieldUpdates = null;\n }\n }\n\n /** Resolve the connection for `key` and open its field-updates subscription. */\n async function start(key: string): Promise<void> {\n const entry = entries.get(key);\n if (\n entry == null ||\n entry.resolving ||\n entry.unsubscribeFieldUpdates != null\n ) {\n return;\n }\n entry.resolving = true;\n const gen = entry.generation;\n try {\n const connection = await resolveConnection(key);\n if (\n gen !== entry.generation ||\n entry.listeners.size === 0 ||\n entries.get(key) !== entry\n ) {\n return;\n }\n if (connection == null) {\n log.debug('No connection available for worker', key);\n return;\n }\n // entry.list is replaced with a fresh array each delta so snapshot\n // identity is stable for `useSyncExternalStore` consumers.\n const unsubscribe = connection.subscribeToFieldUpdates(changes => {\n if (gen !== entry.generation) return;\n const removedKeys = new Set(\n changes.removed.map(getVariableKey).filter(k => k != null)\n );\n const updatedKeys = new Set(\n changes.updated.map(getVariableKey).filter(k => k != null)\n );\n // Keep keyless items (they can't be matched) and items whose key was\n // not removed or updated; updated/created items are re-appended below.\n const next = (entry.list ?? []).filter(v => {\n const k = getVariableKey(v);\n return k == null || (!removedKeys.has(k) && !updatedKeys.has(k));\n });\n next.push(...changes.updated, ...changes.created);\n entry.list = next;\n notify(entry);\n });\n entry.unsubscribeFieldUpdates = unsubscribe;\n } catch (e) {\n log.error('Failed to resolve worker connection', key, e);\n } finally {\n entry.resolving = false;\n // If `invalidate` ran while this resolve was in flight, it bumped\n // `generation` but couldn't start a fresh resolve (this one was still\n // marked `resolving`). The in-flight resolve above then bailed out as\n // stale, so kick off another resolve now that `resolving` is cleared —\n // otherwise the entry would be stuck with `list === null` and no\n // subscription until the next `invalidate`/subscribe. `gen` now equals\n // `entry.generation` when no invalidation occurred, so this never loops.\n if (\n entries.get(key) === entry &&\n gen !== entry.generation &&\n entry.unsubscribeFieldUpdates == null &&\n entry.listeners.size > 0\n ) {\n start(key).catch(() => undefined);\n }\n }\n }\n\n /** Current list for `key`, or `null` if not yet resolved. */\n function snapshot(key: string): WorkerVariables | null {\n return entries.get(key)?.list ?? null;\n }\n\n /** Register `listener` for `key`, starting the subscription on first listener. */\n function subscribe(key: string, listener: () => void): () => void {\n const entry = getOrCreate(key);\n entry.listeners.add(listener);\n if (entry.unsubscribeFieldUpdates == null && !entry.resolving) {\n // start handles its own errors; nothing to do on rejection\n start(key).catch(() => undefined);\n }\n return () => {\n entry.listeners.delete(listener);\n if (entry.listeners.size === 0) {\n teardown(key);\n entry.list = null;\n entries.delete(key);\n }\n };\n }\n\n /** Drop the cached list/subscription for `key` and re-resolve if observed. */\n function invalidate(key: string): void {\n const entry = entries.get(key);\n if (entry == null) return;\n entry.generation += 1;\n teardown(key);\n entry.list = null;\n notify(entry);\n if (entry.listeners.size > 0) {\n // start handles its own errors; nothing to do on rejection\n start(key).catch(() => undefined);\n }\n }\n\n /** Tear down every entry and clear all state. */\n function destroy(): void {\n Array.from(entries.keys()).forEach(key => {\n teardown(key);\n });\n entries.clear();\n }\n\n return { snapshot, subscribe, invalidate, destroy };\n}\n"],"mappings":";;AACA,OAAOA,GAAG,MAAM,gBAAgB;AAEhC,IAAMC,GAAG,GAAGD,GAAG,CAACE,MAAM,CAAC,6CAA6C,CAAC;;AAErE;AACA;AACA;AACA;AACA;;AAGA;AACA,OAAO,IAAMC,kBAAkB,GAAG,SAAS;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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AAOA,CAAA,EAAS;IACvBC,KAAK,CAACC,IAAI,CAACvD,OAAO,CAACwD,IAAI,CAAC,CAAC,CAAC,CAAC1C,OAAO,CAACX,GAAG,IAAI;MACxCe,QAAQ,CAACf,GAAG,CAAC;IACf,CAAC,CAAC;IACFH,OAAO,CAACyD,KAAK,CAAC,CAAC;EACjB;EAEA,OAAO;IAAEX,QAAQ;IAAEG,SAAS;IAAEG,UAAU;IAAEC;EAAQ,CAAC;AACrD","ignoreList":[]}
|
|
@@ -61,12 +61,15 @@ export class DateTimeColumnFormatter extends TableColumnFormatter {
|
|
|
61
61
|
return [...formatStringMap.keys()];
|
|
62
62
|
}
|
|
63
63
|
constructor(dh) {
|
|
64
|
-
var {
|
|
65
|
-
timeZone
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
65
|
+
_ref$timeZone = _ref.timeZone,
|
|
66
|
+
timeZoneParam = _ref$timeZone === void 0 ? '' : _ref$timeZone,
|
|
67
|
+
_ref$showTimeZone = _ref.showTimeZone,
|
|
68
|
+
showTimeZone = _ref$showTimeZone === void 0 ? true : _ref$showTimeZone,
|
|
69
|
+
_ref$showTSeparator = _ref.showTSeparator,
|
|
70
|
+
showTSeparator = _ref$showTSeparator === void 0 ? false : _ref$showTSeparator,
|
|
71
|
+
_ref$defaultDateTimeF = _ref.defaultDateTimeFormatString,
|
|
72
|
+
defaultDateTimeFormatString = _ref$defaultDateTimeF === void 0 ? DateTimeColumnFormatter.DEFAULT_DATETIME_FORMAT_STRING : _ref$defaultDateTimeF;
|
|
70
73
|
super();
|
|
71
74
|
_defineProperty(this, "dh", void 0);
|
|
72
75
|
_defineProperty(this, "dhTimeZone", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimeColumnFormatter.js","names":["Log","TableColumnFormatter","log","module","DateTimeColumnFormatter","isValid","dh","format","formatString","i18n","DateTimeFormat","Date","e","makeFormat","label","type","arguments","length","undefined","TYPE_CONTEXT_PRESET","isSameFormat","formatA","formatB","makeGlobalFormatStringMap","showTimeZone","showTSeparator","separator","tz","Map","concat","getGlobalFormats","formatStringMap","keys","makeFormatStringMap","getFormats","constructor","timeZone","timeZoneParam","defaultDateTimeFormatString","DEFAULT_DATETIME_FORMAT_STRING","_defineProperty","DEFAULT_TIME_ZONE_ID","dhTimeZone","TimeZone","getTimeZone","error","getEffectiveFormatString","baseFormatString","_this$formatStringMap","get","value"],"sources":["../../src/formatters/DateTimeColumnFormatter.ts"],"sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport type { dh as DhType } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport TableColumnFormatter, {\n type TableColumnFormat,\n} from './TableColumnFormatter';\n\nconst log = Log.module('DateTimeColumnFormatter');\n\nexport type DateTimeColumnFormatterOptions = {\n // Time zone\n timeZone?: string;\n\n // Show time zone in DateTime values\n showTimeZone?: boolean;\n\n // Show 'T' separator in DateTime values\n showTSeparator?: boolean;\n\n // DateTime format to use if columnFormats for DateTime isn't set\n defaultDateTimeFormatString?: string;\n};\n\nexport class DateTimeColumnFormatter extends TableColumnFormatter<\n Date | DhType.DateWrapper | number\n> {\n /**\n * Validates format object\n * @param dh JSAPI instance\n * @param format Format object\n * @returns true for valid object\n */\n static isValid(\n dh: typeof DhType,\n format: Pick<TableColumnFormat, 'formatString'>\n ): boolean {\n if (format.formatString == null) {\n return false;\n }\n try {\n dh.i18n.DateTimeFormat.format(format.formatString, new Date());\n return true;\n } catch (e) {\n return false;\n }\n }\n\n static makeFormat(\n label: string,\n formatString: string,\n type = TableColumnFormatter.TYPE_CONTEXT_PRESET\n ): TableColumnFormat {\n return {\n label,\n formatString,\n type,\n };\n }\n\n /**\n * Check if the given formats match\n * @param formatA format object to check\n * @param formatB format object to check\n * @returns True if the formats match\n */\n static isSameFormat(\n formatA: TableColumnFormat | null,\n formatB: TableColumnFormat | null\n ): boolean {\n return (\n formatA === formatB ||\n (formatA !== null &&\n formatB !== null &&\n formatA.type === formatB.type &&\n formatA.formatString === formatB.formatString)\n );\n }\n\n static DEFAULT_DATETIME_FORMAT_STRING = 'yyyy-MM-dd HH:mm:ss.SSS';\n\n static DEFAULT_TIME_ZONE_ID = 'America/New_York';\n\n static makeGlobalFormatStringMap(\n showTimeZone: boolean,\n showTSeparator: boolean\n ): Map<string, string> {\n const separator = showTSeparator ? `'T'` : ' ';\n const tz = showTimeZone ? ' z' : '';\n return new Map([\n ['yyyy-MM-dd HH:mm:ss', `yyyy-MM-dd${separator}HH:mm:ss${tz}`],\n ['yyyy-MM-dd HH:mm:ss.SSS', `yyyy-MM-dd${separator}HH:mm:ss.SSS${tz}`],\n [\n 'yyyy-MM-dd HH:mm:ss.SSSSSSSSS',\n `yyyy-MM-dd${separator}HH:mm:ss.SSSSSSSSS${tz}`,\n ],\n ]);\n }\n\n static getGlobalFormats(\n showTimeZone: boolean,\n showTSeparator: boolean\n ): string[] {\n const formatStringMap = DateTimeColumnFormatter.makeGlobalFormatStringMap(\n showTimeZone,\n showTSeparator\n );\n return [...formatStringMap.keys()];\n }\n\n static makeFormatStringMap(\n showTimeZone?: boolean,\n showTSeparator?: boolean\n ): Map<string, string> {\n const separator =\n showTSeparator !== undefined && showTSeparator ? `'T'` : ' ';\n const tz = showTimeZone !== undefined && showTimeZone ? ' z' : '';\n return new Map([\n ['yyyy-MM-dd', `yyyy-MM-dd${tz}`],\n ['MM-dd-yyyy', `MM-dd-yyyy${tz}`],\n ['HH:mm:ss', `HH:mm:ss${tz}`],\n ['HH:mm:ss.SSS', `HH:mm:ss.SSS${tz}`],\n ['HH:mm:ss.SSSSSSSSS', `HH:mm:ss.SSSSSSSSS${tz}`],\n ['yyyy-MM-dd HH:mm:ss', `yyyy-MM-dd${separator}HH:mm:ss${tz}`],\n ['yyyy-MM-dd HH:mm:ss.SSS', `yyyy-MM-dd${separator}HH:mm:ss.SSS${tz}`],\n [\n 'yyyy-MM-dd HH:mm:ss.SSSSSSSSS',\n `yyyy-MM-dd${separator}HH:mm:ss.SSSSSSSSS${tz}`,\n ],\n ]);\n }\n\n static getFormats(\n showTimeZone?: boolean,\n showTSeparator?: boolean\n ): string[] {\n const formatStringMap = DateTimeColumnFormatter.makeFormatStringMap(\n showTimeZone,\n showTSeparator\n );\n return [...formatStringMap.keys()];\n }\n\n dh: typeof DhType;\n\n dhTimeZone: DhType.i18n.TimeZone;\n\n defaultDateTimeFormatString: string;\n\n showTimeZone: boolean;\n\n showTSeparator: boolean;\n\n formatStringMap: Map<string, string>;\n\n constructor(\n dh: typeof DhType,\n {\n timeZone: timeZoneParam = '',\n showTimeZone = true,\n showTSeparator = false,\n defaultDateTimeFormatString = DateTimeColumnFormatter.DEFAULT_DATETIME_FORMAT_STRING,\n }: DateTimeColumnFormatterOptions = {}\n ) {\n super();\n\n const timeZone =\n timeZoneParam || DateTimeColumnFormatter.DEFAULT_TIME_ZONE_ID;\n\n try {\n this.dhTimeZone = dh.i18n.TimeZone.getTimeZone(timeZone);\n } catch (e) {\n log.error('Unsupported time zone id', timeZone);\n this.dhTimeZone = dh.i18n.TimeZone.getTimeZone(\n DateTimeColumnFormatter.DEFAULT_TIME_ZONE_ID\n );\n }\n this.dh = dh;\n this.defaultDateTimeFormatString = defaultDateTimeFormatString;\n this.showTimeZone = showTimeZone;\n this.showTSeparator = showTSeparator;\n this.formatStringMap = DateTimeColumnFormatter.makeFormatStringMap(\n showTimeZone,\n showTSeparator\n );\n }\n\n getEffectiveFormatString(baseFormatString: string): string {\n return this.formatStringMap.get(baseFormatString) ?? baseFormatString;\n }\n\n format(\n value: Date | DhType.DateWrapper | number,\n format: Partial<TableColumnFormat> = {}\n ): string {\n const baseFormatString =\n format.formatString != null && format.formatString !== ''\n ? format.formatString\n : this.defaultDateTimeFormatString;\n const formatString = this.getEffectiveFormatString(baseFormatString);\n try {\n return this.dh.i18n.DateTimeFormat.format(\n formatString,\n value,\n this.dhTimeZone\n );\n } catch (e) {\n log.error('Invalid format arguments');\n }\n return '';\n }\n}\n\nexport default DateTimeColumnFormatter;\n"],"mappings":";;;AAAA;;AAEA,OAAOA,GAAG,MAAM,gBAAgB;AAAC,OAC1BC,oBAAoB;AAI3B,IAAMC,GAAG,GAAGF,GAAG,CAACG,MAAM,CAAC,yBAAyB,CAAC;AAgBjD,OAAO,MAAMC,uBAAuB,SAASH,oBAAoB,CAE/D;EACA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOI,OAAOA,CACZC,EAAiB,EACjBC,MAA+C,EACtC;IACT,IAAIA,MAAM,CAACC,YAAY,IAAI,IAAI,EAAE;MAC/B,OAAO,KAAK;IACd;IACA,IAAI;MACFF,EAAE,CAACG,IAAI,CAACC,cAAc,CAACH,MAAM,CAACA,MAAM,CAACC,YAAY,EAAE,IAAIG,IAAI,CAAC,CAAC,CAAC;MAC9D,OAAO,IAAI;IACb,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV,OAAO,KAAK;IACd;EACF;EAEA,OAAOC,UAAUA,CACfC,KAAa,EACbN,YAAoB,EAED;IAAA,IADnBO,IAAI,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGf,oBAAoB,CAACkB,mBAAmB;IAE/C,OAAO;MACLL,KAAK;MACLN,YAAY;MACZO;IACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOK,YAAYA,CACjBC,OAAiC,EACjCC,OAAiC,EACxB;IACT,OACED,OAAO,KAAKC,OAAO,IAClBD,OAAO,KAAK,IAAI,IACfC,OAAO,KAAK,IAAI,IAChBD,OAAO,CAACN,IAAI,KAAKO,OAAO,CAACP,IAAI,IAC7BM,OAAO,CAACb,YAAY,KAAKc,OAAO,CAACd,YAAa;EAEpD;EAMA,OAAOe,yBAAyBA,CAC9BC,YAAqB,EACrBC,cAAuB,EACF;IACrB,IAAMC,SAAS,GAAGD,cAAc,WAAW,GAAG;IAC9C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3B,uBAAuB,CAAC6B,mBAAmB,CAChET,YAAY,EACZC,cACF,CAAC;EACH;EAEAqB,wBAAwBA,CAACC,gBAAwB,EAAU;IAAA,IAAAC,qBAAA;IACzD,QAAAA,qBAAA,GAAO,IAAI,CAACjB,eAAe,CAACkB,GAAG,CAACF,gBAAgB,CAAC,cAAAC,qBAAA,cAAAA,qBAAA,GAAID,gBAAgB;EACvE;EAEAxC,MAAMA,CACJ2C,KAAyC,EAEjC;IAAA,IADR3C,MAAkC,GAAAS,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAEvC,IAAM+B,gBAAgB,GACpBxC,MAAM,CAACC,YAAY,IAAI,IAAI,IAAID,MAAM,CAACC,YAAY,KAAK,EAAE,GACrDD,MAAM,CAACC,YAAY,GACnB,IAAI,CAAC8B,2BAA2B;IACtC,IAAM9B,YAAY,GAAG,IAAI,CAACsC,wBAAwB,CAACC,gBAAgB,CAAC;IACpE,IAAI;MACF,OAAO,IAAI,CAACzC,EAAE,CAACG,IAAI,CAACC,cAAc,CAACH,MAAM,CACvCC,YAAY,EACZ0C,KAAK,EACL,IAAI,CAACR,UACP,CAAC;IACH,CAAC,CAAC,OAAO9B,CAAC,EAAE;MACVV,GAAG,CAAC2C,KAAK,CAAC,0BAA0B,CAAC;IACvC;IACA,OAAO,EAAE;EACX;AACF;AAACL,eAAA,CA3LYpC,uBAAuB,oCAuDM,yBAAyB;AAAAoC,eAAA,CAvDtDpC,uBAAuB,0BAyDJ,kBAAkB;AAoIlD,eAAeA,uBAAuB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"DateTimeColumnFormatter.js","names":["Log","TableColumnFormatter","log","module","DateTimeColumnFormatter","isValid","dh","format","formatString","i18n","DateTimeFormat","Date","e","makeFormat","label","type","arguments","length","undefined","TYPE_CONTEXT_PRESET","isSameFormat","formatA","formatB","makeGlobalFormatStringMap","showTimeZone","showTSeparator","separator","tz","Map","concat","getGlobalFormats","formatStringMap","keys","makeFormatStringMap","getFormats","constructor","_ref","_ref$timeZone","timeZone","timeZoneParam","_ref$showTimeZone","_ref$showTSeparator","_ref$defaultDateTimeF","defaultDateTimeFormatString","DEFAULT_DATETIME_FORMAT_STRING","_defineProperty","DEFAULT_TIME_ZONE_ID","dhTimeZone","TimeZone","getTimeZone","error","getEffectiveFormatString","baseFormatString","_this$formatStringMap","get","value"],"sources":["../../src/formatters/DateTimeColumnFormatter.ts"],"sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport type { dh as DhType } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport TableColumnFormatter, {\n type TableColumnFormat,\n} from './TableColumnFormatter';\n\nconst log = Log.module('DateTimeColumnFormatter');\n\nexport type DateTimeColumnFormatterOptions = {\n // Time zone\n timeZone?: string;\n\n // Show time zone in DateTime values\n showTimeZone?: boolean;\n\n // Show 'T' separator in DateTime values\n showTSeparator?: boolean;\n\n // DateTime format to use if columnFormats for DateTime isn't set\n defaultDateTimeFormatString?: string;\n};\n\nexport class DateTimeColumnFormatter extends TableColumnFormatter<\n Date | DhType.DateWrapper | number\n> {\n /**\n * Validates format object\n * @param dh JSAPI instance\n * @param format Format object\n * @returns true for valid object\n */\n static isValid(\n dh: typeof DhType,\n format: Pick<TableColumnFormat, 'formatString'>\n ): boolean {\n if (format.formatString == null) {\n return false;\n }\n try {\n dh.i18n.DateTimeFormat.format(format.formatString, new Date());\n return true;\n } catch (e) {\n return false;\n }\n }\n\n static makeFormat(\n label: string,\n formatString: string,\n type = TableColumnFormatter.TYPE_CONTEXT_PRESET\n ): TableColumnFormat {\n return {\n label,\n formatString,\n type,\n };\n }\n\n /**\n * Check if the given formats match\n * @param formatA format object to check\n * @param formatB format object to check\n * @returns True if the formats match\n */\n static isSameFormat(\n formatA: TableColumnFormat | null,\n formatB: TableColumnFormat | null\n ): boolean {\n return (\n formatA === formatB ||\n (formatA !== null &&\n formatB !== null &&\n formatA.type === formatB.type &&\n formatA.formatString === formatB.formatString)\n );\n }\n\n static DEFAULT_DATETIME_FORMAT_STRING = 'yyyy-MM-dd HH:mm:ss.SSS';\n\n static DEFAULT_TIME_ZONE_ID = 'America/New_York';\n\n static makeGlobalFormatStringMap(\n showTimeZone: boolean,\n showTSeparator: boolean\n ): Map<string, string> {\n const separator = showTSeparator ? `'T'` : ' ';\n const tz = showTimeZone ? ' z' : '';\n return new Map([\n ['yyyy-MM-dd HH:mm:ss', `yyyy-MM-dd${separator}HH:mm:ss${tz}`],\n ['yyyy-MM-dd HH:mm:ss.SSS', `yyyy-MM-dd${separator}HH:mm:ss.SSS${tz}`],\n [\n 'yyyy-MM-dd HH:mm:ss.SSSSSSSSS',\n `yyyy-MM-dd${separator}HH:mm:ss.SSSSSSSSS${tz}`,\n ],\n ]);\n }\n\n static getGlobalFormats(\n showTimeZone: boolean,\n showTSeparator: boolean\n ): string[] {\n const formatStringMap = DateTimeColumnFormatter.makeGlobalFormatStringMap(\n showTimeZone,\n showTSeparator\n );\n return [...formatStringMap.keys()];\n }\n\n static makeFormatStringMap(\n showTimeZone?: boolean,\n showTSeparator?: boolean\n ): Map<string, string> {\n const separator =\n showTSeparator !== undefined && showTSeparator ? `'T'` : ' ';\n const tz = showTimeZone !== undefined && showTimeZone ? ' z' : '';\n return new Map([\n ['yyyy-MM-dd', `yyyy-MM-dd${tz}`],\n ['MM-dd-yyyy', `MM-dd-yyyy${tz}`],\n ['HH:mm:ss', `HH:mm:ss${tz}`],\n ['HH:mm:ss.SSS', `HH:mm:ss.SSS${tz}`],\n ['HH:mm:ss.SSSSSSSSS', `HH:mm:ss.SSSSSSSSS${tz}`],\n ['yyyy-MM-dd HH:mm:ss', `yyyy-MM-dd${separator}HH:mm:ss${tz}`],\n ['yyyy-MM-dd HH:mm:ss.SSS', `yyyy-MM-dd${separator}HH:mm:ss.SSS${tz}`],\n [\n 'yyyy-MM-dd HH:mm:ss.SSSSSSSSS',\n `yyyy-MM-dd${separator}HH:mm:ss.SSSSSSSSS${tz}`,\n ],\n ]);\n }\n\n static getFormats(\n showTimeZone?: boolean,\n showTSeparator?: boolean\n ): string[] {\n const formatStringMap = DateTimeColumnFormatter.makeFormatStringMap(\n showTimeZone,\n showTSeparator\n );\n return [...formatStringMap.keys()];\n }\n\n dh: typeof DhType;\n\n dhTimeZone: DhType.i18n.TimeZone;\n\n defaultDateTimeFormatString: string;\n\n showTimeZone: boolean;\n\n showTSeparator: boolean;\n\n formatStringMap: Map<string, string>;\n\n constructor(\n dh: typeof DhType,\n {\n timeZone: timeZoneParam = '',\n showTimeZone = true,\n showTSeparator = false,\n defaultDateTimeFormatString = DateTimeColumnFormatter.DEFAULT_DATETIME_FORMAT_STRING,\n }: DateTimeColumnFormatterOptions = {}\n ) {\n super();\n\n const timeZone =\n timeZoneParam || DateTimeColumnFormatter.DEFAULT_TIME_ZONE_ID;\n\n try {\n this.dhTimeZone = dh.i18n.TimeZone.getTimeZone(timeZone);\n } catch (e) {\n log.error('Unsupported time zone id', timeZone);\n this.dhTimeZone = dh.i18n.TimeZone.getTimeZone(\n DateTimeColumnFormatter.DEFAULT_TIME_ZONE_ID\n );\n }\n this.dh = dh;\n this.defaultDateTimeFormatString = defaultDateTimeFormatString;\n this.showTimeZone = showTimeZone;\n this.showTSeparator = showTSeparator;\n this.formatStringMap = DateTimeColumnFormatter.makeFormatStringMap(\n showTimeZone,\n showTSeparator\n );\n }\n\n getEffectiveFormatString(baseFormatString: string): string {\n return this.formatStringMap.get(baseFormatString) ?? baseFormatString;\n }\n\n format(\n value: Date | DhType.DateWrapper | number,\n format: Partial<TableColumnFormat> = {}\n ): string {\n const baseFormatString =\n format.formatString != null && format.formatString !== ''\n ? format.formatString\n : this.defaultDateTimeFormatString;\n const formatString = this.getEffectiveFormatString(baseFormatString);\n try {\n return this.dh.i18n.DateTimeFormat.format(\n formatString,\n value,\n this.dhTimeZone\n );\n } catch (e) {\n log.error('Invalid format arguments');\n }\n return '';\n }\n}\n\nexport default DateTimeColumnFormatter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DecimalColumnFormatter extends TableColumnFormatter {
|
|
|
79
79
|
return formatA === formatB || formatA != null && formatB != null && formatA.type === formatB.type && formatA.formatString === formatB.formatString && formatA.multiplier === formatB.multiplier;
|
|
80
80
|
}
|
|
81
81
|
constructor(dh) {
|
|
82
|
-
var {
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
83
|
+
_ref$defaultFormatStr = _ref.defaultFormatString,
|
|
84
|
+
defaultFormatString = _ref$defaultFormatStr === void 0 ? DecimalColumnFormatter.DEFAULT_FORMAT_STRING : _ref$defaultFormatStr;
|
|
85
85
|
super();
|
|
86
86
|
_defineProperty(this, "defaultFormatString", void 0);
|
|
87
87
|
_defineProperty(this, "dh", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecimalColumnFormatter.js","names":["Log","TableColumnFormatter","log","module","DecimalColumnFormatter","isValid","dh","format","formatString","i18n","NumberFormat","e","makeFormat","label","type","arguments","length","undefined","TYPE_CONTEXT_PRESET","multiplier","makePresetFormat","makeCustomFormat","TYPE_CONTEXT_CUSTOM","isSameFormat","formatA","formatB","constructor","defaultFormatString","DEFAULT_FORMAT_STRING","_defineProperty","valueParam","value","error","_DecimalColumnFormatter"],"sources":["../../src/formatters/DecimalColumnFormatter.ts"],"sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport type { dh as DhType } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport TableColumnFormatter, {\n type TableColumnFormat,\n} from './TableColumnFormatter';\n\nconst log = Log.module('DecimalColumnFormatter');\n\nexport type DecimalColumnFormat = TableColumnFormat & {\n multiplier?: number | null;\n};\n\nexport type DecimalColumnFormatterOptions = {\n // Default format string to use. Defaults to DecimalColumnFormatter.DEFAULT_FORMAT_STRING\n defaultFormatString?: string;\n};\n\nexport class DecimalColumnFormatter extends TableColumnFormatter<number> {\n /**\n * Validates format object\n * @param dh JSAPI instance\n * @param format Format object\n * @returns true for valid object\n */\n static isValid(\n dh: typeof DhType,\n format: Pick<TableColumnFormat, 'formatString'>\n ): boolean {\n if (format.formatString == null) {\n return false;\n }\n try {\n dh.i18n.NumberFormat.format(format.formatString, 0);\n return true;\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Create a DecimalColumnFormat object with the parameters specified\n * @param label Label for the format\n * @param formatString Format string for the format\n * @param multiplier Optional multiplier for the formatter\n * @param type Type of format created\n * @returns DecimalColumnFormat object\n */\n static makeFormat(\n label: string,\n formatString: string,\n type = TableColumnFormatter.TYPE_CONTEXT_PRESET,\n multiplier?: number\n ): DecimalColumnFormat {\n return {\n label,\n type,\n formatString,\n multiplier,\n };\n }\n\n /**\n * Convenient function to create a DecimalFormatObject with Preset type set\n * @param label Label for this format object\n * @param formatString Format string to use\n * @param multiplier Multiplier to use\n * @returns DecimalColumnFormat object\n */\n static makePresetFormat(\n label: string,\n formatString = '',\n multiplier?: number\n ): DecimalColumnFormat {\n return DecimalColumnFormatter.makeFormat(\n label,\n formatString,\n TableColumnFormatter.TYPE_CONTEXT_PRESET,\n multiplier\n );\n }\n\n /**\n * Convenient function to create a DecimalFormatObject with a default 'Custom Format' label and Custom type\n * @param formatString Format string to use\n * @param multiplier Multiplier to use\n * @returns DecimalColumnFormat object\n */\n static makeCustomFormat(\n formatString = '',\n multiplier?: number\n ): DecimalColumnFormat {\n return DecimalColumnFormatter.makeFormat(\n 'Custom Format',\n formatString,\n TableColumnFormatter.TYPE_CONTEXT_CUSTOM,\n multiplier\n );\n }\n\n static DEFAULT_FORMAT_STRING = '###,##0.0000';\n\n static FORMAT_PERCENT = DecimalColumnFormatter.makePresetFormat(\n 'Percent',\n '##0.00%'\n );\n\n static FORMAT_BASIS_POINTS = DecimalColumnFormatter.makePresetFormat(\n 'Basis Points',\n '###,##0 bp',\n 10000\n );\n\n static FORMAT_THOUSANDS = DecimalColumnFormatter.makePresetFormat(\n 'Thousands',\n '##0.000 k',\n 0.001\n );\n\n static FORMAT_MILLIONS = DecimalColumnFormatter.makePresetFormat(\n 'Millions',\n '###,##0.000 mm',\n 0.000001\n );\n\n static FORMAT_SCIENTIFIC_NOTATION = DecimalColumnFormatter.makePresetFormat(\n 'Scientific Notation',\n '0.0000E0'\n );\n\n static FORMAT_ROUND = DecimalColumnFormatter.makePresetFormat(\n 'Round',\n '###,##0'\n );\n\n static FORMAT_ROUND_TWO_DECIMALS = DecimalColumnFormatter.makePresetFormat(\n '0.00',\n '###,##0.00'\n );\n\n static FORMAT_ROUND_FOUR_DECIMALS = DecimalColumnFormatter.makePresetFormat(\n '0.0000',\n '###,##0.0000'\n );\n\n /**\n * Check if the given formats match\n * @param formatA format object to check\n * @param formatB format object to check\n * @returns True if the formats match\n */\n static isSameFormat(\n formatA: DecimalColumnFormat | null,\n formatB: DecimalColumnFormat | null\n ): boolean {\n return (\n formatA === formatB ||\n (formatA != null &&\n formatB != null &&\n formatA.type === formatB.type &&\n formatA.formatString === formatB.formatString &&\n formatA.multiplier === formatB.multiplier)\n );\n }\n\n defaultFormatString: string;\n\n dh: typeof DhType;\n\n constructor(\n dh: typeof DhType,\n {\n defaultFormatString = DecimalColumnFormatter.DEFAULT_FORMAT_STRING,\n }: DecimalColumnFormatterOptions = {}\n ) {\n super();\n\n this.dh = dh;\n this.defaultFormatString = defaultFormatString;\n }\n\n /**\n * Format a value with the provided format object\n * @param valueParam Value to format\n * @param format Format object\n * @returns Formatted string\n */\n format(\n valueParam: number,\n format: Partial<DecimalColumnFormat> = {}\n ): string {\n const formatString =\n format.formatString != null && format.formatString !== ''\n ? format.formatString\n : this.defaultFormatString;\n const value =\n format.multiplier != null && format.multiplier !== 0\n ? valueParam * format.multiplier\n : valueParam;\n try {\n return this.dh.i18n.NumberFormat.format(formatString, value);\n } catch (e) {\n log.error('Invalid format arguments');\n }\n return '';\n }\n}\n\nexport default DecimalColumnFormatter;\n"],"mappings":";;;;AAAA;;AAEA,OAAOA,GAAG,MAAM,gBAAgB;AAAC,OAC1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BAAgBA,CAAA,EAGA;IAAA,IAFrBb,YAAY,GAAAO,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;IAAA,IACjBI,UAAmB,GAAAJ,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;IAEnB,OAAOb,sBAAsB,CAACQ,UAAU,CACtC,eAAe,EACfJ,YAAY,EACZP,oBAAoB,CAACqB,mBAAmB,EACxCH,UACF,CAAC;EACH;EA+CA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOI,YAAYA,CACjBC,OAAmC,EACnCC,OAAmC,EAC1B;IACT,OACED,OAAO,KAAKC,OAAO,IAClBD,OAAO,IAAI,IAAI,IACdC,OAAO,IAAI,IAAI,IACfD,OAAO,CAACV,IAAI,KAAKW,OAAO,CAACX,IAAI,IAC7BU,OAAO,CAAChB,YAAY,KAAKiB,OAAO,CAACjB,YAAY,IAC7CgB,OAAO,CAACL,UAAU,KAAKM,OAAO,CAACN,UAAW;EAEhD;EAMAO,WAAWA,CACTpB,EAAiB,EAIjB;IAAA,
|
|
1
|
+
{"version":3,"file":"DecimalColumnFormatter.js","names":["Log","TableColumnFormatter","log","module","DecimalColumnFormatter","isValid","dh","format","formatString","i18n","NumberFormat","e","makeFormat","label","type","arguments","length","undefined","TYPE_CONTEXT_PRESET","multiplier","makePresetFormat","makeCustomFormat","TYPE_CONTEXT_CUSTOM","isSameFormat","formatA","formatB","constructor","_ref","_ref$defaultFormatStr","defaultFormatString","DEFAULT_FORMAT_STRING","_defineProperty","valueParam","value","error","_DecimalColumnFormatter"],"sources":["../../src/formatters/DecimalColumnFormatter.ts"],"sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport type { dh as DhType } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport TableColumnFormatter, {\n type TableColumnFormat,\n} from './TableColumnFormatter';\n\nconst log = Log.module('DecimalColumnFormatter');\n\nexport type DecimalColumnFormat = TableColumnFormat & {\n multiplier?: number | null;\n};\n\nexport type DecimalColumnFormatterOptions = {\n // Default format string to use. Defaults to DecimalColumnFormatter.DEFAULT_FORMAT_STRING\n defaultFormatString?: string;\n};\n\nexport class DecimalColumnFormatter extends TableColumnFormatter<number> {\n /**\n * Validates format object\n * @param dh JSAPI instance\n * @param format Format object\n * @returns true for valid object\n */\n static isValid(\n dh: typeof DhType,\n format: Pick<TableColumnFormat, 'formatString'>\n ): boolean {\n if (format.formatString == null) {\n return false;\n }\n try {\n dh.i18n.NumberFormat.format(format.formatString, 0);\n return true;\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Create a DecimalColumnFormat object with the parameters specified\n * @param label Label for the format\n * @param formatString Format string for the format\n * @param multiplier Optional multiplier for the formatter\n * @param type Type of format created\n * @returns DecimalColumnFormat object\n */\n static makeFormat(\n label: string,\n formatString: string,\n type = TableColumnFormatter.TYPE_CONTEXT_PRESET,\n multiplier?: number\n ): DecimalColumnFormat {\n return {\n label,\n type,\n formatString,\n multiplier,\n };\n }\n\n /**\n * Convenient function to create a DecimalFormatObject with Preset type set\n * @param label Label for this format object\n * @param formatString Format string to use\n * @param multiplier Multiplier to use\n * @returns DecimalColumnFormat object\n */\n static makePresetFormat(\n label: string,\n formatString = '',\n multiplier?: number\n ): DecimalColumnFormat {\n return DecimalColumnFormatter.makeFormat(\n label,\n formatString,\n TableColumnFormatter.TYPE_CONTEXT_PRESET,\n multiplier\n );\n }\n\n /**\n * Convenient function to create a DecimalFormatObject with a default 'Custom Format' label and Custom type\n * @param formatString Format string to use\n * @param multiplier Multiplier to use\n * @returns DecimalColumnFormat object\n */\n static makeCustomFormat(\n formatString = '',\n multiplier?: number\n ): DecimalColumnFormat {\n return DecimalColumnFormatter.makeFormat(\n 'Custom Format',\n formatString,\n TableColumnFormatter.TYPE_CONTEXT_CUSTOM,\n multiplier\n );\n }\n\n static DEFAULT_FORMAT_STRING = '###,##0.0000';\n\n static FORMAT_PERCENT = DecimalColumnFormatter.makePresetFormat(\n 'Percent',\n '##0.00%'\n );\n\n static FORMAT_BASIS_POINTS = DecimalColumnFormatter.makePresetFormat(\n 'Basis Points',\n '###,##0 bp',\n 10000\n );\n\n static FORMAT_THOUSANDS = DecimalColumnFormatter.makePresetFormat(\n 'Thousands',\n '##0.000 k',\n 0.001\n );\n\n static FORMAT_MILLIONS = DecimalColumnFormatter.makePresetFormat(\n 'Millions',\n '###,##0.000 mm',\n 0.000001\n );\n\n static FORMAT_SCIENTIFIC_NOTATION = DecimalColumnFormatter.makePresetFormat(\n 'Scientific Notation',\n '0.0000E0'\n );\n\n static FORMAT_ROUND = DecimalColumnFormatter.makePresetFormat(\n 'Round',\n '###,##0'\n );\n\n static FORMAT_ROUND_TWO_DECIMALS = DecimalColumnFormatter.makePresetFormat(\n '0.00',\n '###,##0.00'\n );\n\n static FORMAT_ROUND_FOUR_DECIMALS = DecimalColumnFormatter.makePresetFormat(\n '0.0000',\n '###,##0.0000'\n );\n\n /**\n * Check if the given formats match\n * @param formatA format object to check\n * @param formatB format object to check\n * @returns True if the formats match\n */\n static isSameFormat(\n formatA: DecimalColumnFormat | null,\n formatB: DecimalColumnFormat | null\n ): boolean {\n return (\n formatA === formatB ||\n (formatA != null &&\n formatB != null &&\n formatA.type === formatB.type &&\n formatA.formatString === formatB.formatString &&\n formatA.multiplier === formatB.multiplier)\n );\n }\n\n defaultFormatString: string;\n\n dh: typeof DhType;\n\n constructor(\n dh: typeof DhType,\n {\n defaultFormatString = DecimalColumnFormatter.DEFAULT_FORMAT_STRING,\n }: DecimalColumnFormatterOptions = {}\n ) {\n super();\n\n this.dh = dh;\n this.defaultFormatString = defaultFormatString;\n }\n\n /**\n * Format a value with the provided format object\n * @param valueParam Value to format\n * @param format Format object\n * @returns Formatted string\n */\n format(\n valueParam: number,\n format: Partial<DecimalColumnFormat> = {}\n ): string {\n const formatString =\n format.formatString != null && format.formatString !== ''\n ? format.formatString\n : this.defaultFormatString;\n const value =\n format.multiplier != null && format.multiplier !== 0\n ? valueParam * format.multiplier\n : valueParam;\n try {\n return this.dh.i18n.NumberFormat.format(formatString, value);\n } catch (e) {\n log.error('Invalid format arguments');\n }\n return '';\n }\n}\n\nexport default DecimalColumnFormatter;\n"],"mappings":";;;;AAAA;;AAEA,OAAOA,GAAG,MAAM,gBAAgB;AAAC,OAC1BC,oBAAoB;AAI3B,IAAMC,GAAG,GAAGF,GAAG,CAACG,MAAM,CAAC,wBAAwB,CAAC;AAWhD,OAAO,MAAMC,sBAAsB,SAASH,oBAAoB,CAAS;EACvE;AACF;AACA;AACA;AACA;AACA;EACE,OAAOI,OAAOA,CACZC,EAAiB,EACjBC,MAA+C,EACtC;IACT,IAAIA,MAAM,CAACC,YAAY,IAAI,IAAI,EAAE;MAC/B,OAAO,KAAK;IACd;IACA,IAAI;MACFF,EAAE,CAACG,IAAI,CAACC,YAAY,CAACH,MAAM,CAACA,MAAM,CAACC,YAAY,EAAE,CAAC,CAAC;MACnD,OAAO,IAAI;IACb,CAAC,CAAC,OAAOG,CAAC,EAAE;MACV,OAAO,KAAK;IACd;EACF;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,UAAUA,CACfC,KAAa,EACbL,YAAoB,EAGC;IAAA,IAFrBM,IAAI,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGd,oBAAoB,CAACiB,mBAAmB;IAAA,IAC/CC,UAAmB,GAAAJ,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;IAEnB,OAAO;MACLJ,KAAK;MACLC,IAAI;MACJN,YAAY;MACZW;IACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,gBAAgBA,CACrBP,KAAa,EAGQ;IAAA,IAFrBL,YAAY,GAAAO,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;IAAA,IACjBI,UAAmB,GAAAJ,SAAA,CAAAC,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uBAAsB,CAACgB,gBAAgB,CACzE,qBAAqB,EACrB,UACF,CAAC;AAAAW,eAAA,CA9GU3B,sBAAsB,kBAgHXA,uBAAsB,CAACgB,gBAAgB,CAC3D,OAAO,EACP,SACF,CAAC;AAAAW,eAAA,CAnHU3B,sBAAsB,+BAqHEA,uBAAsB,CAACgB,gBAAgB,CACxE,MAAM,EACN,YACF,CAAC;AAAAW,eAAA,CAxHU3B,sBAAsB,gCA0HGA,uBAAsB,CAACgB,gBAAgB,CACzE,QAAQ,EACR,cACF,CAAC;AAiEH,eAAehB,sBAAsB","ignoreList":[]}
|
|
@@ -81,9 +81,9 @@ export class IntegerColumnFormatter extends TableColumnFormatter {
|
|
|
81
81
|
return formatA === formatB || formatA != null && formatB != null && formatA.type === formatB.type && formatA.formatString === formatB.formatString && formatA.multiplier === formatB.multiplier;
|
|
82
82
|
}
|
|
83
83
|
constructor(dh) {
|
|
84
|
-
var {
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
85
|
+
_ref$defaultFormatStr = _ref.defaultFormatString,
|
|
86
|
+
defaultFormatString = _ref$defaultFormatStr === void 0 ? IntegerColumnFormatter.DEFAULT_FORMAT_STRING : _ref$defaultFormatStr;
|
|
87
87
|
super();
|
|
88
88
|
_defineProperty(this, "dh", void 0);
|
|
89
89
|
_defineProperty(this, "defaultFormatString", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntegerColumnFormatter.js","names":["Log","TableColumnFormatter","log","module","IntegerColumnFormatter","isValid","dh","format","formatString","i18n","NumberFormat","e","makeFormat","label","type","arguments","length","undefined","TYPE_CONTEXT_PRESET","multiplier","makePresetFormat","makeCustomFormat","TYPE_CONTEXT_CUSTOM","isSameFormat","formatA","formatB","constructor","defaultFormatString","DEFAULT_FORMAT_STRING","_defineProperty","valueParam","value","error","_IntegerColumnFormatter"],"sources":["../../src/formatters/IntegerColumnFormatter.ts"],"sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport type { dh as DhType } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport TableColumnFormatter, {\n type TableColumnFormat,\n} from './TableColumnFormatter';\n\nconst log = Log.module('IntegerColumnFormatter');\n\nexport type IntegerColumnFormat = TableColumnFormat & {\n multiplier?: number | null;\n};\n\nexport type IntegerColumnFormatterOptions = {\n // Default format string to use. Defaults to IntegerColumnFormatter.DEFAULT_FORMAT_STRING\n defaultFormatString?: string;\n};\n\n/** Column formatter for integers/whole numbers */\nexport class IntegerColumnFormatter extends TableColumnFormatter<number> {\n /**\n * Validates format object\n * @param dh JSAPI instance\n * @param format Format object\n * @returns true for valid object\n */\n static isValid(\n dh: typeof DhType,\n format: Pick<TableColumnFormat, 'formatString'>\n ): boolean {\n if (format.formatString == null) {\n return false;\n }\n try {\n dh.i18n.NumberFormat.format(format.formatString, 0);\n return true;\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Create an IntegerColumnFormat object with the parameters specified\n * @param label Label for the format\n * @param formatString Format string for the format\n * @param multiplier Optional multiplier for the formatter\n * @param type Type of format created\n * @returns IntegerColumnFormat object\n */\n static makeFormat(\n label: string,\n formatString: string,\n type = TableColumnFormatter.TYPE_CONTEXT_PRESET,\n multiplier?: number\n ): IntegerColumnFormat {\n return {\n label,\n type,\n formatString,\n multiplier,\n };\n }\n\n /**\n * Convenient function to create a IntegerFormatObject with Preset type set\n * @param label Label for this format object\n * @param formatString Format string to use\n * @param multiplier Multiplier to use\n * @returns IntegerColumnFormat object\n */\n static makePresetFormat(\n label: string,\n formatString = '',\n multiplier?: number\n ): IntegerColumnFormat {\n return IntegerColumnFormatter.makeFormat(\n label,\n formatString,\n TableColumnFormatter.TYPE_CONTEXT_PRESET,\n multiplier\n );\n }\n\n /**\n * Convenient function to create a IntegerFormatObject with a default 'Custom Format' label and Custom type\n * @param formatString Format string to use\n * @param multiplier Multiplier to use\n * @returns IntegerColumnFormat object\n */\n static makeCustomFormat(\n formatString = '',\n multiplier?: number\n ): IntegerColumnFormat {\n return IntegerColumnFormatter.makeFormat(\n 'Custom Format',\n formatString,\n TableColumnFormatter.TYPE_CONTEXT_CUSTOM,\n multiplier\n );\n }\n\n /**\n * Check if the given formats match\n * @param formatA format object to check\n * @param formatB format object to check\n * @returns True if the formats match\n */\n static isSameFormat(\n formatA: IntegerColumnFormat | null,\n formatB: IntegerColumnFormat | null\n ): boolean {\n return (\n formatA === formatB ||\n (formatA != null &&\n formatB != null &&\n formatA.type === formatB.type &&\n formatA.formatString === formatB.formatString &&\n formatA.multiplier === formatB.multiplier)\n );\n }\n\n static DEFAULT_FORMAT_STRING = '###,##0';\n\n static FORMAT_THOUSANDS = IntegerColumnFormatter.makePresetFormat(\n 'Thousands',\n '##0.000 k',\n 0.001\n );\n\n static FORMAT_MILLIONS = IntegerColumnFormatter.makePresetFormat(\n 'Millions',\n '###,##0.000 mm',\n 0.000001\n );\n\n static FORMAT_SCIENTIFIC_NOTATION = IntegerColumnFormatter.makePresetFormat(\n 'Scientific Notation',\n '0.0000E0'\n );\n\n dh: typeof DhType;\n\n defaultFormatString: string;\n\n constructor(\n dh: typeof DhType,\n {\n defaultFormatString = IntegerColumnFormatter.DEFAULT_FORMAT_STRING,\n }: IntegerColumnFormatterOptions = {}\n ) {\n super();\n this.dh = dh;\n this.defaultFormatString = defaultFormatString;\n }\n\n /**\n * Format a value with the provided format object\n * @param valueParam Value to format\n * @param format Format object\n * @returns Formatted string\n */\n format(\n valueParam: number,\n format: Partial<IntegerColumnFormat> = {}\n ): string {\n const formatString =\n format.formatString != null && format.formatString !== ''\n ? format.formatString\n : this.defaultFormatString;\n const value =\n format.multiplier != null && format.multiplier !== 0\n ? valueParam * format.multiplier\n : valueParam;\n try {\n return this.dh.i18n.NumberFormat.format(formatString, value);\n } catch (e) {\n log.error('Invalid format arguments');\n }\n return '';\n }\n}\n\nexport default IntegerColumnFormatter;\n"],"mappings":";;;;AAAA;;AAEA,OAAOA,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ACF;AACA;AACA;AACA;AACA;EACE,OAAOE,gBAAgBA,CAAA,EAGA;IAAA,IAFrBb,YAAY,GAAAO,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;IAAA,IACjBI,UAAmB,GAAAJ,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;IAEnB,OAAOb,sBAAsB,CAACQ,UAAU,CACtC,eAAe,EACfJ,YAAY,EACZP,oBAAoB,CAACqB,mBAAmB,EACxCH,UACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOI,YAAYA,CACjBC,OAAmC,EACnCC,OAAmC,EAC1B;IACT,OACED,OAAO,KAAKC,OAAO,IAClBD,OAAO,IAAI,IAAI,IACdC,OAAO,IAAI,IAAI,IACfD,OAAO,CAACV,IAAI,KAAKW,OAAO,CAACX,IAAI,IAC7BU,OAAO,CAAChB,YAAY,KAAKiB,OAAO,CAACjB,YAAY,IAC7CgB,OAAO,CAACL,UAAU,KAAKM,OAAO,CAACN,UAAW;EAEhD;EAyBAO,WAAWA,CACTpB,EAAiB,EAIjB;IAAA,
|
|
1
|
+
{"version":3,"file":"IntegerColumnFormatter.js","names":["Log","TableColumnFormatter","log","module","IntegerColumnFormatter","isValid","dh","format","formatString","i18n","NumberFormat","e","makeFormat","label","type","arguments","length","undefined","TYPE_CONTEXT_PRESET","multiplier","makePresetFormat","makeCustomFormat","TYPE_CONTEXT_CUSTOM","isSameFormat","formatA","formatB","constructor","_ref","_ref$defaultFormatStr","defaultFormatString","DEFAULT_FORMAT_STRING","_defineProperty","valueParam","value","error","_IntegerColumnFormatter"],"sources":["../../src/formatters/IntegerColumnFormatter.ts"],"sourcesContent":["/* eslint class-methods-use-this: \"off\" */\nimport type { dh as DhType } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport TableColumnFormatter, {\n type TableColumnFormat,\n} from './TableColumnFormatter';\n\nconst log = Log.module('IntegerColumnFormatter');\n\nexport type IntegerColumnFormat = TableColumnFormat & {\n multiplier?: number | null;\n};\n\nexport type IntegerColumnFormatterOptions = {\n // Default format string to use. Defaults to IntegerColumnFormatter.DEFAULT_FORMAT_STRING\n defaultFormatString?: string;\n};\n\n/** Column formatter for integers/whole numbers */\nexport class IntegerColumnFormatter extends TableColumnFormatter<number> {\n /**\n * Validates format object\n * @param dh JSAPI instance\n * @param format Format object\n * @returns true for valid object\n */\n static isValid(\n dh: typeof DhType,\n format: Pick<TableColumnFormat, 'formatString'>\n ): boolean {\n if (format.formatString == null) {\n return false;\n }\n try {\n dh.i18n.NumberFormat.format(format.formatString, 0);\n return true;\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Create an IntegerColumnFormat object with the parameters specified\n * @param label Label for the format\n * @param formatString Format string for the format\n * @param multiplier Optional multiplier for the formatter\n * @param type Type of format created\n * @returns IntegerColumnFormat object\n */\n static makeFormat(\n label: string,\n formatString: string,\n type = TableColumnFormatter.TYPE_CONTEXT_PRESET,\n multiplier?: number\n ): IntegerColumnFormat {\n return {\n label,\n type,\n formatString,\n multiplier,\n };\n }\n\n /**\n * Convenient function to create a IntegerFormatObject with Preset type set\n * @param label Label for this format object\n * @param formatString Format string to use\n * @param multiplier Multiplier to use\n * @returns IntegerColumnFormat object\n */\n static makePresetFormat(\n label: string,\n formatString = '',\n multiplier?: number\n ): IntegerColumnFormat {\n return IntegerColumnFormatter.makeFormat(\n label,\n formatString,\n TableColumnFormatter.TYPE_CONTEXT_PRESET,\n multiplier\n );\n }\n\n /**\n * Convenient function to create a IntegerFormatObject with a default 'Custom Format' label and Custom type\n * @param formatString Format string to use\n * @param multiplier Multiplier to use\n * @returns IntegerColumnFormat object\n */\n static makeCustomFormat(\n formatString = '',\n multiplier?: number\n ): IntegerColumnFormat {\n return IntegerColumnFormatter.makeFormat(\n 'Custom Format',\n formatString,\n TableColumnFormatter.TYPE_CONTEXT_CUSTOM,\n multiplier\n );\n }\n\n /**\n * Check if the given formats match\n * @param formatA format object to check\n * @param formatB format object to check\n * @returns True if the formats match\n */\n static isSameFormat(\n formatA: IntegerColumnFormat | null,\n formatB: IntegerColumnFormat | null\n ): boolean {\n return (\n formatA === formatB ||\n (formatA != null &&\n formatB != null &&\n formatA.type === formatB.type &&\n formatA.formatString === formatB.formatString &&\n formatA.multiplier === formatB.multiplier)\n );\n }\n\n static DEFAULT_FORMAT_STRING = '###,##0';\n\n static FORMAT_THOUSANDS = IntegerColumnFormatter.makePresetFormat(\n 'Thousands',\n '##0.000 k',\n 0.001\n );\n\n static FORMAT_MILLIONS = IntegerColumnFormatter.makePresetFormat(\n 'Millions',\n '###,##0.000 mm',\n 0.000001\n );\n\n static FORMAT_SCIENTIFIC_NOTATION = IntegerColumnFormatter.makePresetFormat(\n 'Scientific Notation',\n '0.0000E0'\n );\n\n dh: typeof DhType;\n\n defaultFormatString: string;\n\n constructor(\n dh: typeof DhType,\n {\n defaultFormatString = IntegerColumnFormatter.DEFAULT_FORMAT_STRING,\n }: IntegerColumnFormatterOptions = {}\n ) {\n super();\n this.dh = dh;\n this.defaultFormatString = defaultFormatString;\n }\n\n /**\n * Format a value with the provided format object\n * @param valueParam Value to format\n * @param format Format object\n * @returns Formatted string\n */\n format(\n valueParam: number,\n format: Partial<IntegerColumnFormat> = {}\n ): string {\n const formatString =\n format.formatString != null && format.formatString !== ''\n ? format.formatString\n : this.defaultFormatString;\n const value =\n format.multiplier != null && format.multiplier !== 0\n ? valueParam * format.multiplier\n : valueParam;\n try {\n return this.dh.i18n.NumberFormat.format(formatString, value);\n } catch (e) {\n log.error('Invalid format arguments');\n }\n return '';\n }\n}\n\nexport default IntegerColumnFormatter;\n"],"mappings":";;;;AAAA;;AAEA,OAAOA,GAAG,MAAM,gBAAgB;AAAC,OAC1BC,oBAAoB;AAI3B,IAAMC,GAAG,GAAGF,GAAG,CAACG,MAAM,CAAC,wBAAwB,CAAC;AAWhD;AACA,OAAO,MAAMC,sBAAsB,SAASH,oBAAoB,CAAS;EACvE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B,IAAMI,KAAK,GACT1B,MAAM,CAACY,UAAU,IAAI,IAAI,IAAIZ,MAAM,CAACY,UAAU,KAAK,CAAC,GAChDa,UAAU,GAAGzB,MAAM,CAACY,UAAU,GAC9Ba,UAAU;IAChB,IAAI;MACF,OAAO,IAAI,CAAC1B,EAAE,CAACG,IAAI,CAACC,YAAY,CAACH,MAAM,CAACC,YAAY,EAAEyB,KAAK,CAAC;IAC9D,CAAC,CAAC,OAAOtB,CAAC,EAAE;MACVT,GAAG,CAACgC,KAAK,CAAC,0BAA0B,CAAC;IACvC;IACA,OAAO,EAAE;EACX;AACF;AAACC,uBAAA,GAjKY/B,sBAAsB;AAAA2B,eAAA,CAAtB3B,sBAAsB,2BAsGF,SAAS;AAAA2B,eAAA,CAtG7B3B,sBAAsB,sBAwGPA,uBAAsB,CAACgB,gBAAgB,CAC/D,WAAW,EACX,WAAW,EACX,KACF,CAAC;AAAAW,eAAA,CA5GU3B,sBAAsB,qBA8GRA,uBAAsB,CAACgB,gBAAgB,CAC9D,UAAU,EACV,gBAAgB,EAChB,QACF,CAAC;AAAAW,eAAA,CAlHU3B,sBAAsB,gCAoHGA,uBAAsB,CAACgB,gBAAgB,CACzE,qBAAqB,EACrB,UACF,CAAC;AA4CH,eAAehB,sBAAsB","ignoreList":[]}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["default","FormatterUtils"],"sources":["../src/index.ts"],"sourcesContent":["export * from './ConnectionUtils';\nexport * from './formatters';\nexport * from './DateUtils';\nexport * from './FilterUtils';\nexport * from './Formatter';\nexport { default as FormatterUtils } from './FormatterUtils';\nexport * from './FormatterUtils';\nexport * from './MessageUtils';\nexport * from './NewTableColumnTypes';\nexport * from './NoConsolesError';\nexport * from './SessionUtils';\nexport * from './Settings';\nexport * from './TableUtils';\nexport * from './ViewportDataUtils';\n"],"mappings":";;;;;SAKSA,OAAO,IAAIC,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","FormatterUtils"],"sources":["../src/index.ts"],"sourcesContent":["export * from './ConnectionUtils';\nexport * from './formatters';\nexport * from './DateUtils';\nexport * from './FilterUtils';\nexport * from './Formatter';\nexport { default as FormatterUtils } from './FormatterUtils';\nexport * from './FormatterUtils';\nexport * from './MessageUtils';\nexport * from './NewTableColumnTypes';\nexport * from './NoConsolesError';\nexport * from './SessionUtils';\nexport * from './Settings';\nexport * from './TableUtils';\nexport * from './ViewportDataUtils';\nexport * from './WorkerVariablesStore';\n"],"mappings":";;;;;SAKSA,OAAO,IAAIC,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","ignoreList":[]}
|