Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jsapi core module #1075

Closed
wants to merge 10 commits into from
Closed
11 changes: 10 additions & 1 deletion jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import '@testing-library/jest-dom';
import 'jest-canvas-mock';
import './__mocks__/dh-core';
import Log from '@deephaven/log';

jest.mock('@deephaven/jsapi-shim', () => {
return jest.fn().mockImplementation(() => {
return {
Client: {
connect: jest.fn(),
},
};
});
});

let logLevel = parseInt(process.env.DH_LOG_LEVEL ?? '', 10);
if (!Number.isFinite(logLevel)) {
logLevel = -1;
Expand Down
32 changes: 0 additions & 32 deletions packages/code-studio/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,6 @@
<link rel="manifest" href="/manifest.json" />

<link rel="icon" href="#VITE_FAVICON#" />

<!-- The script is currently tightly coupled with the server -->
<script
src="#VITE_CORE_API_URL#/#VITE_OPEN_API_NAME#"
type="text/javascript"
></script>
<script
src="#VITE_CORE_API_URL#/#VITE_CORE_API_NAME#"
type="text/javascript"
></script>
<script>
(function () {
document.addEventListener('DOMContentLoaded', function () {
// If for some reason the API doesn't load, our app will not work. Write out a message to help the user.
if (!window.dh) {
document.getElementById('root').insertAdjacentHTML(
'afterbegin',
`<div class="modal d-block">
<div class="modal-dialog modal-dialog-centered theme-bg-light">
<div class="modal-content">
<div class="modal-body">
<h5 class="modal-title">Error: Unable to load API</h5>
<p class="text-break">Ensure the server is running and you are able to reach #VITE_CORE_API_URL#/#VITE_CORE_API_NAME#, then refresh the page.</p>
</div>
</div>
</div>
</div>`
);
}
});
})();
</script>
<title>Deephaven</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion packages/code-studio/src/storage/grpc/GrpcFileStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
FileStorageTable,
FileUtils,
} from '@deephaven/file-explorer';
import { StorageService } from '@deephaven/jsapi-shim';
import dh, { StorageService } from '@deephaven/jsapi-shim';
import Log from '@deephaven/log';
import GrpcFileStorageTable from './GrpcFileStorageTable';

Expand Down
1 change: 1 addition & 0 deletions packages/code-studio/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default defineConfig(({ mode }) => {
outDir: path.resolve(__dirname, env.VITE_BUILD_PATH),
emptyOutDir: true,
sourcemap: true,
target: 'esnext',
rollupOptions: {
output: {
manualChunks: id => {
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard-core-plugins/src/ChartPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PanelHydrateFunction,
useListener,
} from '@deephaven/dashboard';
import { Figure, VariableDefinition } from '@deephaven/jsapi-shim';
import dh, { Figure, VariableDefinition } from '@deephaven/jsapi-shim';
import shortid from 'shortid';
import { ChartPanel, ChartPanelProps } from './panels';

Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard-core-plugins/src/GridPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useListener,
} from '@deephaven/dashboard';
import { IrisGridModelFactory, IrisGridThemeType } from '@deephaven/iris-grid';
import { Table, VariableDefinition } from '@deephaven/jsapi-shim';
import dh, { Table, VariableDefinition } from '@deephaven/jsapi-shim';
import shortid from 'shortid';
import { IrisGridPanel, IrisGridPanelProps } from './panels';

Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard-core-plugins/src/PandasPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useListener,
} from '@deephaven/dashboard';
import { IrisGridModelFactory } from '@deephaven/iris-grid';
import { Table } from '@deephaven/jsapi-shim';
import dh, { Table } from '@deephaven/jsapi-shim';
import shortid from 'shortid';
import { PandasPanel, PandasPanelProps } from './panels';

Expand Down
1 change: 1 addition & 0 deletions packages/embed-chart/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default defineConfig(({ mode }) => {
outDir: env.VITE_BUILD_PATH,
emptyOutDir: true,
sourcemap: true,
target: 'esnext',
rollupOptions: {
output: {
manualChunks: id => {
Expand Down
1 change: 1 addition & 0 deletions packages/embed-grid/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default defineConfig(({ mode }) => {
outDir: env.VITE_BUILD_PATH,
emptyOutDir: true,
sourcemap: true,
target: 'esnext',
rollupOptions: {
output: {
manualChunks: id => {
Expand Down
2 changes: 1 addition & 1 deletion packages/iris-grid/src/GotoRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
useRef,
useState,
} from 'react';
import { Column } from '@deephaven/jsapi-shim';
import dh, { Column } from '@deephaven/jsapi-shim';
import {
Type as FilterType,
TypeValue as FilterTypeValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, CustomColumn } from '@deephaven/jsapi-shim';
import dh, { Column, CustomColumn } from '@deephaven/jsapi-shim';
import {
BaseFormatConfig,
getConditionDBString,
Expand Down
2 changes: 1 addition & 1 deletion packages/jsapi-components/src/useTable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from 'react';
import { Column, Row, Table } from '@deephaven/jsapi-shim';
import dh, { Column, Row, Table } from '@deephaven/jsapi-shim';
import Log from '@deephaven/log';
import useTableListener from './useTableListener';
import ColumnNameError from './ColumnNameError';
Expand Down
10 changes: 5 additions & 5 deletions packages/jsapi-shim/src/dh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// This include file is simply a wrapper so that it behaves like a module, and can be mocked easily for unit tests
import type dhType from './dh.types';

declare global {
// eslint-disable-next-line vars-on-top,no-var
var dh: dhType;
}
const dhModule = await import(
/* @vite-ignore */
`${import.meta.env.VITE_CORE_API_URL}/${import.meta.env.VITE_CORE_API_NAME}`
);

const { dh } = globalThis;
const dh = dhModule.default as dhType;

export default dh;
20 changes: 10 additions & 10 deletions packages/jsapi-shim/src/dh.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface dh {
storage: {
FileContents: FileContentsStatic;
};
ValueType: ValueTypeStatic;
ValueType: typeof ValueType;
}

const VariableType = {
Expand All @@ -48,16 +48,16 @@ const VariableType = {
PARTITIONEDTABLE: 'PartitionedTable',
} as const;

export interface ValueTypeStatic {
STRING: 'String';
NUMBER: 'Number';
DOUBLE: 'Double';
LONG: 'Long';
DATETIME: 'Datetime';
BOOLEAN: 'Boolean';
}
const ValueType = {
STRING: 'String',
NUMBER: 'Number',
DOUBLE: 'Double',
LONG: 'Long',
DATETIME: 'Datetime',
BOOLEAN: 'Boolean',
} as const;

export type ValueTypeUnion = typeof dh.ValueType[keyof typeof dh.ValueType];
export type ValueTypeUnion = typeof ValueType[keyof typeof ValueType];

export interface CalendarStatic {
DayOfWeek: { values: () => string[] };
Expand Down
1 change: 1 addition & 0 deletions packages/jsapi-shim/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
9 changes: 9 additions & 0 deletions packages/mocks/src/jsapi-shim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Client {
constructor() {}
}

const dh = {
Client,
};

export default dh;